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

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

Committer:
wolfSSL
Date:
Thu Apr 28 00:57:21 2016 +0000
Revision:
4:1b0d80432c79
wolfSSL 3.9.0

Who changed what in which revision?

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