wolf SSL / CyaSSL

Dependents:   HTTPClient-SSL HTTPClient HTTPClient-SSL http_access ... more

Committer:
wolfSSL
Date:
Sat Jul 12 07:18:23 2014 +0000
Revision:
0:1239e9b70ca2
CyaSSL 3.0.0;

Who changed what in which revision?

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