Xuyi Wang / wolfSSL

Dependents:   OS

Committer:
wolfSSL
Date:
Fri Jun 26 00:39:20 2015 +0000
Revision:
0:d92f9d21154c
wolfSSL 3.6.0

Who changed what in which revision?

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