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

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

Committer:
wolfSSL
Date:
Tue Aug 22 10:48:22 2017 +0000
Revision:
13:f67a6c6013ca
Parent:
11:cee25a834751
wolfSSL3.12.0 with TLS1.3

Who changed what in which revision?

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