00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef BIGINT_HEADER
00020 #define BIGINT_HEADER
00021
00022
00023 #if defined(CONFIG_SSL_FULL_MODE)
00024 #define CONFIG_SSL_ENABLE_CLIENT
00025 #define CONFIG_SSL_CERT_VERIFICATION
00026 #elif defined(CONFIG_SSL_ENABLE_CLIENT)
00027 #define CONFIG_SSL_CERT_VERIFICATION
00028 #endif
00029
00030 #include "os_port.h"
00031 #include "bigint_impl.h"
00032
00033 #ifndef CONFIG_BIGINT_CHECK_ON
00034 #define check(A)
00035 #endif
00036 BI_CTX *bi_initialize(void);
00037 void bi_terminate(BI_CTX *ctx);
00038 void bi_permanent(bigint *bi);
00039 void bi_depermanent(bigint *bi);
00040 void bi_free(BI_CTX *ctx, bigint *bi);
00041 bigint *bi_copy(bigint *bi);
00042 bigint *bi_clone(BI_CTX *ctx, const bigint *bi);
00043 void bi_export(BI_CTX *ctx, bigint *bi, uint8_t *data, int size);
00044 bigint *bi_import(BI_CTX *ctx, const uint8_t *data, int len);
00045 bigint *int_to_bi(BI_CTX *ctx, comp i);
00046
00047
00048 bigint *bi_add(BI_CTX *ctx, bigint *bia, bigint *bib);
00049 bigint *bi_subtract(BI_CTX *ctx, bigint *bia,
00050 bigint *bib, int *is_negative);
00051 bigint *bi_divide(BI_CTX *ctx, bigint *bia, bigint *bim, int is_mod);
00052 bigint *bi_multiply(BI_CTX *ctx, bigint *bia, bigint *bib);
00053 bigint *bi_mod_power(BI_CTX *ctx, bigint *bi, bigint *biexp);
00054 bigint *bi_mod_power2(BI_CTX *ctx, bigint *bi, bigint *bim, bigint *biexp);
00055 int bi_compare(bigint *bia, bigint *bib);
00056 void bi_set_mod(BI_CTX *ctx, bigint *bim, int mod_offset);
00057 void bi_free_mod(BI_CTX *ctx, int mod_offset);
00058
00059 #ifdef CONFIG_SSL_FULL_MODE
00060 void bi_print(const char *label, bigint *bi);
00061 bigint *bi_str_import(BI_CTX *ctx, const char *data);
00062 #endif
00063
00064
00065
00066
00067
00068 #define bi_mod(A, B) bi_divide(A, B, ctx->bi_mod[ctx->mod_offset], 1)
00069
00070
00071
00072
00073
00074
00075 #if defined(CONFIG_BIGINT_MONTGOMERY)
00076 #define bi_residue(A, B) bi_mont(A, B)
00077 bigint *bi_mont(BI_CTX *ctx, bigint *bixy);
00078 #elif defined(CONFIG_BIGINT_BARRETT)
00079 #define bi_residue(A, B) bi_barrett(A, B)
00080 bigint *bi_barrett(BI_CTX *ctx, bigint *bi);
00081 #else
00082 #define bi_residue(A, B) bi_mod(A, B)
00083 #endif
00084
00085 #ifdef CONFIG_BIGINT_SQUARE
00086 bigint *bi_square(BI_CTX *ctx, bigint *bi);
00087 #else
00088 #define bi_square(A, B) bi_multiply(A, bi_copy(B), B)
00089 #endif
00090
00091 #endif