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