|
|
1.1 ! root 1: /* ! 2: * Copyright(C) 2006 Cameron Rich ! 3: * ! 4: * This library is free software; you can redistribute it and/or modify ! 5: * it under the terms of the GNU Lesser General Public License as published by ! 6: * the Free Software Foundation; either version 2 of the License, or ! 7: * (at your option) any later version. ! 8: * ! 9: * This library is distributed in the hope that it will be useful, ! 10: * but WITHOUT ANY WARRANTY; without even the implied warranty of ! 11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! 12: * GNU Lesser General Public License for more details. ! 13: * ! 14: * You should have received a copy of the GNU Lesser General Public License ! 15: * along with this library; if not, write to the Free Software ! 16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ! 17: */ ! 18: ! 19: FILE_LICENCE ( GPL2_OR_LATER ); ! 20: ! 21: #ifndef BIGINT_HEADER ! 22: #define BIGINT_HEADER ! 23: ! 24: /* enable features based on a 'super-set' capbaility. */ ! 25: #if defined(CONFIG_SSL_FULL_MODE) ! 26: #define CONFIG_SSL_ENABLE_CLIENT ! 27: #define CONFIG_SSL_CERT_VERIFICATION ! 28: #elif defined(CONFIG_SSL_ENABLE_CLIENT) ! 29: #define CONFIG_SSL_CERT_VERIFICATION ! 30: #endif ! 31: ! 32: #include "os_port.h" ! 33: #include "bigint_impl.h" ! 34: ! 35: #ifndef CONFIG_BIGINT_CHECK_ON ! 36: #define check(A) /**< disappears in normal production mode */ ! 37: #endif ! 38: BI_CTX *bi_initialize(void); ! 39: void bi_terminate(BI_CTX *ctx); ! 40: void bi_permanent(bigint *bi); ! 41: void bi_depermanent(bigint *bi); ! 42: void bi_free(BI_CTX *ctx, bigint *bi); ! 43: bigint *bi_copy(bigint *bi); ! 44: bigint *bi_clone(BI_CTX *ctx, const bigint *bi); ! 45: void bi_export(BI_CTX *ctx, bigint *bi, uint8_t *data, int size); ! 46: bigint *bi_import(BI_CTX *ctx, const uint8_t *data, int len); ! 47: bigint *int_to_bi(BI_CTX *ctx, comp i); ! 48: ! 49: /* the functions that actually do something interesting */ ! 50: bigint *bi_add(BI_CTX *ctx, bigint *bia, bigint *bib); ! 51: bigint *bi_subtract(BI_CTX *ctx, bigint *bia, ! 52: bigint *bib, int *is_negative); ! 53: bigint *bi_divide(BI_CTX *ctx, bigint *bia, bigint *bim, int is_mod); ! 54: bigint *bi_multiply(BI_CTX *ctx, bigint *bia, bigint *bib); ! 55: bigint *bi_mod_power(BI_CTX *ctx, bigint *bi, bigint *biexp); ! 56: bigint *bi_mod_power2(BI_CTX *ctx, bigint *bi, bigint *bim, bigint *biexp); ! 57: int bi_compare(bigint *bia, bigint *bib); ! 58: void bi_set_mod(BI_CTX *ctx, bigint *bim, int mod_offset); ! 59: void bi_free_mod(BI_CTX *ctx, int mod_offset); ! 60: ! 61: #ifdef CONFIG_SSL_FULL_MODE ! 62: void bi_print(const char *label, bigint *bi); ! 63: bigint *bi_str_import(BI_CTX *ctx, const char *data); ! 64: #endif ! 65: ! 66: /** ! 67: * @def bi_mod ! 68: * Find the residue of B. bi_set_mod() must be called before hand. ! 69: */ ! 70: #define bi_mod(A, B) bi_divide(A, B, ctx->bi_mod[ctx->mod_offset], 1) ! 71: ! 72: /** ! 73: * bi_residue() is technically the same as bi_mod(), but it uses the ! 74: * appropriate reduction technique (which is bi_mod() when doing classical ! 75: * reduction). ! 76: */ ! 77: #if defined(CONFIG_BIGINT_MONTGOMERY) ! 78: #define bi_residue(A, B) bi_mont(A, B) ! 79: bigint *bi_mont(BI_CTX *ctx, bigint *bixy); ! 80: #elif defined(CONFIG_BIGINT_BARRETT) ! 81: #define bi_residue(A, B) bi_barrett(A, B) ! 82: bigint *bi_barrett(BI_CTX *ctx, bigint *bi); ! 83: #else /* if defined(CONFIG_BIGINT_CLASSICAL) */ ! 84: #define bi_residue(A, B) bi_mod(A, B) ! 85: #endif ! 86: ! 87: #ifdef CONFIG_BIGINT_SQUARE ! 88: bigint *bi_square(BI_CTX *ctx, bigint *bi); ! 89: #else ! 90: #define bi_square(A, B) bi_multiply(A, bi_copy(B), B) ! 91: #endif ! 92: ! 93: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.