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