bigint.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright(C) 2006 Cameron Rich
00003  *
00004  *  This library is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with this library; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 
00019 #ifndef BIGINT_HEADER
00020 #define BIGINT_HEADER
00021 
00022 /* enable features based on a 'super-set' capbaility. */
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)                /**< disappears in normal production mode */
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 /* the functions that actually do something interesting */
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  * @def bi_mod
00066  * Find the residue of B. bi_set_mod() must be called before hand.
00067  */
00068 #define bi_mod(A, B)      bi_divide(A, B, ctx->bi_mod[ctx->mod_offset], 1)
00069 
00070 /**
00071  * bi_residue() is technically the same as bi_mod(), but it uses the
00072  * appropriate reduction technique (which is bi_mod() when doing classical
00073  * reduction).
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 /* if defined(CONFIG_BIGINT_CLASSICAL) */
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

Generated on Tue Apr 6 20:00:52 2010 for gPXE by  doxygen 1.5.7.1