wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Tue May 02 08:44:47 2017 +0000
Revision:
7:481bce714567
wolfSSL3.10.2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 7:481bce714567 1 /* integer.h
wolfSSL 7:481bce714567 2 *
wolfSSL 7:481bce714567 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 7:481bce714567 4 *
wolfSSL 7:481bce714567 5 * This file is part of wolfSSL.
wolfSSL 7:481bce714567 6 *
wolfSSL 7:481bce714567 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 7:481bce714567 8 * it under the terms of the GNU General Public License as published by
wolfSSL 7:481bce714567 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 7:481bce714567 10 * (at your option) any later version.
wolfSSL 7:481bce714567 11 *
wolfSSL 7:481bce714567 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 7:481bce714567 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 7:481bce714567 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 7:481bce714567 15 * GNU General Public License for more details.
wolfSSL 7:481bce714567 16 *
wolfSSL 7:481bce714567 17 * You should have received a copy of the GNU General Public License
wolfSSL 7:481bce714567 18 * along with this program; if not, write to the Free Software
wolfSSL 7:481bce714567 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 7:481bce714567 20 */
wolfSSL 7:481bce714567 21
wolfSSL 7:481bce714567 22
wolfSSL 7:481bce714567 23 /*
wolfSSL 7:481bce714567 24 * Based on public domain LibTomMath 0.38 by Tom St Denis, tomstdenis@iahu.ca,
wolfSSL 7:481bce714567 25 * http://math.libtomcrypt.com
wolfSSL 7:481bce714567 26 */
wolfSSL 7:481bce714567 27
wolfSSL 7:481bce714567 28
wolfSSL 7:481bce714567 29 #ifndef WOLF_CRYPT_INTEGER_H
wolfSSL 7:481bce714567 30 #define WOLF_CRYPT_INTEGER_H
wolfSSL 7:481bce714567 31
wolfSSL 7:481bce714567 32 /* may optionally use fast math instead, not yet supported on all platforms and
wolfSSL 7:481bce714567 33 may not be faster on all
wolfSSL 7:481bce714567 34 */
wolfSSL 7:481bce714567 35 #include <wolfssl/wolfcrypt/types.h> /* will set MP_xxBIT if not default */
wolfSSL 7:481bce714567 36 #ifdef USE_FAST_MATH
wolfSSL 7:481bce714567 37 #include <wolfssl/wolfcrypt/tfm.h>
wolfSSL 7:481bce714567 38 #else
wolfSSL 7:481bce714567 39
wolfSSL 7:481bce714567 40 #include <wolfssl/wolfcrypt/random.h>
wolfSSL 7:481bce714567 41
wolfSSL 7:481bce714567 42 #ifndef CHAR_BIT
wolfSSL 7:481bce714567 43 #include <limits.h>
wolfSSL 7:481bce714567 44 #endif
wolfSSL 7:481bce714567 45
wolfSSL 7:481bce714567 46 #include <wolfssl/wolfcrypt/mpi_class.h>
wolfSSL 7:481bce714567 47
wolfSSL 7:481bce714567 48 #ifndef MIN
wolfSSL 7:481bce714567 49 #define MIN(x,y) ((x)<(y)?(x):(y))
wolfSSL 7:481bce714567 50 #endif
wolfSSL 7:481bce714567 51
wolfSSL 7:481bce714567 52 #ifndef MAX
wolfSSL 7:481bce714567 53 #define MAX(x,y) ((x)>(y)?(x):(y))
wolfSSL 7:481bce714567 54 #endif
wolfSSL 7:481bce714567 55
wolfSSL 7:481bce714567 56 #ifdef __cplusplus
wolfSSL 7:481bce714567 57 extern "C" {
wolfSSL 7:481bce714567 58
wolfSSL 7:481bce714567 59 /* C++ compilers don't like assigning void * to mp_digit * */
wolfSSL 7:481bce714567 60 #define OPT_CAST(x) (x *)
wolfSSL 7:481bce714567 61
wolfSSL 7:481bce714567 62 #else
wolfSSL 7:481bce714567 63
wolfSSL 7:481bce714567 64 /* C on the other hand doesn't care */
wolfSSL 7:481bce714567 65 #define OPT_CAST(x)
wolfSSL 7:481bce714567 66
wolfSSL 7:481bce714567 67 #endif /* __cplusplus */
wolfSSL 7:481bce714567 68
wolfSSL 7:481bce714567 69
wolfSSL 7:481bce714567 70 /* detect 64-bit mode if possible */
wolfSSL 7:481bce714567 71 #if defined(__x86_64__)
wolfSSL 7:481bce714567 72 #if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
wolfSSL 7:481bce714567 73 #define MP_64BIT
wolfSSL 7:481bce714567 74 #endif
wolfSSL 7:481bce714567 75 #endif
wolfSSL 7:481bce714567 76 /* if intel compiler doesn't provide 128 bit type don't turn on 64bit */
wolfSSL 7:481bce714567 77 #if defined(MP_64BIT) && defined(__INTEL_COMPILER) && !defined(HAVE___UINT128_T)
wolfSSL 7:481bce714567 78 #undef MP_64BIT
wolfSSL 7:481bce714567 79 #endif
wolfSSL 7:481bce714567 80
wolfSSL 7:481bce714567 81
wolfSSL 7:481bce714567 82 /* allow user to define on mp_digit, mp_word, DIGIT_BIT types */
wolfSSL 7:481bce714567 83 #ifndef WOLFSSL_BIGINT_TYPES
wolfSSL 7:481bce714567 84
wolfSSL 7:481bce714567 85 /* some default configurations.
wolfSSL 7:481bce714567 86 *
wolfSSL 7:481bce714567 87 * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
wolfSSL 7:481bce714567 88 * A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
wolfSSL 7:481bce714567 89 *
wolfSSL 7:481bce714567 90 * At the very least a mp_digit must be able to hold 7 bits
wolfSSL 7:481bce714567 91 * [any size beyond that is ok provided it doesn't overflow the data type]
wolfSSL 7:481bce714567 92 */
wolfSSL 7:481bce714567 93 #ifdef MP_8BIT
wolfSSL 7:481bce714567 94 typedef unsigned char mp_digit;
wolfSSL 7:481bce714567 95 typedef unsigned short mp_word;
wolfSSL 7:481bce714567 96 #elif defined(MP_16BIT) || defined(NO_64BIT)
wolfSSL 7:481bce714567 97 typedef unsigned short mp_digit;
wolfSSL 7:481bce714567 98 typedef unsigned int mp_word;
wolfSSL 7:481bce714567 99 #define DIGIT_BIT 12
wolfSSL 7:481bce714567 100 #elif defined(MP_64BIT)
wolfSSL 7:481bce714567 101 /* for GCC only on supported platforms */
wolfSSL 7:481bce714567 102 typedef unsigned long long mp_digit; /* 64 bit type, 128 uses mode(TI) */
wolfSSL 7:481bce714567 103 typedef unsigned long mp_word __attribute__ ((mode(TI)));
wolfSSL 7:481bce714567 104
wolfSSL 7:481bce714567 105 #define DIGIT_BIT 60
wolfSSL 7:481bce714567 106 #else
wolfSSL 7:481bce714567 107 /* this is the default case, 28-bit digits */
wolfSSL 7:481bce714567 108
wolfSSL 7:481bce714567 109 #if defined(_MSC_VER) || defined(__BORLANDC__)
wolfSSL 7:481bce714567 110 typedef unsigned __int64 ulong64;
wolfSSL 7:481bce714567 111 #else
wolfSSL 7:481bce714567 112 typedef unsigned long long ulong64;
wolfSSL 7:481bce714567 113 #endif
wolfSSL 7:481bce714567 114
wolfSSL 7:481bce714567 115 typedef unsigned int mp_digit; /* long could be 64 now, changed TAO */
wolfSSL 7:481bce714567 116 typedef ulong64 mp_word;
wolfSSL 7:481bce714567 117
wolfSSL 7:481bce714567 118 #ifdef MP_31BIT
wolfSSL 7:481bce714567 119 /* this is an extension that uses 31-bit digits */
wolfSSL 7:481bce714567 120 #define DIGIT_BIT 31
wolfSSL 7:481bce714567 121 #else
wolfSSL 7:481bce714567 122 /* default case is 28-bit digits, defines MP_28BIT as a handy test macro */
wolfSSL 7:481bce714567 123 #define DIGIT_BIT 28
wolfSSL 7:481bce714567 124 #define MP_28BIT
wolfSSL 7:481bce714567 125 #endif
wolfSSL 7:481bce714567 126 #endif
wolfSSL 7:481bce714567 127
wolfSSL 7:481bce714567 128 #endif /* WOLFSSL_BIGINT_TYPES */
wolfSSL 7:481bce714567 129
wolfSSL 7:481bce714567 130 /* otherwise the bits per digit is calculated automatically from the size of
wolfSSL 7:481bce714567 131 a mp_digit */
wolfSSL 7:481bce714567 132 #ifndef DIGIT_BIT
wolfSSL 7:481bce714567 133 #define DIGIT_BIT ((int)((CHAR_BIT * sizeof(mp_digit) - 1)))
wolfSSL 7:481bce714567 134 /* bits per digit */
wolfSSL 7:481bce714567 135 #endif
wolfSSL 7:481bce714567 136
wolfSSL 7:481bce714567 137 #define MP_DIGIT_BIT DIGIT_BIT
wolfSSL 7:481bce714567 138 #define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
wolfSSL 7:481bce714567 139 #define MP_DIGIT_MAX MP_MASK
wolfSSL 7:481bce714567 140
wolfSSL 7:481bce714567 141 /* equalities */
wolfSSL 7:481bce714567 142 #define MP_LT -1 /* less than */
wolfSSL 7:481bce714567 143 #define MP_EQ 0 /* equal to */
wolfSSL 7:481bce714567 144 #define MP_GT 1 /* greater than */
wolfSSL 7:481bce714567 145
wolfSSL 7:481bce714567 146 #define MP_ZPOS 0 /* positive integer */
wolfSSL 7:481bce714567 147 #define MP_NEG 1 /* negative */
wolfSSL 7:481bce714567 148
wolfSSL 7:481bce714567 149 #define MP_OKAY 0 /* ok result */
wolfSSL 7:481bce714567 150 #define MP_MEM -2 /* out of mem */
wolfSSL 7:481bce714567 151 #define MP_VAL -3 /* invalid input */
wolfSSL 7:481bce714567 152 #define MP_NOT_INF -4 /* point not at infinity */
wolfSSL 7:481bce714567 153 #define MP_RANGE MP_NOT_INF
wolfSSL 7:481bce714567 154
wolfSSL 7:481bce714567 155 #define MP_YES 1 /* yes response */
wolfSSL 7:481bce714567 156 #define MP_NO 0 /* no response */
wolfSSL 7:481bce714567 157
wolfSSL 7:481bce714567 158 /* Primality generation flags */
wolfSSL 7:481bce714567 159 #define LTM_PRIME_BBS 0x0001 /* BBS style prime */
wolfSSL 7:481bce714567 160 #define LTM_PRIME_SAFE 0x0002 /* Safe prime (p-1)/2 == prime */
wolfSSL 7:481bce714567 161 #define LTM_PRIME_2MSB_ON 0x0008 /* force 2nd MSB to 1 */
wolfSSL 7:481bce714567 162
wolfSSL 7:481bce714567 163 typedef int mp_err;
wolfSSL 7:481bce714567 164
wolfSSL 7:481bce714567 165 /* define this to use lower memory usage routines (exptmods mostly) */
wolfSSL 7:481bce714567 166 #define MP_LOW_MEM
wolfSSL 7:481bce714567 167
wolfSSL 7:481bce714567 168 /* default precision */
wolfSSL 7:481bce714567 169 #ifndef MP_PREC
wolfSSL 7:481bce714567 170 #ifndef MP_LOW_MEM
wolfSSL 7:481bce714567 171 #define MP_PREC 32 /* default digits of precision */
wolfSSL 7:481bce714567 172 #else
wolfSSL 7:481bce714567 173 #define MP_PREC 1 /* default digits of precision */
wolfSSL 7:481bce714567 174 #endif
wolfSSL 7:481bce714567 175 #endif
wolfSSL 7:481bce714567 176
wolfSSL 7:481bce714567 177 /* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD -
wolfSSL 7:481bce714567 178 BITS_PER_DIGIT*2) */
wolfSSL 7:481bce714567 179 #define MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
wolfSSL 7:481bce714567 180
wolfSSL 7:481bce714567 181 /* the infamous mp_int structure */
wolfSSL 7:481bce714567 182 typedef struct mp_int {
wolfSSL 7:481bce714567 183 int used, alloc, sign;
wolfSSL 7:481bce714567 184 mp_digit *dp;
wolfSSL 7:481bce714567 185 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 7:481bce714567 186 byte* dpraw; /* Used for hardware crypto */
wolfSSL 7:481bce714567 187 #endif
wolfSSL 7:481bce714567 188 } mp_int;
wolfSSL 7:481bce714567 189
wolfSSL 7:481bce714567 190 /* callback for mp_prime_random, should fill dst with random bytes and return
wolfSSL 7:481bce714567 191 how many read [up to len] */
wolfSSL 7:481bce714567 192 typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
wolfSSL 7:481bce714567 193
wolfSSL 7:481bce714567 194
wolfSSL 7:481bce714567 195 #define USED(m) ((m)->used)
wolfSSL 7:481bce714567 196 #define DIGIT(m,k) ((m)->dp[(k)])
wolfSSL 7:481bce714567 197 #define SIGN(m) ((m)->sign)
wolfSSL 7:481bce714567 198
wolfSSL 7:481bce714567 199
wolfSSL 7:481bce714567 200 /* ---> Basic Manipulations <--- */
wolfSSL 7:481bce714567 201 #define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
wolfSSL 7:481bce714567 202 #define mp_isone(a) \
wolfSSL 7:481bce714567 203 (((((a)->used == 1)) && ((a)->dp[0] == 1u)) ? MP_YES : MP_NO)
wolfSSL 7:481bce714567 204 #define mp_iseven(a) \
wolfSSL 7:481bce714567 205 (((a)->used > 0 && (((a)->dp[0] & 1u) == 0u)) ? MP_YES : MP_NO)
wolfSSL 7:481bce714567 206 #define mp_isodd(a) \
wolfSSL 7:481bce714567 207 (((a)->used > 0 && (((a)->dp[0] & 1u) == 1u)) ? MP_YES : MP_NO)
wolfSSL 7:481bce714567 208 #define mp_isneg(a) (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
wolfSSL 7:481bce714567 209
wolfSSL 7:481bce714567 210 /* number of primes */
wolfSSL 7:481bce714567 211 #ifdef MP_8BIT
wolfSSL 7:481bce714567 212 #define PRIME_SIZE 31
wolfSSL 7:481bce714567 213 #else
wolfSSL 7:481bce714567 214 #define PRIME_SIZE 256
wolfSSL 7:481bce714567 215 #endif
wolfSSL 7:481bce714567 216
wolfSSL 7:481bce714567 217 #define mp_prime_random(a, t, size, bbs, cb, dat) \
wolfSSL 7:481bce714567 218 mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat)
wolfSSL 7:481bce714567 219
wolfSSL 7:481bce714567 220 #define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
wolfSSL 7:481bce714567 221 #define mp_raw_size(mp) mp_signed_bin_size(mp)
wolfSSL 7:481bce714567 222 #define mp_toraw(mp, str) mp_to_signed_bin((mp), (str))
wolfSSL 7:481bce714567 223 #define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
wolfSSL 7:481bce714567 224 #define mp_mag_size(mp) mp_unsigned_bin_size(mp)
wolfSSL 7:481bce714567 225 #define mp_tomag(mp, str) mp_to_unsigned_bin((mp), (str))
wolfSSL 7:481bce714567 226
wolfSSL 7:481bce714567 227 #define mp_tobinary(M, S) mp_toradix((M), (S), 2)
wolfSSL 7:481bce714567 228 #define mp_tooctal(M, S) mp_toradix((M), (S), 8)
wolfSSL 7:481bce714567 229 #define mp_todecimal(M, S) mp_toradix((M), (S), 10)
wolfSSL 7:481bce714567 230 #define mp_tohex(M, S) mp_toradix((M), (S), 16)
wolfSSL 7:481bce714567 231
wolfSSL 7:481bce714567 232 #define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
wolfSSL 7:481bce714567 233
wolfSSL 7:481bce714567 234 extern const char *mp_s_rmap;
wolfSSL 7:481bce714567 235
wolfSSL 7:481bce714567 236 /* 6 functions needed by Rsa */
wolfSSL 7:481bce714567 237 int mp_init (mp_int * a);
wolfSSL 7:481bce714567 238 void mp_clear (mp_int * a);
wolfSSL 7:481bce714567 239 void mp_forcezero(mp_int * a);
wolfSSL 7:481bce714567 240 int mp_unsigned_bin_size(mp_int * a);
wolfSSL 7:481bce714567 241 int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c);
wolfSSL 7:481bce714567 242 int mp_to_unsigned_bin_at_pos(int x, mp_int *t, unsigned char *b);
wolfSSL 7:481bce714567 243 int mp_to_unsigned_bin (mp_int * a, unsigned char *b);
wolfSSL 7:481bce714567 244 int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y);
wolfSSL 7:481bce714567 245 /* end functions needed by Rsa */
wolfSSL 7:481bce714567 246
wolfSSL 7:481bce714567 247 /* functions added to support above needed, removed TOOM and KARATSUBA */
wolfSSL 7:481bce714567 248 int mp_count_bits (mp_int * a);
wolfSSL 7:481bce714567 249 int mp_leading_bit (mp_int * a);
wolfSSL 7:481bce714567 250 int mp_init_copy (mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 251 int mp_copy (mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 252 int mp_grow (mp_int * a, int size);
wolfSSL 7:481bce714567 253 int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d);
wolfSSL 7:481bce714567 254 void mp_zero (mp_int * a);
wolfSSL 7:481bce714567 255 void mp_clamp (mp_int * a);
wolfSSL 7:481bce714567 256 void mp_exch (mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 257 void mp_rshd (mp_int * a, int b);
wolfSSL 7:481bce714567 258 void mp_rshb (mp_int * a, int b);
wolfSSL 7:481bce714567 259 int mp_mod_2d (mp_int * a, int b, mp_int * c);
wolfSSL 7:481bce714567 260 int mp_mul_2d (mp_int * a, int b, mp_int * c);
wolfSSL 7:481bce714567 261 int mp_lshd (mp_int * a, int b);
wolfSSL 7:481bce714567 262 int mp_abs (mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 263 int mp_invmod (mp_int * a, mp_int * b, mp_int * c);
wolfSSL 7:481bce714567 264 int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c);
wolfSSL 7:481bce714567 265 int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
wolfSSL 7:481bce714567 266 int mp_cmp_mag (mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 267 int mp_cmp (mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 268 int mp_cmp_d(mp_int * a, mp_digit b);
wolfSSL 7:481bce714567 269 int mp_set (mp_int * a, mp_digit b);
wolfSSL 7:481bce714567 270 int mp_is_bit_set (mp_int * a, mp_digit b);
wolfSSL 7:481bce714567 271 int mp_mod (mp_int * a, mp_int * b, mp_int * c);
wolfSSL 7:481bce714567 272 int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d);
wolfSSL 7:481bce714567 273 int mp_div_2(mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 274 int mp_add (mp_int * a, mp_int * b, mp_int * c);
wolfSSL 7:481bce714567 275 int s_mp_add (mp_int * a, mp_int * b, mp_int * c);
wolfSSL 7:481bce714567 276 int s_mp_sub (mp_int * a, mp_int * b, mp_int * c);
wolfSSL 7:481bce714567 277 int mp_sub (mp_int * a, mp_int * b, mp_int * c);
wolfSSL 7:481bce714567 278 int mp_reduce_is_2k_l(mp_int *a);
wolfSSL 7:481bce714567 279 int mp_reduce_is_2k(mp_int *a);
wolfSSL 7:481bce714567 280 int mp_dr_is_modulus(mp_int *a);
wolfSSL 7:481bce714567 281 int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int);
wolfSSL 7:481bce714567 282 int mp_montgomery_setup (mp_int * n, mp_digit * rho);
wolfSSL 7:481bce714567 283 int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho);
wolfSSL 7:481bce714567 284 int mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho);
wolfSSL 7:481bce714567 285 void mp_dr_setup(mp_int *a, mp_digit *d);
wolfSSL 7:481bce714567 286 int mp_dr_reduce (mp_int * x, mp_int * n, mp_digit k);
wolfSSL 7:481bce714567 287 int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
wolfSSL 7:481bce714567 288 int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
wolfSSL 7:481bce714567 289 int s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
wolfSSL 7:481bce714567 290 int mp_reduce_2k_setup_l(mp_int *a, mp_int *d);
wolfSSL 7:481bce714567 291 int mp_reduce_2k_l(mp_int *a, mp_int *n, mp_int *d);
wolfSSL 7:481bce714567 292 int mp_reduce (mp_int * x, mp_int * m, mp_int * mu);
wolfSSL 7:481bce714567 293 int mp_reduce_setup (mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 294 int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode);
wolfSSL 7:481bce714567 295 int mp_montgomery_calc_normalization (mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 296 int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
wolfSSL 7:481bce714567 297 int s_mp_sqr (mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 298 int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs);
wolfSSL 7:481bce714567 299 int fast_s_mp_sqr (mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 300 int mp_init_size (mp_int * a, int size);
wolfSSL 7:481bce714567 301 int mp_div_3 (mp_int * a, mp_int *c, mp_digit * d);
wolfSSL 7:481bce714567 302 int mp_mul_2(mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 303 int mp_mul (mp_int * a, mp_int * b, mp_int * c);
wolfSSL 7:481bce714567 304 int mp_sqr (mp_int * a, mp_int * b);
wolfSSL 7:481bce714567 305 int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d);
wolfSSL 7:481bce714567 306 int mp_submod (mp_int* a, mp_int* b, mp_int* c, mp_int* d);
wolfSSL 7:481bce714567 307 int mp_addmod (mp_int* a, mp_int* b, mp_int* c, mp_int* d);
wolfSSL 7:481bce714567 308 int mp_mul_d (mp_int * a, mp_digit b, mp_int * c);
wolfSSL 7:481bce714567 309 int mp_2expt (mp_int * a, int b);
wolfSSL 7:481bce714567 310 int mp_set_bit (mp_int * a, int b);
wolfSSL 7:481bce714567 311 int mp_reduce_2k_setup(mp_int *a, mp_digit *d);
wolfSSL 7:481bce714567 312 int mp_add_d (mp_int* a, mp_digit b, mp_int* c);
wolfSSL 7:481bce714567 313 int mp_set_int (mp_int * a, unsigned long b);
wolfSSL 7:481bce714567 314 int mp_sub_d (mp_int * a, mp_digit b, mp_int * c);
wolfSSL 7:481bce714567 315 /* end support added functions */
wolfSSL 7:481bce714567 316
wolfSSL 7:481bce714567 317 /* added */
wolfSSL 7:481bce714567 318 int mp_init_multi(mp_int* a, mp_int* b, mp_int* c, mp_int* d, mp_int* e,
wolfSSL 7:481bce714567 319 mp_int* f);
wolfSSL 7:481bce714567 320 int mp_toradix (mp_int *a, char *str, int radix);
wolfSSL 7:481bce714567 321 int mp_radix_size (mp_int * a, int radix, int *size);
wolfSSL 7:481bce714567 322
wolfSSL 7:481bce714567 323 #ifdef WOLFSSL_DEBUG_MATH
wolfSSL 7:481bce714567 324 void mp_dump(const char* desc, mp_int* a, byte verbose);
wolfSSL 7:481bce714567 325 #else
wolfSSL 7:481bce714567 326 #define mp_dump(desc, a, verbose)
wolfSSL 7:481bce714567 327 #endif
wolfSSL 7:481bce714567 328
wolfSSL 7:481bce714567 329 #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
wolfSSL 7:481bce714567 330 int mp_sqrmod(mp_int* a, mp_int* b, mp_int* c);
wolfSSL 7:481bce714567 331 #endif
wolfSSL 7:481bce714567 332 #if defined(HAVE_ECC) || defined(WOLFSSL_KEY_GEN)
wolfSSL 7:481bce714567 333 int mp_read_radix(mp_int* a, const char* str, int radix);
wolfSSL 7:481bce714567 334 #endif
wolfSSL 7:481bce714567 335
wolfSSL 7:481bce714567 336 #ifdef WOLFSSL_KEY_GEN
wolfSSL 7:481bce714567 337 int mp_prime_is_prime (mp_int * a, int t, int *result);
wolfSSL 7:481bce714567 338 int mp_gcd (mp_int * a, mp_int * b, mp_int * c);
wolfSSL 7:481bce714567 339 int mp_lcm (mp_int * a, mp_int * b, mp_int * c);
wolfSSL 7:481bce714567 340 int mp_rand_prime(mp_int* N, int len, WC_RNG* rng, void* heap);
wolfSSL 7:481bce714567 341 #endif
wolfSSL 7:481bce714567 342
wolfSSL 7:481bce714567 343 int mp_cnt_lsb(mp_int *a);
wolfSSL 7:481bce714567 344 int mp_mod_d(mp_int* a, mp_digit b, mp_digit* c);
wolfSSL 7:481bce714567 345
wolfSSL 7:481bce714567 346
wolfSSL 7:481bce714567 347 /* wolf big int and common functions */
wolfSSL 7:481bce714567 348 #include <wolfssl/wolfcrypt/wolfmath.h>
wolfSSL 7:481bce714567 349
wolfSSL 7:481bce714567 350
wolfSSL 7:481bce714567 351 #ifdef __cplusplus
wolfSSL 7:481bce714567 352 }
wolfSSL 7:481bce714567 353 #endif
wolfSSL 7:481bce714567 354
wolfSSL 7:481bce714567 355
wolfSSL 7:481bce714567 356 #endif /* USE_FAST_MATH */
wolfSSL 7:481bce714567 357
wolfSSL 7:481bce714567 358 #endif /* WOLF_CRYPT_INTEGER_H */
wolfSSL 7:481bce714567 359
wolfSSL 7:481bce714567 360