This is a fork of the mbed port of axTLS
Dependents: TLS_axTLS-Example HTTPSClientExample
bigint.h
00001 /* 00002 * Copyright (c) 2007, Cameron Rich 00003 * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * * Redistributions of source code must retain the above copyright notice, 00010 * this list of conditions and the following disclaimer. 00011 * * Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * * Neither the name of the axTLS project nor the names of its contributors 00015 * may be used to endorse or promote products derived from this software 00016 * without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00021 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00022 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00024 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00025 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00026 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00027 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00031 #ifndef BIGINT_HEADER 00032 #define BIGINT_HEADER 00033 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif 00037 00038 #include "crypto.h " 00039 00040 BI_CTX *bi_initialize(void); 00041 void bi_terminate(BI_CTX *ctx); 00042 void bi_permanent(bigint *bi); 00043 void bi_depermanent(bigint *bi); 00044 void bi_clear_cache(BI_CTX *ctx); 00045 void bi_free(BI_CTX *ctx, bigint *bi); 00046 bigint *bi_copy(bigint *bi); 00047 bigint *bi_clone(BI_CTX *ctx, const bigint *bi); 00048 void bi_export(BI_CTX *ctx, bigint *bi, uint8_t *data, int size); 00049 bigint *bi_import(BI_CTX *ctx, const uint8_t *data, int len); 00050 bigint *int_to_bi(BI_CTX *ctx, comp i); 00051 00052 /* the functions that actually do something interesting */ 00053 bigint *bi_add(BI_CTX *ctx, bigint *bia, bigint *bib); 00054 bigint *bi_subtract(BI_CTX *ctx, bigint *bia, 00055 bigint *bib, int *is_negative); 00056 bigint *bi_divide(BI_CTX *ctx, bigint *bia, bigint *bim, int is_mod); 00057 bigint *bi_multiply(BI_CTX *ctx, bigint *bia, bigint *bib); 00058 bigint *bi_mod_power(BI_CTX *ctx, bigint *bi, bigint *biexp); 00059 bigint *bi_mod_power2(BI_CTX *ctx, bigint *bi, bigint *bim, bigint *biexp); 00060 int bi_compare(bigint *bia, bigint *bib); 00061 void bi_set_mod(BI_CTX *ctx, bigint *bim, int mod_offset); 00062 void bi_free_mod(BI_CTX *ctx, int mod_offset); 00063 00064 //#ifdef CONFIG_SSL_FULL_MODE 00065 void bi_print(const char *label, bigint *bi); 00066 bigint *bi_str_import(BI_CTX *ctx, const char *data); 00067 //#endif 00068 00069 /** 00070 * @def bi_mod 00071 * Find the residue of B. bi_set_mod() must be called before hand. 00072 */ 00073 #define bi_mod(A, B) bi_divide(A, B, ctx->bi_mod[ctx->mod_offset], 1) 00074 00075 /** 00076 * bi_residue() is technically the same as bi_mod(), but it uses the 00077 * appropriate reduction technique (which is bi_mod() when doing classical 00078 * reduction). 00079 */ 00080 #if defined(CONFIG_BIGINT_MONTGOMERY) 00081 #define bi_residue(A, B) bi_mont(A, B) 00082 bigint *bi_mont(BI_CTX *ctx, bigint *bixy); 00083 #elif defined(CONFIG_BIGINT_BARRETT) 00084 #define bi_residue(A, B) bi_barrett(A, B) 00085 bigint *bi_barrett(BI_CTX *ctx, bigint *bi); 00086 #else /* if defined(CONFIG_BIGINT_CLASSICAL) */ 00087 #define bi_residue(A, B) bi_mod(A, B) 00088 #endif 00089 00090 #ifdef CONFIG_BIGINT_SQUARE 00091 bigint *bi_square(BI_CTX *ctx, bigint *bi); 00092 #else 00093 #define bi_square(A, B) bi_multiply(A, bi_copy(B), B) 00094 #endif 00095 00096 #ifdef CONFIG_BIGINT_CRT 00097 bigint *bi_crt(BI_CTX *ctx, bigint *bi, 00098 bigint *dP, bigint *dQ, 00099 bigint *p, bigint *q, 00100 bigint *qInv); 00101 #endif 00102 00103 #ifdef __cplusplus 00104 } 00105 #endif 00106 00107 #endif 00108 00109
Generated on Wed Jul 13 2022 19:30:07 by 1.7.2