SSL/TLS Library
CyaSSL is SSL/TLS library for embedded systems.
ctaocrypt/src/ecc.c@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 | /* ecc.c |
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 | #ifdef HAVE_CONFIG_H |
wolfSSL | 0:9d17e4342598 | 24 | #include <config.h> |
wolfSSL | 0:9d17e4342598 | 25 | #endif |
wolfSSL | 0:9d17e4342598 | 26 | |
wolfSSL | 0:9d17e4342598 | 27 | /* in case user set HAVE_ECC there */ |
wolfSSL | 0:9d17e4342598 | 28 | #include <cyassl/ctaocrypt/settings.h> |
wolfSSL | 0:9d17e4342598 | 29 | |
wolfSSL | 0:9d17e4342598 | 30 | #ifdef HAVE_ECC |
wolfSSL | 0:9d17e4342598 | 31 | |
wolfSSL | 0:9d17e4342598 | 32 | #include <cyassl/ctaocrypt/ecc.h> |
wolfSSL | 0:9d17e4342598 | 33 | #include <cyassl/ctaocrypt/asn.h> |
wolfSSL | 0:9d17e4342598 | 34 | #include <cyassl/ctaocrypt/error-crypt.h> |
wolfSSL | 0:9d17e4342598 | 35 | |
wolfSSL | 0:9d17e4342598 | 36 | #ifdef HAVE_ECC_ENCRYPT |
wolfSSL | 0:9d17e4342598 | 37 | #include <cyassl/ctaocrypt/hmac.h> |
wolfSSL | 0:9d17e4342598 | 38 | #include <cyassl/ctaocrypt/aes.h> |
wolfSSL | 0:9d17e4342598 | 39 | #endif |
wolfSSL | 0:9d17e4342598 | 40 | |
wolfSSL | 0:9d17e4342598 | 41 | |
wolfSSL | 0:9d17e4342598 | 42 | /* map |
wolfSSL | 0:9d17e4342598 | 43 | |
wolfSSL | 0:9d17e4342598 | 44 | ptmul -> mulmod |
wolfSSL | 0:9d17e4342598 | 45 | |
wolfSSL | 0:9d17e4342598 | 46 | */ |
wolfSSL | 0:9d17e4342598 | 47 | |
wolfSSL | 0:9d17e4342598 | 48 | #define ECC112 |
wolfSSL | 0:9d17e4342598 | 49 | #define ECC128 |
wolfSSL | 0:9d17e4342598 | 50 | #define ECC160 |
wolfSSL | 0:9d17e4342598 | 51 | #define ECC192 |
wolfSSL | 0:9d17e4342598 | 52 | #define ECC224 |
wolfSSL | 0:9d17e4342598 | 53 | #define ECC256 |
wolfSSL | 0:9d17e4342598 | 54 | #define ECC384 |
wolfSSL | 0:9d17e4342598 | 55 | #define ECC521 |
wolfSSL | 0:9d17e4342598 | 56 | |
wolfSSL | 0:9d17e4342598 | 57 | |
wolfSSL | 0:9d17e4342598 | 58 | |
wolfSSL | 0:9d17e4342598 | 59 | /* This holds the key settings. ***MUST*** be organized by size from |
wolfSSL | 0:9d17e4342598 | 60 | smallest to largest. */ |
wolfSSL | 0:9d17e4342598 | 61 | |
wolfSSL | 0:9d17e4342598 | 62 | const ecc_set_type ecc_sets[] = { |
wolfSSL | 0:9d17e4342598 | 63 | #ifdef ECC112 |
wolfSSL | 0:9d17e4342598 | 64 | { |
wolfSSL | 0:9d17e4342598 | 65 | 14, |
wolfSSL | 0:9d17e4342598 | 66 | "SECP112R1", |
wolfSSL | 0:9d17e4342598 | 67 | "DB7C2ABF62E35E668076BEAD208B", |
wolfSSL | 0:9d17e4342598 | 68 | "659EF8BA043916EEDE8911702B22", |
wolfSSL | 0:9d17e4342598 | 69 | "DB7C2ABF62E35E7628DFAC6561C5", |
wolfSSL | 0:9d17e4342598 | 70 | "09487239995A5EE76B55F9C2F098", |
wolfSSL | 0:9d17e4342598 | 71 | "A89CE5AF8724C0A23E0E0FF77500" |
wolfSSL | 0:9d17e4342598 | 72 | }, |
wolfSSL | 0:9d17e4342598 | 73 | #endif |
wolfSSL | 0:9d17e4342598 | 74 | #ifdef ECC128 |
wolfSSL | 0:9d17e4342598 | 75 | { |
wolfSSL | 0:9d17e4342598 | 76 | 16, |
wolfSSL | 0:9d17e4342598 | 77 | "SECP128R1", |
wolfSSL | 0:9d17e4342598 | 78 | "FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFF", |
wolfSSL | 0:9d17e4342598 | 79 | "E87579C11079F43DD824993C2CEE5ED3", |
wolfSSL | 0:9d17e4342598 | 80 | "FFFFFFFE0000000075A30D1B9038A115", |
wolfSSL | 0:9d17e4342598 | 81 | "161FF7528B899B2D0C28607CA52C5B86", |
wolfSSL | 0:9d17e4342598 | 82 | "CF5AC8395BAFEB13C02DA292DDED7A83", |
wolfSSL | 0:9d17e4342598 | 83 | }, |
wolfSSL | 0:9d17e4342598 | 84 | #endif |
wolfSSL | 0:9d17e4342598 | 85 | #ifdef ECC160 |
wolfSSL | 0:9d17e4342598 | 86 | { |
wolfSSL | 0:9d17e4342598 | 87 | 20, |
wolfSSL | 0:9d17e4342598 | 88 | "SECP160R1", |
wolfSSL | 0:9d17e4342598 | 89 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF", |
wolfSSL | 0:9d17e4342598 | 90 | "1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45", |
wolfSSL | 0:9d17e4342598 | 91 | "0100000000000000000001F4C8F927AED3CA752257", |
wolfSSL | 0:9d17e4342598 | 92 | "4A96B5688EF573284664698968C38BB913CBFC82", |
wolfSSL | 0:9d17e4342598 | 93 | "23A628553168947D59DCC912042351377AC5FB32", |
wolfSSL | 0:9d17e4342598 | 94 | }, |
wolfSSL | 0:9d17e4342598 | 95 | #endif |
wolfSSL | 0:9d17e4342598 | 96 | #ifdef ECC192 |
wolfSSL | 0:9d17e4342598 | 97 | { |
wolfSSL | 0:9d17e4342598 | 98 | 24, |
wolfSSL | 0:9d17e4342598 | 99 | "ECC-192", |
wolfSSL | 0:9d17e4342598 | 100 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF", |
wolfSSL | 0:9d17e4342598 | 101 | "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1", |
wolfSSL | 0:9d17e4342598 | 102 | "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831", |
wolfSSL | 0:9d17e4342598 | 103 | "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012", |
wolfSSL | 0:9d17e4342598 | 104 | "7192B95FFC8DA78631011ED6B24CDD573F977A11E794811", |
wolfSSL | 0:9d17e4342598 | 105 | }, |
wolfSSL | 0:9d17e4342598 | 106 | #endif |
wolfSSL | 0:9d17e4342598 | 107 | #ifdef ECC224 |
wolfSSL | 0:9d17e4342598 | 108 | { |
wolfSSL | 0:9d17e4342598 | 109 | 28, |
wolfSSL | 0:9d17e4342598 | 110 | "ECC-224", |
wolfSSL | 0:9d17e4342598 | 111 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", |
wolfSSL | 0:9d17e4342598 | 112 | "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4", |
wolfSSL | 0:9d17e4342598 | 113 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D", |
wolfSSL | 0:9d17e4342598 | 114 | "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21", |
wolfSSL | 0:9d17e4342598 | 115 | "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34", |
wolfSSL | 0:9d17e4342598 | 116 | }, |
wolfSSL | 0:9d17e4342598 | 117 | #endif |
wolfSSL | 0:9d17e4342598 | 118 | #ifdef ECC256 |
wolfSSL | 0:9d17e4342598 | 119 | { |
wolfSSL | 0:9d17e4342598 | 120 | 32, |
wolfSSL | 0:9d17e4342598 | 121 | "ECC-256", |
wolfSSL | 0:9d17e4342598 | 122 | "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", |
wolfSSL | 0:9d17e4342598 | 123 | "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B", |
wolfSSL | 0:9d17e4342598 | 124 | "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", |
wolfSSL | 0:9d17e4342598 | 125 | "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", |
wolfSSL | 0:9d17e4342598 | 126 | "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", |
wolfSSL | 0:9d17e4342598 | 127 | }, |
wolfSSL | 0:9d17e4342598 | 128 | #endif |
wolfSSL | 0:9d17e4342598 | 129 | #ifdef ECC384 |
wolfSSL | 0:9d17e4342598 | 130 | { |
wolfSSL | 0:9d17e4342598 | 131 | 48, |
wolfSSL | 0:9d17e4342598 | 132 | "ECC-384", |
wolfSSL | 0:9d17e4342598 | 133 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", |
wolfSSL | 0:9d17e4342598 | 134 | "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF", |
wolfSSL | 0:9d17e4342598 | 135 | "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973", |
wolfSSL | 0:9d17e4342598 | 136 | "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7", |
wolfSSL | 0:9d17e4342598 | 137 | "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F", |
wolfSSL | 0:9d17e4342598 | 138 | }, |
wolfSSL | 0:9d17e4342598 | 139 | #endif |
wolfSSL | 0:9d17e4342598 | 140 | #ifdef ECC521 |
wolfSSL | 0:9d17e4342598 | 141 | { |
wolfSSL | 0:9d17e4342598 | 142 | 66, |
wolfSSL | 0:9d17e4342598 | 143 | "ECC-521", |
wolfSSL | 0:9d17e4342598 | 144 | "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", |
wolfSSL | 0:9d17e4342598 | 145 | "51953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00", |
wolfSSL | 0:9d17e4342598 | 146 | "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409", |
wolfSSL | 0:9d17e4342598 | 147 | "C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66", |
wolfSSL | 0:9d17e4342598 | 148 | "11839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650", |
wolfSSL | 0:9d17e4342598 | 149 | }, |
wolfSSL | 0:9d17e4342598 | 150 | #endif |
wolfSSL | 0:9d17e4342598 | 151 | { |
wolfSSL | 0:9d17e4342598 | 152 | 0, |
wolfSSL | 0:9d17e4342598 | 153 | NULL, NULL, NULL, NULL, NULL, NULL |
wolfSSL | 0:9d17e4342598 | 154 | } |
wolfSSL | 0:9d17e4342598 | 155 | }; |
wolfSSL | 0:9d17e4342598 | 156 | |
wolfSSL | 0:9d17e4342598 | 157 | |
wolfSSL | 0:9d17e4342598 | 158 | ecc_point* ecc_new_point(void); |
wolfSSL | 0:9d17e4342598 | 159 | void ecc_del_point(ecc_point* p); |
wolfSSL | 0:9d17e4342598 | 160 | int ecc_map(ecc_point*, mp_int*, mp_digit*); |
wolfSSL | 0:9d17e4342598 | 161 | int ecc_projective_add_point(ecc_point* P, ecc_point* Q, ecc_point* R, |
wolfSSL | 0:9d17e4342598 | 162 | mp_int* modulus, mp_digit* mp); |
wolfSSL | 0:9d17e4342598 | 163 | int ecc_projective_dbl_point(ecc_point* P, ecc_point* R, mp_int* modulus, |
wolfSSL | 0:9d17e4342598 | 164 | mp_digit* mp); |
wolfSSL | 0:9d17e4342598 | 165 | static int ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, |
wolfSSL | 0:9d17e4342598 | 166 | int map); |
wolfSSL | 0:9d17e4342598 | 167 | #ifdef ECC_SHAMIR |
wolfSSL | 0:9d17e4342598 | 168 | static int ecc_mul2add(ecc_point* A, mp_int* kA, ecc_point* B, mp_int* kB, |
wolfSSL | 0:9d17e4342598 | 169 | ecc_point* C, mp_int* modulus); |
wolfSSL | 0:9d17e4342598 | 170 | #endif |
wolfSSL | 0:9d17e4342598 | 171 | |
wolfSSL | 0:9d17e4342598 | 172 | |
wolfSSL | 0:9d17e4342598 | 173 | /* helper for either lib */ |
wolfSSL | 0:9d17e4342598 | 174 | static int get_digit_count(mp_int* a) |
wolfSSL | 0:9d17e4342598 | 175 | { |
wolfSSL | 0:9d17e4342598 | 176 | if (a == NULL) |
wolfSSL | 0:9d17e4342598 | 177 | return 0; |
wolfSSL | 0:9d17e4342598 | 178 | |
wolfSSL | 0:9d17e4342598 | 179 | return a->used; |
wolfSSL | 0:9d17e4342598 | 180 | } |
wolfSSL | 0:9d17e4342598 | 181 | |
wolfSSL | 0:9d17e4342598 | 182 | /* helper for either lib */ |
wolfSSL | 0:9d17e4342598 | 183 | static unsigned long get_digit(mp_int* a, int n) |
wolfSSL | 0:9d17e4342598 | 184 | { |
wolfSSL | 0:9d17e4342598 | 185 | if (a == NULL) |
wolfSSL | 0:9d17e4342598 | 186 | return 0; |
wolfSSL | 0:9d17e4342598 | 187 | |
wolfSSL | 0:9d17e4342598 | 188 | return (n >= a->used || n < 0) ? 0 : a->dp[n]; |
wolfSSL | 0:9d17e4342598 | 189 | } |
wolfSSL | 0:9d17e4342598 | 190 | |
wolfSSL | 0:9d17e4342598 | 191 | |
wolfSSL | 0:9d17e4342598 | 192 | #if defined(USE_FAST_MATH) |
wolfSSL | 0:9d17e4342598 | 193 | |
wolfSSL | 0:9d17e4342598 | 194 | /* fast math accelerated version, but not for fp ecc yet */ |
wolfSSL | 0:9d17e4342598 | 195 | |
wolfSSL | 0:9d17e4342598 | 196 | /** |
wolfSSL | 0:9d17e4342598 | 197 | Add two ECC points |
wolfSSL | 0:9d17e4342598 | 198 | P The point to add |
wolfSSL | 0:9d17e4342598 | 199 | Q The point to add |
wolfSSL | 0:9d17e4342598 | 200 | R [out] The destination of the double |
wolfSSL | 0:9d17e4342598 | 201 | modulus The modulus of the field the ECC curve is in |
wolfSSL | 0:9d17e4342598 | 202 | mp The "b" value from montgomery_setup() |
wolfSSL | 0:9d17e4342598 | 203 | return MP_OKAY on success |
wolfSSL | 0:9d17e4342598 | 204 | */ |
wolfSSL | 0:9d17e4342598 | 205 | int ecc_projective_add_point(ecc_point *P, ecc_point *Q, ecc_point *R, |
wolfSSL | 0:9d17e4342598 | 206 | mp_int* modulus, mp_digit* mp) |
wolfSSL | 0:9d17e4342598 | 207 | { |
wolfSSL | 0:9d17e4342598 | 208 | fp_int t1, t2, x, y, z; |
wolfSSL | 0:9d17e4342598 | 209 | int err; |
wolfSSL | 0:9d17e4342598 | 210 | |
wolfSSL | 0:9d17e4342598 | 211 | if (P == NULL || Q == NULL || R == NULL || modulus == NULL || mp == NULL) |
wolfSSL | 0:9d17e4342598 | 212 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 213 | |
wolfSSL | 0:9d17e4342598 | 214 | if ((err = mp_init_multi(&t1, &t2, &x, &y, &z, NULL)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 215 | return err; |
wolfSSL | 0:9d17e4342598 | 216 | } |
wolfSSL | 0:9d17e4342598 | 217 | |
wolfSSL | 0:9d17e4342598 | 218 | /* should we dbl instead? */ |
wolfSSL | 0:9d17e4342598 | 219 | fp_sub(modulus, &Q->y, &t1); |
wolfSSL | 0:9d17e4342598 | 220 | if ( (fp_cmp(&P->x, &Q->x) == FP_EQ) && |
wolfSSL | 0:9d17e4342598 | 221 | (get_digit_count(&Q->z) && fp_cmp(&P->z, &Q->z) == FP_EQ) && |
wolfSSL | 0:9d17e4342598 | 222 | (fp_cmp(&P->y, &Q->y) == FP_EQ || fp_cmp(&P->y, &t1) == FP_EQ)) { |
wolfSSL | 0:9d17e4342598 | 223 | return ecc_projective_dbl_point(P, R, modulus, mp); |
wolfSSL | 0:9d17e4342598 | 224 | } |
wolfSSL | 0:9d17e4342598 | 225 | |
wolfSSL | 0:9d17e4342598 | 226 | fp_copy(&P->x, &x); |
wolfSSL | 0:9d17e4342598 | 227 | fp_copy(&P->y, &y); |
wolfSSL | 0:9d17e4342598 | 228 | fp_copy(&P->z, &z); |
wolfSSL | 0:9d17e4342598 | 229 | |
wolfSSL | 0:9d17e4342598 | 230 | /* if Z is one then these are no-operations */ |
wolfSSL | 0:9d17e4342598 | 231 | if (get_digit_count(&Q->z)) { |
wolfSSL | 0:9d17e4342598 | 232 | /* T1 = Z' * Z' */ |
wolfSSL | 0:9d17e4342598 | 233 | fp_sqr(&Q->z, &t1); |
wolfSSL | 0:9d17e4342598 | 234 | fp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 235 | /* X = X * T1 */ |
wolfSSL | 0:9d17e4342598 | 236 | fp_mul(&t1, &x, &x); |
wolfSSL | 0:9d17e4342598 | 237 | fp_montgomery_reduce(&x, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 238 | /* T1 = Z' * T1 */ |
wolfSSL | 0:9d17e4342598 | 239 | fp_mul(&Q->z, &t1, &t1); |
wolfSSL | 0:9d17e4342598 | 240 | fp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 241 | /* Y = Y * T1 */ |
wolfSSL | 0:9d17e4342598 | 242 | fp_mul(&t1, &y, &y); |
wolfSSL | 0:9d17e4342598 | 243 | fp_montgomery_reduce(&y, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 244 | } |
wolfSSL | 0:9d17e4342598 | 245 | |
wolfSSL | 0:9d17e4342598 | 246 | /* T1 = Z*Z */ |
wolfSSL | 0:9d17e4342598 | 247 | fp_sqr(&z, &t1); |
wolfSSL | 0:9d17e4342598 | 248 | fp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 249 | /* T2 = X' * T1 */ |
wolfSSL | 0:9d17e4342598 | 250 | fp_mul(&Q->x, &t1, &t2); |
wolfSSL | 0:9d17e4342598 | 251 | fp_montgomery_reduce(&t2, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 252 | /* T1 = Z * T1 */ |
wolfSSL | 0:9d17e4342598 | 253 | fp_mul(&z, &t1, &t1); |
wolfSSL | 0:9d17e4342598 | 254 | fp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 255 | /* T1 = Y' * T1 */ |
wolfSSL | 0:9d17e4342598 | 256 | fp_mul(&Q->y, &t1, &t1); |
wolfSSL | 0:9d17e4342598 | 257 | fp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 258 | |
wolfSSL | 0:9d17e4342598 | 259 | /* Y = Y - T1 */ |
wolfSSL | 0:9d17e4342598 | 260 | fp_sub(&y, &t1, &y); |
wolfSSL | 0:9d17e4342598 | 261 | if (fp_cmp_d(&y, 0) == FP_LT) { |
wolfSSL | 0:9d17e4342598 | 262 | fp_add(&y, modulus, &y); |
wolfSSL | 0:9d17e4342598 | 263 | } |
wolfSSL | 0:9d17e4342598 | 264 | /* T1 = 2T1 */ |
wolfSSL | 0:9d17e4342598 | 265 | fp_add(&t1, &t1, &t1); |
wolfSSL | 0:9d17e4342598 | 266 | if (fp_cmp(&t1, modulus) != FP_LT) { |
wolfSSL | 0:9d17e4342598 | 267 | fp_sub(&t1, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 268 | } |
wolfSSL | 0:9d17e4342598 | 269 | /* T1 = Y + T1 */ |
wolfSSL | 0:9d17e4342598 | 270 | fp_add(&t1, &y, &t1); |
wolfSSL | 0:9d17e4342598 | 271 | if (fp_cmp(&t1, modulus) != FP_LT) { |
wolfSSL | 0:9d17e4342598 | 272 | fp_sub(&t1, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 273 | } |
wolfSSL | 0:9d17e4342598 | 274 | /* X = X - T2 */ |
wolfSSL | 0:9d17e4342598 | 275 | fp_sub(&x, &t2, &x); |
wolfSSL | 0:9d17e4342598 | 276 | if (fp_cmp_d(&x, 0) == FP_LT) { |
wolfSSL | 0:9d17e4342598 | 277 | fp_add(&x, modulus, &x); |
wolfSSL | 0:9d17e4342598 | 278 | } |
wolfSSL | 0:9d17e4342598 | 279 | /* T2 = 2T2 */ |
wolfSSL | 0:9d17e4342598 | 280 | fp_add(&t2, &t2, &t2); |
wolfSSL | 0:9d17e4342598 | 281 | if (fp_cmp(&t2, modulus) != FP_LT) { |
wolfSSL | 0:9d17e4342598 | 282 | fp_sub(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 283 | } |
wolfSSL | 0:9d17e4342598 | 284 | /* T2 = X + T2 */ |
wolfSSL | 0:9d17e4342598 | 285 | fp_add(&t2, &x, &t2); |
wolfSSL | 0:9d17e4342598 | 286 | if (fp_cmp(&t2, modulus) != FP_LT) { |
wolfSSL | 0:9d17e4342598 | 287 | fp_sub(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 288 | } |
wolfSSL | 0:9d17e4342598 | 289 | |
wolfSSL | 0:9d17e4342598 | 290 | /* if Z' != 1 */ |
wolfSSL | 0:9d17e4342598 | 291 | if (get_digit_count(&Q->z)) { |
wolfSSL | 0:9d17e4342598 | 292 | /* Z = Z * Z' */ |
wolfSSL | 0:9d17e4342598 | 293 | fp_mul(&z, &Q->z, &z); |
wolfSSL | 0:9d17e4342598 | 294 | fp_montgomery_reduce(&z, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 295 | } |
wolfSSL | 0:9d17e4342598 | 296 | |
wolfSSL | 0:9d17e4342598 | 297 | /* Z = Z * X */ |
wolfSSL | 0:9d17e4342598 | 298 | fp_mul(&z, &x, &z); |
wolfSSL | 0:9d17e4342598 | 299 | fp_montgomery_reduce(&z, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 300 | |
wolfSSL | 0:9d17e4342598 | 301 | /* T1 = T1 * X */ |
wolfSSL | 0:9d17e4342598 | 302 | fp_mul(&t1, &x, &t1); |
wolfSSL | 0:9d17e4342598 | 303 | fp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 304 | /* X = X * X */ |
wolfSSL | 0:9d17e4342598 | 305 | fp_sqr(&x, &x); |
wolfSSL | 0:9d17e4342598 | 306 | fp_montgomery_reduce(&x, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 307 | /* T2 = T2 * x */ |
wolfSSL | 0:9d17e4342598 | 308 | fp_mul(&t2, &x, &t2); |
wolfSSL | 0:9d17e4342598 | 309 | fp_montgomery_reduce(&t2, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 310 | /* T1 = T1 * X */ |
wolfSSL | 0:9d17e4342598 | 311 | fp_mul(&t1, &x, &t1); |
wolfSSL | 0:9d17e4342598 | 312 | fp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 313 | |
wolfSSL | 0:9d17e4342598 | 314 | /* X = Y*Y */ |
wolfSSL | 0:9d17e4342598 | 315 | fp_sqr(&y, &x); |
wolfSSL | 0:9d17e4342598 | 316 | fp_montgomery_reduce(&x, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 317 | /* X = X - T2 */ |
wolfSSL | 0:9d17e4342598 | 318 | fp_sub(&x, &t2, &x); |
wolfSSL | 0:9d17e4342598 | 319 | if (fp_cmp_d(&x, 0) == FP_LT) { |
wolfSSL | 0:9d17e4342598 | 320 | fp_add(&x, modulus, &x); |
wolfSSL | 0:9d17e4342598 | 321 | } |
wolfSSL | 0:9d17e4342598 | 322 | |
wolfSSL | 0:9d17e4342598 | 323 | /* T2 = T2 - X */ |
wolfSSL | 0:9d17e4342598 | 324 | fp_sub(&t2, &x, &t2); |
wolfSSL | 0:9d17e4342598 | 325 | if (fp_cmp_d(&t2, 0) == FP_LT) { |
wolfSSL | 0:9d17e4342598 | 326 | fp_add(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 327 | } |
wolfSSL | 0:9d17e4342598 | 328 | /* T2 = T2 - X */ |
wolfSSL | 0:9d17e4342598 | 329 | fp_sub(&t2, &x, &t2); |
wolfSSL | 0:9d17e4342598 | 330 | if (fp_cmp_d(&t2, 0) == FP_LT) { |
wolfSSL | 0:9d17e4342598 | 331 | fp_add(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 332 | } |
wolfSSL | 0:9d17e4342598 | 333 | /* T2 = T2 * Y */ |
wolfSSL | 0:9d17e4342598 | 334 | fp_mul(&t2, &y, &t2); |
wolfSSL | 0:9d17e4342598 | 335 | fp_montgomery_reduce(&t2, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 336 | /* Y = T2 - T1 */ |
wolfSSL | 0:9d17e4342598 | 337 | fp_sub(&t2, &t1, &y); |
wolfSSL | 0:9d17e4342598 | 338 | if (fp_cmp_d(&y, 0) == FP_LT) { |
wolfSSL | 0:9d17e4342598 | 339 | fp_add(&y, modulus, &y); |
wolfSSL | 0:9d17e4342598 | 340 | } |
wolfSSL | 0:9d17e4342598 | 341 | /* Y = Y/2 */ |
wolfSSL | 0:9d17e4342598 | 342 | if (fp_isodd(&y)) { |
wolfSSL | 0:9d17e4342598 | 343 | fp_add(&y, modulus, &y); |
wolfSSL | 0:9d17e4342598 | 344 | } |
wolfSSL | 0:9d17e4342598 | 345 | fp_div_2(&y, &y); |
wolfSSL | 0:9d17e4342598 | 346 | |
wolfSSL | 0:9d17e4342598 | 347 | fp_copy(&x, &R->x); |
wolfSSL | 0:9d17e4342598 | 348 | fp_copy(&y, &R->y); |
wolfSSL | 0:9d17e4342598 | 349 | fp_copy(&z, &R->z); |
wolfSSL | 0:9d17e4342598 | 350 | |
wolfSSL | 0:9d17e4342598 | 351 | return MP_OKAY; |
wolfSSL | 0:9d17e4342598 | 352 | } |
wolfSSL | 0:9d17e4342598 | 353 | |
wolfSSL | 0:9d17e4342598 | 354 | |
wolfSSL | 0:9d17e4342598 | 355 | /** |
wolfSSL | 0:9d17e4342598 | 356 | Double an ECC point |
wolfSSL | 0:9d17e4342598 | 357 | P The point to double |
wolfSSL | 0:9d17e4342598 | 358 | R [out] The destination of the double |
wolfSSL | 0:9d17e4342598 | 359 | modulus The modulus of the field the ECC curve is in |
wolfSSL | 0:9d17e4342598 | 360 | mp The "b" value from montgomery_setup() |
wolfSSL | 0:9d17e4342598 | 361 | return MP_OKAY on success |
wolfSSL | 0:9d17e4342598 | 362 | */ |
wolfSSL | 0:9d17e4342598 | 363 | int ecc_projective_dbl_point(ecc_point *P, ecc_point *R, mp_int* modulus, |
wolfSSL | 0:9d17e4342598 | 364 | mp_digit* mp) |
wolfSSL | 0:9d17e4342598 | 365 | { |
wolfSSL | 0:9d17e4342598 | 366 | fp_int t1, t2; |
wolfSSL | 0:9d17e4342598 | 367 | int err; |
wolfSSL | 0:9d17e4342598 | 368 | |
wolfSSL | 0:9d17e4342598 | 369 | if (P == NULL || R == NULL || modulus == NULL || mp == NULL) |
wolfSSL | 0:9d17e4342598 | 370 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 371 | |
wolfSSL | 0:9d17e4342598 | 372 | if (P != R) { |
wolfSSL | 0:9d17e4342598 | 373 | fp_copy(&P->x, &R->x); |
wolfSSL | 0:9d17e4342598 | 374 | fp_copy(&P->y, &R->y); |
wolfSSL | 0:9d17e4342598 | 375 | fp_copy(&P->z, &R->z); |
wolfSSL | 0:9d17e4342598 | 376 | } |
wolfSSL | 0:9d17e4342598 | 377 | |
wolfSSL | 0:9d17e4342598 | 378 | if ((err = mp_init_multi(&t1, &t2, NULL, NULL, NULL, NULL)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 379 | return err; |
wolfSSL | 0:9d17e4342598 | 380 | } |
wolfSSL | 0:9d17e4342598 | 381 | |
wolfSSL | 0:9d17e4342598 | 382 | /* t1 = Z * Z */ |
wolfSSL | 0:9d17e4342598 | 383 | fp_sqr(&R->z, &t1); |
wolfSSL | 0:9d17e4342598 | 384 | fp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 385 | /* Z = Y * Z */ |
wolfSSL | 0:9d17e4342598 | 386 | fp_mul(&R->z, &R->y, &R->z); |
wolfSSL | 0:9d17e4342598 | 387 | fp_montgomery_reduce(&R->z, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 388 | /* Z = 2Z */ |
wolfSSL | 0:9d17e4342598 | 389 | fp_add(&R->z, &R->z, &R->z); |
wolfSSL | 0:9d17e4342598 | 390 | if (fp_cmp(&R->z, modulus) != FP_LT) { |
wolfSSL | 0:9d17e4342598 | 391 | fp_sub(&R->z, modulus, &R->z); |
wolfSSL | 0:9d17e4342598 | 392 | } |
wolfSSL | 0:9d17e4342598 | 393 | |
wolfSSL | 0:9d17e4342598 | 394 | /* &t2 = X - T1 */ |
wolfSSL | 0:9d17e4342598 | 395 | fp_sub(&R->x, &t1, &t2); |
wolfSSL | 0:9d17e4342598 | 396 | if (fp_cmp_d(&t2, 0) == FP_LT) { |
wolfSSL | 0:9d17e4342598 | 397 | fp_add(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 398 | } |
wolfSSL | 0:9d17e4342598 | 399 | /* T1 = X + T1 */ |
wolfSSL | 0:9d17e4342598 | 400 | fp_add(&t1, &R->x, &t1); |
wolfSSL | 0:9d17e4342598 | 401 | if (fp_cmp(&t1, modulus) != FP_LT) { |
wolfSSL | 0:9d17e4342598 | 402 | fp_sub(&t1, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 403 | } |
wolfSSL | 0:9d17e4342598 | 404 | /* T2 = T1 * T2 */ |
wolfSSL | 0:9d17e4342598 | 405 | fp_mul(&t1, &t2, &t2); |
wolfSSL | 0:9d17e4342598 | 406 | fp_montgomery_reduce(&t2, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 407 | /* T1 = 2T2 */ |
wolfSSL | 0:9d17e4342598 | 408 | fp_add(&t2, &t2, &t1); |
wolfSSL | 0:9d17e4342598 | 409 | if (fp_cmp(&t1, modulus) != FP_LT) { |
wolfSSL | 0:9d17e4342598 | 410 | fp_sub(&t1, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 411 | } |
wolfSSL | 0:9d17e4342598 | 412 | /* T1 = T1 + T2 */ |
wolfSSL | 0:9d17e4342598 | 413 | fp_add(&t1, &t2, &t1); |
wolfSSL | 0:9d17e4342598 | 414 | if (fp_cmp(&t1, modulus) != FP_LT) { |
wolfSSL | 0:9d17e4342598 | 415 | fp_sub(&t1, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 416 | } |
wolfSSL | 0:9d17e4342598 | 417 | |
wolfSSL | 0:9d17e4342598 | 418 | /* Y = 2Y */ |
wolfSSL | 0:9d17e4342598 | 419 | fp_add(&R->y, &R->y, &R->y); |
wolfSSL | 0:9d17e4342598 | 420 | if (fp_cmp(&R->y, modulus) != FP_LT) { |
wolfSSL | 0:9d17e4342598 | 421 | fp_sub(&R->y, modulus, &R->y); |
wolfSSL | 0:9d17e4342598 | 422 | } |
wolfSSL | 0:9d17e4342598 | 423 | /* Y = Y * Y */ |
wolfSSL | 0:9d17e4342598 | 424 | fp_sqr(&R->y, &R->y); |
wolfSSL | 0:9d17e4342598 | 425 | fp_montgomery_reduce(&R->y, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 426 | /* T2 = Y * Y */ |
wolfSSL | 0:9d17e4342598 | 427 | fp_sqr(&R->y, &t2); |
wolfSSL | 0:9d17e4342598 | 428 | fp_montgomery_reduce(&t2, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 429 | /* T2 = T2/2 */ |
wolfSSL | 0:9d17e4342598 | 430 | if (fp_isodd(&t2)) { |
wolfSSL | 0:9d17e4342598 | 431 | fp_add(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 432 | } |
wolfSSL | 0:9d17e4342598 | 433 | fp_div_2(&t2, &t2); |
wolfSSL | 0:9d17e4342598 | 434 | /* Y = Y * X */ |
wolfSSL | 0:9d17e4342598 | 435 | fp_mul(&R->y, &R->x, &R->y); |
wolfSSL | 0:9d17e4342598 | 436 | fp_montgomery_reduce(&R->y, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 437 | |
wolfSSL | 0:9d17e4342598 | 438 | /* X = T1 * T1 */ |
wolfSSL | 0:9d17e4342598 | 439 | fp_sqr(&t1, &R->x); |
wolfSSL | 0:9d17e4342598 | 440 | fp_montgomery_reduce(&R->x, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 441 | /* X = X - Y */ |
wolfSSL | 0:9d17e4342598 | 442 | fp_sub(&R->x, &R->y, &R->x); |
wolfSSL | 0:9d17e4342598 | 443 | if (fp_cmp_d(&R->x, 0) == FP_LT) { |
wolfSSL | 0:9d17e4342598 | 444 | fp_add(&R->x, modulus, &R->x); |
wolfSSL | 0:9d17e4342598 | 445 | } |
wolfSSL | 0:9d17e4342598 | 446 | /* X = X - Y */ |
wolfSSL | 0:9d17e4342598 | 447 | fp_sub(&R->x, &R->y, &R->x); |
wolfSSL | 0:9d17e4342598 | 448 | if (fp_cmp_d(&R->x, 0) == FP_LT) { |
wolfSSL | 0:9d17e4342598 | 449 | fp_add(&R->x, modulus, &R->x); |
wolfSSL | 0:9d17e4342598 | 450 | } |
wolfSSL | 0:9d17e4342598 | 451 | |
wolfSSL | 0:9d17e4342598 | 452 | /* Y = Y - X */ |
wolfSSL | 0:9d17e4342598 | 453 | fp_sub(&R->y, &R->x, &R->y); |
wolfSSL | 0:9d17e4342598 | 454 | if (fp_cmp_d(&R->y, 0) == FP_LT) { |
wolfSSL | 0:9d17e4342598 | 455 | fp_add(&R->y, modulus, &R->y); |
wolfSSL | 0:9d17e4342598 | 456 | } |
wolfSSL | 0:9d17e4342598 | 457 | /* Y = Y * T1 */ |
wolfSSL | 0:9d17e4342598 | 458 | fp_mul(&R->y, &t1, &R->y); |
wolfSSL | 0:9d17e4342598 | 459 | fp_montgomery_reduce(&R->y, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 460 | /* Y = Y - T2 */ |
wolfSSL | 0:9d17e4342598 | 461 | fp_sub(&R->y, &t2, &R->y); |
wolfSSL | 0:9d17e4342598 | 462 | if (fp_cmp_d(&R->y, 0) == FP_LT) { |
wolfSSL | 0:9d17e4342598 | 463 | fp_add(&R->y, modulus, &R->y); |
wolfSSL | 0:9d17e4342598 | 464 | } |
wolfSSL | 0:9d17e4342598 | 465 | |
wolfSSL | 0:9d17e4342598 | 466 | return MP_OKAY; |
wolfSSL | 0:9d17e4342598 | 467 | } |
wolfSSL | 0:9d17e4342598 | 468 | |
wolfSSL | 0:9d17e4342598 | 469 | #else /* USE_FAST_MATH */ |
wolfSSL | 0:9d17e4342598 | 470 | |
wolfSSL | 0:9d17e4342598 | 471 | /** |
wolfSSL | 0:9d17e4342598 | 472 | Add two ECC points |
wolfSSL | 0:9d17e4342598 | 473 | P The point to add |
wolfSSL | 0:9d17e4342598 | 474 | Q The point to add |
wolfSSL | 0:9d17e4342598 | 475 | R [out] The destination of the double |
wolfSSL | 0:9d17e4342598 | 476 | modulus The modulus of the field the ECC curve is in |
wolfSSL | 0:9d17e4342598 | 477 | mp The "b" value from montgomery_setup() |
wolfSSL | 0:9d17e4342598 | 478 | return MP_OKAY on success |
wolfSSL | 0:9d17e4342598 | 479 | */ |
wolfSSL | 0:9d17e4342598 | 480 | int ecc_projective_add_point(ecc_point* P, ecc_point* Q, ecc_point* R, |
wolfSSL | 0:9d17e4342598 | 481 | mp_int* modulus, mp_digit* mp) |
wolfSSL | 0:9d17e4342598 | 482 | { |
wolfSSL | 0:9d17e4342598 | 483 | mp_int t1; |
wolfSSL | 0:9d17e4342598 | 484 | mp_int t2; |
wolfSSL | 0:9d17e4342598 | 485 | mp_int x; |
wolfSSL | 0:9d17e4342598 | 486 | mp_int y; |
wolfSSL | 0:9d17e4342598 | 487 | mp_int z; |
wolfSSL | 0:9d17e4342598 | 488 | int err; |
wolfSSL | 0:9d17e4342598 | 489 | |
wolfSSL | 0:9d17e4342598 | 490 | if (P == NULL || Q == NULL || R == NULL || modulus == NULL || mp == NULL) |
wolfSSL | 0:9d17e4342598 | 491 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 492 | |
wolfSSL | 0:9d17e4342598 | 493 | if ((err = mp_init_multi(&t1, &t2, &x, &y, &z, NULL)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 494 | return err; |
wolfSSL | 0:9d17e4342598 | 495 | } |
wolfSSL | 0:9d17e4342598 | 496 | |
wolfSSL | 0:9d17e4342598 | 497 | /* should we dbl instead? */ |
wolfSSL | 0:9d17e4342598 | 498 | err = mp_sub(modulus, &Q->y, &t1); |
wolfSSL | 0:9d17e4342598 | 499 | |
wolfSSL | 0:9d17e4342598 | 500 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 501 | if ( (mp_cmp(&P->x, &Q->x) == MP_EQ) && |
wolfSSL | 0:9d17e4342598 | 502 | (get_digit_count(&Q->z) && mp_cmp(&P->z, &Q->z) == MP_EQ) && |
wolfSSL | 0:9d17e4342598 | 503 | (mp_cmp(&P->y, &Q->y) == MP_EQ || mp_cmp(&P->y, &t1) == MP_EQ)) { |
wolfSSL | 0:9d17e4342598 | 504 | mp_clear(&t1); |
wolfSSL | 0:9d17e4342598 | 505 | mp_clear(&t2); |
wolfSSL | 0:9d17e4342598 | 506 | mp_clear(&x); |
wolfSSL | 0:9d17e4342598 | 507 | mp_clear(&y); |
wolfSSL | 0:9d17e4342598 | 508 | mp_clear(&z); |
wolfSSL | 0:9d17e4342598 | 509 | |
wolfSSL | 0:9d17e4342598 | 510 | return ecc_projective_dbl_point(P, R, modulus, mp); |
wolfSSL | 0:9d17e4342598 | 511 | } |
wolfSSL | 0:9d17e4342598 | 512 | } |
wolfSSL | 0:9d17e4342598 | 513 | |
wolfSSL | 0:9d17e4342598 | 514 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 515 | err = mp_copy(&P->x, &x); |
wolfSSL | 0:9d17e4342598 | 516 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 517 | err = mp_copy(&P->y, &y); |
wolfSSL | 0:9d17e4342598 | 518 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 519 | err = mp_copy(&P->z, &z); |
wolfSSL | 0:9d17e4342598 | 520 | |
wolfSSL | 0:9d17e4342598 | 521 | /* if Z is one then these are no-operations */ |
wolfSSL | 0:9d17e4342598 | 522 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 523 | if (get_digit_count(&Q->z)) { |
wolfSSL | 0:9d17e4342598 | 524 | /* T1 = Z' * Z' */ |
wolfSSL | 0:9d17e4342598 | 525 | err = mp_sqr(&Q->z, &t1); |
wolfSSL | 0:9d17e4342598 | 526 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 527 | err = mp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 528 | |
wolfSSL | 0:9d17e4342598 | 529 | /* X = X * T1 */ |
wolfSSL | 0:9d17e4342598 | 530 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 531 | err = mp_mul(&t1, &x, &x); |
wolfSSL | 0:9d17e4342598 | 532 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 533 | err = mp_montgomery_reduce(&x, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 534 | |
wolfSSL | 0:9d17e4342598 | 535 | /* T1 = Z' * T1 */ |
wolfSSL | 0:9d17e4342598 | 536 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 537 | err = mp_mul(&Q->z, &t1, &t1); |
wolfSSL | 0:9d17e4342598 | 538 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 539 | err = mp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 540 | |
wolfSSL | 0:9d17e4342598 | 541 | /* Y = Y * T1 */ |
wolfSSL | 0:9d17e4342598 | 542 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 543 | err = mp_mul(&t1, &y, &y); |
wolfSSL | 0:9d17e4342598 | 544 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 545 | err = mp_montgomery_reduce(&y, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 546 | } |
wolfSSL | 0:9d17e4342598 | 547 | } |
wolfSSL | 0:9d17e4342598 | 548 | |
wolfSSL | 0:9d17e4342598 | 549 | /* T1 = Z*Z */ |
wolfSSL | 0:9d17e4342598 | 550 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 551 | err = mp_sqr(&z, &t1); |
wolfSSL | 0:9d17e4342598 | 552 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 553 | err = mp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 554 | |
wolfSSL | 0:9d17e4342598 | 555 | /* T2 = X' * T1 */ |
wolfSSL | 0:9d17e4342598 | 556 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 557 | err = mp_mul(&Q->x, &t1, &t2); |
wolfSSL | 0:9d17e4342598 | 558 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 559 | err = mp_montgomery_reduce(&t2, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 560 | |
wolfSSL | 0:9d17e4342598 | 561 | /* T1 = Z * T1 */ |
wolfSSL | 0:9d17e4342598 | 562 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 563 | err = mp_mul(&z, &t1, &t1); |
wolfSSL | 0:9d17e4342598 | 564 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 565 | err = mp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 566 | |
wolfSSL | 0:9d17e4342598 | 567 | /* T1 = Y' * T1 */ |
wolfSSL | 0:9d17e4342598 | 568 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 569 | err = mp_mul(&Q->y, &t1, &t1); |
wolfSSL | 0:9d17e4342598 | 570 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 571 | err = mp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 572 | |
wolfSSL | 0:9d17e4342598 | 573 | /* Y = Y - T1 */ |
wolfSSL | 0:9d17e4342598 | 574 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 575 | err = mp_sub(&y, &t1, &y); |
wolfSSL | 0:9d17e4342598 | 576 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 577 | if (mp_cmp_d(&y, 0) == MP_LT) |
wolfSSL | 0:9d17e4342598 | 578 | err = mp_add(&y, modulus, &y); |
wolfSSL | 0:9d17e4342598 | 579 | } |
wolfSSL | 0:9d17e4342598 | 580 | /* T1 = 2T1 */ |
wolfSSL | 0:9d17e4342598 | 581 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 582 | err = mp_add(&t1, &t1, &t1); |
wolfSSL | 0:9d17e4342598 | 583 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 584 | if (mp_cmp(&t1, modulus) != MP_LT) |
wolfSSL | 0:9d17e4342598 | 585 | err = mp_sub(&t1, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 586 | } |
wolfSSL | 0:9d17e4342598 | 587 | /* T1 = Y + T1 */ |
wolfSSL | 0:9d17e4342598 | 588 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 589 | err = mp_add(&t1, &y, &t1); |
wolfSSL | 0:9d17e4342598 | 590 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 591 | if (mp_cmp(&t1, modulus) != MP_LT) |
wolfSSL | 0:9d17e4342598 | 592 | err = mp_sub(&t1, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 593 | } |
wolfSSL | 0:9d17e4342598 | 594 | /* X = X - T2 */ |
wolfSSL | 0:9d17e4342598 | 595 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 596 | err = mp_sub(&x, &t2, &x); |
wolfSSL | 0:9d17e4342598 | 597 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 598 | if (mp_cmp_d(&x, 0) == MP_LT) |
wolfSSL | 0:9d17e4342598 | 599 | err = mp_add(&x, modulus, &x); |
wolfSSL | 0:9d17e4342598 | 600 | } |
wolfSSL | 0:9d17e4342598 | 601 | /* T2 = 2T2 */ |
wolfSSL | 0:9d17e4342598 | 602 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 603 | err = mp_add(&t2, &t2, &t2); |
wolfSSL | 0:9d17e4342598 | 604 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 605 | if (mp_cmp(&t2, modulus) != MP_LT) |
wolfSSL | 0:9d17e4342598 | 606 | err = mp_sub(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 607 | } |
wolfSSL | 0:9d17e4342598 | 608 | /* T2 = X + T2 */ |
wolfSSL | 0:9d17e4342598 | 609 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 610 | err = mp_add(&t2, &x, &t2); |
wolfSSL | 0:9d17e4342598 | 611 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 612 | if (mp_cmp(&t2, modulus) != MP_LT) |
wolfSSL | 0:9d17e4342598 | 613 | err = mp_sub(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 614 | } |
wolfSSL | 0:9d17e4342598 | 615 | |
wolfSSL | 0:9d17e4342598 | 616 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 617 | if (get_digit_count(&Q->z)) { |
wolfSSL | 0:9d17e4342598 | 618 | /* Z = Z * Z' */ |
wolfSSL | 0:9d17e4342598 | 619 | err = mp_mul(&z, &Q->z, &z); |
wolfSSL | 0:9d17e4342598 | 620 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 621 | err = mp_montgomery_reduce(&z, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 622 | } |
wolfSSL | 0:9d17e4342598 | 623 | } |
wolfSSL | 0:9d17e4342598 | 624 | |
wolfSSL | 0:9d17e4342598 | 625 | /* Z = Z * X */ |
wolfSSL | 0:9d17e4342598 | 626 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 627 | err = mp_mul(&z, &x, &z); |
wolfSSL | 0:9d17e4342598 | 628 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 629 | err = mp_montgomery_reduce(&z, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 630 | |
wolfSSL | 0:9d17e4342598 | 631 | /* T1 = T1 * X */ |
wolfSSL | 0:9d17e4342598 | 632 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 633 | err = mp_mul(&t1, &x, &t1); |
wolfSSL | 0:9d17e4342598 | 634 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 635 | err = mp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 636 | |
wolfSSL | 0:9d17e4342598 | 637 | /* X = X * X */ |
wolfSSL | 0:9d17e4342598 | 638 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 639 | err = mp_sqr(&x, &x); |
wolfSSL | 0:9d17e4342598 | 640 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 641 | err = mp_montgomery_reduce(&x, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 642 | |
wolfSSL | 0:9d17e4342598 | 643 | /* T2 = T2 * x */ |
wolfSSL | 0:9d17e4342598 | 644 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 645 | err = mp_mul(&t2, &x, &t2); |
wolfSSL | 0:9d17e4342598 | 646 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 647 | err = mp_montgomery_reduce(&t2, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 648 | |
wolfSSL | 0:9d17e4342598 | 649 | /* T1 = T1 * X */ |
wolfSSL | 0:9d17e4342598 | 650 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 651 | err = mp_mul(&t1, &x, &t1); |
wolfSSL | 0:9d17e4342598 | 652 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 653 | err = mp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 654 | |
wolfSSL | 0:9d17e4342598 | 655 | /* X = Y*Y */ |
wolfSSL | 0:9d17e4342598 | 656 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 657 | err = mp_sqr(&y, &x); |
wolfSSL | 0:9d17e4342598 | 658 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 659 | err = mp_montgomery_reduce(&x, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 660 | |
wolfSSL | 0:9d17e4342598 | 661 | /* X = X - T2 */ |
wolfSSL | 0:9d17e4342598 | 662 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 663 | err = mp_sub(&x, &t2, &x); |
wolfSSL | 0:9d17e4342598 | 664 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 665 | if (mp_cmp_d(&x, 0) == MP_LT) |
wolfSSL | 0:9d17e4342598 | 666 | err = mp_add(&x, modulus, &x); |
wolfSSL | 0:9d17e4342598 | 667 | } |
wolfSSL | 0:9d17e4342598 | 668 | /* T2 = T2 - X */ |
wolfSSL | 0:9d17e4342598 | 669 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 670 | err = mp_sub(&t2, &x, &t2); |
wolfSSL | 0:9d17e4342598 | 671 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 672 | if (mp_cmp_d(&t2, 0) == MP_LT) |
wolfSSL | 0:9d17e4342598 | 673 | err = mp_add(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 674 | } |
wolfSSL | 0:9d17e4342598 | 675 | /* T2 = T2 - X */ |
wolfSSL | 0:9d17e4342598 | 676 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 677 | err = mp_sub(&t2, &x, &t2); |
wolfSSL | 0:9d17e4342598 | 678 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 679 | if (mp_cmp_d(&t2, 0) == MP_LT) |
wolfSSL | 0:9d17e4342598 | 680 | err = mp_add(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 681 | } |
wolfSSL | 0:9d17e4342598 | 682 | /* T2 = T2 * Y */ |
wolfSSL | 0:9d17e4342598 | 683 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 684 | err = mp_mul(&t2, &y, &t2); |
wolfSSL | 0:9d17e4342598 | 685 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 686 | err = mp_montgomery_reduce(&t2, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 687 | |
wolfSSL | 0:9d17e4342598 | 688 | /* Y = T2 - T1 */ |
wolfSSL | 0:9d17e4342598 | 689 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 690 | err = mp_sub(&t2, &t1, &y); |
wolfSSL | 0:9d17e4342598 | 691 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 692 | if (mp_cmp_d(&y, 0) == MP_LT) |
wolfSSL | 0:9d17e4342598 | 693 | err = mp_add(&y, modulus, &y); |
wolfSSL | 0:9d17e4342598 | 694 | } |
wolfSSL | 0:9d17e4342598 | 695 | /* Y = Y/2 */ |
wolfSSL | 0:9d17e4342598 | 696 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 697 | if (mp_isodd(&y)) |
wolfSSL | 0:9d17e4342598 | 698 | err = mp_add(&y, modulus, &y); |
wolfSSL | 0:9d17e4342598 | 699 | } |
wolfSSL | 0:9d17e4342598 | 700 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 701 | err = mp_div_2(&y, &y); |
wolfSSL | 0:9d17e4342598 | 702 | |
wolfSSL | 0:9d17e4342598 | 703 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 704 | err = mp_copy(&x, &R->x); |
wolfSSL | 0:9d17e4342598 | 705 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 706 | err = mp_copy(&y, &R->y); |
wolfSSL | 0:9d17e4342598 | 707 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 708 | err = mp_copy(&z, &R->z); |
wolfSSL | 0:9d17e4342598 | 709 | |
wolfSSL | 0:9d17e4342598 | 710 | /* clean up */ |
wolfSSL | 0:9d17e4342598 | 711 | mp_clear(&t1); |
wolfSSL | 0:9d17e4342598 | 712 | mp_clear(&t2); |
wolfSSL | 0:9d17e4342598 | 713 | mp_clear(&x); |
wolfSSL | 0:9d17e4342598 | 714 | mp_clear(&y); |
wolfSSL | 0:9d17e4342598 | 715 | mp_clear(&z); |
wolfSSL | 0:9d17e4342598 | 716 | |
wolfSSL | 0:9d17e4342598 | 717 | return err; |
wolfSSL | 0:9d17e4342598 | 718 | } |
wolfSSL | 0:9d17e4342598 | 719 | |
wolfSSL | 0:9d17e4342598 | 720 | |
wolfSSL | 0:9d17e4342598 | 721 | /** |
wolfSSL | 0:9d17e4342598 | 722 | Double an ECC point |
wolfSSL | 0:9d17e4342598 | 723 | P The point to double |
wolfSSL | 0:9d17e4342598 | 724 | R [out] The destination of the double |
wolfSSL | 0:9d17e4342598 | 725 | modulus The modulus of the field the ECC curve is in |
wolfSSL | 0:9d17e4342598 | 726 | mp The "b" value from montgomery_setup() |
wolfSSL | 0:9d17e4342598 | 727 | return MP_OKAY on success |
wolfSSL | 0:9d17e4342598 | 728 | */ |
wolfSSL | 0:9d17e4342598 | 729 | int ecc_projective_dbl_point(ecc_point *P, ecc_point *R, mp_int* modulus, |
wolfSSL | 0:9d17e4342598 | 730 | mp_digit* mp) |
wolfSSL | 0:9d17e4342598 | 731 | { |
wolfSSL | 0:9d17e4342598 | 732 | mp_int t1; |
wolfSSL | 0:9d17e4342598 | 733 | mp_int t2; |
wolfSSL | 0:9d17e4342598 | 734 | int err; |
wolfSSL | 0:9d17e4342598 | 735 | |
wolfSSL | 0:9d17e4342598 | 736 | if (P == NULL || R == NULL || modulus == NULL || mp == NULL) |
wolfSSL | 0:9d17e4342598 | 737 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 738 | |
wolfSSL | 0:9d17e4342598 | 739 | if ((err = mp_init_multi(&t1, &t2, NULL, NULL, NULL, NULL)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 740 | return err; |
wolfSSL | 0:9d17e4342598 | 741 | } |
wolfSSL | 0:9d17e4342598 | 742 | |
wolfSSL | 0:9d17e4342598 | 743 | if (P != R) { |
wolfSSL | 0:9d17e4342598 | 744 | err = mp_copy(&P->x, &R->x); |
wolfSSL | 0:9d17e4342598 | 745 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 746 | err = mp_copy(&P->y, &R->y); |
wolfSSL | 0:9d17e4342598 | 747 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 748 | err = mp_copy(&P->z, &R->z); |
wolfSSL | 0:9d17e4342598 | 749 | } |
wolfSSL | 0:9d17e4342598 | 750 | |
wolfSSL | 0:9d17e4342598 | 751 | /* t1 = Z * Z */ |
wolfSSL | 0:9d17e4342598 | 752 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 753 | err = mp_sqr(&R->z, &t1); |
wolfSSL | 0:9d17e4342598 | 754 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 755 | err = mp_montgomery_reduce(&t1, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 756 | |
wolfSSL | 0:9d17e4342598 | 757 | /* Z = Y * Z */ |
wolfSSL | 0:9d17e4342598 | 758 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 759 | err = mp_mul(&R->z, &R->y, &R->z); |
wolfSSL | 0:9d17e4342598 | 760 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 761 | err = mp_montgomery_reduce(&R->z, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 762 | |
wolfSSL | 0:9d17e4342598 | 763 | /* Z = 2Z */ |
wolfSSL | 0:9d17e4342598 | 764 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 765 | err = mp_add(&R->z, &R->z, &R->z); |
wolfSSL | 0:9d17e4342598 | 766 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 767 | if (mp_cmp(&R->z, modulus) != MP_LT) |
wolfSSL | 0:9d17e4342598 | 768 | err = mp_sub(&R->z, modulus, &R->z); |
wolfSSL | 0:9d17e4342598 | 769 | } |
wolfSSL | 0:9d17e4342598 | 770 | |
wolfSSL | 0:9d17e4342598 | 771 | /* T2 = X - T1 */ |
wolfSSL | 0:9d17e4342598 | 772 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 773 | err = mp_sub(&R->x, &t1, &t2); |
wolfSSL | 0:9d17e4342598 | 774 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 775 | if (mp_cmp_d(&t2, 0) == MP_LT) |
wolfSSL | 0:9d17e4342598 | 776 | err = mp_add(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 777 | } |
wolfSSL | 0:9d17e4342598 | 778 | /* T1 = X + T1 */ |
wolfSSL | 0:9d17e4342598 | 779 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 780 | err = mp_add(&t1, &R->x, &t1); |
wolfSSL | 0:9d17e4342598 | 781 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 782 | if (mp_cmp(&t1, modulus) != MP_LT) |
wolfSSL | 0:9d17e4342598 | 783 | err = mp_sub(&t1, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 784 | } |
wolfSSL | 0:9d17e4342598 | 785 | /* T2 = T1 * T2 */ |
wolfSSL | 0:9d17e4342598 | 786 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 787 | err = mp_mul(&t1, &t2, &t2); |
wolfSSL | 0:9d17e4342598 | 788 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 789 | err = mp_montgomery_reduce(&t2, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 790 | |
wolfSSL | 0:9d17e4342598 | 791 | /* T1 = 2T2 */ |
wolfSSL | 0:9d17e4342598 | 792 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 793 | err = mp_add(&t2, &t2, &t1); |
wolfSSL | 0:9d17e4342598 | 794 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 795 | if (mp_cmp(&t1, modulus) != MP_LT) |
wolfSSL | 0:9d17e4342598 | 796 | err = mp_sub(&t1, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 797 | } |
wolfSSL | 0:9d17e4342598 | 798 | /* T1 = T1 + T2 */ |
wolfSSL | 0:9d17e4342598 | 799 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 800 | err = mp_add(&t1, &t2, &t1); |
wolfSSL | 0:9d17e4342598 | 801 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 802 | if (mp_cmp(&t1, modulus) != MP_LT) |
wolfSSL | 0:9d17e4342598 | 803 | err = mp_sub(&t1, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 804 | } |
wolfSSL | 0:9d17e4342598 | 805 | /* Y = 2Y */ |
wolfSSL | 0:9d17e4342598 | 806 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 807 | err = mp_add(&R->y, &R->y, &R->y); |
wolfSSL | 0:9d17e4342598 | 808 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 809 | if (mp_cmp(&R->y, modulus) != MP_LT) |
wolfSSL | 0:9d17e4342598 | 810 | err = mp_sub(&R->y, modulus, &R->y); |
wolfSSL | 0:9d17e4342598 | 811 | } |
wolfSSL | 0:9d17e4342598 | 812 | /* Y = Y * Y */ |
wolfSSL | 0:9d17e4342598 | 813 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 814 | err = mp_sqr(&R->y, &R->y); |
wolfSSL | 0:9d17e4342598 | 815 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 816 | err = mp_montgomery_reduce(&R->y, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 817 | |
wolfSSL | 0:9d17e4342598 | 818 | /* T2 = Y * Y */ |
wolfSSL | 0:9d17e4342598 | 819 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 820 | err = mp_sqr(&R->y, &t2); |
wolfSSL | 0:9d17e4342598 | 821 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 822 | err = mp_montgomery_reduce(&t2, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 823 | |
wolfSSL | 0:9d17e4342598 | 824 | /* T2 = T2/2 */ |
wolfSSL | 0:9d17e4342598 | 825 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 826 | if (mp_isodd(&t2)) |
wolfSSL | 0:9d17e4342598 | 827 | err = mp_add(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 828 | } |
wolfSSL | 0:9d17e4342598 | 829 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 830 | err = mp_div_2(&t2, &t2); |
wolfSSL | 0:9d17e4342598 | 831 | |
wolfSSL | 0:9d17e4342598 | 832 | /* Y = Y * X */ |
wolfSSL | 0:9d17e4342598 | 833 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 834 | err = mp_mul(&R->y, &R->x, &R->y); |
wolfSSL | 0:9d17e4342598 | 835 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 836 | err = mp_montgomery_reduce(&R->y, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 837 | |
wolfSSL | 0:9d17e4342598 | 838 | /* X = T1 * T1 */ |
wolfSSL | 0:9d17e4342598 | 839 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 840 | err = mp_sqr(&t1, &R->x); |
wolfSSL | 0:9d17e4342598 | 841 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 842 | err = mp_montgomery_reduce(&R->x, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 843 | |
wolfSSL | 0:9d17e4342598 | 844 | /* X = X - Y */ |
wolfSSL | 0:9d17e4342598 | 845 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 846 | err = mp_sub(&R->x, &R->y, &R->x); |
wolfSSL | 0:9d17e4342598 | 847 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 848 | if (mp_cmp_d(&R->x, 0) == MP_LT) |
wolfSSL | 0:9d17e4342598 | 849 | err = mp_add(&R->x, modulus, &R->x); |
wolfSSL | 0:9d17e4342598 | 850 | } |
wolfSSL | 0:9d17e4342598 | 851 | /* X = X - Y */ |
wolfSSL | 0:9d17e4342598 | 852 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 853 | err = mp_sub(&R->x, &R->y, &R->x); |
wolfSSL | 0:9d17e4342598 | 854 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 855 | if (mp_cmp_d(&R->x, 0) == MP_LT) |
wolfSSL | 0:9d17e4342598 | 856 | err = mp_add(&R->x, modulus, &R->x); |
wolfSSL | 0:9d17e4342598 | 857 | } |
wolfSSL | 0:9d17e4342598 | 858 | /* Y = Y - X */ |
wolfSSL | 0:9d17e4342598 | 859 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 860 | err = mp_sub(&R->y, &R->x, &R->y); |
wolfSSL | 0:9d17e4342598 | 861 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 862 | if (mp_cmp_d(&R->y, 0) == MP_LT) |
wolfSSL | 0:9d17e4342598 | 863 | err = mp_add(&R->y, modulus, &R->y); |
wolfSSL | 0:9d17e4342598 | 864 | } |
wolfSSL | 0:9d17e4342598 | 865 | /* Y = Y * T1 */ |
wolfSSL | 0:9d17e4342598 | 866 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 867 | err = mp_mul(&R->y, &t1, &R->y); |
wolfSSL | 0:9d17e4342598 | 868 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 869 | err = mp_montgomery_reduce(&R->y, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 870 | |
wolfSSL | 0:9d17e4342598 | 871 | /* Y = Y - T2 */ |
wolfSSL | 0:9d17e4342598 | 872 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 873 | err = mp_sub(&R->y, &t2, &R->y); |
wolfSSL | 0:9d17e4342598 | 874 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 875 | if (mp_cmp_d(&R->y, 0) == MP_LT) |
wolfSSL | 0:9d17e4342598 | 876 | err = mp_add(&R->y, modulus, &R->y); |
wolfSSL | 0:9d17e4342598 | 877 | } |
wolfSSL | 0:9d17e4342598 | 878 | |
wolfSSL | 0:9d17e4342598 | 879 | /* clean up */ |
wolfSSL | 0:9d17e4342598 | 880 | mp_clear(&t1); |
wolfSSL | 0:9d17e4342598 | 881 | mp_clear(&t2); |
wolfSSL | 0:9d17e4342598 | 882 | |
wolfSSL | 0:9d17e4342598 | 883 | return err; |
wolfSSL | 0:9d17e4342598 | 884 | } |
wolfSSL | 0:9d17e4342598 | 885 | |
wolfSSL | 0:9d17e4342598 | 886 | #endif /* USE_FAST_MATH */ |
wolfSSL | 0:9d17e4342598 | 887 | |
wolfSSL | 0:9d17e4342598 | 888 | /** |
wolfSSL | 0:9d17e4342598 | 889 | Map a projective jacbobian point back to affine space |
wolfSSL | 0:9d17e4342598 | 890 | P [in/out] The point to map |
wolfSSL | 0:9d17e4342598 | 891 | modulus The modulus of the field the ECC curve is in |
wolfSSL | 0:9d17e4342598 | 892 | mp The "b" value from montgomery_setup() |
wolfSSL | 0:9d17e4342598 | 893 | return MP_OKAY on success |
wolfSSL | 0:9d17e4342598 | 894 | */ |
wolfSSL | 0:9d17e4342598 | 895 | int ecc_map(ecc_point* P, mp_int* modulus, mp_digit* mp) |
wolfSSL | 0:9d17e4342598 | 896 | { |
wolfSSL | 0:9d17e4342598 | 897 | mp_int t1; |
wolfSSL | 0:9d17e4342598 | 898 | mp_int t2; |
wolfSSL | 0:9d17e4342598 | 899 | int err; |
wolfSSL | 0:9d17e4342598 | 900 | |
wolfSSL | 0:9d17e4342598 | 901 | if (P == NULL || mp == NULL || modulus == NULL) |
wolfSSL | 0:9d17e4342598 | 902 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 903 | |
wolfSSL | 0:9d17e4342598 | 904 | if ((err = mp_init_multi(&t1, &t2, NULL, NULL, NULL, NULL)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 905 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 906 | } |
wolfSSL | 0:9d17e4342598 | 907 | |
wolfSSL | 0:9d17e4342598 | 908 | /* first map z back to normal */ |
wolfSSL | 0:9d17e4342598 | 909 | err = mp_montgomery_reduce(&P->z, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 910 | |
wolfSSL | 0:9d17e4342598 | 911 | /* get 1/z */ |
wolfSSL | 0:9d17e4342598 | 912 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 913 | err = mp_invmod(&P->z, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 914 | |
wolfSSL | 0:9d17e4342598 | 915 | /* get 1/z^2 and 1/z^3 */ |
wolfSSL | 0:9d17e4342598 | 916 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 917 | err = mp_sqr(&t1, &t2); |
wolfSSL | 0:9d17e4342598 | 918 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 919 | err = mp_mod(&t2, modulus, &t2); |
wolfSSL | 0:9d17e4342598 | 920 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 921 | err = mp_mul(&t1, &t2, &t1); |
wolfSSL | 0:9d17e4342598 | 922 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 923 | err = mp_mod(&t1, modulus, &t1); |
wolfSSL | 0:9d17e4342598 | 924 | |
wolfSSL | 0:9d17e4342598 | 925 | /* multiply against x/y */ |
wolfSSL | 0:9d17e4342598 | 926 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 927 | err = mp_mul(&P->x, &t2, &P->x); |
wolfSSL | 0:9d17e4342598 | 928 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 929 | err = mp_montgomery_reduce(&P->x, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 930 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 931 | err = mp_mul(&P->y, &t1, &P->y); |
wolfSSL | 0:9d17e4342598 | 932 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 933 | err = mp_montgomery_reduce(&P->y, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 934 | |
wolfSSL | 0:9d17e4342598 | 935 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 936 | mp_set(&P->z, 1); |
wolfSSL | 0:9d17e4342598 | 937 | |
wolfSSL | 0:9d17e4342598 | 938 | /* clean up */ |
wolfSSL | 0:9d17e4342598 | 939 | mp_clear(&t1); |
wolfSSL | 0:9d17e4342598 | 940 | mp_clear(&t2); |
wolfSSL | 0:9d17e4342598 | 941 | |
wolfSSL | 0:9d17e4342598 | 942 | return err; |
wolfSSL | 0:9d17e4342598 | 943 | } |
wolfSSL | 0:9d17e4342598 | 944 | |
wolfSSL | 0:9d17e4342598 | 945 | |
wolfSSL | 0:9d17e4342598 | 946 | #ifndef ECC_TIMING_RESISTANT |
wolfSSL | 0:9d17e4342598 | 947 | |
wolfSSL | 0:9d17e4342598 | 948 | /* size of sliding window, don't change this! */ |
wolfSSL | 0:9d17e4342598 | 949 | #define WINSIZE 4 |
wolfSSL | 0:9d17e4342598 | 950 | |
wolfSSL | 0:9d17e4342598 | 951 | /** |
wolfSSL | 0:9d17e4342598 | 952 | Perform a point multiplication |
wolfSSL | 0:9d17e4342598 | 953 | k The scalar to multiply by |
wolfSSL | 0:9d17e4342598 | 954 | G The base point |
wolfSSL | 0:9d17e4342598 | 955 | R [out] Destination for kG |
wolfSSL | 0:9d17e4342598 | 956 | modulus The modulus of the field the ECC curve is in |
wolfSSL | 0:9d17e4342598 | 957 | map Boolean whether to map back to affine or not |
wolfSSL | 0:9d17e4342598 | 958 | (1==map, 0 == leave in projective) |
wolfSSL | 0:9d17e4342598 | 959 | return MP_OKAY on success |
wolfSSL | 0:9d17e4342598 | 960 | */ |
wolfSSL | 0:9d17e4342598 | 961 | #ifdef FP_ECC |
wolfSSL | 0:9d17e4342598 | 962 | static int normal_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, |
wolfSSL | 0:9d17e4342598 | 963 | mp_int* modulus, int map) |
wolfSSL | 0:9d17e4342598 | 964 | #else |
wolfSSL | 0:9d17e4342598 | 965 | static int ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, |
wolfSSL | 0:9d17e4342598 | 966 | int map) |
wolfSSL | 0:9d17e4342598 | 967 | #endif |
wolfSSL | 0:9d17e4342598 | 968 | { |
wolfSSL | 0:9d17e4342598 | 969 | ecc_point *tG, *M[8]; |
wolfSSL | 0:9d17e4342598 | 970 | int i, j, err; |
wolfSSL | 0:9d17e4342598 | 971 | mp_int mu; |
wolfSSL | 0:9d17e4342598 | 972 | mp_digit mp; |
wolfSSL | 0:9d17e4342598 | 973 | unsigned long buf; |
wolfSSL | 0:9d17e4342598 | 974 | int first = 1, bitbuf = 0, bitcpy = 0, bitcnt = 0, mode = 0, |
wolfSSL | 0:9d17e4342598 | 975 | digidx = 0; |
wolfSSL | 0:9d17e4342598 | 976 | |
wolfSSL | 0:9d17e4342598 | 977 | if (k == NULL || G == NULL || R == NULL || modulus == NULL) |
wolfSSL | 0:9d17e4342598 | 978 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 979 | |
wolfSSL | 0:9d17e4342598 | 980 | /* init montgomery reduction */ |
wolfSSL | 0:9d17e4342598 | 981 | if ((err = mp_montgomery_setup(modulus, &mp)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 982 | return err; |
wolfSSL | 0:9d17e4342598 | 983 | } |
wolfSSL | 0:9d17e4342598 | 984 | if ((err = mp_init(&mu)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 985 | return err; |
wolfSSL | 0:9d17e4342598 | 986 | } |
wolfSSL | 0:9d17e4342598 | 987 | if ((err = mp_montgomery_calc_normalization(&mu, modulus)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 988 | mp_clear(&mu); |
wolfSSL | 0:9d17e4342598 | 989 | return err; |
wolfSSL | 0:9d17e4342598 | 990 | } |
wolfSSL | 0:9d17e4342598 | 991 | |
wolfSSL | 0:9d17e4342598 | 992 | /* alloc ram for window temps */ |
wolfSSL | 0:9d17e4342598 | 993 | for (i = 0; i < 8; i++) { |
wolfSSL | 0:9d17e4342598 | 994 | M[i] = ecc_new_point(); |
wolfSSL | 0:9d17e4342598 | 995 | if (M[i] == NULL) { |
wolfSSL | 0:9d17e4342598 | 996 | for (j = 0; j < i; j++) { |
wolfSSL | 0:9d17e4342598 | 997 | ecc_del_point(M[j]); |
wolfSSL | 0:9d17e4342598 | 998 | } |
wolfSSL | 0:9d17e4342598 | 999 | mp_clear(&mu); |
wolfSSL | 0:9d17e4342598 | 1000 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1001 | } |
wolfSSL | 0:9d17e4342598 | 1002 | } |
wolfSSL | 0:9d17e4342598 | 1003 | |
wolfSSL | 0:9d17e4342598 | 1004 | /* make a copy of G incase R==G */ |
wolfSSL | 0:9d17e4342598 | 1005 | tG = ecc_new_point(); |
wolfSSL | 0:9d17e4342598 | 1006 | if (tG == NULL) |
wolfSSL | 0:9d17e4342598 | 1007 | err = MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1008 | |
wolfSSL | 0:9d17e4342598 | 1009 | /* tG = G and convert to montgomery */ |
wolfSSL | 0:9d17e4342598 | 1010 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1011 | if (mp_cmp_d(&mu, 1) == MP_EQ) { |
wolfSSL | 0:9d17e4342598 | 1012 | err = mp_copy(&G->x, &tG->x); |
wolfSSL | 0:9d17e4342598 | 1013 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1014 | err = mp_copy(&G->y, &tG->y); |
wolfSSL | 0:9d17e4342598 | 1015 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1016 | err = mp_copy(&G->z, &tG->z); |
wolfSSL | 0:9d17e4342598 | 1017 | } else { |
wolfSSL | 0:9d17e4342598 | 1018 | err = mp_mulmod(&G->x, &mu, modulus, &tG->x); |
wolfSSL | 0:9d17e4342598 | 1019 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1020 | err = mp_mulmod(&G->y, &mu, modulus, &tG->y); |
wolfSSL | 0:9d17e4342598 | 1021 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1022 | err = mp_mulmod(&G->z, &mu, modulus, &tG->z); |
wolfSSL | 0:9d17e4342598 | 1023 | } |
wolfSSL | 0:9d17e4342598 | 1024 | } |
wolfSSL | 0:9d17e4342598 | 1025 | mp_clear(&mu); |
wolfSSL | 0:9d17e4342598 | 1026 | |
wolfSSL | 0:9d17e4342598 | 1027 | /* calc the M tab, which holds kG for k==8..15 */ |
wolfSSL | 0:9d17e4342598 | 1028 | /* M[0] == 8G */ |
wolfSSL | 0:9d17e4342598 | 1029 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1030 | err = ecc_projective_dbl_point(tG, M[0], modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1031 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1032 | err = ecc_projective_dbl_point(M[0], M[0], modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1033 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1034 | err = ecc_projective_dbl_point(M[0], M[0], modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1035 | |
wolfSSL | 0:9d17e4342598 | 1036 | /* now find (8+k)G for k=1..7 */ |
wolfSSL | 0:9d17e4342598 | 1037 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1038 | for (j = 9; j < 16; j++) { |
wolfSSL | 0:9d17e4342598 | 1039 | err = ecc_projective_add_point(M[j-9], tG, M[j-8], modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1040 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1041 | } |
wolfSSL | 0:9d17e4342598 | 1042 | |
wolfSSL | 0:9d17e4342598 | 1043 | /* setup sliding window */ |
wolfSSL | 0:9d17e4342598 | 1044 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1045 | mode = 0; |
wolfSSL | 0:9d17e4342598 | 1046 | bitcnt = 1; |
wolfSSL | 0:9d17e4342598 | 1047 | buf = 0; |
wolfSSL | 0:9d17e4342598 | 1048 | digidx = get_digit_count(k) - 1; |
wolfSSL | 0:9d17e4342598 | 1049 | bitcpy = bitbuf = 0; |
wolfSSL | 0:9d17e4342598 | 1050 | first = 1; |
wolfSSL | 0:9d17e4342598 | 1051 | |
wolfSSL | 0:9d17e4342598 | 1052 | /* perform ops */ |
wolfSSL | 0:9d17e4342598 | 1053 | for (;;) { |
wolfSSL | 0:9d17e4342598 | 1054 | /* grab next digit as required */ |
wolfSSL | 0:9d17e4342598 | 1055 | if (--bitcnt == 0) { |
wolfSSL | 0:9d17e4342598 | 1056 | if (digidx == -1) { |
wolfSSL | 0:9d17e4342598 | 1057 | break; |
wolfSSL | 0:9d17e4342598 | 1058 | } |
wolfSSL | 0:9d17e4342598 | 1059 | buf = get_digit(k, digidx); |
wolfSSL | 0:9d17e4342598 | 1060 | bitcnt = (int) DIGIT_BIT; |
wolfSSL | 0:9d17e4342598 | 1061 | --digidx; |
wolfSSL | 0:9d17e4342598 | 1062 | } |
wolfSSL | 0:9d17e4342598 | 1063 | |
wolfSSL | 0:9d17e4342598 | 1064 | /* grab the next msb from the ltiplicand */ |
wolfSSL | 0:9d17e4342598 | 1065 | i = (int)(buf >> (DIGIT_BIT - 1)) & 1; |
wolfSSL | 0:9d17e4342598 | 1066 | buf <<= 1; |
wolfSSL | 0:9d17e4342598 | 1067 | |
wolfSSL | 0:9d17e4342598 | 1068 | /* skip leading zero bits */ |
wolfSSL | 0:9d17e4342598 | 1069 | if (mode == 0 && i == 0) |
wolfSSL | 0:9d17e4342598 | 1070 | continue; |
wolfSSL | 0:9d17e4342598 | 1071 | |
wolfSSL | 0:9d17e4342598 | 1072 | /* if the bit is zero and mode == 1 then we double */ |
wolfSSL | 0:9d17e4342598 | 1073 | if (mode == 1 && i == 0) { |
wolfSSL | 0:9d17e4342598 | 1074 | err = ecc_projective_dbl_point(R, R, modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1075 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1076 | continue; |
wolfSSL | 0:9d17e4342598 | 1077 | } |
wolfSSL | 0:9d17e4342598 | 1078 | |
wolfSSL | 0:9d17e4342598 | 1079 | /* else we add it to the window */ |
wolfSSL | 0:9d17e4342598 | 1080 | bitbuf |= (i << (WINSIZE - ++bitcpy)); |
wolfSSL | 0:9d17e4342598 | 1081 | mode = 2; |
wolfSSL | 0:9d17e4342598 | 1082 | |
wolfSSL | 0:9d17e4342598 | 1083 | if (bitcpy == WINSIZE) { |
wolfSSL | 0:9d17e4342598 | 1084 | /* if this is the first window we do a simple copy */ |
wolfSSL | 0:9d17e4342598 | 1085 | if (first == 1) { |
wolfSSL | 0:9d17e4342598 | 1086 | /* R = kG [k = first window] */ |
wolfSSL | 0:9d17e4342598 | 1087 | err = mp_copy(&M[bitbuf-8]->x, &R->x); |
wolfSSL | 0:9d17e4342598 | 1088 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1089 | |
wolfSSL | 0:9d17e4342598 | 1090 | err = mp_copy(&M[bitbuf-8]->y, &R->y); |
wolfSSL | 0:9d17e4342598 | 1091 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1092 | |
wolfSSL | 0:9d17e4342598 | 1093 | err = mp_copy(&M[bitbuf-8]->z, &R->z); |
wolfSSL | 0:9d17e4342598 | 1094 | first = 0; |
wolfSSL | 0:9d17e4342598 | 1095 | } else { |
wolfSSL | 0:9d17e4342598 | 1096 | /* normal window */ |
wolfSSL | 0:9d17e4342598 | 1097 | /* ok window is filled so double as required and add */ |
wolfSSL | 0:9d17e4342598 | 1098 | /* double first */ |
wolfSSL | 0:9d17e4342598 | 1099 | for (j = 0; j < WINSIZE; j++) { |
wolfSSL | 0:9d17e4342598 | 1100 | err = ecc_projective_dbl_point(R, R, modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1101 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1102 | } |
wolfSSL | 0:9d17e4342598 | 1103 | if (err != MP_OKAY) break; /* out of first for(;;) */ |
wolfSSL | 0:9d17e4342598 | 1104 | |
wolfSSL | 0:9d17e4342598 | 1105 | /* then add, bitbuf will be 8..15 [8..2^WINSIZE] guaranted */ |
wolfSSL | 0:9d17e4342598 | 1106 | err = ecc_projective_add_point(R,M[bitbuf-8],R,modulus,&mp); |
wolfSSL | 0:9d17e4342598 | 1107 | } |
wolfSSL | 0:9d17e4342598 | 1108 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1109 | /* empty window and reset */ |
wolfSSL | 0:9d17e4342598 | 1110 | bitcpy = bitbuf = 0; |
wolfSSL | 0:9d17e4342598 | 1111 | mode = 1; |
wolfSSL | 0:9d17e4342598 | 1112 | } |
wolfSSL | 0:9d17e4342598 | 1113 | } |
wolfSSL | 0:9d17e4342598 | 1114 | } |
wolfSSL | 0:9d17e4342598 | 1115 | |
wolfSSL | 0:9d17e4342598 | 1116 | /* if bits remain then double/add */ |
wolfSSL | 0:9d17e4342598 | 1117 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1118 | if (mode == 2 && bitcpy > 0) { |
wolfSSL | 0:9d17e4342598 | 1119 | /* double then add */ |
wolfSSL | 0:9d17e4342598 | 1120 | for (j = 0; j < bitcpy; j++) { |
wolfSSL | 0:9d17e4342598 | 1121 | /* only double if we have had at least one add first */ |
wolfSSL | 0:9d17e4342598 | 1122 | if (first == 0) { |
wolfSSL | 0:9d17e4342598 | 1123 | err = ecc_projective_dbl_point(R, R, modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1124 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1125 | } |
wolfSSL | 0:9d17e4342598 | 1126 | |
wolfSSL | 0:9d17e4342598 | 1127 | bitbuf <<= 1; |
wolfSSL | 0:9d17e4342598 | 1128 | if ((bitbuf & (1 << WINSIZE)) != 0) { |
wolfSSL | 0:9d17e4342598 | 1129 | if (first == 1) { |
wolfSSL | 0:9d17e4342598 | 1130 | /* first add, so copy */ |
wolfSSL | 0:9d17e4342598 | 1131 | err = mp_copy(&tG->x, &R->x); |
wolfSSL | 0:9d17e4342598 | 1132 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1133 | |
wolfSSL | 0:9d17e4342598 | 1134 | err = mp_copy(&tG->y, &R->y); |
wolfSSL | 0:9d17e4342598 | 1135 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1136 | |
wolfSSL | 0:9d17e4342598 | 1137 | err = mp_copy(&tG->z, &R->z); |
wolfSSL | 0:9d17e4342598 | 1138 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1139 | first = 0; |
wolfSSL | 0:9d17e4342598 | 1140 | } else { |
wolfSSL | 0:9d17e4342598 | 1141 | /* then add */ |
wolfSSL | 0:9d17e4342598 | 1142 | err = ecc_projective_add_point(R, tG, R, modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1143 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1144 | } |
wolfSSL | 0:9d17e4342598 | 1145 | } |
wolfSSL | 0:9d17e4342598 | 1146 | } |
wolfSSL | 0:9d17e4342598 | 1147 | } |
wolfSSL | 0:9d17e4342598 | 1148 | } |
wolfSSL | 0:9d17e4342598 | 1149 | |
wolfSSL | 0:9d17e4342598 | 1150 | /* map R back from projective space */ |
wolfSSL | 0:9d17e4342598 | 1151 | if (err == MP_OKAY && map) |
wolfSSL | 0:9d17e4342598 | 1152 | err = ecc_map(R, modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1153 | |
wolfSSL | 0:9d17e4342598 | 1154 | mp_clear(&mu); |
wolfSSL | 0:9d17e4342598 | 1155 | ecc_del_point(tG); |
wolfSSL | 0:9d17e4342598 | 1156 | for (i = 0; i < 8; i++) { |
wolfSSL | 0:9d17e4342598 | 1157 | ecc_del_point(M[i]); |
wolfSSL | 0:9d17e4342598 | 1158 | } |
wolfSSL | 0:9d17e4342598 | 1159 | return err; |
wolfSSL | 0:9d17e4342598 | 1160 | } |
wolfSSL | 0:9d17e4342598 | 1161 | |
wolfSSL | 0:9d17e4342598 | 1162 | #undef WINSIZE |
wolfSSL | 0:9d17e4342598 | 1163 | #endif /* ECC_TIMING_RESISTANT */ |
wolfSSL | 0:9d17e4342598 | 1164 | |
wolfSSL | 0:9d17e4342598 | 1165 | |
wolfSSL | 0:9d17e4342598 | 1166 | /** |
wolfSSL | 0:9d17e4342598 | 1167 | Allocate a new ECC point |
wolfSSL | 0:9d17e4342598 | 1168 | return A newly allocated point or NULL on error |
wolfSSL | 0:9d17e4342598 | 1169 | */ |
wolfSSL | 0:9d17e4342598 | 1170 | ecc_point* ecc_new_point(void) |
wolfSSL | 0:9d17e4342598 | 1171 | { |
wolfSSL | 0:9d17e4342598 | 1172 | ecc_point* p; |
wolfSSL | 0:9d17e4342598 | 1173 | p = (ecc_point*)XMALLOC(sizeof(ecc_point), 0, DYNAMIC_TYPE_BIGINT); |
wolfSSL | 0:9d17e4342598 | 1174 | if (p == NULL) { |
wolfSSL | 0:9d17e4342598 | 1175 | return NULL; |
wolfSSL | 0:9d17e4342598 | 1176 | } |
wolfSSL | 0:9d17e4342598 | 1177 | XMEMSET(p, 0, sizeof(ecc_point)); |
wolfSSL | 0:9d17e4342598 | 1178 | if (mp_init_multi(&p->x, &p->y, &p->z, NULL, NULL, NULL) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1179 | XFREE(p, 0, DYNAMIC_TYPE_BIGINT); |
wolfSSL | 0:9d17e4342598 | 1180 | return NULL; |
wolfSSL | 0:9d17e4342598 | 1181 | } |
wolfSSL | 0:9d17e4342598 | 1182 | return p; |
wolfSSL | 0:9d17e4342598 | 1183 | } |
wolfSSL | 0:9d17e4342598 | 1184 | |
wolfSSL | 0:9d17e4342598 | 1185 | /** Free an ECC point from memory |
wolfSSL | 0:9d17e4342598 | 1186 | p The point to free |
wolfSSL | 0:9d17e4342598 | 1187 | */ |
wolfSSL | 0:9d17e4342598 | 1188 | void ecc_del_point(ecc_point* p) |
wolfSSL | 0:9d17e4342598 | 1189 | { |
wolfSSL | 0:9d17e4342598 | 1190 | /* prevents free'ing null arguments */ |
wolfSSL | 0:9d17e4342598 | 1191 | if (p != NULL) { |
wolfSSL | 0:9d17e4342598 | 1192 | mp_clear(&p->x); |
wolfSSL | 0:9d17e4342598 | 1193 | mp_clear(&p->y); |
wolfSSL | 0:9d17e4342598 | 1194 | mp_clear(&p->z); |
wolfSSL | 0:9d17e4342598 | 1195 | XFREE(p, 0, DYNAMIC_TYPE_BIGINT); |
wolfSSL | 0:9d17e4342598 | 1196 | } |
wolfSSL | 0:9d17e4342598 | 1197 | } |
wolfSSL | 0:9d17e4342598 | 1198 | |
wolfSSL | 0:9d17e4342598 | 1199 | |
wolfSSL | 0:9d17e4342598 | 1200 | /** Returns whether an ECC idx is valid or not |
wolfSSL | 0:9d17e4342598 | 1201 | n The idx number to check |
wolfSSL | 0:9d17e4342598 | 1202 | return 1 if valid, 0 if not |
wolfSSL | 0:9d17e4342598 | 1203 | */ |
wolfSSL | 0:9d17e4342598 | 1204 | static int ecc_is_valid_idx(int n) |
wolfSSL | 0:9d17e4342598 | 1205 | { |
wolfSSL | 0:9d17e4342598 | 1206 | int x; |
wolfSSL | 0:9d17e4342598 | 1207 | |
wolfSSL | 0:9d17e4342598 | 1208 | for (x = 0; ecc_sets[x].size != 0; x++) |
wolfSSL | 0:9d17e4342598 | 1209 | ; |
wolfSSL | 0:9d17e4342598 | 1210 | /* -1 is a valid index --- indicating that the domain params |
wolfSSL | 0:9d17e4342598 | 1211 | were supplied by the user */ |
wolfSSL | 0:9d17e4342598 | 1212 | if ((n >= -1) && (n < x)) { |
wolfSSL | 0:9d17e4342598 | 1213 | return 1; |
wolfSSL | 0:9d17e4342598 | 1214 | } |
wolfSSL | 0:9d17e4342598 | 1215 | return 0; |
wolfSSL | 0:9d17e4342598 | 1216 | } |
wolfSSL | 0:9d17e4342598 | 1217 | |
wolfSSL | 0:9d17e4342598 | 1218 | |
wolfSSL | 0:9d17e4342598 | 1219 | /** |
wolfSSL | 0:9d17e4342598 | 1220 | Create an ECC shared secret between two keys |
wolfSSL | 0:9d17e4342598 | 1221 | private_key The private ECC key |
wolfSSL | 0:9d17e4342598 | 1222 | public_key The public key |
wolfSSL | 0:9d17e4342598 | 1223 | out [out] Destination of the shared secret |
wolfSSL | 0:9d17e4342598 | 1224 | Conforms to EC-DH from ANSI X9.63 |
wolfSSL | 0:9d17e4342598 | 1225 | outlen [in/out] The max size and resulting size of the shared secret |
wolfSSL | 0:9d17e4342598 | 1226 | return MP_OKAY if successful |
wolfSSL | 0:9d17e4342598 | 1227 | */ |
wolfSSL | 0:9d17e4342598 | 1228 | int ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out, |
wolfSSL | 0:9d17e4342598 | 1229 | word32* outlen) |
wolfSSL | 0:9d17e4342598 | 1230 | { |
wolfSSL | 0:9d17e4342598 | 1231 | word32 x = 0; |
wolfSSL | 0:9d17e4342598 | 1232 | ecc_point* result; |
wolfSSL | 0:9d17e4342598 | 1233 | mp_int prime; |
wolfSSL | 0:9d17e4342598 | 1234 | int err; |
wolfSSL | 0:9d17e4342598 | 1235 | |
wolfSSL | 0:9d17e4342598 | 1236 | if (private_key == NULL || public_key == NULL || out == NULL || |
wolfSSL | 0:9d17e4342598 | 1237 | outlen == NULL) |
wolfSSL | 0:9d17e4342598 | 1238 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 1239 | |
wolfSSL | 0:9d17e4342598 | 1240 | /* type valid? */ |
wolfSSL | 0:9d17e4342598 | 1241 | if (private_key->type != ECC_PRIVATEKEY) { |
wolfSSL | 0:9d17e4342598 | 1242 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1243 | } |
wolfSSL | 0:9d17e4342598 | 1244 | |
wolfSSL | 0:9d17e4342598 | 1245 | if (ecc_is_valid_idx(private_key->idx) == 0 || |
wolfSSL | 0:9d17e4342598 | 1246 | ecc_is_valid_idx(public_key->idx) == 0) |
wolfSSL | 0:9d17e4342598 | 1247 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1248 | |
wolfSSL | 0:9d17e4342598 | 1249 | if (XSTRNCMP(private_key->dp->name, public_key->dp->name, ECC_MAXNAME) != 0) |
wolfSSL | 0:9d17e4342598 | 1250 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1251 | |
wolfSSL | 0:9d17e4342598 | 1252 | /* make new point */ |
wolfSSL | 0:9d17e4342598 | 1253 | result = ecc_new_point(); |
wolfSSL | 0:9d17e4342598 | 1254 | if (result == NULL) { |
wolfSSL | 0:9d17e4342598 | 1255 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1256 | } |
wolfSSL | 0:9d17e4342598 | 1257 | |
wolfSSL | 0:9d17e4342598 | 1258 | if ((err = mp_init(&prime)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1259 | ecc_del_point(result); |
wolfSSL | 0:9d17e4342598 | 1260 | return err; |
wolfSSL | 0:9d17e4342598 | 1261 | } |
wolfSSL | 0:9d17e4342598 | 1262 | |
wolfSSL | 0:9d17e4342598 | 1263 | err = mp_read_radix(&prime, (char *)private_key->dp->prime, 16); |
wolfSSL | 0:9d17e4342598 | 1264 | |
wolfSSL | 0:9d17e4342598 | 1265 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1266 | err = ecc_mulmod(&private_key->k, &public_key->pubkey, result, &prime,1); |
wolfSSL | 0:9d17e4342598 | 1267 | |
wolfSSL | 0:9d17e4342598 | 1268 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1269 | x = mp_unsigned_bin_size(&prime); |
wolfSSL | 0:9d17e4342598 | 1270 | if (*outlen < x) |
wolfSSL | 0:9d17e4342598 | 1271 | err = BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 1272 | } |
wolfSSL | 0:9d17e4342598 | 1273 | |
wolfSSL | 0:9d17e4342598 | 1274 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1275 | XMEMSET(out, 0, x); |
wolfSSL | 0:9d17e4342598 | 1276 | err = mp_to_unsigned_bin(&result->x,out + (x - |
wolfSSL | 0:9d17e4342598 | 1277 | mp_unsigned_bin_size(&result->x))); |
wolfSSL | 0:9d17e4342598 | 1278 | *outlen = x; |
wolfSSL | 0:9d17e4342598 | 1279 | } |
wolfSSL | 0:9d17e4342598 | 1280 | |
wolfSSL | 0:9d17e4342598 | 1281 | mp_clear(&prime); |
wolfSSL | 0:9d17e4342598 | 1282 | ecc_del_point(result); |
wolfSSL | 0:9d17e4342598 | 1283 | |
wolfSSL | 0:9d17e4342598 | 1284 | return err; |
wolfSSL | 0:9d17e4342598 | 1285 | } |
wolfSSL | 0:9d17e4342598 | 1286 | |
wolfSSL | 0:9d17e4342598 | 1287 | |
wolfSSL | 0:9d17e4342598 | 1288 | int ecc_make_key_ex(RNG* rng, ecc_key* key, const ecc_set_type* dp); |
wolfSSL | 0:9d17e4342598 | 1289 | |
wolfSSL | 0:9d17e4342598 | 1290 | /** |
wolfSSL | 0:9d17e4342598 | 1291 | Make a new ECC key |
wolfSSL | 0:9d17e4342598 | 1292 | rng An active RNG state |
wolfSSL | 0:9d17e4342598 | 1293 | keysize The keysize for the new key (in octets from 20 to 65 bytes) |
wolfSSL | 0:9d17e4342598 | 1294 | key [out] Destination of the newly created key |
wolfSSL | 0:9d17e4342598 | 1295 | return MP_OKAY if successful, |
wolfSSL | 0:9d17e4342598 | 1296 | upon error all allocated memory will be freed |
wolfSSL | 0:9d17e4342598 | 1297 | */ |
wolfSSL | 0:9d17e4342598 | 1298 | int ecc_make_key(RNG* rng, int keysize, ecc_key* key) |
wolfSSL | 0:9d17e4342598 | 1299 | { |
wolfSSL | 0:9d17e4342598 | 1300 | int x, err; |
wolfSSL | 0:9d17e4342598 | 1301 | |
wolfSSL | 0:9d17e4342598 | 1302 | /* find key size */ |
wolfSSL | 0:9d17e4342598 | 1303 | for (x = 0; (keysize > ecc_sets[x].size) && (ecc_sets[x].size != 0); x++) |
wolfSSL | 0:9d17e4342598 | 1304 | ; |
wolfSSL | 0:9d17e4342598 | 1305 | keysize = ecc_sets[x].size; |
wolfSSL | 0:9d17e4342598 | 1306 | |
wolfSSL | 0:9d17e4342598 | 1307 | if (keysize > ECC_MAXSIZE || ecc_sets[x].size == 0) { |
wolfSSL | 0:9d17e4342598 | 1308 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 1309 | } |
wolfSSL | 0:9d17e4342598 | 1310 | err = ecc_make_key_ex(rng, key, &ecc_sets[x]); |
wolfSSL | 0:9d17e4342598 | 1311 | key->idx = x; |
wolfSSL | 0:9d17e4342598 | 1312 | |
wolfSSL | 0:9d17e4342598 | 1313 | return err; |
wolfSSL | 0:9d17e4342598 | 1314 | } |
wolfSSL | 0:9d17e4342598 | 1315 | |
wolfSSL | 0:9d17e4342598 | 1316 | int ecc_make_key_ex(RNG* rng, ecc_key* key, const ecc_set_type* dp) |
wolfSSL | 0:9d17e4342598 | 1317 | { |
wolfSSL | 0:9d17e4342598 | 1318 | int err; |
wolfSSL | 0:9d17e4342598 | 1319 | ecc_point* base; |
wolfSSL | 0:9d17e4342598 | 1320 | mp_int prime; |
wolfSSL | 0:9d17e4342598 | 1321 | mp_int order; |
wolfSSL | 0:9d17e4342598 | 1322 | byte buf[ECC_MAXSIZE]; |
wolfSSL | 0:9d17e4342598 | 1323 | int keysize; |
wolfSSL | 0:9d17e4342598 | 1324 | |
wolfSSL | 0:9d17e4342598 | 1325 | if (key == NULL || rng == NULL || dp == NULL) |
wolfSSL | 0:9d17e4342598 | 1326 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1327 | |
wolfSSL | 0:9d17e4342598 | 1328 | key->idx = -1; |
wolfSSL | 0:9d17e4342598 | 1329 | key->dp = dp; |
wolfSSL | 0:9d17e4342598 | 1330 | keysize = dp->size; |
wolfSSL | 0:9d17e4342598 | 1331 | |
wolfSSL | 0:9d17e4342598 | 1332 | /* allocate ram */ |
wolfSSL | 0:9d17e4342598 | 1333 | base = NULL; |
wolfSSL | 0:9d17e4342598 | 1334 | |
wolfSSL | 0:9d17e4342598 | 1335 | /* make up random string */ |
wolfSSL | 0:9d17e4342598 | 1336 | RNG_GenerateBlock(rng, buf, keysize); |
wolfSSL | 0:9d17e4342598 | 1337 | buf[0] |= 0x0c; |
wolfSSL | 0:9d17e4342598 | 1338 | |
wolfSSL | 0:9d17e4342598 | 1339 | /* setup the key variables */ |
wolfSSL | 0:9d17e4342598 | 1340 | if ((err = mp_init_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, |
wolfSSL | 0:9d17e4342598 | 1341 | &key->k, &prime, &order)) != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1342 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1343 | |
wolfSSL | 0:9d17e4342598 | 1344 | base = ecc_new_point(); |
wolfSSL | 0:9d17e4342598 | 1345 | if (base == NULL) |
wolfSSL | 0:9d17e4342598 | 1346 | err = MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1347 | |
wolfSSL | 0:9d17e4342598 | 1348 | /* read in the specs for this key */ |
wolfSSL | 0:9d17e4342598 | 1349 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1350 | err = mp_read_radix(&prime, (char *)key->dp->prime, 16); |
wolfSSL | 0:9d17e4342598 | 1351 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1352 | err = mp_read_radix(&order, (char *)key->dp->order, 16); |
wolfSSL | 0:9d17e4342598 | 1353 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1354 | err = mp_read_radix(&base->x, (char *)key->dp->Gx, 16); |
wolfSSL | 0:9d17e4342598 | 1355 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1356 | err = mp_read_radix(&base->y, (char *)key->dp->Gy, 16); |
wolfSSL | 0:9d17e4342598 | 1357 | |
wolfSSL | 0:9d17e4342598 | 1358 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1359 | mp_set(&base->z, 1); |
wolfSSL | 0:9d17e4342598 | 1360 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1361 | err = mp_read_unsigned_bin(&key->k, (byte*)buf, keysize); |
wolfSSL | 0:9d17e4342598 | 1362 | |
wolfSSL | 0:9d17e4342598 | 1363 | /* the key should be smaller than the order of base point */ |
wolfSSL | 0:9d17e4342598 | 1364 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1365 | if (mp_cmp(&key->k, &order) != MP_LT) |
wolfSSL | 0:9d17e4342598 | 1366 | err = mp_mod(&key->k, &order, &key->k); |
wolfSSL | 0:9d17e4342598 | 1367 | } |
wolfSSL | 0:9d17e4342598 | 1368 | /* make the public key */ |
wolfSSL | 0:9d17e4342598 | 1369 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1370 | err = ecc_mulmod(&key->k, base, &key->pubkey, &prime, 1); |
wolfSSL | 0:9d17e4342598 | 1371 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1372 | key->type = ECC_PRIVATEKEY; |
wolfSSL | 0:9d17e4342598 | 1373 | |
wolfSSL | 0:9d17e4342598 | 1374 | if (err != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1375 | /* clean up */ |
wolfSSL | 0:9d17e4342598 | 1376 | mp_clear(&key->pubkey.x); |
wolfSSL | 0:9d17e4342598 | 1377 | mp_clear(&key->pubkey.y); |
wolfSSL | 0:9d17e4342598 | 1378 | mp_clear(&key->pubkey.z); |
wolfSSL | 0:9d17e4342598 | 1379 | mp_clear(&key->k); |
wolfSSL | 0:9d17e4342598 | 1380 | } |
wolfSSL | 0:9d17e4342598 | 1381 | ecc_del_point(base); |
wolfSSL | 0:9d17e4342598 | 1382 | mp_clear(&prime); |
wolfSSL | 0:9d17e4342598 | 1383 | mp_clear(&order); |
wolfSSL | 0:9d17e4342598 | 1384 | #ifdef ECC_CLEAN_STACK |
wolfSSL | 0:9d17e4342598 | 1385 | XMEMSET(buff, 0, ECC_MAXSIZE); |
wolfSSL | 0:9d17e4342598 | 1386 | #endif |
wolfSSL | 0:9d17e4342598 | 1387 | return err; |
wolfSSL | 0:9d17e4342598 | 1388 | } |
wolfSSL | 0:9d17e4342598 | 1389 | |
wolfSSL | 0:9d17e4342598 | 1390 | |
wolfSSL | 0:9d17e4342598 | 1391 | /* Setup dynamic pointers is using normal math for proper freeing */ |
wolfSSL | 0:9d17e4342598 | 1392 | void ecc_init(ecc_key* key) |
wolfSSL | 0:9d17e4342598 | 1393 | { |
wolfSSL | 0:9d17e4342598 | 1394 | (void)key; |
wolfSSL | 0:9d17e4342598 | 1395 | #ifndef USE_FAST_MATH |
wolfSSL | 0:9d17e4342598 | 1396 | key->pubkey.x.dp = NULL; |
wolfSSL | 0:9d17e4342598 | 1397 | key->pubkey.y.dp = NULL; |
wolfSSL | 0:9d17e4342598 | 1398 | key->pubkey.z.dp = NULL; |
wolfSSL | 0:9d17e4342598 | 1399 | |
wolfSSL | 0:9d17e4342598 | 1400 | key->k.dp = NULL; |
wolfSSL | 0:9d17e4342598 | 1401 | #endif |
wolfSSL | 0:9d17e4342598 | 1402 | } |
wolfSSL | 0:9d17e4342598 | 1403 | |
wolfSSL | 0:9d17e4342598 | 1404 | |
wolfSSL | 0:9d17e4342598 | 1405 | /** |
wolfSSL | 0:9d17e4342598 | 1406 | Sign a message digest |
wolfSSL | 0:9d17e4342598 | 1407 | in The message digest to sign |
wolfSSL | 0:9d17e4342598 | 1408 | inlen The length of the digest |
wolfSSL | 0:9d17e4342598 | 1409 | out [out] The destination for the signature |
wolfSSL | 0:9d17e4342598 | 1410 | outlen [in/out] The max size and resulting size of the signature |
wolfSSL | 0:9d17e4342598 | 1411 | key A private ECC key |
wolfSSL | 0:9d17e4342598 | 1412 | return MP_OKAY if successful |
wolfSSL | 0:9d17e4342598 | 1413 | */ |
wolfSSL | 0:9d17e4342598 | 1414 | int ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen, |
wolfSSL | 0:9d17e4342598 | 1415 | RNG* rng, ecc_key* key) |
wolfSSL | 0:9d17e4342598 | 1416 | { |
wolfSSL | 0:9d17e4342598 | 1417 | mp_int r; |
wolfSSL | 0:9d17e4342598 | 1418 | mp_int s; |
wolfSSL | 0:9d17e4342598 | 1419 | mp_int e; |
wolfSSL | 0:9d17e4342598 | 1420 | mp_int p; |
wolfSSL | 0:9d17e4342598 | 1421 | int err; |
wolfSSL | 0:9d17e4342598 | 1422 | |
wolfSSL | 0:9d17e4342598 | 1423 | if (in == NULL || out == NULL || outlen == NULL || key == NULL || rng ==NULL) |
wolfSSL | 0:9d17e4342598 | 1424 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1425 | |
wolfSSL | 0:9d17e4342598 | 1426 | /* is this a private key? */ |
wolfSSL | 0:9d17e4342598 | 1427 | if (key->type != ECC_PRIVATEKEY) { |
wolfSSL | 0:9d17e4342598 | 1428 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1429 | } |
wolfSSL | 0:9d17e4342598 | 1430 | |
wolfSSL | 0:9d17e4342598 | 1431 | /* is the IDX valid ? */ |
wolfSSL | 0:9d17e4342598 | 1432 | if (ecc_is_valid_idx(key->idx) != 1) { |
wolfSSL | 0:9d17e4342598 | 1433 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1434 | } |
wolfSSL | 0:9d17e4342598 | 1435 | |
wolfSSL | 0:9d17e4342598 | 1436 | /* get the hash and load it as a bignum into 'e' */ |
wolfSSL | 0:9d17e4342598 | 1437 | /* init the bignums */ |
wolfSSL | 0:9d17e4342598 | 1438 | if ((err = mp_init_multi(&r, &s, &p, &e, NULL, NULL)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1439 | return err; |
wolfSSL | 0:9d17e4342598 | 1440 | } |
wolfSSL | 0:9d17e4342598 | 1441 | err = mp_read_radix(&p, (char *)key->dp->order, 16); |
wolfSSL | 0:9d17e4342598 | 1442 | |
wolfSSL | 0:9d17e4342598 | 1443 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1444 | /* we may need to truncate if hash is longer than key size */ |
wolfSSL | 0:9d17e4342598 | 1445 | word32 orderBits = mp_count_bits(&p); |
wolfSSL | 0:9d17e4342598 | 1446 | |
wolfSSL | 0:9d17e4342598 | 1447 | /* truncate down to byte size, may be all that's needed */ |
wolfSSL | 0:9d17e4342598 | 1448 | if ( (CYASSL_BIT_SIZE * inlen) > orderBits) |
wolfSSL | 0:9d17e4342598 | 1449 | inlen = (orderBits + CYASSL_BIT_SIZE - 1)/CYASSL_BIT_SIZE; |
wolfSSL | 0:9d17e4342598 | 1450 | err = mp_read_unsigned_bin(&e, (byte*)in, inlen); |
wolfSSL | 0:9d17e4342598 | 1451 | |
wolfSSL | 0:9d17e4342598 | 1452 | /* may still need bit truncation too */ |
wolfSSL | 0:9d17e4342598 | 1453 | if (err == MP_OKAY && (CYASSL_BIT_SIZE * inlen) > orderBits) |
wolfSSL | 0:9d17e4342598 | 1454 | mp_rshb(&e, CYASSL_BIT_SIZE - (orderBits & 0x7)); |
wolfSSL | 0:9d17e4342598 | 1455 | } |
wolfSSL | 0:9d17e4342598 | 1456 | |
wolfSSL | 0:9d17e4342598 | 1457 | /* make up a key and export the public copy */ |
wolfSSL | 0:9d17e4342598 | 1458 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1459 | ecc_key pubkey; |
wolfSSL | 0:9d17e4342598 | 1460 | ecc_init(&pubkey); |
wolfSSL | 0:9d17e4342598 | 1461 | for (;;) { |
wolfSSL | 0:9d17e4342598 | 1462 | err = ecc_make_key_ex(rng, &pubkey, key->dp); |
wolfSSL | 0:9d17e4342598 | 1463 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1464 | |
wolfSSL | 0:9d17e4342598 | 1465 | /* find r = x1 mod n */ |
wolfSSL | 0:9d17e4342598 | 1466 | err = mp_mod(&pubkey.pubkey.x, &p, &r); |
wolfSSL | 0:9d17e4342598 | 1467 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1468 | |
wolfSSL | 0:9d17e4342598 | 1469 | if (mp_iszero(&r) == MP_YES) |
wolfSSL | 0:9d17e4342598 | 1470 | ecc_free(&pubkey); |
wolfSSL | 0:9d17e4342598 | 1471 | else { |
wolfSSL | 0:9d17e4342598 | 1472 | /* find s = (e + xr)/k */ |
wolfSSL | 0:9d17e4342598 | 1473 | err = mp_invmod(&pubkey.k, &p, &pubkey.k); |
wolfSSL | 0:9d17e4342598 | 1474 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1475 | |
wolfSSL | 0:9d17e4342598 | 1476 | err = mp_mulmod(&key->k, &r, &p, &s); /* s = xr */ |
wolfSSL | 0:9d17e4342598 | 1477 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1478 | |
wolfSSL | 0:9d17e4342598 | 1479 | err = mp_add(&e, &s, &s); /* s = e + xr */ |
wolfSSL | 0:9d17e4342598 | 1480 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1481 | |
wolfSSL | 0:9d17e4342598 | 1482 | err = mp_mod(&s, &p, &s); /* s = e + xr */ |
wolfSSL | 0:9d17e4342598 | 1483 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1484 | |
wolfSSL | 0:9d17e4342598 | 1485 | err = mp_mulmod(&s, &pubkey.k, &p, &s); /* s = (e + xr)/k */ |
wolfSSL | 0:9d17e4342598 | 1486 | if (err != MP_OKAY) break; |
wolfSSL | 0:9d17e4342598 | 1487 | |
wolfSSL | 0:9d17e4342598 | 1488 | ecc_free(&pubkey); |
wolfSSL | 0:9d17e4342598 | 1489 | if (mp_iszero(&s) == MP_NO) |
wolfSSL | 0:9d17e4342598 | 1490 | break; |
wolfSSL | 0:9d17e4342598 | 1491 | } |
wolfSSL | 0:9d17e4342598 | 1492 | } |
wolfSSL | 0:9d17e4342598 | 1493 | ecc_free(&pubkey); |
wolfSSL | 0:9d17e4342598 | 1494 | } |
wolfSSL | 0:9d17e4342598 | 1495 | |
wolfSSL | 0:9d17e4342598 | 1496 | /* store as SEQUENCE { r, s -- integer } */ |
wolfSSL | 0:9d17e4342598 | 1497 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1498 | err = StoreECC_DSA_Sig(out, outlen, &r, &s); |
wolfSSL | 0:9d17e4342598 | 1499 | |
wolfSSL | 0:9d17e4342598 | 1500 | mp_clear(&r); |
wolfSSL | 0:9d17e4342598 | 1501 | mp_clear(&s); |
wolfSSL | 0:9d17e4342598 | 1502 | mp_clear(&p); |
wolfSSL | 0:9d17e4342598 | 1503 | mp_clear(&e); |
wolfSSL | 0:9d17e4342598 | 1504 | |
wolfSSL | 0:9d17e4342598 | 1505 | return err; |
wolfSSL | 0:9d17e4342598 | 1506 | } |
wolfSSL | 0:9d17e4342598 | 1507 | |
wolfSSL | 0:9d17e4342598 | 1508 | |
wolfSSL | 0:9d17e4342598 | 1509 | /** |
wolfSSL | 0:9d17e4342598 | 1510 | Free an ECC key from memory |
wolfSSL | 0:9d17e4342598 | 1511 | key The key you wish to free |
wolfSSL | 0:9d17e4342598 | 1512 | */ |
wolfSSL | 0:9d17e4342598 | 1513 | void ecc_free(ecc_key* key) |
wolfSSL | 0:9d17e4342598 | 1514 | { |
wolfSSL | 0:9d17e4342598 | 1515 | if (key == NULL) |
wolfSSL | 0:9d17e4342598 | 1516 | return; |
wolfSSL | 0:9d17e4342598 | 1517 | |
wolfSSL | 0:9d17e4342598 | 1518 | mp_clear(&key->pubkey.x); |
wolfSSL | 0:9d17e4342598 | 1519 | mp_clear(&key->pubkey.y); |
wolfSSL | 0:9d17e4342598 | 1520 | mp_clear(&key->pubkey.z); |
wolfSSL | 0:9d17e4342598 | 1521 | mp_clear(&key->k); |
wolfSSL | 0:9d17e4342598 | 1522 | } |
wolfSSL | 0:9d17e4342598 | 1523 | |
wolfSSL | 0:9d17e4342598 | 1524 | |
wolfSSL | 0:9d17e4342598 | 1525 | #ifdef USE_FAST_MATH |
wolfSSL | 0:9d17e4342598 | 1526 | #define GEN_MEM_ERR FP_MEM |
wolfSSL | 0:9d17e4342598 | 1527 | #else |
wolfSSL | 0:9d17e4342598 | 1528 | #define GEN_MEM_ERR MP_MEM |
wolfSSL | 0:9d17e4342598 | 1529 | #endif |
wolfSSL | 0:9d17e4342598 | 1530 | |
wolfSSL | 0:9d17e4342598 | 1531 | #ifdef ECC_SHAMIR |
wolfSSL | 0:9d17e4342598 | 1532 | |
wolfSSL | 0:9d17e4342598 | 1533 | /** Computes kA*A + kB*B = C using Shamir's Trick |
wolfSSL | 0:9d17e4342598 | 1534 | A First point to multiply |
wolfSSL | 0:9d17e4342598 | 1535 | kA What to multiple A by |
wolfSSL | 0:9d17e4342598 | 1536 | B Second point to multiply |
wolfSSL | 0:9d17e4342598 | 1537 | kB What to multiple B by |
wolfSSL | 0:9d17e4342598 | 1538 | C [out] Destination point (can overlap with A or B) |
wolfSSL | 0:9d17e4342598 | 1539 | modulus Modulus for curve |
wolfSSL | 0:9d17e4342598 | 1540 | return MP_OKAY on success |
wolfSSL | 0:9d17e4342598 | 1541 | */ |
wolfSSL | 0:9d17e4342598 | 1542 | #ifdef FP_ECC |
wolfSSL | 0:9d17e4342598 | 1543 | static int normal_ecc_mul2add(ecc_point* A, mp_int* kA, |
wolfSSL | 0:9d17e4342598 | 1544 | ecc_point* B, mp_int* kB, |
wolfSSL | 0:9d17e4342598 | 1545 | ecc_point* C, mp_int* modulus) |
wolfSSL | 0:9d17e4342598 | 1546 | #else |
wolfSSL | 0:9d17e4342598 | 1547 | static int ecc_mul2add(ecc_point* A, mp_int* kA, |
wolfSSL | 0:9d17e4342598 | 1548 | ecc_point* B, mp_int* kB, |
wolfSSL | 0:9d17e4342598 | 1549 | ecc_point* C, mp_int* modulus) |
wolfSSL | 0:9d17e4342598 | 1550 | #endif |
wolfSSL | 0:9d17e4342598 | 1551 | { |
wolfSSL | 0:9d17e4342598 | 1552 | ecc_point* precomp[16]; |
wolfSSL | 0:9d17e4342598 | 1553 | unsigned bitbufA, bitbufB, lenA, lenB, len, x, y, nA, nB, nibble; |
wolfSSL | 0:9d17e4342598 | 1554 | unsigned char* tA; |
wolfSSL | 0:9d17e4342598 | 1555 | unsigned char* tB; |
wolfSSL | 0:9d17e4342598 | 1556 | int err = MP_OKAY, first; |
wolfSSL | 0:9d17e4342598 | 1557 | int muInit = 0; |
wolfSSL | 0:9d17e4342598 | 1558 | int tableInit = 0; |
wolfSSL | 0:9d17e4342598 | 1559 | mp_digit mp; |
wolfSSL | 0:9d17e4342598 | 1560 | mp_int mu; |
wolfSSL | 0:9d17e4342598 | 1561 | |
wolfSSL | 0:9d17e4342598 | 1562 | /* argchks */ |
wolfSSL | 0:9d17e4342598 | 1563 | if (A == NULL || kA == NULL || B == NULL || kB == NULL || C == NULL || |
wolfSSL | 0:9d17e4342598 | 1564 | modulus == NULL) |
wolfSSL | 0:9d17e4342598 | 1565 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1566 | |
wolfSSL | 0:9d17e4342598 | 1567 | |
wolfSSL | 0:9d17e4342598 | 1568 | /* allocate memory */ |
wolfSSL | 0:9d17e4342598 | 1569 | tA = XMALLOC(ECC_BUFSIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
wolfSSL | 0:9d17e4342598 | 1570 | if (tA == NULL) { |
wolfSSL | 0:9d17e4342598 | 1571 | return GEN_MEM_ERR; |
wolfSSL | 0:9d17e4342598 | 1572 | } |
wolfSSL | 0:9d17e4342598 | 1573 | tB = XMALLOC(ECC_BUFSIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
wolfSSL | 0:9d17e4342598 | 1574 | if (tB == NULL) { |
wolfSSL | 0:9d17e4342598 | 1575 | XFREE(tA, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
wolfSSL | 0:9d17e4342598 | 1576 | return GEN_MEM_ERR; |
wolfSSL | 0:9d17e4342598 | 1577 | } |
wolfSSL | 0:9d17e4342598 | 1578 | XMEMSET(tA, 0, ECC_BUFSIZE); |
wolfSSL | 0:9d17e4342598 | 1579 | XMEMSET(tB, 0, ECC_BUFSIZE); |
wolfSSL | 0:9d17e4342598 | 1580 | |
wolfSSL | 0:9d17e4342598 | 1581 | /* get sizes */ |
wolfSSL | 0:9d17e4342598 | 1582 | lenA = mp_unsigned_bin_size(kA); |
wolfSSL | 0:9d17e4342598 | 1583 | lenB = mp_unsigned_bin_size(kB); |
wolfSSL | 0:9d17e4342598 | 1584 | len = MAX(lenA, lenB); |
wolfSSL | 0:9d17e4342598 | 1585 | |
wolfSSL | 0:9d17e4342598 | 1586 | /* sanity check */ |
wolfSSL | 0:9d17e4342598 | 1587 | if ((lenA > ECC_BUFSIZE) || (lenB > ECC_BUFSIZE)) { |
wolfSSL | 0:9d17e4342598 | 1588 | err = BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 1589 | } |
wolfSSL | 0:9d17e4342598 | 1590 | |
wolfSSL | 0:9d17e4342598 | 1591 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1592 | /* extract and justify kA */ |
wolfSSL | 0:9d17e4342598 | 1593 | err = mp_to_unsigned_bin(kA, (len - lenA) + tA); |
wolfSSL | 0:9d17e4342598 | 1594 | |
wolfSSL | 0:9d17e4342598 | 1595 | /* extract and justify kB */ |
wolfSSL | 0:9d17e4342598 | 1596 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1597 | err = mp_to_unsigned_bin(kB, (len - lenB) + tB); |
wolfSSL | 0:9d17e4342598 | 1598 | |
wolfSSL | 0:9d17e4342598 | 1599 | /* allocate the table */ |
wolfSSL | 0:9d17e4342598 | 1600 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1601 | for (x = 0; x < 16; x++) { |
wolfSSL | 0:9d17e4342598 | 1602 | precomp[x] = ecc_new_point(); |
wolfSSL | 0:9d17e4342598 | 1603 | if (precomp[x] == NULL) { |
wolfSSL | 0:9d17e4342598 | 1604 | for (y = 0; y < x; ++y) { |
wolfSSL | 0:9d17e4342598 | 1605 | ecc_del_point(precomp[y]); |
wolfSSL | 0:9d17e4342598 | 1606 | } |
wolfSSL | 0:9d17e4342598 | 1607 | err = GEN_MEM_ERR; |
wolfSSL | 0:9d17e4342598 | 1608 | break; |
wolfSSL | 0:9d17e4342598 | 1609 | } |
wolfSSL | 0:9d17e4342598 | 1610 | } |
wolfSSL | 0:9d17e4342598 | 1611 | } |
wolfSSL | 0:9d17e4342598 | 1612 | } |
wolfSSL | 0:9d17e4342598 | 1613 | |
wolfSSL | 0:9d17e4342598 | 1614 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1615 | tableInit = 1; |
wolfSSL | 0:9d17e4342598 | 1616 | |
wolfSSL | 0:9d17e4342598 | 1617 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1618 | /* init montgomery reduction */ |
wolfSSL | 0:9d17e4342598 | 1619 | err = mp_montgomery_setup(modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1620 | |
wolfSSL | 0:9d17e4342598 | 1621 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1622 | err = mp_init(&mu); |
wolfSSL | 0:9d17e4342598 | 1623 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1624 | muInit = 1; |
wolfSSL | 0:9d17e4342598 | 1625 | |
wolfSSL | 0:9d17e4342598 | 1626 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1627 | err = mp_montgomery_calc_normalization(&mu, modulus); |
wolfSSL | 0:9d17e4342598 | 1628 | |
wolfSSL | 0:9d17e4342598 | 1629 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1630 | /* copy ones ... */ |
wolfSSL | 0:9d17e4342598 | 1631 | err = mp_mulmod(&A->x, &mu, modulus, &precomp[1]->x); |
wolfSSL | 0:9d17e4342598 | 1632 | |
wolfSSL | 0:9d17e4342598 | 1633 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1634 | err = mp_mulmod(&A->y, &mu, modulus, &precomp[1]->y); |
wolfSSL | 0:9d17e4342598 | 1635 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1636 | err = mp_mulmod(&A->z, &mu, modulus, &precomp[1]->z); |
wolfSSL | 0:9d17e4342598 | 1637 | |
wolfSSL | 0:9d17e4342598 | 1638 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1639 | err = mp_mulmod(&B->x, &mu, modulus, &precomp[1<<2]->x); |
wolfSSL | 0:9d17e4342598 | 1640 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1641 | err = mp_mulmod(&B->y, &mu, modulus, &precomp[1<<2]->y); |
wolfSSL | 0:9d17e4342598 | 1642 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1643 | err = mp_mulmod(&B->z, &mu, modulus, &precomp[1<<2]->z); |
wolfSSL | 0:9d17e4342598 | 1644 | |
wolfSSL | 0:9d17e4342598 | 1645 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1646 | /* precomp [i,0](A + B) table */ |
wolfSSL | 0:9d17e4342598 | 1647 | err = ecc_projective_dbl_point(precomp[1], precomp[2], modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1648 | |
wolfSSL | 0:9d17e4342598 | 1649 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1650 | err = ecc_projective_add_point(precomp[1], precomp[2], precomp[3], |
wolfSSL | 0:9d17e4342598 | 1651 | modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1652 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1653 | /* precomp [0,i](A + B) table */ |
wolfSSL | 0:9d17e4342598 | 1654 | err = ecc_projective_dbl_point(precomp[1<<2], precomp[2<<2], modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1655 | |
wolfSSL | 0:9d17e4342598 | 1656 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1657 | err = ecc_projective_add_point(precomp[1<<2], precomp[2<<2], precomp[3<<2], |
wolfSSL | 0:9d17e4342598 | 1658 | modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1659 | |
wolfSSL | 0:9d17e4342598 | 1660 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1661 | /* precomp [i,j](A + B) table (i != 0, j != 0) */ |
wolfSSL | 0:9d17e4342598 | 1662 | for (x = 1; x < 4; x++) { |
wolfSSL | 0:9d17e4342598 | 1663 | for (y = 1; y < 4; y++) { |
wolfSSL | 0:9d17e4342598 | 1664 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1665 | err = ecc_projective_add_point(precomp[x], precomp[(y<<2)], |
wolfSSL | 0:9d17e4342598 | 1666 | precomp[x+(y<<2)], modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1667 | } |
wolfSSL | 0:9d17e4342598 | 1668 | } |
wolfSSL | 0:9d17e4342598 | 1669 | } |
wolfSSL | 0:9d17e4342598 | 1670 | |
wolfSSL | 0:9d17e4342598 | 1671 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1672 | nibble = 3; |
wolfSSL | 0:9d17e4342598 | 1673 | first = 1; |
wolfSSL | 0:9d17e4342598 | 1674 | bitbufA = tA[0]; |
wolfSSL | 0:9d17e4342598 | 1675 | bitbufB = tB[0]; |
wolfSSL | 0:9d17e4342598 | 1676 | |
wolfSSL | 0:9d17e4342598 | 1677 | /* for every byte of the multiplicands */ |
wolfSSL | 0:9d17e4342598 | 1678 | for (x = -1;; ) { |
wolfSSL | 0:9d17e4342598 | 1679 | /* grab a nibble */ |
wolfSSL | 0:9d17e4342598 | 1680 | if (++nibble == 4) { |
wolfSSL | 0:9d17e4342598 | 1681 | ++x; if (x == len) break; |
wolfSSL | 0:9d17e4342598 | 1682 | bitbufA = tA[x]; |
wolfSSL | 0:9d17e4342598 | 1683 | bitbufB = tB[x]; |
wolfSSL | 0:9d17e4342598 | 1684 | nibble = 0; |
wolfSSL | 0:9d17e4342598 | 1685 | } |
wolfSSL | 0:9d17e4342598 | 1686 | |
wolfSSL | 0:9d17e4342598 | 1687 | /* extract two bits from both, shift/update */ |
wolfSSL | 0:9d17e4342598 | 1688 | nA = (bitbufA >> 6) & 0x03; |
wolfSSL | 0:9d17e4342598 | 1689 | nB = (bitbufB >> 6) & 0x03; |
wolfSSL | 0:9d17e4342598 | 1690 | bitbufA = (bitbufA << 2) & 0xFF; |
wolfSSL | 0:9d17e4342598 | 1691 | bitbufB = (bitbufB << 2) & 0xFF; |
wolfSSL | 0:9d17e4342598 | 1692 | |
wolfSSL | 0:9d17e4342598 | 1693 | /* if both zero, if first, continue */ |
wolfSSL | 0:9d17e4342598 | 1694 | if ((nA == 0) && (nB == 0) && (first == 1)) { |
wolfSSL | 0:9d17e4342598 | 1695 | continue; |
wolfSSL | 0:9d17e4342598 | 1696 | } |
wolfSSL | 0:9d17e4342598 | 1697 | |
wolfSSL | 0:9d17e4342598 | 1698 | /* double twice, only if this isn't the first */ |
wolfSSL | 0:9d17e4342598 | 1699 | if (first == 0) { |
wolfSSL | 0:9d17e4342598 | 1700 | /* double twice */ |
wolfSSL | 0:9d17e4342598 | 1701 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1702 | err = ecc_projective_dbl_point(C, C, modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1703 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1704 | err = ecc_projective_dbl_point(C, C, modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1705 | else |
wolfSSL | 0:9d17e4342598 | 1706 | break; |
wolfSSL | 0:9d17e4342598 | 1707 | } |
wolfSSL | 0:9d17e4342598 | 1708 | |
wolfSSL | 0:9d17e4342598 | 1709 | /* if not both zero */ |
wolfSSL | 0:9d17e4342598 | 1710 | if ((nA != 0) || (nB != 0)) { |
wolfSSL | 0:9d17e4342598 | 1711 | if (first == 1) { |
wolfSSL | 0:9d17e4342598 | 1712 | /* if first, copy from table */ |
wolfSSL | 0:9d17e4342598 | 1713 | first = 0; |
wolfSSL | 0:9d17e4342598 | 1714 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1715 | err = mp_copy(&precomp[nA + (nB<<2)]->x, &C->x); |
wolfSSL | 0:9d17e4342598 | 1716 | |
wolfSSL | 0:9d17e4342598 | 1717 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1718 | err = mp_copy(&precomp[nA + (nB<<2)]->y, &C->y); |
wolfSSL | 0:9d17e4342598 | 1719 | |
wolfSSL | 0:9d17e4342598 | 1720 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1721 | err = mp_copy(&precomp[nA + (nB<<2)]->z, &C->z); |
wolfSSL | 0:9d17e4342598 | 1722 | else |
wolfSSL | 0:9d17e4342598 | 1723 | break; |
wolfSSL | 0:9d17e4342598 | 1724 | } else { |
wolfSSL | 0:9d17e4342598 | 1725 | /* if not first, add from table */ |
wolfSSL | 0:9d17e4342598 | 1726 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1727 | err = ecc_projective_add_point(C, precomp[nA + (nB<<2)], C, |
wolfSSL | 0:9d17e4342598 | 1728 | modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1729 | else |
wolfSSL | 0:9d17e4342598 | 1730 | break; |
wolfSSL | 0:9d17e4342598 | 1731 | } |
wolfSSL | 0:9d17e4342598 | 1732 | } |
wolfSSL | 0:9d17e4342598 | 1733 | } |
wolfSSL | 0:9d17e4342598 | 1734 | } |
wolfSSL | 0:9d17e4342598 | 1735 | |
wolfSSL | 0:9d17e4342598 | 1736 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1737 | /* reduce to affine */ |
wolfSSL | 0:9d17e4342598 | 1738 | err = ecc_map(C, modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 1739 | |
wolfSSL | 0:9d17e4342598 | 1740 | /* clean up */ |
wolfSSL | 0:9d17e4342598 | 1741 | if (muInit) |
wolfSSL | 0:9d17e4342598 | 1742 | mp_clear(&mu); |
wolfSSL | 0:9d17e4342598 | 1743 | |
wolfSSL | 0:9d17e4342598 | 1744 | if (tableInit) { |
wolfSSL | 0:9d17e4342598 | 1745 | for (x = 0; x < 16; x++) { |
wolfSSL | 0:9d17e4342598 | 1746 | ecc_del_point(precomp[x]); |
wolfSSL | 0:9d17e4342598 | 1747 | } |
wolfSSL | 0:9d17e4342598 | 1748 | } |
wolfSSL | 0:9d17e4342598 | 1749 | #ifdef ECC_CLEAN_STACK |
wolfSSL | 0:9d17e4342598 | 1750 | XMEMSET(tA, 0, ECC_BUF_SIZE); |
wolfSSL | 0:9d17e4342598 | 1751 | XMEMSET(tB, 0, ECC_BUF_SIZE); |
wolfSSL | 0:9d17e4342598 | 1752 | #endif |
wolfSSL | 0:9d17e4342598 | 1753 | XFREE(tA, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
wolfSSL | 0:9d17e4342598 | 1754 | XFREE(tB, NULL, DYNAMIC_TYPE_TMP_BUFFER); |
wolfSSL | 0:9d17e4342598 | 1755 | |
wolfSSL | 0:9d17e4342598 | 1756 | return err; |
wolfSSL | 0:9d17e4342598 | 1757 | } |
wolfSSL | 0:9d17e4342598 | 1758 | |
wolfSSL | 0:9d17e4342598 | 1759 | |
wolfSSL | 0:9d17e4342598 | 1760 | #endif /* ECC_SHAMIR */ |
wolfSSL | 0:9d17e4342598 | 1761 | |
wolfSSL | 0:9d17e4342598 | 1762 | |
wolfSSL | 0:9d17e4342598 | 1763 | |
wolfSSL | 0:9d17e4342598 | 1764 | /* verify |
wolfSSL | 0:9d17e4342598 | 1765 | * |
wolfSSL | 0:9d17e4342598 | 1766 | * w = s^-1 mod n |
wolfSSL | 0:9d17e4342598 | 1767 | * u1 = xw |
wolfSSL | 0:9d17e4342598 | 1768 | * u2 = rw |
wolfSSL | 0:9d17e4342598 | 1769 | * X = u1*G + u2*Q |
wolfSSL | 0:9d17e4342598 | 1770 | * v = X_x1 mod n |
wolfSSL | 0:9d17e4342598 | 1771 | * accept if v == r |
wolfSSL | 0:9d17e4342598 | 1772 | */ |
wolfSSL | 0:9d17e4342598 | 1773 | |
wolfSSL | 0:9d17e4342598 | 1774 | /** |
wolfSSL | 0:9d17e4342598 | 1775 | Verify an ECC signature |
wolfSSL | 0:9d17e4342598 | 1776 | sig The signature to verify |
wolfSSL | 0:9d17e4342598 | 1777 | siglen The length of the signature (octets) |
wolfSSL | 0:9d17e4342598 | 1778 | hash The hash (message digest) that was signed |
wolfSSL | 0:9d17e4342598 | 1779 | hashlen The length of the hash (octets) |
wolfSSL | 0:9d17e4342598 | 1780 | stat Result of signature, 1==valid, 0==invalid |
wolfSSL | 0:9d17e4342598 | 1781 | key The corresponding public ECC key |
wolfSSL | 0:9d17e4342598 | 1782 | return MP_OKAY if successful (even if the signature is not valid) |
wolfSSL | 0:9d17e4342598 | 1783 | */ |
wolfSSL | 0:9d17e4342598 | 1784 | int ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash, |
wolfSSL | 0:9d17e4342598 | 1785 | word32 hashlen, int* stat, ecc_key* key) |
wolfSSL | 0:9d17e4342598 | 1786 | { |
wolfSSL | 0:9d17e4342598 | 1787 | ecc_point *mG, *mQ; |
wolfSSL | 0:9d17e4342598 | 1788 | mp_int r; |
wolfSSL | 0:9d17e4342598 | 1789 | mp_int s; |
wolfSSL | 0:9d17e4342598 | 1790 | mp_int v; |
wolfSSL | 0:9d17e4342598 | 1791 | mp_int w; |
wolfSSL | 0:9d17e4342598 | 1792 | mp_int u1; |
wolfSSL | 0:9d17e4342598 | 1793 | mp_int u2; |
wolfSSL | 0:9d17e4342598 | 1794 | mp_int e; |
wolfSSL | 0:9d17e4342598 | 1795 | mp_int p; |
wolfSSL | 0:9d17e4342598 | 1796 | mp_int m; |
wolfSSL | 0:9d17e4342598 | 1797 | int err; |
wolfSSL | 0:9d17e4342598 | 1798 | |
wolfSSL | 0:9d17e4342598 | 1799 | if (sig == NULL || hash == NULL || stat == NULL || key == NULL) |
wolfSSL | 0:9d17e4342598 | 1800 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1801 | |
wolfSSL | 0:9d17e4342598 | 1802 | /* default to invalid signature */ |
wolfSSL | 0:9d17e4342598 | 1803 | *stat = 0; |
wolfSSL | 0:9d17e4342598 | 1804 | |
wolfSSL | 0:9d17e4342598 | 1805 | /* is the IDX valid ? */ |
wolfSSL | 0:9d17e4342598 | 1806 | if (ecc_is_valid_idx(key->idx) != 1) { |
wolfSSL | 0:9d17e4342598 | 1807 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1808 | } |
wolfSSL | 0:9d17e4342598 | 1809 | |
wolfSSL | 0:9d17e4342598 | 1810 | /* allocate ints */ |
wolfSSL | 0:9d17e4342598 | 1811 | if ((err = mp_init_multi(&v, &w, &u1, &u2, &p, &e)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1812 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1813 | } |
wolfSSL | 0:9d17e4342598 | 1814 | |
wolfSSL | 0:9d17e4342598 | 1815 | if ((err = mp_init(&m)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1816 | mp_clear(&v); |
wolfSSL | 0:9d17e4342598 | 1817 | mp_clear(&w); |
wolfSSL | 0:9d17e4342598 | 1818 | mp_clear(&u1); |
wolfSSL | 0:9d17e4342598 | 1819 | mp_clear(&u2); |
wolfSSL | 0:9d17e4342598 | 1820 | mp_clear(&p); |
wolfSSL | 0:9d17e4342598 | 1821 | mp_clear(&e); |
wolfSSL | 0:9d17e4342598 | 1822 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1823 | } |
wolfSSL | 0:9d17e4342598 | 1824 | |
wolfSSL | 0:9d17e4342598 | 1825 | /* allocate points */ |
wolfSSL | 0:9d17e4342598 | 1826 | mG = ecc_new_point(); |
wolfSSL | 0:9d17e4342598 | 1827 | mQ = ecc_new_point(); |
wolfSSL | 0:9d17e4342598 | 1828 | if (mQ == NULL || mG == NULL) |
wolfSSL | 0:9d17e4342598 | 1829 | err = MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 1830 | |
wolfSSL | 0:9d17e4342598 | 1831 | /* Note, DecodeECC_DSA_Sig() calls mp_init() on r and s. |
wolfSSL | 0:9d17e4342598 | 1832 | * If either of those don't allocate correctly, none of |
wolfSSL | 0:9d17e4342598 | 1833 | * the rest of this function will execute, and everything |
wolfSSL | 0:9d17e4342598 | 1834 | * gets cleaned up at the end. */ |
wolfSSL | 0:9d17e4342598 | 1835 | XMEMSET(&r, 0, sizeof(r)); |
wolfSSL | 0:9d17e4342598 | 1836 | XMEMSET(&s, 0, sizeof(s)); |
wolfSSL | 0:9d17e4342598 | 1837 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1838 | err = DecodeECC_DSA_Sig(sig, siglen, &r, &s); |
wolfSSL | 0:9d17e4342598 | 1839 | |
wolfSSL | 0:9d17e4342598 | 1840 | /* get the order */ |
wolfSSL | 0:9d17e4342598 | 1841 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1842 | err = mp_read_radix(&p, (char *)key->dp->order, 16); |
wolfSSL | 0:9d17e4342598 | 1843 | |
wolfSSL | 0:9d17e4342598 | 1844 | /* get the modulus */ |
wolfSSL | 0:9d17e4342598 | 1845 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1846 | err = mp_read_radix(&m, (char *)key->dp->prime, 16); |
wolfSSL | 0:9d17e4342598 | 1847 | |
wolfSSL | 0:9d17e4342598 | 1848 | /* check for zero */ |
wolfSSL | 0:9d17e4342598 | 1849 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1850 | if (mp_iszero(&r) || mp_iszero(&s) || mp_cmp(&r, &p) != MP_LT || |
wolfSSL | 0:9d17e4342598 | 1851 | mp_cmp(&s, &p) != MP_LT) |
wolfSSL | 0:9d17e4342598 | 1852 | err = MP_ZERO_E; |
wolfSSL | 0:9d17e4342598 | 1853 | } |
wolfSSL | 0:9d17e4342598 | 1854 | /* read hash */ |
wolfSSL | 0:9d17e4342598 | 1855 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1856 | /* we may need to truncate if hash is longer than key size */ |
wolfSSL | 0:9d17e4342598 | 1857 | unsigned int orderBits = mp_count_bits(&p); |
wolfSSL | 0:9d17e4342598 | 1858 | |
wolfSSL | 0:9d17e4342598 | 1859 | /* truncate down to byte size, may be all that's needed */ |
wolfSSL | 0:9d17e4342598 | 1860 | if ( (CYASSL_BIT_SIZE * hashlen) > orderBits) |
wolfSSL | 0:9d17e4342598 | 1861 | hashlen = (orderBits + CYASSL_BIT_SIZE - 1)/CYASSL_BIT_SIZE; |
wolfSSL | 0:9d17e4342598 | 1862 | err = mp_read_unsigned_bin(&e, hash, hashlen); |
wolfSSL | 0:9d17e4342598 | 1863 | |
wolfSSL | 0:9d17e4342598 | 1864 | /* may still need bit truncation too */ |
wolfSSL | 0:9d17e4342598 | 1865 | if (err == MP_OKAY && (CYASSL_BIT_SIZE * hashlen) > orderBits) |
wolfSSL | 0:9d17e4342598 | 1866 | mp_rshb(&e, CYASSL_BIT_SIZE - (orderBits & 0x7)); |
wolfSSL | 0:9d17e4342598 | 1867 | } |
wolfSSL | 0:9d17e4342598 | 1868 | |
wolfSSL | 0:9d17e4342598 | 1869 | /* w = s^-1 mod n */ |
wolfSSL | 0:9d17e4342598 | 1870 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1871 | err = mp_invmod(&s, &p, &w); |
wolfSSL | 0:9d17e4342598 | 1872 | |
wolfSSL | 0:9d17e4342598 | 1873 | /* u1 = ew */ |
wolfSSL | 0:9d17e4342598 | 1874 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1875 | err = mp_mulmod(&e, &w, &p, &u1); |
wolfSSL | 0:9d17e4342598 | 1876 | |
wolfSSL | 0:9d17e4342598 | 1877 | /* u2 = rw */ |
wolfSSL | 0:9d17e4342598 | 1878 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1879 | err = mp_mulmod(&r, &w, &p, &u2); |
wolfSSL | 0:9d17e4342598 | 1880 | |
wolfSSL | 0:9d17e4342598 | 1881 | /* find mG and mQ */ |
wolfSSL | 0:9d17e4342598 | 1882 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1883 | err = mp_read_radix(&mG->x, (char *)key->dp->Gx, 16); |
wolfSSL | 0:9d17e4342598 | 1884 | |
wolfSSL | 0:9d17e4342598 | 1885 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1886 | err = mp_read_radix(&mG->y, (char *)key->dp->Gy, 16); |
wolfSSL | 0:9d17e4342598 | 1887 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1888 | mp_set(&mG->z, 1); |
wolfSSL | 0:9d17e4342598 | 1889 | |
wolfSSL | 0:9d17e4342598 | 1890 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1891 | err = mp_copy(&key->pubkey.x, &mQ->x); |
wolfSSL | 0:9d17e4342598 | 1892 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1893 | err = mp_copy(&key->pubkey.y, &mQ->y); |
wolfSSL | 0:9d17e4342598 | 1894 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1895 | err = mp_copy(&key->pubkey.z, &mQ->z); |
wolfSSL | 0:9d17e4342598 | 1896 | |
wolfSSL | 0:9d17e4342598 | 1897 | #ifndef ECC_SHAMIR |
wolfSSL | 0:9d17e4342598 | 1898 | { |
wolfSSL | 0:9d17e4342598 | 1899 | mp_digit mp; |
wolfSSL | 0:9d17e4342598 | 1900 | |
wolfSSL | 0:9d17e4342598 | 1901 | /* compute u1*mG + u2*mQ = mG */ |
wolfSSL | 0:9d17e4342598 | 1902 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1903 | err = ecc_mulmod(&u1, mG, mG, &m, 0); |
wolfSSL | 0:9d17e4342598 | 1904 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1905 | err = ecc_mulmod(&u2, mQ, mQ, &m, 0); |
wolfSSL | 0:9d17e4342598 | 1906 | |
wolfSSL | 0:9d17e4342598 | 1907 | /* find the montgomery mp */ |
wolfSSL | 0:9d17e4342598 | 1908 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1909 | err = mp_montgomery_setup(&m, &mp); |
wolfSSL | 0:9d17e4342598 | 1910 | |
wolfSSL | 0:9d17e4342598 | 1911 | /* add them */ |
wolfSSL | 0:9d17e4342598 | 1912 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1913 | err = ecc_projective_add_point(mQ, mG, mG, &m, &mp); |
wolfSSL | 0:9d17e4342598 | 1914 | |
wolfSSL | 0:9d17e4342598 | 1915 | /* reduce */ |
wolfSSL | 0:9d17e4342598 | 1916 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1917 | err = ecc_map(mG, &m, &mp); |
wolfSSL | 0:9d17e4342598 | 1918 | } |
wolfSSL | 0:9d17e4342598 | 1919 | #else |
wolfSSL | 0:9d17e4342598 | 1920 | /* use Shamir's trick to compute u1*mG + u2*mQ using half the doubles */ |
wolfSSL | 0:9d17e4342598 | 1921 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1922 | err = ecc_mul2add(mG, &u1, mQ, &u2, mG, &m); |
wolfSSL | 0:9d17e4342598 | 1923 | #endif /* ECC_SHAMIR */ |
wolfSSL | 0:9d17e4342598 | 1924 | |
wolfSSL | 0:9d17e4342598 | 1925 | /* v = X_x1 mod n */ |
wolfSSL | 0:9d17e4342598 | 1926 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1927 | err = mp_mod(&mG->x, &p, &v); |
wolfSSL | 0:9d17e4342598 | 1928 | |
wolfSSL | 0:9d17e4342598 | 1929 | /* does v == r */ |
wolfSSL | 0:9d17e4342598 | 1930 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 1931 | if (mp_cmp(&v, &r) == MP_EQ) |
wolfSSL | 0:9d17e4342598 | 1932 | *stat = 1; |
wolfSSL | 0:9d17e4342598 | 1933 | } |
wolfSSL | 0:9d17e4342598 | 1934 | |
wolfSSL | 0:9d17e4342598 | 1935 | ecc_del_point(mG); |
wolfSSL | 0:9d17e4342598 | 1936 | ecc_del_point(mQ); |
wolfSSL | 0:9d17e4342598 | 1937 | |
wolfSSL | 0:9d17e4342598 | 1938 | mp_clear(&r); |
wolfSSL | 0:9d17e4342598 | 1939 | mp_clear(&s); |
wolfSSL | 0:9d17e4342598 | 1940 | mp_clear(&v); |
wolfSSL | 0:9d17e4342598 | 1941 | mp_clear(&w); |
wolfSSL | 0:9d17e4342598 | 1942 | mp_clear(&u1); |
wolfSSL | 0:9d17e4342598 | 1943 | mp_clear(&u2); |
wolfSSL | 0:9d17e4342598 | 1944 | mp_clear(&p); |
wolfSSL | 0:9d17e4342598 | 1945 | mp_clear(&e); |
wolfSSL | 0:9d17e4342598 | 1946 | mp_clear(&m); |
wolfSSL | 0:9d17e4342598 | 1947 | |
wolfSSL | 0:9d17e4342598 | 1948 | return err; |
wolfSSL | 0:9d17e4342598 | 1949 | } |
wolfSSL | 0:9d17e4342598 | 1950 | |
wolfSSL | 0:9d17e4342598 | 1951 | |
wolfSSL | 0:9d17e4342598 | 1952 | /* export public ECC key in ANSI X9.63 format */ |
wolfSSL | 0:9d17e4342598 | 1953 | int ecc_export_x963(ecc_key* key, byte* out, word32* outLen) |
wolfSSL | 0:9d17e4342598 | 1954 | { |
wolfSSL | 0:9d17e4342598 | 1955 | byte buf[ECC_BUFSIZE]; |
wolfSSL | 0:9d17e4342598 | 1956 | word32 numlen; |
wolfSSL | 0:9d17e4342598 | 1957 | int ret = MP_OKAY; |
wolfSSL | 0:9d17e4342598 | 1958 | |
wolfSSL | 0:9d17e4342598 | 1959 | if (key == NULL || out == NULL || outLen == NULL) |
wolfSSL | 0:9d17e4342598 | 1960 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1961 | |
wolfSSL | 0:9d17e4342598 | 1962 | if (ecc_is_valid_idx(key->idx) == 0) { |
wolfSSL | 0:9d17e4342598 | 1963 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 1964 | } |
wolfSSL | 0:9d17e4342598 | 1965 | numlen = key->dp->size; |
wolfSSL | 0:9d17e4342598 | 1966 | |
wolfSSL | 0:9d17e4342598 | 1967 | if (*outLen < (1 + 2*numlen)) { |
wolfSSL | 0:9d17e4342598 | 1968 | *outLen = 1 + 2*numlen; |
wolfSSL | 0:9d17e4342598 | 1969 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 1970 | } |
wolfSSL | 0:9d17e4342598 | 1971 | |
wolfSSL | 0:9d17e4342598 | 1972 | /* store byte 0x04 */ |
wolfSSL | 0:9d17e4342598 | 1973 | out[0] = 0x04; |
wolfSSL | 0:9d17e4342598 | 1974 | |
wolfSSL | 0:9d17e4342598 | 1975 | /* pad and store x */ |
wolfSSL | 0:9d17e4342598 | 1976 | XMEMSET(buf, 0, sizeof(buf)); |
wolfSSL | 0:9d17e4342598 | 1977 | ret = mp_to_unsigned_bin(&key->pubkey.x, |
wolfSSL | 0:9d17e4342598 | 1978 | buf + (numlen - mp_unsigned_bin_size(&key->pubkey.x))); |
wolfSSL | 0:9d17e4342598 | 1979 | if (ret != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1980 | return ret; |
wolfSSL | 0:9d17e4342598 | 1981 | XMEMCPY(out+1, buf, numlen); |
wolfSSL | 0:9d17e4342598 | 1982 | |
wolfSSL | 0:9d17e4342598 | 1983 | /* pad and store y */ |
wolfSSL | 0:9d17e4342598 | 1984 | XMEMSET(buf, 0, sizeof(buf)); |
wolfSSL | 0:9d17e4342598 | 1985 | ret = mp_to_unsigned_bin(&key->pubkey.y, |
wolfSSL | 0:9d17e4342598 | 1986 | buf + (numlen - mp_unsigned_bin_size(&key->pubkey.y))); |
wolfSSL | 0:9d17e4342598 | 1987 | if (ret != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 1988 | return ret; |
wolfSSL | 0:9d17e4342598 | 1989 | XMEMCPY(out+1+numlen, buf, numlen); |
wolfSSL | 0:9d17e4342598 | 1990 | |
wolfSSL | 0:9d17e4342598 | 1991 | *outLen = 1 + 2*numlen; |
wolfSSL | 0:9d17e4342598 | 1992 | |
wolfSSL | 0:9d17e4342598 | 1993 | return 0; |
wolfSSL | 0:9d17e4342598 | 1994 | } |
wolfSSL | 0:9d17e4342598 | 1995 | |
wolfSSL | 0:9d17e4342598 | 1996 | |
wolfSSL | 0:9d17e4342598 | 1997 | /* import public ECC key in ANSI X9.63 format */ |
wolfSSL | 0:9d17e4342598 | 1998 | int ecc_import_x963(const byte* in, word32 inLen, ecc_key* key) |
wolfSSL | 0:9d17e4342598 | 1999 | { |
wolfSSL | 0:9d17e4342598 | 2000 | int x, err; |
wolfSSL | 0:9d17e4342598 | 2001 | |
wolfSSL | 0:9d17e4342598 | 2002 | if (in == NULL || key == NULL) |
wolfSSL | 0:9d17e4342598 | 2003 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 2004 | |
wolfSSL | 0:9d17e4342598 | 2005 | /* must be odd */ |
wolfSSL | 0:9d17e4342598 | 2006 | if ((inLen & 1) == 0) { |
wolfSSL | 0:9d17e4342598 | 2007 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 2008 | } |
wolfSSL | 0:9d17e4342598 | 2009 | |
wolfSSL | 0:9d17e4342598 | 2010 | /* init key */ |
wolfSSL | 0:9d17e4342598 | 2011 | if (mp_init_multi(&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k, |
wolfSSL | 0:9d17e4342598 | 2012 | NULL, NULL) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 2013 | return MEMORY_E; |
wolfSSL | 0:9d17e4342598 | 2014 | } |
wolfSSL | 0:9d17e4342598 | 2015 | err = MP_OKAY; |
wolfSSL | 0:9d17e4342598 | 2016 | |
wolfSSL | 0:9d17e4342598 | 2017 | /* check for 4, 6 or 7 */ |
wolfSSL | 0:9d17e4342598 | 2018 | if (in[0] != 4 && in[0] != 6 && in[0] != 7) { |
wolfSSL | 0:9d17e4342598 | 2019 | err = ASN_PARSE_E; |
wolfSSL | 0:9d17e4342598 | 2020 | } |
wolfSSL | 0:9d17e4342598 | 2021 | |
wolfSSL | 0:9d17e4342598 | 2022 | /* read data */ |
wolfSSL | 0:9d17e4342598 | 2023 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2024 | err = mp_read_unsigned_bin(&key->pubkey.x, (byte*)in+1, (inLen-1)>>1); |
wolfSSL | 0:9d17e4342598 | 2025 | |
wolfSSL | 0:9d17e4342598 | 2026 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2027 | err = mp_read_unsigned_bin(&key->pubkey.y, (byte*)in+1+((inLen-1)>>1), |
wolfSSL | 0:9d17e4342598 | 2028 | (inLen-1)>>1); |
wolfSSL | 0:9d17e4342598 | 2029 | |
wolfSSL | 0:9d17e4342598 | 2030 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2031 | mp_set(&key->pubkey.z, 1); |
wolfSSL | 0:9d17e4342598 | 2032 | |
wolfSSL | 0:9d17e4342598 | 2033 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 2034 | /* determine the idx */ |
wolfSSL | 0:9d17e4342598 | 2035 | for (x = 0; ecc_sets[x].size != 0; x++) { |
wolfSSL | 0:9d17e4342598 | 2036 | if ((unsigned)ecc_sets[x].size >= ((inLen-1)>>1)) { |
wolfSSL | 0:9d17e4342598 | 2037 | break; |
wolfSSL | 0:9d17e4342598 | 2038 | } |
wolfSSL | 0:9d17e4342598 | 2039 | } |
wolfSSL | 0:9d17e4342598 | 2040 | if (ecc_sets[x].size == 0) { |
wolfSSL | 0:9d17e4342598 | 2041 | err = ASN_PARSE_E; |
wolfSSL | 0:9d17e4342598 | 2042 | } else { |
wolfSSL | 0:9d17e4342598 | 2043 | /* set the idx */ |
wolfSSL | 0:9d17e4342598 | 2044 | key->idx = x; |
wolfSSL | 0:9d17e4342598 | 2045 | key->dp = &ecc_sets[x]; |
wolfSSL | 0:9d17e4342598 | 2046 | key->type = ECC_PUBLICKEY; |
wolfSSL | 0:9d17e4342598 | 2047 | } |
wolfSSL | 0:9d17e4342598 | 2048 | } |
wolfSSL | 0:9d17e4342598 | 2049 | |
wolfSSL | 0:9d17e4342598 | 2050 | if (err != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 2051 | mp_clear(&key->pubkey.x); |
wolfSSL | 0:9d17e4342598 | 2052 | mp_clear(&key->pubkey.y); |
wolfSSL | 0:9d17e4342598 | 2053 | mp_clear(&key->pubkey.z); |
wolfSSL | 0:9d17e4342598 | 2054 | mp_clear(&key->k); |
wolfSSL | 0:9d17e4342598 | 2055 | } |
wolfSSL | 0:9d17e4342598 | 2056 | |
wolfSSL | 0:9d17e4342598 | 2057 | return err; |
wolfSSL | 0:9d17e4342598 | 2058 | } |
wolfSSL | 0:9d17e4342598 | 2059 | |
wolfSSL | 0:9d17e4342598 | 2060 | |
wolfSSL | 0:9d17e4342598 | 2061 | /* export ecc private key only raw, outLen is in/out size |
wolfSSL | 0:9d17e4342598 | 2062 | return MP_OKAY on success */ |
wolfSSL | 0:9d17e4342598 | 2063 | int ecc_export_private_only(ecc_key* key, byte* out, word32* outLen) |
wolfSSL | 0:9d17e4342598 | 2064 | { |
wolfSSL | 0:9d17e4342598 | 2065 | word32 numlen; |
wolfSSL | 0:9d17e4342598 | 2066 | |
wolfSSL | 0:9d17e4342598 | 2067 | if (key == NULL || out == NULL || outLen == NULL) |
wolfSSL | 0:9d17e4342598 | 2068 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 2069 | |
wolfSSL | 0:9d17e4342598 | 2070 | if (ecc_is_valid_idx(key->idx) == 0) { |
wolfSSL | 0:9d17e4342598 | 2071 | return ECC_BAD_ARG_E; |
wolfSSL | 0:9d17e4342598 | 2072 | } |
wolfSSL | 0:9d17e4342598 | 2073 | numlen = key->dp->size; |
wolfSSL | 0:9d17e4342598 | 2074 | |
wolfSSL | 0:9d17e4342598 | 2075 | if (*outLen < numlen) { |
wolfSSL | 0:9d17e4342598 | 2076 | *outLen = numlen; |
wolfSSL | 0:9d17e4342598 | 2077 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 2078 | } |
wolfSSL | 0:9d17e4342598 | 2079 | *outLen = numlen; |
wolfSSL | 0:9d17e4342598 | 2080 | XMEMSET(out, 0, *outLen); |
wolfSSL | 0:9d17e4342598 | 2081 | return mp_to_unsigned_bin(&key->k, out + (numlen - |
wolfSSL | 0:9d17e4342598 | 2082 | mp_unsigned_bin_size(&key->k))); |
wolfSSL | 0:9d17e4342598 | 2083 | } |
wolfSSL | 0:9d17e4342598 | 2084 | |
wolfSSL | 0:9d17e4342598 | 2085 | |
wolfSSL | 0:9d17e4342598 | 2086 | /* ecc private key import, public key in ANSI X9.63 format, private raw */ |
wolfSSL | 0:9d17e4342598 | 2087 | int ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub, |
wolfSSL | 0:9d17e4342598 | 2088 | word32 pubSz, ecc_key* key) |
wolfSSL | 0:9d17e4342598 | 2089 | { |
wolfSSL | 0:9d17e4342598 | 2090 | int ret = ecc_import_x963(pub, pubSz, key); |
wolfSSL | 0:9d17e4342598 | 2091 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 2092 | return ret; |
wolfSSL | 0:9d17e4342598 | 2093 | |
wolfSSL | 0:9d17e4342598 | 2094 | key->type = ECC_PRIVATEKEY; |
wolfSSL | 0:9d17e4342598 | 2095 | |
wolfSSL | 0:9d17e4342598 | 2096 | return mp_read_unsigned_bin(&key->k, priv, privSz); |
wolfSSL | 0:9d17e4342598 | 2097 | } |
wolfSSL | 0:9d17e4342598 | 2098 | |
wolfSSL | 0:9d17e4342598 | 2099 | |
wolfSSL | 0:9d17e4342598 | 2100 | /* key size in octets */ |
wolfSSL | 0:9d17e4342598 | 2101 | int ecc_size(ecc_key* key) |
wolfSSL | 0:9d17e4342598 | 2102 | { |
wolfSSL | 0:9d17e4342598 | 2103 | if (key == NULL) return 0; |
wolfSSL | 0:9d17e4342598 | 2104 | |
wolfSSL | 0:9d17e4342598 | 2105 | return key->dp->size; |
wolfSSL | 0:9d17e4342598 | 2106 | } |
wolfSSL | 0:9d17e4342598 | 2107 | |
wolfSSL | 0:9d17e4342598 | 2108 | |
wolfSSL | 0:9d17e4342598 | 2109 | /* worst case estimate, check actual return from ecc_sign_hash for actual value |
wolfSSL | 0:9d17e4342598 | 2110 | of signature size in octets */ |
wolfSSL | 0:9d17e4342598 | 2111 | int ecc_sig_size(ecc_key* key) |
wolfSSL | 0:9d17e4342598 | 2112 | { |
wolfSSL | 0:9d17e4342598 | 2113 | int sz = ecc_size(key); |
wolfSSL | 0:9d17e4342598 | 2114 | if (sz < 0) |
wolfSSL | 0:9d17e4342598 | 2115 | return sz; |
wolfSSL | 0:9d17e4342598 | 2116 | |
wolfSSL | 0:9d17e4342598 | 2117 | return sz * 2 + SIG_HEADER_SZ + 4; /* (4) worst case estimate */ |
wolfSSL | 0:9d17e4342598 | 2118 | } |
wolfSSL | 0:9d17e4342598 | 2119 | |
wolfSSL | 0:9d17e4342598 | 2120 | |
wolfSSL | 0:9d17e4342598 | 2121 | #ifdef FP_ECC |
wolfSSL | 0:9d17e4342598 | 2122 | |
wolfSSL | 0:9d17e4342598 | 2123 | /* fixed point ECC cache */ |
wolfSSL | 0:9d17e4342598 | 2124 | /* number of entries in the cache */ |
wolfSSL | 0:9d17e4342598 | 2125 | #ifndef FP_ENTRIES |
wolfSSL | 0:9d17e4342598 | 2126 | #define FP_ENTRIES 16 |
wolfSSL | 0:9d17e4342598 | 2127 | #endif |
wolfSSL | 0:9d17e4342598 | 2128 | |
wolfSSL | 0:9d17e4342598 | 2129 | /* number of bits in LUT */ |
wolfSSL | 0:9d17e4342598 | 2130 | #ifndef FP_LUT |
wolfSSL | 0:9d17e4342598 | 2131 | #define FP_LUT 8U |
wolfSSL | 0:9d17e4342598 | 2132 | #endif |
wolfSSL | 0:9d17e4342598 | 2133 | |
wolfSSL | 0:9d17e4342598 | 2134 | #ifdef ECC_SHAMIR |
wolfSSL | 0:9d17e4342598 | 2135 | /* Sharmir requires a bigger LUT, TAO */ |
wolfSSL | 0:9d17e4342598 | 2136 | #if (FP_LUT > 12) || (FP_LUT < 4) |
wolfSSL | 0:9d17e4342598 | 2137 | #error FP_LUT must be between 4 and 12 inclusively |
wolfSSL | 0:9d17e4342598 | 2138 | #endif |
wolfSSL | 0:9d17e4342598 | 2139 | #else |
wolfSSL | 0:9d17e4342598 | 2140 | #if (FP_LUT > 12) || (FP_LUT < 2) |
wolfSSL | 0:9d17e4342598 | 2141 | #error FP_LUT must be between 2 and 12 inclusively |
wolfSSL | 0:9d17e4342598 | 2142 | #endif |
wolfSSL | 0:9d17e4342598 | 2143 | #endif |
wolfSSL | 0:9d17e4342598 | 2144 | |
wolfSSL | 0:9d17e4342598 | 2145 | |
wolfSSL | 0:9d17e4342598 | 2146 | /** Our FP cache */ |
wolfSSL | 0:9d17e4342598 | 2147 | typedef struct { |
wolfSSL | 0:9d17e4342598 | 2148 | ecc_point* g; /* cached COPY of base point */ |
wolfSSL | 0:9d17e4342598 | 2149 | ecc_point* LUT[1U<<FP_LUT]; /* fixed point lookup */ |
wolfSSL | 0:9d17e4342598 | 2150 | mp_int mu; /* copy of the montgomery constant */ |
wolfSSL | 0:9d17e4342598 | 2151 | int lru_count; /* amount of times this entry has been used */ |
wolfSSL | 0:9d17e4342598 | 2152 | int lock; /* flag to indicate cache eviction */ |
wolfSSL | 0:9d17e4342598 | 2153 | /* permitted (0) or not (1) */ |
wolfSSL | 0:9d17e4342598 | 2154 | } fp_cache_t; |
wolfSSL | 0:9d17e4342598 | 2155 | |
wolfSSL | 0:9d17e4342598 | 2156 | /* if HAVE_THREAD_LS this cache is per thread, no locking needed */ |
wolfSSL | 0:9d17e4342598 | 2157 | static THREAD_LS_T fp_cache_t fp_cache[FP_ENTRIES]; |
wolfSSL | 0:9d17e4342598 | 2158 | |
wolfSSL | 0:9d17e4342598 | 2159 | #ifndef HAVE_THREAD_LS |
wolfSSL | 0:9d17e4342598 | 2160 | static volatile int initMutex = 0; /* prevent multiple mutex inits */ |
wolfSSL | 0:9d17e4342598 | 2161 | static CyaSSL_Mutex ecc_fp_lock; |
wolfSSL | 0:9d17e4342598 | 2162 | #endif /* HAVE_THREAD_LS */ |
wolfSSL | 0:9d17e4342598 | 2163 | |
wolfSSL | 0:9d17e4342598 | 2164 | /* simple table to help direct the generation of the LUT */ |
wolfSSL | 0:9d17e4342598 | 2165 | static const struct { |
wolfSSL | 0:9d17e4342598 | 2166 | int ham, terma, termb; |
wolfSSL | 0:9d17e4342598 | 2167 | } lut_orders[] = { |
wolfSSL | 0:9d17e4342598 | 2168 | { 0, 0, 0 }, { 1, 0, 0 }, { 1, 0, 0 }, { 2, 1, 2 }, { 1, 0, 0 }, { 2, 1, 4 }, { 2, 2, 4 }, { 3, 3, 4 }, |
wolfSSL | 0:9d17e4342598 | 2169 | { 1, 0, 0 }, { 2, 1, 8 }, { 2, 2, 8 }, { 3, 3, 8 }, { 2, 4, 8 }, { 3, 5, 8 }, { 3, 6, 8 }, { 4, 7, 8 }, |
wolfSSL | 0:9d17e4342598 | 2170 | { 1, 0, 0 }, { 2, 1, 16 }, { 2, 2, 16 }, { 3, 3, 16 }, { 2, 4, 16 }, { 3, 5, 16 }, { 3, 6, 16 }, { 4, 7, 16 }, |
wolfSSL | 0:9d17e4342598 | 2171 | { 2, 8, 16 }, { 3, 9, 16 }, { 3, 10, 16 }, { 4, 11, 16 }, { 3, 12, 16 }, { 4, 13, 16 }, { 4, 14, 16 }, { 5, 15, 16 }, |
wolfSSL | 0:9d17e4342598 | 2172 | { 1, 0, 0 }, { 2, 1, 32 }, { 2, 2, 32 }, { 3, 3, 32 }, { 2, 4, 32 }, { 3, 5, 32 }, { 3, 6, 32 }, { 4, 7, 32 }, |
wolfSSL | 0:9d17e4342598 | 2173 | { 2, 8, 32 }, { 3, 9, 32 }, { 3, 10, 32 }, { 4, 11, 32 }, { 3, 12, 32 }, { 4, 13, 32 }, { 4, 14, 32 }, { 5, 15, 32 }, |
wolfSSL | 0:9d17e4342598 | 2174 | { 2, 16, 32 }, { 3, 17, 32 }, { 3, 18, 32 }, { 4, 19, 32 }, { 3, 20, 32 }, { 4, 21, 32 }, { 4, 22, 32 }, { 5, 23, 32 }, |
wolfSSL | 0:9d17e4342598 | 2175 | { 3, 24, 32 }, { 4, 25, 32 }, { 4, 26, 32 }, { 5, 27, 32 }, { 4, 28, 32 }, { 5, 29, 32 }, { 5, 30, 32 }, { 6, 31, 32 }, |
wolfSSL | 0:9d17e4342598 | 2176 | #if FP_LUT > 6 |
wolfSSL | 0:9d17e4342598 | 2177 | { 1, 0, 0 }, { 2, 1, 64 }, { 2, 2, 64 }, { 3, 3, 64 }, { 2, 4, 64 }, { 3, 5, 64 }, { 3, 6, 64 }, { 4, 7, 64 }, |
wolfSSL | 0:9d17e4342598 | 2178 | { 2, 8, 64 }, { 3, 9, 64 }, { 3, 10, 64 }, { 4, 11, 64 }, { 3, 12, 64 }, { 4, 13, 64 }, { 4, 14, 64 }, { 5, 15, 64 }, |
wolfSSL | 0:9d17e4342598 | 2179 | { 2, 16, 64 }, { 3, 17, 64 }, { 3, 18, 64 }, { 4, 19, 64 }, { 3, 20, 64 }, { 4, 21, 64 }, { 4, 22, 64 }, { 5, 23, 64 }, |
wolfSSL | 0:9d17e4342598 | 2180 | { 3, 24, 64 }, { 4, 25, 64 }, { 4, 26, 64 }, { 5, 27, 64 }, { 4, 28, 64 }, { 5, 29, 64 }, { 5, 30, 64 }, { 6, 31, 64 }, |
wolfSSL | 0:9d17e4342598 | 2181 | { 2, 32, 64 }, { 3, 33, 64 }, { 3, 34, 64 }, { 4, 35, 64 }, { 3, 36, 64 }, { 4, 37, 64 }, { 4, 38, 64 }, { 5, 39, 64 }, |
wolfSSL | 0:9d17e4342598 | 2182 | { 3, 40, 64 }, { 4, 41, 64 }, { 4, 42, 64 }, { 5, 43, 64 }, { 4, 44, 64 }, { 5, 45, 64 }, { 5, 46, 64 }, { 6, 47, 64 }, |
wolfSSL | 0:9d17e4342598 | 2183 | { 3, 48, 64 }, { 4, 49, 64 }, { 4, 50, 64 }, { 5, 51, 64 }, { 4, 52, 64 }, { 5, 53, 64 }, { 5, 54, 64 }, { 6, 55, 64 }, |
wolfSSL | 0:9d17e4342598 | 2184 | { 4, 56, 64 }, { 5, 57, 64 }, { 5, 58, 64 }, { 6, 59, 64 }, { 5, 60, 64 }, { 6, 61, 64 }, { 6, 62, 64 }, { 7, 63, 64 }, |
wolfSSL | 0:9d17e4342598 | 2185 | #if FP_LUT > 7 |
wolfSSL | 0:9d17e4342598 | 2186 | { 1, 0, 0 }, { 2, 1, 128 }, { 2, 2, 128 }, { 3, 3, 128 }, { 2, 4, 128 }, { 3, 5, 128 }, { 3, 6, 128 }, { 4, 7, 128 }, |
wolfSSL | 0:9d17e4342598 | 2187 | { 2, 8, 128 }, { 3, 9, 128 }, { 3, 10, 128 }, { 4, 11, 128 }, { 3, 12, 128 }, { 4, 13, 128 }, { 4, 14, 128 }, { 5, 15, 128 }, |
wolfSSL | 0:9d17e4342598 | 2188 | { 2, 16, 128 }, { 3, 17, 128 }, { 3, 18, 128 }, { 4, 19, 128 }, { 3, 20, 128 }, { 4, 21, 128 }, { 4, 22, 128 }, { 5, 23, 128 }, |
wolfSSL | 0:9d17e4342598 | 2189 | { 3, 24, 128 }, { 4, 25, 128 }, { 4, 26, 128 }, { 5, 27, 128 }, { 4, 28, 128 }, { 5, 29, 128 }, { 5, 30, 128 }, { 6, 31, 128 }, |
wolfSSL | 0:9d17e4342598 | 2190 | { 2, 32, 128 }, { 3, 33, 128 }, { 3, 34, 128 }, { 4, 35, 128 }, { 3, 36, 128 }, { 4, 37, 128 }, { 4, 38, 128 }, { 5, 39, 128 }, |
wolfSSL | 0:9d17e4342598 | 2191 | { 3, 40, 128 }, { 4, 41, 128 }, { 4, 42, 128 }, { 5, 43, 128 }, { 4, 44, 128 }, { 5, 45, 128 }, { 5, 46, 128 }, { 6, 47, 128 }, |
wolfSSL | 0:9d17e4342598 | 2192 | { 3, 48, 128 }, { 4, 49, 128 }, { 4, 50, 128 }, { 5, 51, 128 }, { 4, 52, 128 }, { 5, 53, 128 }, { 5, 54, 128 }, { 6, 55, 128 }, |
wolfSSL | 0:9d17e4342598 | 2193 | { 4, 56, 128 }, { 5, 57, 128 }, { 5, 58, 128 }, { 6, 59, 128 }, { 5, 60, 128 }, { 6, 61, 128 }, { 6, 62, 128 }, { 7, 63, 128 }, |
wolfSSL | 0:9d17e4342598 | 2194 | { 2, 64, 128 }, { 3, 65, 128 }, { 3, 66, 128 }, { 4, 67, 128 }, { 3, 68, 128 }, { 4, 69, 128 }, { 4, 70, 128 }, { 5, 71, 128 }, |
wolfSSL | 0:9d17e4342598 | 2195 | { 3, 72, 128 }, { 4, 73, 128 }, { 4, 74, 128 }, { 5, 75, 128 }, { 4, 76, 128 }, { 5, 77, 128 }, { 5, 78, 128 }, { 6, 79, 128 }, |
wolfSSL | 0:9d17e4342598 | 2196 | { 3, 80, 128 }, { 4, 81, 128 }, { 4, 82, 128 }, { 5, 83, 128 }, { 4, 84, 128 }, { 5, 85, 128 }, { 5, 86, 128 }, { 6, 87, 128 }, |
wolfSSL | 0:9d17e4342598 | 2197 | { 4, 88, 128 }, { 5, 89, 128 }, { 5, 90, 128 }, { 6, 91, 128 }, { 5, 92, 128 }, { 6, 93, 128 }, { 6, 94, 128 }, { 7, 95, 128 }, |
wolfSSL | 0:9d17e4342598 | 2198 | { 3, 96, 128 }, { 4, 97, 128 }, { 4, 98, 128 }, { 5, 99, 128 }, { 4, 100, 128 }, { 5, 101, 128 }, { 5, 102, 128 }, { 6, 103, 128 }, |
wolfSSL | 0:9d17e4342598 | 2199 | { 4, 104, 128 }, { 5, 105, 128 }, { 5, 106, 128 }, { 6, 107, 128 }, { 5, 108, 128 }, { 6, 109, 128 }, { 6, 110, 128 }, { 7, 111, 128 }, |
wolfSSL | 0:9d17e4342598 | 2200 | { 4, 112, 128 }, { 5, 113, 128 }, { 5, 114, 128 }, { 6, 115, 128 }, { 5, 116, 128 }, { 6, 117, 128 }, { 6, 118, 128 }, { 7, 119, 128 }, |
wolfSSL | 0:9d17e4342598 | 2201 | { 5, 120, 128 }, { 6, 121, 128 }, { 6, 122, 128 }, { 7, 123, 128 }, { 6, 124, 128 }, { 7, 125, 128 }, { 7, 126, 128 }, { 8, 127, 128 }, |
wolfSSL | 0:9d17e4342598 | 2202 | #if FP_LUT > 8 |
wolfSSL | 0:9d17e4342598 | 2203 | { 1, 0, 0 }, { 2, 1, 256 }, { 2, 2, 256 }, { 3, 3, 256 }, { 2, 4, 256 }, { 3, 5, 256 }, { 3, 6, 256 }, { 4, 7, 256 }, |
wolfSSL | 0:9d17e4342598 | 2204 | { 2, 8, 256 }, { 3, 9, 256 }, { 3, 10, 256 }, { 4, 11, 256 }, { 3, 12, 256 }, { 4, 13, 256 }, { 4, 14, 256 }, { 5, 15, 256 }, |
wolfSSL | 0:9d17e4342598 | 2205 | { 2, 16, 256 }, { 3, 17, 256 }, { 3, 18, 256 }, { 4, 19, 256 }, { 3, 20, 256 }, { 4, 21, 256 }, { 4, 22, 256 }, { 5, 23, 256 }, |
wolfSSL | 0:9d17e4342598 | 2206 | { 3, 24, 256 }, { 4, 25, 256 }, { 4, 26, 256 }, { 5, 27, 256 }, { 4, 28, 256 }, { 5, 29, 256 }, { 5, 30, 256 }, { 6, 31, 256 }, |
wolfSSL | 0:9d17e4342598 | 2207 | { 2, 32, 256 }, { 3, 33, 256 }, { 3, 34, 256 }, { 4, 35, 256 }, { 3, 36, 256 }, { 4, 37, 256 }, { 4, 38, 256 }, { 5, 39, 256 }, |
wolfSSL | 0:9d17e4342598 | 2208 | { 3, 40, 256 }, { 4, 41, 256 }, { 4, 42, 256 }, { 5, 43, 256 }, { 4, 44, 256 }, { 5, 45, 256 }, { 5, 46, 256 }, { 6, 47, 256 }, |
wolfSSL | 0:9d17e4342598 | 2209 | { 3, 48, 256 }, { 4, 49, 256 }, { 4, 50, 256 }, { 5, 51, 256 }, { 4, 52, 256 }, { 5, 53, 256 }, { 5, 54, 256 }, { 6, 55, 256 }, |
wolfSSL | 0:9d17e4342598 | 2210 | { 4, 56, 256 }, { 5, 57, 256 }, { 5, 58, 256 }, { 6, 59, 256 }, { 5, 60, 256 }, { 6, 61, 256 }, { 6, 62, 256 }, { 7, 63, 256 }, |
wolfSSL | 0:9d17e4342598 | 2211 | { 2, 64, 256 }, { 3, 65, 256 }, { 3, 66, 256 }, { 4, 67, 256 }, { 3, 68, 256 }, { 4, 69, 256 }, { 4, 70, 256 }, { 5, 71, 256 }, |
wolfSSL | 0:9d17e4342598 | 2212 | { 3, 72, 256 }, { 4, 73, 256 }, { 4, 74, 256 }, { 5, 75, 256 }, { 4, 76, 256 }, { 5, 77, 256 }, { 5, 78, 256 }, { 6, 79, 256 }, |
wolfSSL | 0:9d17e4342598 | 2213 | { 3, 80, 256 }, { 4, 81, 256 }, { 4, 82, 256 }, { 5, 83, 256 }, { 4, 84, 256 }, { 5, 85, 256 }, { 5, 86, 256 }, { 6, 87, 256 }, |
wolfSSL | 0:9d17e4342598 | 2214 | { 4, 88, 256 }, { 5, 89, 256 }, { 5, 90, 256 }, { 6, 91, 256 }, { 5, 92, 256 }, { 6, 93, 256 }, { 6, 94, 256 }, { 7, 95, 256 }, |
wolfSSL | 0:9d17e4342598 | 2215 | { 3, 96, 256 }, { 4, 97, 256 }, { 4, 98, 256 }, { 5, 99, 256 }, { 4, 100, 256 }, { 5, 101, 256 }, { 5, 102, 256 }, { 6, 103, 256 }, |
wolfSSL | 0:9d17e4342598 | 2216 | { 4, 104, 256 }, { 5, 105, 256 }, { 5, 106, 256 }, { 6, 107, 256 }, { 5, 108, 256 }, { 6, 109, 256 }, { 6, 110, 256 }, { 7, 111, 256 }, |
wolfSSL | 0:9d17e4342598 | 2217 | { 4, 112, 256 }, { 5, 113, 256 }, { 5, 114, 256 }, { 6, 115, 256 }, { 5, 116, 256 }, { 6, 117, 256 }, { 6, 118, 256 }, { 7, 119, 256 }, |
wolfSSL | 0:9d17e4342598 | 2218 | { 5, 120, 256 }, { 6, 121, 256 }, { 6, 122, 256 }, { 7, 123, 256 }, { 6, 124, 256 }, { 7, 125, 256 }, { 7, 126, 256 }, { 8, 127, 256 }, |
wolfSSL | 0:9d17e4342598 | 2219 | { 2, 128, 256 }, { 3, 129, 256 }, { 3, 130, 256 }, { 4, 131, 256 }, { 3, 132, 256 }, { 4, 133, 256 }, { 4, 134, 256 }, { 5, 135, 256 }, |
wolfSSL | 0:9d17e4342598 | 2220 | { 3, 136, 256 }, { 4, 137, 256 }, { 4, 138, 256 }, { 5, 139, 256 }, { 4, 140, 256 }, { 5, 141, 256 }, { 5, 142, 256 }, { 6, 143, 256 }, |
wolfSSL | 0:9d17e4342598 | 2221 | { 3, 144, 256 }, { 4, 145, 256 }, { 4, 146, 256 }, { 5, 147, 256 }, { 4, 148, 256 }, { 5, 149, 256 }, { 5, 150, 256 }, { 6, 151, 256 }, |
wolfSSL | 0:9d17e4342598 | 2222 | { 4, 152, 256 }, { 5, 153, 256 }, { 5, 154, 256 }, { 6, 155, 256 }, { 5, 156, 256 }, { 6, 157, 256 }, { 6, 158, 256 }, { 7, 159, 256 }, |
wolfSSL | 0:9d17e4342598 | 2223 | { 3, 160, 256 }, { 4, 161, 256 }, { 4, 162, 256 }, { 5, 163, 256 }, { 4, 164, 256 }, { 5, 165, 256 }, { 5, 166, 256 }, { 6, 167, 256 }, |
wolfSSL | 0:9d17e4342598 | 2224 | { 4, 168, 256 }, { 5, 169, 256 }, { 5, 170, 256 }, { 6, 171, 256 }, { 5, 172, 256 }, { 6, 173, 256 }, { 6, 174, 256 }, { 7, 175, 256 }, |
wolfSSL | 0:9d17e4342598 | 2225 | { 4, 176, 256 }, { 5, 177, 256 }, { 5, 178, 256 }, { 6, 179, 256 }, { 5, 180, 256 }, { 6, 181, 256 }, { 6, 182, 256 }, { 7, 183, 256 }, |
wolfSSL | 0:9d17e4342598 | 2226 | { 5, 184, 256 }, { 6, 185, 256 }, { 6, 186, 256 }, { 7, 187, 256 }, { 6, 188, 256 }, { 7, 189, 256 }, { 7, 190, 256 }, { 8, 191, 256 }, |
wolfSSL | 0:9d17e4342598 | 2227 | { 3, 192, 256 }, { 4, 193, 256 }, { 4, 194, 256 }, { 5, 195, 256 }, { 4, 196, 256 }, { 5, 197, 256 }, { 5, 198, 256 }, { 6, 199, 256 }, |
wolfSSL | 0:9d17e4342598 | 2228 | { 4, 200, 256 }, { 5, 201, 256 }, { 5, 202, 256 }, { 6, 203, 256 }, { 5, 204, 256 }, { 6, 205, 256 }, { 6, 206, 256 }, { 7, 207, 256 }, |
wolfSSL | 0:9d17e4342598 | 2229 | { 4, 208, 256 }, { 5, 209, 256 }, { 5, 210, 256 }, { 6, 211, 256 }, { 5, 212, 256 }, { 6, 213, 256 }, { 6, 214, 256 }, { 7, 215, 256 }, |
wolfSSL | 0:9d17e4342598 | 2230 | { 5, 216, 256 }, { 6, 217, 256 }, { 6, 218, 256 }, { 7, 219, 256 }, { 6, 220, 256 }, { 7, 221, 256 }, { 7, 222, 256 }, { 8, 223, 256 }, |
wolfSSL | 0:9d17e4342598 | 2231 | { 4, 224, 256 }, { 5, 225, 256 }, { 5, 226, 256 }, { 6, 227, 256 }, { 5, 228, 256 }, { 6, 229, 256 }, { 6, 230, 256 }, { 7, 231, 256 }, |
wolfSSL | 0:9d17e4342598 | 2232 | { 5, 232, 256 }, { 6, 233, 256 }, { 6, 234, 256 }, { 7, 235, 256 }, { 6, 236, 256 }, { 7, 237, 256 }, { 7, 238, 256 }, { 8, 239, 256 }, |
wolfSSL | 0:9d17e4342598 | 2233 | { 5, 240, 256 }, { 6, 241, 256 }, { 6, 242, 256 }, { 7, 243, 256 }, { 6, 244, 256 }, { 7, 245, 256 }, { 7, 246, 256 }, { 8, 247, 256 }, |
wolfSSL | 0:9d17e4342598 | 2234 | { 6, 248, 256 }, { 7, 249, 256 }, { 7, 250, 256 }, { 8, 251, 256 }, { 7, 252, 256 }, { 8, 253, 256 }, { 8, 254, 256 }, { 9, 255, 256 }, |
wolfSSL | 0:9d17e4342598 | 2235 | #if FP_LUT > 9 |
wolfSSL | 0:9d17e4342598 | 2236 | { 1, 0, 0 }, { 2, 1, 512 }, { 2, 2, 512 }, { 3, 3, 512 }, { 2, 4, 512 }, { 3, 5, 512 }, { 3, 6, 512 }, { 4, 7, 512 }, |
wolfSSL | 0:9d17e4342598 | 2237 | { 2, 8, 512 }, { 3, 9, 512 }, { 3, 10, 512 }, { 4, 11, 512 }, { 3, 12, 512 }, { 4, 13, 512 }, { 4, 14, 512 }, { 5, 15, 512 }, |
wolfSSL | 0:9d17e4342598 | 2238 | { 2, 16, 512 }, { 3, 17, 512 }, { 3, 18, 512 }, { 4, 19, 512 }, { 3, 20, 512 }, { 4, 21, 512 }, { 4, 22, 512 }, { 5, 23, 512 }, |
wolfSSL | 0:9d17e4342598 | 2239 | { 3, 24, 512 }, { 4, 25, 512 }, { 4, 26, 512 }, { 5, 27, 512 }, { 4, 28, 512 }, { 5, 29, 512 }, { 5, 30, 512 }, { 6, 31, 512 }, |
wolfSSL | 0:9d17e4342598 | 2240 | { 2, 32, 512 }, { 3, 33, 512 }, { 3, 34, 512 }, { 4, 35, 512 }, { 3, 36, 512 }, { 4, 37, 512 }, { 4, 38, 512 }, { 5, 39, 512 }, |
wolfSSL | 0:9d17e4342598 | 2241 | { 3, 40, 512 }, { 4, 41, 512 }, { 4, 42, 512 }, { 5, 43, 512 }, { 4, 44, 512 }, { 5, 45, 512 }, { 5, 46, 512 }, { 6, 47, 512 }, |
wolfSSL | 0:9d17e4342598 | 2242 | { 3, 48, 512 }, { 4, 49, 512 }, { 4, 50, 512 }, { 5, 51, 512 }, { 4, 52, 512 }, { 5, 53, 512 }, { 5, 54, 512 }, { 6, 55, 512 }, |
wolfSSL | 0:9d17e4342598 | 2243 | { 4, 56, 512 }, { 5, 57, 512 }, { 5, 58, 512 }, { 6, 59, 512 }, { 5, 60, 512 }, { 6, 61, 512 }, { 6, 62, 512 }, { 7, 63, 512 }, |
wolfSSL | 0:9d17e4342598 | 2244 | { 2, 64, 512 }, { 3, 65, 512 }, { 3, 66, 512 }, { 4, 67, 512 }, { 3, 68, 512 }, { 4, 69, 512 }, { 4, 70, 512 }, { 5, 71, 512 }, |
wolfSSL | 0:9d17e4342598 | 2245 | { 3, 72, 512 }, { 4, 73, 512 }, { 4, 74, 512 }, { 5, 75, 512 }, { 4, 76, 512 }, { 5, 77, 512 }, { 5, 78, 512 }, { 6, 79, 512 }, |
wolfSSL | 0:9d17e4342598 | 2246 | { 3, 80, 512 }, { 4, 81, 512 }, { 4, 82, 512 }, { 5, 83, 512 }, { 4, 84, 512 }, { 5, 85, 512 }, { 5, 86, 512 }, { 6, 87, 512 }, |
wolfSSL | 0:9d17e4342598 | 2247 | { 4, 88, 512 }, { 5, 89, 512 }, { 5, 90, 512 }, { 6, 91, 512 }, { 5, 92, 512 }, { 6, 93, 512 }, { 6, 94, 512 }, { 7, 95, 512 }, |
wolfSSL | 0:9d17e4342598 | 2248 | { 3, 96, 512 }, { 4, 97, 512 }, { 4, 98, 512 }, { 5, 99, 512 }, { 4, 100, 512 }, { 5, 101, 512 }, { 5, 102, 512 }, { 6, 103, 512 }, |
wolfSSL | 0:9d17e4342598 | 2249 | { 4, 104, 512 }, { 5, 105, 512 }, { 5, 106, 512 }, { 6, 107, 512 }, { 5, 108, 512 }, { 6, 109, 512 }, { 6, 110, 512 }, { 7, 111, 512 }, |
wolfSSL | 0:9d17e4342598 | 2250 | { 4, 112, 512 }, { 5, 113, 512 }, { 5, 114, 512 }, { 6, 115, 512 }, { 5, 116, 512 }, { 6, 117, 512 }, { 6, 118, 512 }, { 7, 119, 512 }, |
wolfSSL | 0:9d17e4342598 | 2251 | { 5, 120, 512 }, { 6, 121, 512 }, { 6, 122, 512 }, { 7, 123, 512 }, { 6, 124, 512 }, { 7, 125, 512 }, { 7, 126, 512 }, { 8, 127, 512 }, |
wolfSSL | 0:9d17e4342598 | 2252 | { 2, 128, 512 }, { 3, 129, 512 }, { 3, 130, 512 }, { 4, 131, 512 }, { 3, 132, 512 }, { 4, 133, 512 }, { 4, 134, 512 }, { 5, 135, 512 }, |
wolfSSL | 0:9d17e4342598 | 2253 | { 3, 136, 512 }, { 4, 137, 512 }, { 4, 138, 512 }, { 5, 139, 512 }, { 4, 140, 512 }, { 5, 141, 512 }, { 5, 142, 512 }, { 6, 143, 512 }, |
wolfSSL | 0:9d17e4342598 | 2254 | { 3, 144, 512 }, { 4, 145, 512 }, { 4, 146, 512 }, { 5, 147, 512 }, { 4, 148, 512 }, { 5, 149, 512 }, { 5, 150, 512 }, { 6, 151, 512 }, |
wolfSSL | 0:9d17e4342598 | 2255 | { 4, 152, 512 }, { 5, 153, 512 }, { 5, 154, 512 }, { 6, 155, 512 }, { 5, 156, 512 }, { 6, 157, 512 }, { 6, 158, 512 }, { 7, 159, 512 }, |
wolfSSL | 0:9d17e4342598 | 2256 | { 3, 160, 512 }, { 4, 161, 512 }, { 4, 162, 512 }, { 5, 163, 512 }, { 4, 164, 512 }, { 5, 165, 512 }, { 5, 166, 512 }, { 6, 167, 512 }, |
wolfSSL | 0:9d17e4342598 | 2257 | { 4, 168, 512 }, { 5, 169, 512 }, { 5, 170, 512 }, { 6, 171, 512 }, { 5, 172, 512 }, { 6, 173, 512 }, { 6, 174, 512 }, { 7, 175, 512 }, |
wolfSSL | 0:9d17e4342598 | 2258 | { 4, 176, 512 }, { 5, 177, 512 }, { 5, 178, 512 }, { 6, 179, 512 }, { 5, 180, 512 }, { 6, 181, 512 }, { 6, 182, 512 }, { 7, 183, 512 }, |
wolfSSL | 0:9d17e4342598 | 2259 | { 5, 184, 512 }, { 6, 185, 512 }, { 6, 186, 512 }, { 7, 187, 512 }, { 6, 188, 512 }, { 7, 189, 512 }, { 7, 190, 512 }, { 8, 191, 512 }, |
wolfSSL | 0:9d17e4342598 | 2260 | { 3, 192, 512 }, { 4, 193, 512 }, { 4, 194, 512 }, { 5, 195, 512 }, { 4, 196, 512 }, { 5, 197, 512 }, { 5, 198, 512 }, { 6, 199, 512 }, |
wolfSSL | 0:9d17e4342598 | 2261 | { 4, 200, 512 }, { 5, 201, 512 }, { 5, 202, 512 }, { 6, 203, 512 }, { 5, 204, 512 }, { 6, 205, 512 }, { 6, 206, 512 }, { 7, 207, 512 }, |
wolfSSL | 0:9d17e4342598 | 2262 | { 4, 208, 512 }, { 5, 209, 512 }, { 5, 210, 512 }, { 6, 211, 512 }, { 5, 212, 512 }, { 6, 213, 512 }, { 6, 214, 512 }, { 7, 215, 512 }, |
wolfSSL | 0:9d17e4342598 | 2263 | { 5, 216, 512 }, { 6, 217, 512 }, { 6, 218, 512 }, { 7, 219, 512 }, { 6, 220, 512 }, { 7, 221, 512 }, { 7, 222, 512 }, { 8, 223, 512 }, |
wolfSSL | 0:9d17e4342598 | 2264 | { 4, 224, 512 }, { 5, 225, 512 }, { 5, 226, 512 }, { 6, 227, 512 }, { 5, 228, 512 }, { 6, 229, 512 }, { 6, 230, 512 }, { 7, 231, 512 }, |
wolfSSL | 0:9d17e4342598 | 2265 | { 5, 232, 512 }, { 6, 233, 512 }, { 6, 234, 512 }, { 7, 235, 512 }, { 6, 236, 512 }, { 7, 237, 512 }, { 7, 238, 512 }, { 8, 239, 512 }, |
wolfSSL | 0:9d17e4342598 | 2266 | { 5, 240, 512 }, { 6, 241, 512 }, { 6, 242, 512 }, { 7, 243, 512 }, { 6, 244, 512 }, { 7, 245, 512 }, { 7, 246, 512 }, { 8, 247, 512 }, |
wolfSSL | 0:9d17e4342598 | 2267 | { 6, 248, 512 }, { 7, 249, 512 }, { 7, 250, 512 }, { 8, 251, 512 }, { 7, 252, 512 }, { 8, 253, 512 }, { 8, 254, 512 }, { 9, 255, 512 }, |
wolfSSL | 0:9d17e4342598 | 2268 | { 2, 256, 512 }, { 3, 257, 512 }, { 3, 258, 512 }, { 4, 259, 512 }, { 3, 260, 512 }, { 4, 261, 512 }, { 4, 262, 512 }, { 5, 263, 512 }, |
wolfSSL | 0:9d17e4342598 | 2269 | { 3, 264, 512 }, { 4, 265, 512 }, { 4, 266, 512 }, { 5, 267, 512 }, { 4, 268, 512 }, { 5, 269, 512 }, { 5, 270, 512 }, { 6, 271, 512 }, |
wolfSSL | 0:9d17e4342598 | 2270 | { 3, 272, 512 }, { 4, 273, 512 }, { 4, 274, 512 }, { 5, 275, 512 }, { 4, 276, 512 }, { 5, 277, 512 }, { 5, 278, 512 }, { 6, 279, 512 }, |
wolfSSL | 0:9d17e4342598 | 2271 | { 4, 280, 512 }, { 5, 281, 512 }, { 5, 282, 512 }, { 6, 283, 512 }, { 5, 284, 512 }, { 6, 285, 512 }, { 6, 286, 512 }, { 7, 287, 512 }, |
wolfSSL | 0:9d17e4342598 | 2272 | { 3, 288, 512 }, { 4, 289, 512 }, { 4, 290, 512 }, { 5, 291, 512 }, { 4, 292, 512 }, { 5, 293, 512 }, { 5, 294, 512 }, { 6, 295, 512 }, |
wolfSSL | 0:9d17e4342598 | 2273 | { 4, 296, 512 }, { 5, 297, 512 }, { 5, 298, 512 }, { 6, 299, 512 }, { 5, 300, 512 }, { 6, 301, 512 }, { 6, 302, 512 }, { 7, 303, 512 }, |
wolfSSL | 0:9d17e4342598 | 2274 | { 4, 304, 512 }, { 5, 305, 512 }, { 5, 306, 512 }, { 6, 307, 512 }, { 5, 308, 512 }, { 6, 309, 512 }, { 6, 310, 512 }, { 7, 311, 512 }, |
wolfSSL | 0:9d17e4342598 | 2275 | { 5, 312, 512 }, { 6, 313, 512 }, { 6, 314, 512 }, { 7, 315, 512 }, { 6, 316, 512 }, { 7, 317, 512 }, { 7, 318, 512 }, { 8, 319, 512 }, |
wolfSSL | 0:9d17e4342598 | 2276 | { 3, 320, 512 }, { 4, 321, 512 }, { 4, 322, 512 }, { 5, 323, 512 }, { 4, 324, 512 }, { 5, 325, 512 }, { 5, 326, 512 }, { 6, 327, 512 }, |
wolfSSL | 0:9d17e4342598 | 2277 | { 4, 328, 512 }, { 5, 329, 512 }, { 5, 330, 512 }, { 6, 331, 512 }, { 5, 332, 512 }, { 6, 333, 512 }, { 6, 334, 512 }, { 7, 335, 512 }, |
wolfSSL | 0:9d17e4342598 | 2278 | { 4, 336, 512 }, { 5, 337, 512 }, { 5, 338, 512 }, { 6, 339, 512 }, { 5, 340, 512 }, { 6, 341, 512 }, { 6, 342, 512 }, { 7, 343, 512 }, |
wolfSSL | 0:9d17e4342598 | 2279 | { 5, 344, 512 }, { 6, 345, 512 }, { 6, 346, 512 }, { 7, 347, 512 }, { 6, 348, 512 }, { 7, 349, 512 }, { 7, 350, 512 }, { 8, 351, 512 }, |
wolfSSL | 0:9d17e4342598 | 2280 | { 4, 352, 512 }, { 5, 353, 512 }, { 5, 354, 512 }, { 6, 355, 512 }, { 5, 356, 512 }, { 6, 357, 512 }, { 6, 358, 512 }, { 7, 359, 512 }, |
wolfSSL | 0:9d17e4342598 | 2281 | { 5, 360, 512 }, { 6, 361, 512 }, { 6, 362, 512 }, { 7, 363, 512 }, { 6, 364, 512 }, { 7, 365, 512 }, { 7, 366, 512 }, { 8, 367, 512 }, |
wolfSSL | 0:9d17e4342598 | 2282 | { 5, 368, 512 }, { 6, 369, 512 }, { 6, 370, 512 }, { 7, 371, 512 }, { 6, 372, 512 }, { 7, 373, 512 }, { 7, 374, 512 }, { 8, 375, 512 }, |
wolfSSL | 0:9d17e4342598 | 2283 | { 6, 376, 512 }, { 7, 377, 512 }, { 7, 378, 512 }, { 8, 379, 512 }, { 7, 380, 512 }, { 8, 381, 512 }, { 8, 382, 512 }, { 9, 383, 512 }, |
wolfSSL | 0:9d17e4342598 | 2284 | { 3, 384, 512 }, { 4, 385, 512 }, { 4, 386, 512 }, { 5, 387, 512 }, { 4, 388, 512 }, { 5, 389, 512 }, { 5, 390, 512 }, { 6, 391, 512 }, |
wolfSSL | 0:9d17e4342598 | 2285 | { 4, 392, 512 }, { 5, 393, 512 }, { 5, 394, 512 }, { 6, 395, 512 }, { 5, 396, 512 }, { 6, 397, 512 }, { 6, 398, 512 }, { 7, 399, 512 }, |
wolfSSL | 0:9d17e4342598 | 2286 | { 4, 400, 512 }, { 5, 401, 512 }, { 5, 402, 512 }, { 6, 403, 512 }, { 5, 404, 512 }, { 6, 405, 512 }, { 6, 406, 512 }, { 7, 407, 512 }, |
wolfSSL | 0:9d17e4342598 | 2287 | { 5, 408, 512 }, { 6, 409, 512 }, { 6, 410, 512 }, { 7, 411, 512 }, { 6, 412, 512 }, { 7, 413, 512 }, { 7, 414, 512 }, { 8, 415, 512 }, |
wolfSSL | 0:9d17e4342598 | 2288 | { 4, 416, 512 }, { 5, 417, 512 }, { 5, 418, 512 }, { 6, 419, 512 }, { 5, 420, 512 }, { 6, 421, 512 }, { 6, 422, 512 }, { 7, 423, 512 }, |
wolfSSL | 0:9d17e4342598 | 2289 | { 5, 424, 512 }, { 6, 425, 512 }, { 6, 426, 512 }, { 7, 427, 512 }, { 6, 428, 512 }, { 7, 429, 512 }, { 7, 430, 512 }, { 8, 431, 512 }, |
wolfSSL | 0:9d17e4342598 | 2290 | { 5, 432, 512 }, { 6, 433, 512 }, { 6, 434, 512 }, { 7, 435, 512 }, { 6, 436, 512 }, { 7, 437, 512 }, { 7, 438, 512 }, { 8, 439, 512 }, |
wolfSSL | 0:9d17e4342598 | 2291 | { 6, 440, 512 }, { 7, 441, 512 }, { 7, 442, 512 }, { 8, 443, 512 }, { 7, 444, 512 }, { 8, 445, 512 }, { 8, 446, 512 }, { 9, 447, 512 }, |
wolfSSL | 0:9d17e4342598 | 2292 | { 4, 448, 512 }, { 5, 449, 512 }, { 5, 450, 512 }, { 6, 451, 512 }, { 5, 452, 512 }, { 6, 453, 512 }, { 6, 454, 512 }, { 7, 455, 512 }, |
wolfSSL | 0:9d17e4342598 | 2293 | { 5, 456, 512 }, { 6, 457, 512 }, { 6, 458, 512 }, { 7, 459, 512 }, { 6, 460, 512 }, { 7, 461, 512 }, { 7, 462, 512 }, { 8, 463, 512 }, |
wolfSSL | 0:9d17e4342598 | 2294 | { 5, 464, 512 }, { 6, 465, 512 }, { 6, 466, 512 }, { 7, 467, 512 }, { 6, 468, 512 }, { 7, 469, 512 }, { 7, 470, 512 }, { 8, 471, 512 }, |
wolfSSL | 0:9d17e4342598 | 2295 | { 6, 472, 512 }, { 7, 473, 512 }, { 7, 474, 512 }, { 8, 475, 512 }, { 7, 476, 512 }, { 8, 477, 512 }, { 8, 478, 512 }, { 9, 479, 512 }, |
wolfSSL | 0:9d17e4342598 | 2296 | { 5, 480, 512 }, { 6, 481, 512 }, { 6, 482, 512 }, { 7, 483, 512 }, { 6, 484, 512 }, { 7, 485, 512 }, { 7, 486, 512 }, { 8, 487, 512 }, |
wolfSSL | 0:9d17e4342598 | 2297 | { 6, 488, 512 }, { 7, 489, 512 }, { 7, 490, 512 }, { 8, 491, 512 }, { 7, 492, 512 }, { 8, 493, 512 }, { 8, 494, 512 }, { 9, 495, 512 }, |
wolfSSL | 0:9d17e4342598 | 2298 | { 6, 496, 512 }, { 7, 497, 512 }, { 7, 498, 512 }, { 8, 499, 512 }, { 7, 500, 512 }, { 8, 501, 512 }, { 8, 502, 512 }, { 9, 503, 512 }, |
wolfSSL | 0:9d17e4342598 | 2299 | { 7, 504, 512 }, { 8, 505, 512 }, { 8, 506, 512 }, { 9, 507, 512 }, { 8, 508, 512 }, { 9, 509, 512 }, { 9, 510, 512 }, { 10, 511, 512 }, |
wolfSSL | 0:9d17e4342598 | 2300 | #if FP_LUT > 10 |
wolfSSL | 0:9d17e4342598 | 2301 | { 1, 0, 0 }, { 2, 1, 1024 }, { 2, 2, 1024 }, { 3, 3, 1024 }, { 2, 4, 1024 }, { 3, 5, 1024 }, { 3, 6, 1024 }, { 4, 7, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2302 | { 2, 8, 1024 }, { 3, 9, 1024 }, { 3, 10, 1024 }, { 4, 11, 1024 }, { 3, 12, 1024 }, { 4, 13, 1024 }, { 4, 14, 1024 }, { 5, 15, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2303 | { 2, 16, 1024 }, { 3, 17, 1024 }, { 3, 18, 1024 }, { 4, 19, 1024 }, { 3, 20, 1024 }, { 4, 21, 1024 }, { 4, 22, 1024 }, { 5, 23, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2304 | { 3, 24, 1024 }, { 4, 25, 1024 }, { 4, 26, 1024 }, { 5, 27, 1024 }, { 4, 28, 1024 }, { 5, 29, 1024 }, { 5, 30, 1024 }, { 6, 31, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2305 | { 2, 32, 1024 }, { 3, 33, 1024 }, { 3, 34, 1024 }, { 4, 35, 1024 }, { 3, 36, 1024 }, { 4, 37, 1024 }, { 4, 38, 1024 }, { 5, 39, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2306 | { 3, 40, 1024 }, { 4, 41, 1024 }, { 4, 42, 1024 }, { 5, 43, 1024 }, { 4, 44, 1024 }, { 5, 45, 1024 }, { 5, 46, 1024 }, { 6, 47, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2307 | { 3, 48, 1024 }, { 4, 49, 1024 }, { 4, 50, 1024 }, { 5, 51, 1024 }, { 4, 52, 1024 }, { 5, 53, 1024 }, { 5, 54, 1024 }, { 6, 55, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2308 | { 4, 56, 1024 }, { 5, 57, 1024 }, { 5, 58, 1024 }, { 6, 59, 1024 }, { 5, 60, 1024 }, { 6, 61, 1024 }, { 6, 62, 1024 }, { 7, 63, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2309 | { 2, 64, 1024 }, { 3, 65, 1024 }, { 3, 66, 1024 }, { 4, 67, 1024 }, { 3, 68, 1024 }, { 4, 69, 1024 }, { 4, 70, 1024 }, { 5, 71, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2310 | { 3, 72, 1024 }, { 4, 73, 1024 }, { 4, 74, 1024 }, { 5, 75, 1024 }, { 4, 76, 1024 }, { 5, 77, 1024 }, { 5, 78, 1024 }, { 6, 79, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2311 | { 3, 80, 1024 }, { 4, 81, 1024 }, { 4, 82, 1024 }, { 5, 83, 1024 }, { 4, 84, 1024 }, { 5, 85, 1024 }, { 5, 86, 1024 }, { 6, 87, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2312 | { 4, 88, 1024 }, { 5, 89, 1024 }, { 5, 90, 1024 }, { 6, 91, 1024 }, { 5, 92, 1024 }, { 6, 93, 1024 }, { 6, 94, 1024 }, { 7, 95, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2313 | { 3, 96, 1024 }, { 4, 97, 1024 }, { 4, 98, 1024 }, { 5, 99, 1024 }, { 4, 100, 1024 }, { 5, 101, 1024 }, { 5, 102, 1024 }, { 6, 103, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2314 | { 4, 104, 1024 }, { 5, 105, 1024 }, { 5, 106, 1024 }, { 6, 107, 1024 }, { 5, 108, 1024 }, { 6, 109, 1024 }, { 6, 110, 1024 }, { 7, 111, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2315 | { 4, 112, 1024 }, { 5, 113, 1024 }, { 5, 114, 1024 }, { 6, 115, 1024 }, { 5, 116, 1024 }, { 6, 117, 1024 }, { 6, 118, 1024 }, { 7, 119, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2316 | { 5, 120, 1024 }, { 6, 121, 1024 }, { 6, 122, 1024 }, { 7, 123, 1024 }, { 6, 124, 1024 }, { 7, 125, 1024 }, { 7, 126, 1024 }, { 8, 127, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2317 | { 2, 128, 1024 }, { 3, 129, 1024 }, { 3, 130, 1024 }, { 4, 131, 1024 }, { 3, 132, 1024 }, { 4, 133, 1024 }, { 4, 134, 1024 }, { 5, 135, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2318 | { 3, 136, 1024 }, { 4, 137, 1024 }, { 4, 138, 1024 }, { 5, 139, 1024 }, { 4, 140, 1024 }, { 5, 141, 1024 }, { 5, 142, 1024 }, { 6, 143, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2319 | { 3, 144, 1024 }, { 4, 145, 1024 }, { 4, 146, 1024 }, { 5, 147, 1024 }, { 4, 148, 1024 }, { 5, 149, 1024 }, { 5, 150, 1024 }, { 6, 151, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2320 | { 4, 152, 1024 }, { 5, 153, 1024 }, { 5, 154, 1024 }, { 6, 155, 1024 }, { 5, 156, 1024 }, { 6, 157, 1024 }, { 6, 158, 1024 }, { 7, 159, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2321 | { 3, 160, 1024 }, { 4, 161, 1024 }, { 4, 162, 1024 }, { 5, 163, 1024 }, { 4, 164, 1024 }, { 5, 165, 1024 }, { 5, 166, 1024 }, { 6, 167, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2322 | { 4, 168, 1024 }, { 5, 169, 1024 }, { 5, 170, 1024 }, { 6, 171, 1024 }, { 5, 172, 1024 }, { 6, 173, 1024 }, { 6, 174, 1024 }, { 7, 175, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2323 | { 4, 176, 1024 }, { 5, 177, 1024 }, { 5, 178, 1024 }, { 6, 179, 1024 }, { 5, 180, 1024 }, { 6, 181, 1024 }, { 6, 182, 1024 }, { 7, 183, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2324 | { 5, 184, 1024 }, { 6, 185, 1024 }, { 6, 186, 1024 }, { 7, 187, 1024 }, { 6, 188, 1024 }, { 7, 189, 1024 }, { 7, 190, 1024 }, { 8, 191, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2325 | { 3, 192, 1024 }, { 4, 193, 1024 }, { 4, 194, 1024 }, { 5, 195, 1024 }, { 4, 196, 1024 }, { 5, 197, 1024 }, { 5, 198, 1024 }, { 6, 199, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2326 | { 4, 200, 1024 }, { 5, 201, 1024 }, { 5, 202, 1024 }, { 6, 203, 1024 }, { 5, 204, 1024 }, { 6, 205, 1024 }, { 6, 206, 1024 }, { 7, 207, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2327 | { 4, 208, 1024 }, { 5, 209, 1024 }, { 5, 210, 1024 }, { 6, 211, 1024 }, { 5, 212, 1024 }, { 6, 213, 1024 }, { 6, 214, 1024 }, { 7, 215, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2328 | { 5, 216, 1024 }, { 6, 217, 1024 }, { 6, 218, 1024 }, { 7, 219, 1024 }, { 6, 220, 1024 }, { 7, 221, 1024 }, { 7, 222, 1024 }, { 8, 223, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2329 | { 4, 224, 1024 }, { 5, 225, 1024 }, { 5, 226, 1024 }, { 6, 227, 1024 }, { 5, 228, 1024 }, { 6, 229, 1024 }, { 6, 230, 1024 }, { 7, 231, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2330 | { 5, 232, 1024 }, { 6, 233, 1024 }, { 6, 234, 1024 }, { 7, 235, 1024 }, { 6, 236, 1024 }, { 7, 237, 1024 }, { 7, 238, 1024 }, { 8, 239, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2331 | { 5, 240, 1024 }, { 6, 241, 1024 }, { 6, 242, 1024 }, { 7, 243, 1024 }, { 6, 244, 1024 }, { 7, 245, 1024 }, { 7, 246, 1024 }, { 8, 247, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2332 | { 6, 248, 1024 }, { 7, 249, 1024 }, { 7, 250, 1024 }, { 8, 251, 1024 }, { 7, 252, 1024 }, { 8, 253, 1024 }, { 8, 254, 1024 }, { 9, 255, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2333 | { 2, 256, 1024 }, { 3, 257, 1024 }, { 3, 258, 1024 }, { 4, 259, 1024 }, { 3, 260, 1024 }, { 4, 261, 1024 }, { 4, 262, 1024 }, { 5, 263, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2334 | { 3, 264, 1024 }, { 4, 265, 1024 }, { 4, 266, 1024 }, { 5, 267, 1024 }, { 4, 268, 1024 }, { 5, 269, 1024 }, { 5, 270, 1024 }, { 6, 271, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2335 | { 3, 272, 1024 }, { 4, 273, 1024 }, { 4, 274, 1024 }, { 5, 275, 1024 }, { 4, 276, 1024 }, { 5, 277, 1024 }, { 5, 278, 1024 }, { 6, 279, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2336 | { 4, 280, 1024 }, { 5, 281, 1024 }, { 5, 282, 1024 }, { 6, 283, 1024 }, { 5, 284, 1024 }, { 6, 285, 1024 }, { 6, 286, 1024 }, { 7, 287, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2337 | { 3, 288, 1024 }, { 4, 289, 1024 }, { 4, 290, 1024 }, { 5, 291, 1024 }, { 4, 292, 1024 }, { 5, 293, 1024 }, { 5, 294, 1024 }, { 6, 295, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2338 | { 4, 296, 1024 }, { 5, 297, 1024 }, { 5, 298, 1024 }, { 6, 299, 1024 }, { 5, 300, 1024 }, { 6, 301, 1024 }, { 6, 302, 1024 }, { 7, 303, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2339 | { 4, 304, 1024 }, { 5, 305, 1024 }, { 5, 306, 1024 }, { 6, 307, 1024 }, { 5, 308, 1024 }, { 6, 309, 1024 }, { 6, 310, 1024 }, { 7, 311, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2340 | { 5, 312, 1024 }, { 6, 313, 1024 }, { 6, 314, 1024 }, { 7, 315, 1024 }, { 6, 316, 1024 }, { 7, 317, 1024 }, { 7, 318, 1024 }, { 8, 319, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2341 | { 3, 320, 1024 }, { 4, 321, 1024 }, { 4, 322, 1024 }, { 5, 323, 1024 }, { 4, 324, 1024 }, { 5, 325, 1024 }, { 5, 326, 1024 }, { 6, 327, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2342 | { 4, 328, 1024 }, { 5, 329, 1024 }, { 5, 330, 1024 }, { 6, 331, 1024 }, { 5, 332, 1024 }, { 6, 333, 1024 }, { 6, 334, 1024 }, { 7, 335, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2343 | { 4, 336, 1024 }, { 5, 337, 1024 }, { 5, 338, 1024 }, { 6, 339, 1024 }, { 5, 340, 1024 }, { 6, 341, 1024 }, { 6, 342, 1024 }, { 7, 343, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2344 | { 5, 344, 1024 }, { 6, 345, 1024 }, { 6, 346, 1024 }, { 7, 347, 1024 }, { 6, 348, 1024 }, { 7, 349, 1024 }, { 7, 350, 1024 }, { 8, 351, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2345 | { 4, 352, 1024 }, { 5, 353, 1024 }, { 5, 354, 1024 }, { 6, 355, 1024 }, { 5, 356, 1024 }, { 6, 357, 1024 }, { 6, 358, 1024 }, { 7, 359, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2346 | { 5, 360, 1024 }, { 6, 361, 1024 }, { 6, 362, 1024 }, { 7, 363, 1024 }, { 6, 364, 1024 }, { 7, 365, 1024 }, { 7, 366, 1024 }, { 8, 367, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2347 | { 5, 368, 1024 }, { 6, 369, 1024 }, { 6, 370, 1024 }, { 7, 371, 1024 }, { 6, 372, 1024 }, { 7, 373, 1024 }, { 7, 374, 1024 }, { 8, 375, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2348 | { 6, 376, 1024 }, { 7, 377, 1024 }, { 7, 378, 1024 }, { 8, 379, 1024 }, { 7, 380, 1024 }, { 8, 381, 1024 }, { 8, 382, 1024 }, { 9, 383, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2349 | { 3, 384, 1024 }, { 4, 385, 1024 }, { 4, 386, 1024 }, { 5, 387, 1024 }, { 4, 388, 1024 }, { 5, 389, 1024 }, { 5, 390, 1024 }, { 6, 391, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2350 | { 4, 392, 1024 }, { 5, 393, 1024 }, { 5, 394, 1024 }, { 6, 395, 1024 }, { 5, 396, 1024 }, { 6, 397, 1024 }, { 6, 398, 1024 }, { 7, 399, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2351 | { 4, 400, 1024 }, { 5, 401, 1024 }, { 5, 402, 1024 }, { 6, 403, 1024 }, { 5, 404, 1024 }, { 6, 405, 1024 }, { 6, 406, 1024 }, { 7, 407, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2352 | { 5, 408, 1024 }, { 6, 409, 1024 }, { 6, 410, 1024 }, { 7, 411, 1024 }, { 6, 412, 1024 }, { 7, 413, 1024 }, { 7, 414, 1024 }, { 8, 415, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2353 | { 4, 416, 1024 }, { 5, 417, 1024 }, { 5, 418, 1024 }, { 6, 419, 1024 }, { 5, 420, 1024 }, { 6, 421, 1024 }, { 6, 422, 1024 }, { 7, 423, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2354 | { 5, 424, 1024 }, { 6, 425, 1024 }, { 6, 426, 1024 }, { 7, 427, 1024 }, { 6, 428, 1024 }, { 7, 429, 1024 }, { 7, 430, 1024 }, { 8, 431, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2355 | { 5, 432, 1024 }, { 6, 433, 1024 }, { 6, 434, 1024 }, { 7, 435, 1024 }, { 6, 436, 1024 }, { 7, 437, 1024 }, { 7, 438, 1024 }, { 8, 439, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2356 | { 6, 440, 1024 }, { 7, 441, 1024 }, { 7, 442, 1024 }, { 8, 443, 1024 }, { 7, 444, 1024 }, { 8, 445, 1024 }, { 8, 446, 1024 }, { 9, 447, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2357 | { 4, 448, 1024 }, { 5, 449, 1024 }, { 5, 450, 1024 }, { 6, 451, 1024 }, { 5, 452, 1024 }, { 6, 453, 1024 }, { 6, 454, 1024 }, { 7, 455, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2358 | { 5, 456, 1024 }, { 6, 457, 1024 }, { 6, 458, 1024 }, { 7, 459, 1024 }, { 6, 460, 1024 }, { 7, 461, 1024 }, { 7, 462, 1024 }, { 8, 463, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2359 | { 5, 464, 1024 }, { 6, 465, 1024 }, { 6, 466, 1024 }, { 7, 467, 1024 }, { 6, 468, 1024 }, { 7, 469, 1024 }, { 7, 470, 1024 }, { 8, 471, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2360 | { 6, 472, 1024 }, { 7, 473, 1024 }, { 7, 474, 1024 }, { 8, 475, 1024 }, { 7, 476, 1024 }, { 8, 477, 1024 }, { 8, 478, 1024 }, { 9, 479, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2361 | { 5, 480, 1024 }, { 6, 481, 1024 }, { 6, 482, 1024 }, { 7, 483, 1024 }, { 6, 484, 1024 }, { 7, 485, 1024 }, { 7, 486, 1024 }, { 8, 487, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2362 | { 6, 488, 1024 }, { 7, 489, 1024 }, { 7, 490, 1024 }, { 8, 491, 1024 }, { 7, 492, 1024 }, { 8, 493, 1024 }, { 8, 494, 1024 }, { 9, 495, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2363 | { 6, 496, 1024 }, { 7, 497, 1024 }, { 7, 498, 1024 }, { 8, 499, 1024 }, { 7, 500, 1024 }, { 8, 501, 1024 }, { 8, 502, 1024 }, { 9, 503, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2364 | { 7, 504, 1024 }, { 8, 505, 1024 }, { 8, 506, 1024 }, { 9, 507, 1024 }, { 8, 508, 1024 }, { 9, 509, 1024 }, { 9, 510, 1024 }, { 10, 511, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2365 | { 2, 512, 1024 }, { 3, 513, 1024 }, { 3, 514, 1024 }, { 4, 515, 1024 }, { 3, 516, 1024 }, { 4, 517, 1024 }, { 4, 518, 1024 }, { 5, 519, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2366 | { 3, 520, 1024 }, { 4, 521, 1024 }, { 4, 522, 1024 }, { 5, 523, 1024 }, { 4, 524, 1024 }, { 5, 525, 1024 }, { 5, 526, 1024 }, { 6, 527, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2367 | { 3, 528, 1024 }, { 4, 529, 1024 }, { 4, 530, 1024 }, { 5, 531, 1024 }, { 4, 532, 1024 }, { 5, 533, 1024 }, { 5, 534, 1024 }, { 6, 535, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2368 | { 4, 536, 1024 }, { 5, 537, 1024 }, { 5, 538, 1024 }, { 6, 539, 1024 }, { 5, 540, 1024 }, { 6, 541, 1024 }, { 6, 542, 1024 }, { 7, 543, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2369 | { 3, 544, 1024 }, { 4, 545, 1024 }, { 4, 546, 1024 }, { 5, 547, 1024 }, { 4, 548, 1024 }, { 5, 549, 1024 }, { 5, 550, 1024 }, { 6, 551, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2370 | { 4, 552, 1024 }, { 5, 553, 1024 }, { 5, 554, 1024 }, { 6, 555, 1024 }, { 5, 556, 1024 }, { 6, 557, 1024 }, { 6, 558, 1024 }, { 7, 559, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2371 | { 4, 560, 1024 }, { 5, 561, 1024 }, { 5, 562, 1024 }, { 6, 563, 1024 }, { 5, 564, 1024 }, { 6, 565, 1024 }, { 6, 566, 1024 }, { 7, 567, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2372 | { 5, 568, 1024 }, { 6, 569, 1024 }, { 6, 570, 1024 }, { 7, 571, 1024 }, { 6, 572, 1024 }, { 7, 573, 1024 }, { 7, 574, 1024 }, { 8, 575, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2373 | { 3, 576, 1024 }, { 4, 577, 1024 }, { 4, 578, 1024 }, { 5, 579, 1024 }, { 4, 580, 1024 }, { 5, 581, 1024 }, { 5, 582, 1024 }, { 6, 583, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2374 | { 4, 584, 1024 }, { 5, 585, 1024 }, { 5, 586, 1024 }, { 6, 587, 1024 }, { 5, 588, 1024 }, { 6, 589, 1024 }, { 6, 590, 1024 }, { 7, 591, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2375 | { 4, 592, 1024 }, { 5, 593, 1024 }, { 5, 594, 1024 }, { 6, 595, 1024 }, { 5, 596, 1024 }, { 6, 597, 1024 }, { 6, 598, 1024 }, { 7, 599, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2376 | { 5, 600, 1024 }, { 6, 601, 1024 }, { 6, 602, 1024 }, { 7, 603, 1024 }, { 6, 604, 1024 }, { 7, 605, 1024 }, { 7, 606, 1024 }, { 8, 607, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2377 | { 4, 608, 1024 }, { 5, 609, 1024 }, { 5, 610, 1024 }, { 6, 611, 1024 }, { 5, 612, 1024 }, { 6, 613, 1024 }, { 6, 614, 1024 }, { 7, 615, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2378 | { 5, 616, 1024 }, { 6, 617, 1024 }, { 6, 618, 1024 }, { 7, 619, 1024 }, { 6, 620, 1024 }, { 7, 621, 1024 }, { 7, 622, 1024 }, { 8, 623, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2379 | { 5, 624, 1024 }, { 6, 625, 1024 }, { 6, 626, 1024 }, { 7, 627, 1024 }, { 6, 628, 1024 }, { 7, 629, 1024 }, { 7, 630, 1024 }, { 8, 631, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2380 | { 6, 632, 1024 }, { 7, 633, 1024 }, { 7, 634, 1024 }, { 8, 635, 1024 }, { 7, 636, 1024 }, { 8, 637, 1024 }, { 8, 638, 1024 }, { 9, 639, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2381 | { 3, 640, 1024 }, { 4, 641, 1024 }, { 4, 642, 1024 }, { 5, 643, 1024 }, { 4, 644, 1024 }, { 5, 645, 1024 }, { 5, 646, 1024 }, { 6, 647, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2382 | { 4, 648, 1024 }, { 5, 649, 1024 }, { 5, 650, 1024 }, { 6, 651, 1024 }, { 5, 652, 1024 }, { 6, 653, 1024 }, { 6, 654, 1024 }, { 7, 655, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2383 | { 4, 656, 1024 }, { 5, 657, 1024 }, { 5, 658, 1024 }, { 6, 659, 1024 }, { 5, 660, 1024 }, { 6, 661, 1024 }, { 6, 662, 1024 }, { 7, 663, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2384 | { 5, 664, 1024 }, { 6, 665, 1024 }, { 6, 666, 1024 }, { 7, 667, 1024 }, { 6, 668, 1024 }, { 7, 669, 1024 }, { 7, 670, 1024 }, { 8, 671, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2385 | { 4, 672, 1024 }, { 5, 673, 1024 }, { 5, 674, 1024 }, { 6, 675, 1024 }, { 5, 676, 1024 }, { 6, 677, 1024 }, { 6, 678, 1024 }, { 7, 679, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2386 | { 5, 680, 1024 }, { 6, 681, 1024 }, { 6, 682, 1024 }, { 7, 683, 1024 }, { 6, 684, 1024 }, { 7, 685, 1024 }, { 7, 686, 1024 }, { 8, 687, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2387 | { 5, 688, 1024 }, { 6, 689, 1024 }, { 6, 690, 1024 }, { 7, 691, 1024 }, { 6, 692, 1024 }, { 7, 693, 1024 }, { 7, 694, 1024 }, { 8, 695, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2388 | { 6, 696, 1024 }, { 7, 697, 1024 }, { 7, 698, 1024 }, { 8, 699, 1024 }, { 7, 700, 1024 }, { 8, 701, 1024 }, { 8, 702, 1024 }, { 9, 703, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2389 | { 4, 704, 1024 }, { 5, 705, 1024 }, { 5, 706, 1024 }, { 6, 707, 1024 }, { 5, 708, 1024 }, { 6, 709, 1024 }, { 6, 710, 1024 }, { 7, 711, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2390 | { 5, 712, 1024 }, { 6, 713, 1024 }, { 6, 714, 1024 }, { 7, 715, 1024 }, { 6, 716, 1024 }, { 7, 717, 1024 }, { 7, 718, 1024 }, { 8, 719, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2391 | { 5, 720, 1024 }, { 6, 721, 1024 }, { 6, 722, 1024 }, { 7, 723, 1024 }, { 6, 724, 1024 }, { 7, 725, 1024 }, { 7, 726, 1024 }, { 8, 727, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2392 | { 6, 728, 1024 }, { 7, 729, 1024 }, { 7, 730, 1024 }, { 8, 731, 1024 }, { 7, 732, 1024 }, { 8, 733, 1024 }, { 8, 734, 1024 }, { 9, 735, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2393 | { 5, 736, 1024 }, { 6, 737, 1024 }, { 6, 738, 1024 }, { 7, 739, 1024 }, { 6, 740, 1024 }, { 7, 741, 1024 }, { 7, 742, 1024 }, { 8, 743, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2394 | { 6, 744, 1024 }, { 7, 745, 1024 }, { 7, 746, 1024 }, { 8, 747, 1024 }, { 7, 748, 1024 }, { 8, 749, 1024 }, { 8, 750, 1024 }, { 9, 751, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2395 | { 6, 752, 1024 }, { 7, 753, 1024 }, { 7, 754, 1024 }, { 8, 755, 1024 }, { 7, 756, 1024 }, { 8, 757, 1024 }, { 8, 758, 1024 }, { 9, 759, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2396 | { 7, 760, 1024 }, { 8, 761, 1024 }, { 8, 762, 1024 }, { 9, 763, 1024 }, { 8, 764, 1024 }, { 9, 765, 1024 }, { 9, 766, 1024 }, { 10, 767, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2397 | { 3, 768, 1024 }, { 4, 769, 1024 }, { 4, 770, 1024 }, { 5, 771, 1024 }, { 4, 772, 1024 }, { 5, 773, 1024 }, { 5, 774, 1024 }, { 6, 775, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2398 | { 4, 776, 1024 }, { 5, 777, 1024 }, { 5, 778, 1024 }, { 6, 779, 1024 }, { 5, 780, 1024 }, { 6, 781, 1024 }, { 6, 782, 1024 }, { 7, 783, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2399 | { 4, 784, 1024 }, { 5, 785, 1024 }, { 5, 786, 1024 }, { 6, 787, 1024 }, { 5, 788, 1024 }, { 6, 789, 1024 }, { 6, 790, 1024 }, { 7, 791, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2400 | { 5, 792, 1024 }, { 6, 793, 1024 }, { 6, 794, 1024 }, { 7, 795, 1024 }, { 6, 796, 1024 }, { 7, 797, 1024 }, { 7, 798, 1024 }, { 8, 799, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2401 | { 4, 800, 1024 }, { 5, 801, 1024 }, { 5, 802, 1024 }, { 6, 803, 1024 }, { 5, 804, 1024 }, { 6, 805, 1024 }, { 6, 806, 1024 }, { 7, 807, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2402 | { 5, 808, 1024 }, { 6, 809, 1024 }, { 6, 810, 1024 }, { 7, 811, 1024 }, { 6, 812, 1024 }, { 7, 813, 1024 }, { 7, 814, 1024 }, { 8, 815, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2403 | { 5, 816, 1024 }, { 6, 817, 1024 }, { 6, 818, 1024 }, { 7, 819, 1024 }, { 6, 820, 1024 }, { 7, 821, 1024 }, { 7, 822, 1024 }, { 8, 823, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2404 | { 6, 824, 1024 }, { 7, 825, 1024 }, { 7, 826, 1024 }, { 8, 827, 1024 }, { 7, 828, 1024 }, { 8, 829, 1024 }, { 8, 830, 1024 }, { 9, 831, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2405 | { 4, 832, 1024 }, { 5, 833, 1024 }, { 5, 834, 1024 }, { 6, 835, 1024 }, { 5, 836, 1024 }, { 6, 837, 1024 }, { 6, 838, 1024 }, { 7, 839, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2406 | { 5, 840, 1024 }, { 6, 841, 1024 }, { 6, 842, 1024 }, { 7, 843, 1024 }, { 6, 844, 1024 }, { 7, 845, 1024 }, { 7, 846, 1024 }, { 8, 847, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2407 | { 5, 848, 1024 }, { 6, 849, 1024 }, { 6, 850, 1024 }, { 7, 851, 1024 }, { 6, 852, 1024 }, { 7, 853, 1024 }, { 7, 854, 1024 }, { 8, 855, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2408 | { 6, 856, 1024 }, { 7, 857, 1024 }, { 7, 858, 1024 }, { 8, 859, 1024 }, { 7, 860, 1024 }, { 8, 861, 1024 }, { 8, 862, 1024 }, { 9, 863, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2409 | { 5, 864, 1024 }, { 6, 865, 1024 }, { 6, 866, 1024 }, { 7, 867, 1024 }, { 6, 868, 1024 }, { 7, 869, 1024 }, { 7, 870, 1024 }, { 8, 871, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2410 | { 6, 872, 1024 }, { 7, 873, 1024 }, { 7, 874, 1024 }, { 8, 875, 1024 }, { 7, 876, 1024 }, { 8, 877, 1024 }, { 8, 878, 1024 }, { 9, 879, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2411 | { 6, 880, 1024 }, { 7, 881, 1024 }, { 7, 882, 1024 }, { 8, 883, 1024 }, { 7, 884, 1024 }, { 8, 885, 1024 }, { 8, 886, 1024 }, { 9, 887, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2412 | { 7, 888, 1024 }, { 8, 889, 1024 }, { 8, 890, 1024 }, { 9, 891, 1024 }, { 8, 892, 1024 }, { 9, 893, 1024 }, { 9, 894, 1024 }, { 10, 895, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2413 | { 4, 896, 1024 }, { 5, 897, 1024 }, { 5, 898, 1024 }, { 6, 899, 1024 }, { 5, 900, 1024 }, { 6, 901, 1024 }, { 6, 902, 1024 }, { 7, 903, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2414 | { 5, 904, 1024 }, { 6, 905, 1024 }, { 6, 906, 1024 }, { 7, 907, 1024 }, { 6, 908, 1024 }, { 7, 909, 1024 }, { 7, 910, 1024 }, { 8, 911, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2415 | { 5, 912, 1024 }, { 6, 913, 1024 }, { 6, 914, 1024 }, { 7, 915, 1024 }, { 6, 916, 1024 }, { 7, 917, 1024 }, { 7, 918, 1024 }, { 8, 919, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2416 | { 6, 920, 1024 }, { 7, 921, 1024 }, { 7, 922, 1024 }, { 8, 923, 1024 }, { 7, 924, 1024 }, { 8, 925, 1024 }, { 8, 926, 1024 }, { 9, 927, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2417 | { 5, 928, 1024 }, { 6, 929, 1024 }, { 6, 930, 1024 }, { 7, 931, 1024 }, { 6, 932, 1024 }, { 7, 933, 1024 }, { 7, 934, 1024 }, { 8, 935, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2418 | { 6, 936, 1024 }, { 7, 937, 1024 }, { 7, 938, 1024 }, { 8, 939, 1024 }, { 7, 940, 1024 }, { 8, 941, 1024 }, { 8, 942, 1024 }, { 9, 943, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2419 | { 6, 944, 1024 }, { 7, 945, 1024 }, { 7, 946, 1024 }, { 8, 947, 1024 }, { 7, 948, 1024 }, { 8, 949, 1024 }, { 8, 950, 1024 }, { 9, 951, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2420 | { 7, 952, 1024 }, { 8, 953, 1024 }, { 8, 954, 1024 }, { 9, 955, 1024 }, { 8, 956, 1024 }, { 9, 957, 1024 }, { 9, 958, 1024 }, { 10, 959, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2421 | { 5, 960, 1024 }, { 6, 961, 1024 }, { 6, 962, 1024 }, { 7, 963, 1024 }, { 6, 964, 1024 }, { 7, 965, 1024 }, { 7, 966, 1024 }, { 8, 967, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2422 | { 6, 968, 1024 }, { 7, 969, 1024 }, { 7, 970, 1024 }, { 8, 971, 1024 }, { 7, 972, 1024 }, { 8, 973, 1024 }, { 8, 974, 1024 }, { 9, 975, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2423 | { 6, 976, 1024 }, { 7, 977, 1024 }, { 7, 978, 1024 }, { 8, 979, 1024 }, { 7, 980, 1024 }, { 8, 981, 1024 }, { 8, 982, 1024 }, { 9, 983, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2424 | { 7, 984, 1024 }, { 8, 985, 1024 }, { 8, 986, 1024 }, { 9, 987, 1024 }, { 8, 988, 1024 }, { 9, 989, 1024 }, { 9, 990, 1024 }, { 10, 991, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2425 | { 6, 992, 1024 }, { 7, 993, 1024 }, { 7, 994, 1024 }, { 8, 995, 1024 }, { 7, 996, 1024 }, { 8, 997, 1024 }, { 8, 998, 1024 }, { 9, 999, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2426 | { 7, 1000, 1024 }, { 8, 1001, 1024 }, { 8, 1002, 1024 }, { 9, 1003, 1024 }, { 8, 1004, 1024 }, { 9, 1005, 1024 }, { 9, 1006, 1024 }, { 10, 1007, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2427 | { 7, 1008, 1024 }, { 8, 1009, 1024 }, { 8, 1010, 1024 }, { 9, 1011, 1024 }, { 8, 1012, 1024 }, { 9, 1013, 1024 }, { 9, 1014, 1024 }, { 10, 1015, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2428 | { 8, 1016, 1024 }, { 9, 1017, 1024 }, { 9, 1018, 1024 }, { 10, 1019, 1024 }, { 9, 1020, 1024 }, { 10, 1021, 1024 }, { 10, 1022, 1024 }, { 11, 1023, 1024 }, |
wolfSSL | 0:9d17e4342598 | 2429 | #if FP_LUT > 11 |
wolfSSL | 0:9d17e4342598 | 2430 | { 1, 0, 0 }, { 2, 1, 2048 }, { 2, 2, 2048 }, { 3, 3, 2048 }, { 2, 4, 2048 }, { 3, 5, 2048 }, { 3, 6, 2048 }, { 4, 7, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2431 | { 2, 8, 2048 }, { 3, 9, 2048 }, { 3, 10, 2048 }, { 4, 11, 2048 }, { 3, 12, 2048 }, { 4, 13, 2048 }, { 4, 14, 2048 }, { 5, 15, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2432 | { 2, 16, 2048 }, { 3, 17, 2048 }, { 3, 18, 2048 }, { 4, 19, 2048 }, { 3, 20, 2048 }, { 4, 21, 2048 }, { 4, 22, 2048 }, { 5, 23, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2433 | { 3, 24, 2048 }, { 4, 25, 2048 }, { 4, 26, 2048 }, { 5, 27, 2048 }, { 4, 28, 2048 }, { 5, 29, 2048 }, { 5, 30, 2048 }, { 6, 31, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2434 | { 2, 32, 2048 }, { 3, 33, 2048 }, { 3, 34, 2048 }, { 4, 35, 2048 }, { 3, 36, 2048 }, { 4, 37, 2048 }, { 4, 38, 2048 }, { 5, 39, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2435 | { 3, 40, 2048 }, { 4, 41, 2048 }, { 4, 42, 2048 }, { 5, 43, 2048 }, { 4, 44, 2048 }, { 5, 45, 2048 }, { 5, 46, 2048 }, { 6, 47, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2436 | { 3, 48, 2048 }, { 4, 49, 2048 }, { 4, 50, 2048 }, { 5, 51, 2048 }, { 4, 52, 2048 }, { 5, 53, 2048 }, { 5, 54, 2048 }, { 6, 55, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2437 | { 4, 56, 2048 }, { 5, 57, 2048 }, { 5, 58, 2048 }, { 6, 59, 2048 }, { 5, 60, 2048 }, { 6, 61, 2048 }, { 6, 62, 2048 }, { 7, 63, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2438 | { 2, 64, 2048 }, { 3, 65, 2048 }, { 3, 66, 2048 }, { 4, 67, 2048 }, { 3, 68, 2048 }, { 4, 69, 2048 }, { 4, 70, 2048 }, { 5, 71, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2439 | { 3, 72, 2048 }, { 4, 73, 2048 }, { 4, 74, 2048 }, { 5, 75, 2048 }, { 4, 76, 2048 }, { 5, 77, 2048 }, { 5, 78, 2048 }, { 6, 79, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2440 | { 3, 80, 2048 }, { 4, 81, 2048 }, { 4, 82, 2048 }, { 5, 83, 2048 }, { 4, 84, 2048 }, { 5, 85, 2048 }, { 5, 86, 2048 }, { 6, 87, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2441 | { 4, 88, 2048 }, { 5, 89, 2048 }, { 5, 90, 2048 }, { 6, 91, 2048 }, { 5, 92, 2048 }, { 6, 93, 2048 }, { 6, 94, 2048 }, { 7, 95, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2442 | { 3, 96, 2048 }, { 4, 97, 2048 }, { 4, 98, 2048 }, { 5, 99, 2048 }, { 4, 100, 2048 }, { 5, 101, 2048 }, { 5, 102, 2048 }, { 6, 103, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2443 | { 4, 104, 2048 }, { 5, 105, 2048 }, { 5, 106, 2048 }, { 6, 107, 2048 }, { 5, 108, 2048 }, { 6, 109, 2048 }, { 6, 110, 2048 }, { 7, 111, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2444 | { 4, 112, 2048 }, { 5, 113, 2048 }, { 5, 114, 2048 }, { 6, 115, 2048 }, { 5, 116, 2048 }, { 6, 117, 2048 }, { 6, 118, 2048 }, { 7, 119, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2445 | { 5, 120, 2048 }, { 6, 121, 2048 }, { 6, 122, 2048 }, { 7, 123, 2048 }, { 6, 124, 2048 }, { 7, 125, 2048 }, { 7, 126, 2048 }, { 8, 127, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2446 | { 2, 128, 2048 }, { 3, 129, 2048 }, { 3, 130, 2048 }, { 4, 131, 2048 }, { 3, 132, 2048 }, { 4, 133, 2048 }, { 4, 134, 2048 }, { 5, 135, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2447 | { 3, 136, 2048 }, { 4, 137, 2048 }, { 4, 138, 2048 }, { 5, 139, 2048 }, { 4, 140, 2048 }, { 5, 141, 2048 }, { 5, 142, 2048 }, { 6, 143, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2448 | { 3, 144, 2048 }, { 4, 145, 2048 }, { 4, 146, 2048 }, { 5, 147, 2048 }, { 4, 148, 2048 }, { 5, 149, 2048 }, { 5, 150, 2048 }, { 6, 151, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2449 | { 4, 152, 2048 }, { 5, 153, 2048 }, { 5, 154, 2048 }, { 6, 155, 2048 }, { 5, 156, 2048 }, { 6, 157, 2048 }, { 6, 158, 2048 }, { 7, 159, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2450 | { 3, 160, 2048 }, { 4, 161, 2048 }, { 4, 162, 2048 }, { 5, 163, 2048 }, { 4, 164, 2048 }, { 5, 165, 2048 }, { 5, 166, 2048 }, { 6, 167, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2451 | { 4, 168, 2048 }, { 5, 169, 2048 }, { 5, 170, 2048 }, { 6, 171, 2048 }, { 5, 172, 2048 }, { 6, 173, 2048 }, { 6, 174, 2048 }, { 7, 175, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2452 | { 4, 176, 2048 }, { 5, 177, 2048 }, { 5, 178, 2048 }, { 6, 179, 2048 }, { 5, 180, 2048 }, { 6, 181, 2048 }, { 6, 182, 2048 }, { 7, 183, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2453 | { 5, 184, 2048 }, { 6, 185, 2048 }, { 6, 186, 2048 }, { 7, 187, 2048 }, { 6, 188, 2048 }, { 7, 189, 2048 }, { 7, 190, 2048 }, { 8, 191, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2454 | { 3, 192, 2048 }, { 4, 193, 2048 }, { 4, 194, 2048 }, { 5, 195, 2048 }, { 4, 196, 2048 }, { 5, 197, 2048 }, { 5, 198, 2048 }, { 6, 199, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2455 | { 4, 200, 2048 }, { 5, 201, 2048 }, { 5, 202, 2048 }, { 6, 203, 2048 }, { 5, 204, 2048 }, { 6, 205, 2048 }, { 6, 206, 2048 }, { 7, 207, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2456 | { 4, 208, 2048 }, { 5, 209, 2048 }, { 5, 210, 2048 }, { 6, 211, 2048 }, { 5, 212, 2048 }, { 6, 213, 2048 }, { 6, 214, 2048 }, { 7, 215, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2457 | { 5, 216, 2048 }, { 6, 217, 2048 }, { 6, 218, 2048 }, { 7, 219, 2048 }, { 6, 220, 2048 }, { 7, 221, 2048 }, { 7, 222, 2048 }, { 8, 223, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2458 | { 4, 224, 2048 }, { 5, 225, 2048 }, { 5, 226, 2048 }, { 6, 227, 2048 }, { 5, 228, 2048 }, { 6, 229, 2048 }, { 6, 230, 2048 }, { 7, 231, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2459 | { 5, 232, 2048 }, { 6, 233, 2048 }, { 6, 234, 2048 }, { 7, 235, 2048 }, { 6, 236, 2048 }, { 7, 237, 2048 }, { 7, 238, 2048 }, { 8, 239, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2460 | { 5, 240, 2048 }, { 6, 241, 2048 }, { 6, 242, 2048 }, { 7, 243, 2048 }, { 6, 244, 2048 }, { 7, 245, 2048 }, { 7, 246, 2048 }, { 8, 247, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2461 | { 6, 248, 2048 }, { 7, 249, 2048 }, { 7, 250, 2048 }, { 8, 251, 2048 }, { 7, 252, 2048 }, { 8, 253, 2048 }, { 8, 254, 2048 }, { 9, 255, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2462 | { 2, 256, 2048 }, { 3, 257, 2048 }, { 3, 258, 2048 }, { 4, 259, 2048 }, { 3, 260, 2048 }, { 4, 261, 2048 }, { 4, 262, 2048 }, { 5, 263, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2463 | { 3, 264, 2048 }, { 4, 265, 2048 }, { 4, 266, 2048 }, { 5, 267, 2048 }, { 4, 268, 2048 }, { 5, 269, 2048 }, { 5, 270, 2048 }, { 6, 271, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2464 | { 3, 272, 2048 }, { 4, 273, 2048 }, { 4, 274, 2048 }, { 5, 275, 2048 }, { 4, 276, 2048 }, { 5, 277, 2048 }, { 5, 278, 2048 }, { 6, 279, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2465 | { 4, 280, 2048 }, { 5, 281, 2048 }, { 5, 282, 2048 }, { 6, 283, 2048 }, { 5, 284, 2048 }, { 6, 285, 2048 }, { 6, 286, 2048 }, { 7, 287, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2466 | { 3, 288, 2048 }, { 4, 289, 2048 }, { 4, 290, 2048 }, { 5, 291, 2048 }, { 4, 292, 2048 }, { 5, 293, 2048 }, { 5, 294, 2048 }, { 6, 295, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2467 | { 4, 296, 2048 }, { 5, 297, 2048 }, { 5, 298, 2048 }, { 6, 299, 2048 }, { 5, 300, 2048 }, { 6, 301, 2048 }, { 6, 302, 2048 }, { 7, 303, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2468 | { 4, 304, 2048 }, { 5, 305, 2048 }, { 5, 306, 2048 }, { 6, 307, 2048 }, { 5, 308, 2048 }, { 6, 309, 2048 }, { 6, 310, 2048 }, { 7, 311, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2469 | { 5, 312, 2048 }, { 6, 313, 2048 }, { 6, 314, 2048 }, { 7, 315, 2048 }, { 6, 316, 2048 }, { 7, 317, 2048 }, { 7, 318, 2048 }, { 8, 319, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2470 | { 3, 320, 2048 }, { 4, 321, 2048 }, { 4, 322, 2048 }, { 5, 323, 2048 }, { 4, 324, 2048 }, { 5, 325, 2048 }, { 5, 326, 2048 }, { 6, 327, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2471 | { 4, 328, 2048 }, { 5, 329, 2048 }, { 5, 330, 2048 }, { 6, 331, 2048 }, { 5, 332, 2048 }, { 6, 333, 2048 }, { 6, 334, 2048 }, { 7, 335, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2472 | { 4, 336, 2048 }, { 5, 337, 2048 }, { 5, 338, 2048 }, { 6, 339, 2048 }, { 5, 340, 2048 }, { 6, 341, 2048 }, { 6, 342, 2048 }, { 7, 343, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2473 | { 5, 344, 2048 }, { 6, 345, 2048 }, { 6, 346, 2048 }, { 7, 347, 2048 }, { 6, 348, 2048 }, { 7, 349, 2048 }, { 7, 350, 2048 }, { 8, 351, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2474 | { 4, 352, 2048 }, { 5, 353, 2048 }, { 5, 354, 2048 }, { 6, 355, 2048 }, { 5, 356, 2048 }, { 6, 357, 2048 }, { 6, 358, 2048 }, { 7, 359, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2475 | { 5, 360, 2048 }, { 6, 361, 2048 }, { 6, 362, 2048 }, { 7, 363, 2048 }, { 6, 364, 2048 }, { 7, 365, 2048 }, { 7, 366, 2048 }, { 8, 367, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2476 | { 5, 368, 2048 }, { 6, 369, 2048 }, { 6, 370, 2048 }, { 7, 371, 2048 }, { 6, 372, 2048 }, { 7, 373, 2048 }, { 7, 374, 2048 }, { 8, 375, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2477 | { 6, 376, 2048 }, { 7, 377, 2048 }, { 7, 378, 2048 }, { 8, 379, 2048 }, { 7, 380, 2048 }, { 8, 381, 2048 }, { 8, 382, 2048 }, { 9, 383, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2478 | { 3, 384, 2048 }, { 4, 385, 2048 }, { 4, 386, 2048 }, { 5, 387, 2048 }, { 4, 388, 2048 }, { 5, 389, 2048 }, { 5, 390, 2048 }, { 6, 391, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2479 | { 4, 392, 2048 }, { 5, 393, 2048 }, { 5, 394, 2048 }, { 6, 395, 2048 }, { 5, 396, 2048 }, { 6, 397, 2048 }, { 6, 398, 2048 }, { 7, 399, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2480 | { 4, 400, 2048 }, { 5, 401, 2048 }, { 5, 402, 2048 }, { 6, 403, 2048 }, { 5, 404, 2048 }, { 6, 405, 2048 }, { 6, 406, 2048 }, { 7, 407, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2481 | { 5, 408, 2048 }, { 6, 409, 2048 }, { 6, 410, 2048 }, { 7, 411, 2048 }, { 6, 412, 2048 }, { 7, 413, 2048 }, { 7, 414, 2048 }, { 8, 415, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2482 | { 4, 416, 2048 }, { 5, 417, 2048 }, { 5, 418, 2048 }, { 6, 419, 2048 }, { 5, 420, 2048 }, { 6, 421, 2048 }, { 6, 422, 2048 }, { 7, 423, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2483 | { 5, 424, 2048 }, { 6, 425, 2048 }, { 6, 426, 2048 }, { 7, 427, 2048 }, { 6, 428, 2048 }, { 7, 429, 2048 }, { 7, 430, 2048 }, { 8, 431, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2484 | { 5, 432, 2048 }, { 6, 433, 2048 }, { 6, 434, 2048 }, { 7, 435, 2048 }, { 6, 436, 2048 }, { 7, 437, 2048 }, { 7, 438, 2048 }, { 8, 439, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2485 | { 6, 440, 2048 }, { 7, 441, 2048 }, { 7, 442, 2048 }, { 8, 443, 2048 }, { 7, 444, 2048 }, { 8, 445, 2048 }, { 8, 446, 2048 }, { 9, 447, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2486 | { 4, 448, 2048 }, { 5, 449, 2048 }, { 5, 450, 2048 }, { 6, 451, 2048 }, { 5, 452, 2048 }, { 6, 453, 2048 }, { 6, 454, 2048 }, { 7, 455, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2487 | { 5, 456, 2048 }, { 6, 457, 2048 }, { 6, 458, 2048 }, { 7, 459, 2048 }, { 6, 460, 2048 }, { 7, 461, 2048 }, { 7, 462, 2048 }, { 8, 463, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2488 | { 5, 464, 2048 }, { 6, 465, 2048 }, { 6, 466, 2048 }, { 7, 467, 2048 }, { 6, 468, 2048 }, { 7, 469, 2048 }, { 7, 470, 2048 }, { 8, 471, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2489 | { 6, 472, 2048 }, { 7, 473, 2048 }, { 7, 474, 2048 }, { 8, 475, 2048 }, { 7, 476, 2048 }, { 8, 477, 2048 }, { 8, 478, 2048 }, { 9, 479, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2490 | { 5, 480, 2048 }, { 6, 481, 2048 }, { 6, 482, 2048 }, { 7, 483, 2048 }, { 6, 484, 2048 }, { 7, 485, 2048 }, { 7, 486, 2048 }, { 8, 487, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2491 | { 6, 488, 2048 }, { 7, 489, 2048 }, { 7, 490, 2048 }, { 8, 491, 2048 }, { 7, 492, 2048 }, { 8, 493, 2048 }, { 8, 494, 2048 }, { 9, 495, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2492 | { 6, 496, 2048 }, { 7, 497, 2048 }, { 7, 498, 2048 }, { 8, 499, 2048 }, { 7, 500, 2048 }, { 8, 501, 2048 }, { 8, 502, 2048 }, { 9, 503, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2493 | { 7, 504, 2048 }, { 8, 505, 2048 }, { 8, 506, 2048 }, { 9, 507, 2048 }, { 8, 508, 2048 }, { 9, 509, 2048 }, { 9, 510, 2048 }, { 10, 511, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2494 | { 2, 512, 2048 }, { 3, 513, 2048 }, { 3, 514, 2048 }, { 4, 515, 2048 }, { 3, 516, 2048 }, { 4, 517, 2048 }, { 4, 518, 2048 }, { 5, 519, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2495 | { 3, 520, 2048 }, { 4, 521, 2048 }, { 4, 522, 2048 }, { 5, 523, 2048 }, { 4, 524, 2048 }, { 5, 525, 2048 }, { 5, 526, 2048 }, { 6, 527, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2496 | { 3, 528, 2048 }, { 4, 529, 2048 }, { 4, 530, 2048 }, { 5, 531, 2048 }, { 4, 532, 2048 }, { 5, 533, 2048 }, { 5, 534, 2048 }, { 6, 535, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2497 | { 4, 536, 2048 }, { 5, 537, 2048 }, { 5, 538, 2048 }, { 6, 539, 2048 }, { 5, 540, 2048 }, { 6, 541, 2048 }, { 6, 542, 2048 }, { 7, 543, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2498 | { 3, 544, 2048 }, { 4, 545, 2048 }, { 4, 546, 2048 }, { 5, 547, 2048 }, { 4, 548, 2048 }, { 5, 549, 2048 }, { 5, 550, 2048 }, { 6, 551, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2499 | { 4, 552, 2048 }, { 5, 553, 2048 }, { 5, 554, 2048 }, { 6, 555, 2048 }, { 5, 556, 2048 }, { 6, 557, 2048 }, { 6, 558, 2048 }, { 7, 559, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2500 | { 4, 560, 2048 }, { 5, 561, 2048 }, { 5, 562, 2048 }, { 6, 563, 2048 }, { 5, 564, 2048 }, { 6, 565, 2048 }, { 6, 566, 2048 }, { 7, 567, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2501 | { 5, 568, 2048 }, { 6, 569, 2048 }, { 6, 570, 2048 }, { 7, 571, 2048 }, { 6, 572, 2048 }, { 7, 573, 2048 }, { 7, 574, 2048 }, { 8, 575, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2502 | { 3, 576, 2048 }, { 4, 577, 2048 }, { 4, 578, 2048 }, { 5, 579, 2048 }, { 4, 580, 2048 }, { 5, 581, 2048 }, { 5, 582, 2048 }, { 6, 583, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2503 | { 4, 584, 2048 }, { 5, 585, 2048 }, { 5, 586, 2048 }, { 6, 587, 2048 }, { 5, 588, 2048 }, { 6, 589, 2048 }, { 6, 590, 2048 }, { 7, 591, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2504 | { 4, 592, 2048 }, { 5, 593, 2048 }, { 5, 594, 2048 }, { 6, 595, 2048 }, { 5, 596, 2048 }, { 6, 597, 2048 }, { 6, 598, 2048 }, { 7, 599, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2505 | { 5, 600, 2048 }, { 6, 601, 2048 }, { 6, 602, 2048 }, { 7, 603, 2048 }, { 6, 604, 2048 }, { 7, 605, 2048 }, { 7, 606, 2048 }, { 8, 607, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2506 | { 4, 608, 2048 }, { 5, 609, 2048 }, { 5, 610, 2048 }, { 6, 611, 2048 }, { 5, 612, 2048 }, { 6, 613, 2048 }, { 6, 614, 2048 }, { 7, 615, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2507 | { 5, 616, 2048 }, { 6, 617, 2048 }, { 6, 618, 2048 }, { 7, 619, 2048 }, { 6, 620, 2048 }, { 7, 621, 2048 }, { 7, 622, 2048 }, { 8, 623, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2508 | { 5, 624, 2048 }, { 6, 625, 2048 }, { 6, 626, 2048 }, { 7, 627, 2048 }, { 6, 628, 2048 }, { 7, 629, 2048 }, { 7, 630, 2048 }, { 8, 631, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2509 | { 6, 632, 2048 }, { 7, 633, 2048 }, { 7, 634, 2048 }, { 8, 635, 2048 }, { 7, 636, 2048 }, { 8, 637, 2048 }, { 8, 638, 2048 }, { 9, 639, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2510 | { 3, 640, 2048 }, { 4, 641, 2048 }, { 4, 642, 2048 }, { 5, 643, 2048 }, { 4, 644, 2048 }, { 5, 645, 2048 }, { 5, 646, 2048 }, { 6, 647, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2511 | { 4, 648, 2048 }, { 5, 649, 2048 }, { 5, 650, 2048 }, { 6, 651, 2048 }, { 5, 652, 2048 }, { 6, 653, 2048 }, { 6, 654, 2048 }, { 7, 655, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2512 | { 4, 656, 2048 }, { 5, 657, 2048 }, { 5, 658, 2048 }, { 6, 659, 2048 }, { 5, 660, 2048 }, { 6, 661, 2048 }, { 6, 662, 2048 }, { 7, 663, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2513 | { 5, 664, 2048 }, { 6, 665, 2048 }, { 6, 666, 2048 }, { 7, 667, 2048 }, { 6, 668, 2048 }, { 7, 669, 2048 }, { 7, 670, 2048 }, { 8, 671, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2514 | { 4, 672, 2048 }, { 5, 673, 2048 }, { 5, 674, 2048 }, { 6, 675, 2048 }, { 5, 676, 2048 }, { 6, 677, 2048 }, { 6, 678, 2048 }, { 7, 679, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2515 | { 5, 680, 2048 }, { 6, 681, 2048 }, { 6, 682, 2048 }, { 7, 683, 2048 }, { 6, 684, 2048 }, { 7, 685, 2048 }, { 7, 686, 2048 }, { 8, 687, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2516 | { 5, 688, 2048 }, { 6, 689, 2048 }, { 6, 690, 2048 }, { 7, 691, 2048 }, { 6, 692, 2048 }, { 7, 693, 2048 }, { 7, 694, 2048 }, { 8, 695, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2517 | { 6, 696, 2048 }, { 7, 697, 2048 }, { 7, 698, 2048 }, { 8, 699, 2048 }, { 7, 700, 2048 }, { 8, 701, 2048 }, { 8, 702, 2048 }, { 9, 703, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2518 | { 4, 704, 2048 }, { 5, 705, 2048 }, { 5, 706, 2048 }, { 6, 707, 2048 }, { 5, 708, 2048 }, { 6, 709, 2048 }, { 6, 710, 2048 }, { 7, 711, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2519 | { 5, 712, 2048 }, { 6, 713, 2048 }, { 6, 714, 2048 }, { 7, 715, 2048 }, { 6, 716, 2048 }, { 7, 717, 2048 }, { 7, 718, 2048 }, { 8, 719, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2520 | { 5, 720, 2048 }, { 6, 721, 2048 }, { 6, 722, 2048 }, { 7, 723, 2048 }, { 6, 724, 2048 }, { 7, 725, 2048 }, { 7, 726, 2048 }, { 8, 727, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2521 | { 6, 728, 2048 }, { 7, 729, 2048 }, { 7, 730, 2048 }, { 8, 731, 2048 }, { 7, 732, 2048 }, { 8, 733, 2048 }, { 8, 734, 2048 }, { 9, 735, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2522 | { 5, 736, 2048 }, { 6, 737, 2048 }, { 6, 738, 2048 }, { 7, 739, 2048 }, { 6, 740, 2048 }, { 7, 741, 2048 }, { 7, 742, 2048 }, { 8, 743, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2523 | { 6, 744, 2048 }, { 7, 745, 2048 }, { 7, 746, 2048 }, { 8, 747, 2048 }, { 7, 748, 2048 }, { 8, 749, 2048 }, { 8, 750, 2048 }, { 9, 751, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2524 | { 6, 752, 2048 }, { 7, 753, 2048 }, { 7, 754, 2048 }, { 8, 755, 2048 }, { 7, 756, 2048 }, { 8, 757, 2048 }, { 8, 758, 2048 }, { 9, 759, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2525 | { 7, 760, 2048 }, { 8, 761, 2048 }, { 8, 762, 2048 }, { 9, 763, 2048 }, { 8, 764, 2048 }, { 9, 765, 2048 }, { 9, 766, 2048 }, { 10, 767, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2526 | { 3, 768, 2048 }, { 4, 769, 2048 }, { 4, 770, 2048 }, { 5, 771, 2048 }, { 4, 772, 2048 }, { 5, 773, 2048 }, { 5, 774, 2048 }, { 6, 775, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2527 | { 4, 776, 2048 }, { 5, 777, 2048 }, { 5, 778, 2048 }, { 6, 779, 2048 }, { 5, 780, 2048 }, { 6, 781, 2048 }, { 6, 782, 2048 }, { 7, 783, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2528 | { 4, 784, 2048 }, { 5, 785, 2048 }, { 5, 786, 2048 }, { 6, 787, 2048 }, { 5, 788, 2048 }, { 6, 789, 2048 }, { 6, 790, 2048 }, { 7, 791, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2529 | { 5, 792, 2048 }, { 6, 793, 2048 }, { 6, 794, 2048 }, { 7, 795, 2048 }, { 6, 796, 2048 }, { 7, 797, 2048 }, { 7, 798, 2048 }, { 8, 799, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2530 | { 4, 800, 2048 }, { 5, 801, 2048 }, { 5, 802, 2048 }, { 6, 803, 2048 }, { 5, 804, 2048 }, { 6, 805, 2048 }, { 6, 806, 2048 }, { 7, 807, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2531 | { 5, 808, 2048 }, { 6, 809, 2048 }, { 6, 810, 2048 }, { 7, 811, 2048 }, { 6, 812, 2048 }, { 7, 813, 2048 }, { 7, 814, 2048 }, { 8, 815, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2532 | { 5, 816, 2048 }, { 6, 817, 2048 }, { 6, 818, 2048 }, { 7, 819, 2048 }, { 6, 820, 2048 }, { 7, 821, 2048 }, { 7, 822, 2048 }, { 8, 823, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2533 | { 6, 824, 2048 }, { 7, 825, 2048 }, { 7, 826, 2048 }, { 8, 827, 2048 }, { 7, 828, 2048 }, { 8, 829, 2048 }, { 8, 830, 2048 }, { 9, 831, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2534 | { 4, 832, 2048 }, { 5, 833, 2048 }, { 5, 834, 2048 }, { 6, 835, 2048 }, { 5, 836, 2048 }, { 6, 837, 2048 }, { 6, 838, 2048 }, { 7, 839, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2535 | { 5, 840, 2048 }, { 6, 841, 2048 }, { 6, 842, 2048 }, { 7, 843, 2048 }, { 6, 844, 2048 }, { 7, 845, 2048 }, { 7, 846, 2048 }, { 8, 847, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2536 | { 5, 848, 2048 }, { 6, 849, 2048 }, { 6, 850, 2048 }, { 7, 851, 2048 }, { 6, 852, 2048 }, { 7, 853, 2048 }, { 7, 854, 2048 }, { 8, 855, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2537 | { 6, 856, 2048 }, { 7, 857, 2048 }, { 7, 858, 2048 }, { 8, 859, 2048 }, { 7, 860, 2048 }, { 8, 861, 2048 }, { 8, 862, 2048 }, { 9, 863, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2538 | { 5, 864, 2048 }, { 6, 865, 2048 }, { 6, 866, 2048 }, { 7, 867, 2048 }, { 6, 868, 2048 }, { 7, 869, 2048 }, { 7, 870, 2048 }, { 8, 871, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2539 | { 6, 872, 2048 }, { 7, 873, 2048 }, { 7, 874, 2048 }, { 8, 875, 2048 }, { 7, 876, 2048 }, { 8, 877, 2048 }, { 8, 878, 2048 }, { 9, 879, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2540 | { 6, 880, 2048 }, { 7, 881, 2048 }, { 7, 882, 2048 }, { 8, 883, 2048 }, { 7, 884, 2048 }, { 8, 885, 2048 }, { 8, 886, 2048 }, { 9, 887, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2541 | { 7, 888, 2048 }, { 8, 889, 2048 }, { 8, 890, 2048 }, { 9, 891, 2048 }, { 8, 892, 2048 }, { 9, 893, 2048 }, { 9, 894, 2048 }, { 10, 895, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2542 | { 4, 896, 2048 }, { 5, 897, 2048 }, { 5, 898, 2048 }, { 6, 899, 2048 }, { 5, 900, 2048 }, { 6, 901, 2048 }, { 6, 902, 2048 }, { 7, 903, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2543 | { 5, 904, 2048 }, { 6, 905, 2048 }, { 6, 906, 2048 }, { 7, 907, 2048 }, { 6, 908, 2048 }, { 7, 909, 2048 }, { 7, 910, 2048 }, { 8, 911, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2544 | { 5, 912, 2048 }, { 6, 913, 2048 }, { 6, 914, 2048 }, { 7, 915, 2048 }, { 6, 916, 2048 }, { 7, 917, 2048 }, { 7, 918, 2048 }, { 8, 919, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2545 | { 6, 920, 2048 }, { 7, 921, 2048 }, { 7, 922, 2048 }, { 8, 923, 2048 }, { 7, 924, 2048 }, { 8, 925, 2048 }, { 8, 926, 2048 }, { 9, 927, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2546 | { 5, 928, 2048 }, { 6, 929, 2048 }, { 6, 930, 2048 }, { 7, 931, 2048 }, { 6, 932, 2048 }, { 7, 933, 2048 }, { 7, 934, 2048 }, { 8, 935, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2547 | { 6, 936, 2048 }, { 7, 937, 2048 }, { 7, 938, 2048 }, { 8, 939, 2048 }, { 7, 940, 2048 }, { 8, 941, 2048 }, { 8, 942, 2048 }, { 9, 943, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2548 | { 6, 944, 2048 }, { 7, 945, 2048 }, { 7, 946, 2048 }, { 8, 947, 2048 }, { 7, 948, 2048 }, { 8, 949, 2048 }, { 8, 950, 2048 }, { 9, 951, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2549 | { 7, 952, 2048 }, { 8, 953, 2048 }, { 8, 954, 2048 }, { 9, 955, 2048 }, { 8, 956, 2048 }, { 9, 957, 2048 }, { 9, 958, 2048 }, { 10, 959, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2550 | { 5, 960, 2048 }, { 6, 961, 2048 }, { 6, 962, 2048 }, { 7, 963, 2048 }, { 6, 964, 2048 }, { 7, 965, 2048 }, { 7, 966, 2048 }, { 8, 967, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2551 | { 6, 968, 2048 }, { 7, 969, 2048 }, { 7, 970, 2048 }, { 8, 971, 2048 }, { 7, 972, 2048 }, { 8, 973, 2048 }, { 8, 974, 2048 }, { 9, 975, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2552 | { 6, 976, 2048 }, { 7, 977, 2048 }, { 7, 978, 2048 }, { 8, 979, 2048 }, { 7, 980, 2048 }, { 8, 981, 2048 }, { 8, 982, 2048 }, { 9, 983, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2553 | { 7, 984, 2048 }, { 8, 985, 2048 }, { 8, 986, 2048 }, { 9, 987, 2048 }, { 8, 988, 2048 }, { 9, 989, 2048 }, { 9, 990, 2048 }, { 10, 991, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2554 | { 6, 992, 2048 }, { 7, 993, 2048 }, { 7, 994, 2048 }, { 8, 995, 2048 }, { 7, 996, 2048 }, { 8, 997, 2048 }, { 8, 998, 2048 }, { 9, 999, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2555 | { 7, 1000, 2048 }, { 8, 1001, 2048 }, { 8, 1002, 2048 }, { 9, 1003, 2048 }, { 8, 1004, 2048 }, { 9, 1005, 2048 }, { 9, 1006, 2048 }, { 10, 1007, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2556 | { 7, 1008, 2048 }, { 8, 1009, 2048 }, { 8, 1010, 2048 }, { 9, 1011, 2048 }, { 8, 1012, 2048 }, { 9, 1013, 2048 }, { 9, 1014, 2048 }, { 10, 1015, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2557 | { 8, 1016, 2048 }, { 9, 1017, 2048 }, { 9, 1018, 2048 }, { 10, 1019, 2048 }, { 9, 1020, 2048 }, { 10, 1021, 2048 }, { 10, 1022, 2048 }, { 11, 1023, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2558 | { 2, 1024, 2048 }, { 3, 1025, 2048 }, { 3, 1026, 2048 }, { 4, 1027, 2048 }, { 3, 1028, 2048 }, { 4, 1029, 2048 }, { 4, 1030, 2048 }, { 5, 1031, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2559 | { 3, 1032, 2048 }, { 4, 1033, 2048 }, { 4, 1034, 2048 }, { 5, 1035, 2048 }, { 4, 1036, 2048 }, { 5, 1037, 2048 }, { 5, 1038, 2048 }, { 6, 1039, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2560 | { 3, 1040, 2048 }, { 4, 1041, 2048 }, { 4, 1042, 2048 }, { 5, 1043, 2048 }, { 4, 1044, 2048 }, { 5, 1045, 2048 }, { 5, 1046, 2048 }, { 6, 1047, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2561 | { 4, 1048, 2048 }, { 5, 1049, 2048 }, { 5, 1050, 2048 }, { 6, 1051, 2048 }, { 5, 1052, 2048 }, { 6, 1053, 2048 }, { 6, 1054, 2048 }, { 7, 1055, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2562 | { 3, 1056, 2048 }, { 4, 1057, 2048 }, { 4, 1058, 2048 }, { 5, 1059, 2048 }, { 4, 1060, 2048 }, { 5, 1061, 2048 }, { 5, 1062, 2048 }, { 6, 1063, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2563 | { 4, 1064, 2048 }, { 5, 1065, 2048 }, { 5, 1066, 2048 }, { 6, 1067, 2048 }, { 5, 1068, 2048 }, { 6, 1069, 2048 }, { 6, 1070, 2048 }, { 7, 1071, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2564 | { 4, 1072, 2048 }, { 5, 1073, 2048 }, { 5, 1074, 2048 }, { 6, 1075, 2048 }, { 5, 1076, 2048 }, { 6, 1077, 2048 }, { 6, 1078, 2048 }, { 7, 1079, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2565 | { 5, 1080, 2048 }, { 6, 1081, 2048 }, { 6, 1082, 2048 }, { 7, 1083, 2048 }, { 6, 1084, 2048 }, { 7, 1085, 2048 }, { 7, 1086, 2048 }, { 8, 1087, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2566 | { 3, 1088, 2048 }, { 4, 1089, 2048 }, { 4, 1090, 2048 }, { 5, 1091, 2048 }, { 4, 1092, 2048 }, { 5, 1093, 2048 }, { 5, 1094, 2048 }, { 6, 1095, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2567 | { 4, 1096, 2048 }, { 5, 1097, 2048 }, { 5, 1098, 2048 }, { 6, 1099, 2048 }, { 5, 1100, 2048 }, { 6, 1101, 2048 }, { 6, 1102, 2048 }, { 7, 1103, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2568 | { 4, 1104, 2048 }, { 5, 1105, 2048 }, { 5, 1106, 2048 }, { 6, 1107, 2048 }, { 5, 1108, 2048 }, { 6, 1109, 2048 }, { 6, 1110, 2048 }, { 7, 1111, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2569 | { 5, 1112, 2048 }, { 6, 1113, 2048 }, { 6, 1114, 2048 }, { 7, 1115, 2048 }, { 6, 1116, 2048 }, { 7, 1117, 2048 }, { 7, 1118, 2048 }, { 8, 1119, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2570 | { 4, 1120, 2048 }, { 5, 1121, 2048 }, { 5, 1122, 2048 }, { 6, 1123, 2048 }, { 5, 1124, 2048 }, { 6, 1125, 2048 }, { 6, 1126, 2048 }, { 7, 1127, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2571 | { 5, 1128, 2048 }, { 6, 1129, 2048 }, { 6, 1130, 2048 }, { 7, 1131, 2048 }, { 6, 1132, 2048 }, { 7, 1133, 2048 }, { 7, 1134, 2048 }, { 8, 1135, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2572 | { 5, 1136, 2048 }, { 6, 1137, 2048 }, { 6, 1138, 2048 }, { 7, 1139, 2048 }, { 6, 1140, 2048 }, { 7, 1141, 2048 }, { 7, 1142, 2048 }, { 8, 1143, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2573 | { 6, 1144, 2048 }, { 7, 1145, 2048 }, { 7, 1146, 2048 }, { 8, 1147, 2048 }, { 7, 1148, 2048 }, { 8, 1149, 2048 }, { 8, 1150, 2048 }, { 9, 1151, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2574 | { 3, 1152, 2048 }, { 4, 1153, 2048 }, { 4, 1154, 2048 }, { 5, 1155, 2048 }, { 4, 1156, 2048 }, { 5, 1157, 2048 }, { 5, 1158, 2048 }, { 6, 1159, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2575 | { 4, 1160, 2048 }, { 5, 1161, 2048 }, { 5, 1162, 2048 }, { 6, 1163, 2048 }, { 5, 1164, 2048 }, { 6, 1165, 2048 }, { 6, 1166, 2048 }, { 7, 1167, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2576 | { 4, 1168, 2048 }, { 5, 1169, 2048 }, { 5, 1170, 2048 }, { 6, 1171, 2048 }, { 5, 1172, 2048 }, { 6, 1173, 2048 }, { 6, 1174, 2048 }, { 7, 1175, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2577 | { 5, 1176, 2048 }, { 6, 1177, 2048 }, { 6, 1178, 2048 }, { 7, 1179, 2048 }, { 6, 1180, 2048 }, { 7, 1181, 2048 }, { 7, 1182, 2048 }, { 8, 1183, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2578 | { 4, 1184, 2048 }, { 5, 1185, 2048 }, { 5, 1186, 2048 }, { 6, 1187, 2048 }, { 5, 1188, 2048 }, { 6, 1189, 2048 }, { 6, 1190, 2048 }, { 7, 1191, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2579 | { 5, 1192, 2048 }, { 6, 1193, 2048 }, { 6, 1194, 2048 }, { 7, 1195, 2048 }, { 6, 1196, 2048 }, { 7, 1197, 2048 }, { 7, 1198, 2048 }, { 8, 1199, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2580 | { 5, 1200, 2048 }, { 6, 1201, 2048 }, { 6, 1202, 2048 }, { 7, 1203, 2048 }, { 6, 1204, 2048 }, { 7, 1205, 2048 }, { 7, 1206, 2048 }, { 8, 1207, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2581 | { 6, 1208, 2048 }, { 7, 1209, 2048 }, { 7, 1210, 2048 }, { 8, 1211, 2048 }, { 7, 1212, 2048 }, { 8, 1213, 2048 }, { 8, 1214, 2048 }, { 9, 1215, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2582 | { 4, 1216, 2048 }, { 5, 1217, 2048 }, { 5, 1218, 2048 }, { 6, 1219, 2048 }, { 5, 1220, 2048 }, { 6, 1221, 2048 }, { 6, 1222, 2048 }, { 7, 1223, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2583 | { 5, 1224, 2048 }, { 6, 1225, 2048 }, { 6, 1226, 2048 }, { 7, 1227, 2048 }, { 6, 1228, 2048 }, { 7, 1229, 2048 }, { 7, 1230, 2048 }, { 8, 1231, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2584 | { 5, 1232, 2048 }, { 6, 1233, 2048 }, { 6, 1234, 2048 }, { 7, 1235, 2048 }, { 6, 1236, 2048 }, { 7, 1237, 2048 }, { 7, 1238, 2048 }, { 8, 1239, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2585 | { 6, 1240, 2048 }, { 7, 1241, 2048 }, { 7, 1242, 2048 }, { 8, 1243, 2048 }, { 7, 1244, 2048 }, { 8, 1245, 2048 }, { 8, 1246, 2048 }, { 9, 1247, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2586 | { 5, 1248, 2048 }, { 6, 1249, 2048 }, { 6, 1250, 2048 }, { 7, 1251, 2048 }, { 6, 1252, 2048 }, { 7, 1253, 2048 }, { 7, 1254, 2048 }, { 8, 1255, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2587 | { 6, 1256, 2048 }, { 7, 1257, 2048 }, { 7, 1258, 2048 }, { 8, 1259, 2048 }, { 7, 1260, 2048 }, { 8, 1261, 2048 }, { 8, 1262, 2048 }, { 9, 1263, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2588 | { 6, 1264, 2048 }, { 7, 1265, 2048 }, { 7, 1266, 2048 }, { 8, 1267, 2048 }, { 7, 1268, 2048 }, { 8, 1269, 2048 }, { 8, 1270, 2048 }, { 9, 1271, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2589 | { 7, 1272, 2048 }, { 8, 1273, 2048 }, { 8, 1274, 2048 }, { 9, 1275, 2048 }, { 8, 1276, 2048 }, { 9, 1277, 2048 }, { 9, 1278, 2048 }, { 10, 1279, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2590 | { 3, 1280, 2048 }, { 4, 1281, 2048 }, { 4, 1282, 2048 }, { 5, 1283, 2048 }, { 4, 1284, 2048 }, { 5, 1285, 2048 }, { 5, 1286, 2048 }, { 6, 1287, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2591 | { 4, 1288, 2048 }, { 5, 1289, 2048 }, { 5, 1290, 2048 }, { 6, 1291, 2048 }, { 5, 1292, 2048 }, { 6, 1293, 2048 }, { 6, 1294, 2048 }, { 7, 1295, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2592 | { 4, 1296, 2048 }, { 5, 1297, 2048 }, { 5, 1298, 2048 }, { 6, 1299, 2048 }, { 5, 1300, 2048 }, { 6, 1301, 2048 }, { 6, 1302, 2048 }, { 7, 1303, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2593 | { 5, 1304, 2048 }, { 6, 1305, 2048 }, { 6, 1306, 2048 }, { 7, 1307, 2048 }, { 6, 1308, 2048 }, { 7, 1309, 2048 }, { 7, 1310, 2048 }, { 8, 1311, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2594 | { 4, 1312, 2048 }, { 5, 1313, 2048 }, { 5, 1314, 2048 }, { 6, 1315, 2048 }, { 5, 1316, 2048 }, { 6, 1317, 2048 }, { 6, 1318, 2048 }, { 7, 1319, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2595 | { 5, 1320, 2048 }, { 6, 1321, 2048 }, { 6, 1322, 2048 }, { 7, 1323, 2048 }, { 6, 1324, 2048 }, { 7, 1325, 2048 }, { 7, 1326, 2048 }, { 8, 1327, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2596 | { 5, 1328, 2048 }, { 6, 1329, 2048 }, { 6, 1330, 2048 }, { 7, 1331, 2048 }, { 6, 1332, 2048 }, { 7, 1333, 2048 }, { 7, 1334, 2048 }, { 8, 1335, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2597 | { 6, 1336, 2048 }, { 7, 1337, 2048 }, { 7, 1338, 2048 }, { 8, 1339, 2048 }, { 7, 1340, 2048 }, { 8, 1341, 2048 }, { 8, 1342, 2048 }, { 9, 1343, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2598 | { 4, 1344, 2048 }, { 5, 1345, 2048 }, { 5, 1346, 2048 }, { 6, 1347, 2048 }, { 5, 1348, 2048 }, { 6, 1349, 2048 }, { 6, 1350, 2048 }, { 7, 1351, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2599 | { 5, 1352, 2048 }, { 6, 1353, 2048 }, { 6, 1354, 2048 }, { 7, 1355, 2048 }, { 6, 1356, 2048 }, { 7, 1357, 2048 }, { 7, 1358, 2048 }, { 8, 1359, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2600 | { 5, 1360, 2048 }, { 6, 1361, 2048 }, { 6, 1362, 2048 }, { 7, 1363, 2048 }, { 6, 1364, 2048 }, { 7, 1365, 2048 }, { 7, 1366, 2048 }, { 8, 1367, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2601 | { 6, 1368, 2048 }, { 7, 1369, 2048 }, { 7, 1370, 2048 }, { 8, 1371, 2048 }, { 7, 1372, 2048 }, { 8, 1373, 2048 }, { 8, 1374, 2048 }, { 9, 1375, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2602 | { 5, 1376, 2048 }, { 6, 1377, 2048 }, { 6, 1378, 2048 }, { 7, 1379, 2048 }, { 6, 1380, 2048 }, { 7, 1381, 2048 }, { 7, 1382, 2048 }, { 8, 1383, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2603 | { 6, 1384, 2048 }, { 7, 1385, 2048 }, { 7, 1386, 2048 }, { 8, 1387, 2048 }, { 7, 1388, 2048 }, { 8, 1389, 2048 }, { 8, 1390, 2048 }, { 9, 1391, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2604 | { 6, 1392, 2048 }, { 7, 1393, 2048 }, { 7, 1394, 2048 }, { 8, 1395, 2048 }, { 7, 1396, 2048 }, { 8, 1397, 2048 }, { 8, 1398, 2048 }, { 9, 1399, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2605 | { 7, 1400, 2048 }, { 8, 1401, 2048 }, { 8, 1402, 2048 }, { 9, 1403, 2048 }, { 8, 1404, 2048 }, { 9, 1405, 2048 }, { 9, 1406, 2048 }, { 10, 1407, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2606 | { 4, 1408, 2048 }, { 5, 1409, 2048 }, { 5, 1410, 2048 }, { 6, 1411, 2048 }, { 5, 1412, 2048 }, { 6, 1413, 2048 }, { 6, 1414, 2048 }, { 7, 1415, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2607 | { 5, 1416, 2048 }, { 6, 1417, 2048 }, { 6, 1418, 2048 }, { 7, 1419, 2048 }, { 6, 1420, 2048 }, { 7, 1421, 2048 }, { 7, 1422, 2048 }, { 8, 1423, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2608 | { 5, 1424, 2048 }, { 6, 1425, 2048 }, { 6, 1426, 2048 }, { 7, 1427, 2048 }, { 6, 1428, 2048 }, { 7, 1429, 2048 }, { 7, 1430, 2048 }, { 8, 1431, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2609 | { 6, 1432, 2048 }, { 7, 1433, 2048 }, { 7, 1434, 2048 }, { 8, 1435, 2048 }, { 7, 1436, 2048 }, { 8, 1437, 2048 }, { 8, 1438, 2048 }, { 9, 1439, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2610 | { 5, 1440, 2048 }, { 6, 1441, 2048 }, { 6, 1442, 2048 }, { 7, 1443, 2048 }, { 6, 1444, 2048 }, { 7, 1445, 2048 }, { 7, 1446, 2048 }, { 8, 1447, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2611 | { 6, 1448, 2048 }, { 7, 1449, 2048 }, { 7, 1450, 2048 }, { 8, 1451, 2048 }, { 7, 1452, 2048 }, { 8, 1453, 2048 }, { 8, 1454, 2048 }, { 9, 1455, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2612 | { 6, 1456, 2048 }, { 7, 1457, 2048 }, { 7, 1458, 2048 }, { 8, 1459, 2048 }, { 7, 1460, 2048 }, { 8, 1461, 2048 }, { 8, 1462, 2048 }, { 9, 1463, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2613 | { 7, 1464, 2048 }, { 8, 1465, 2048 }, { 8, 1466, 2048 }, { 9, 1467, 2048 }, { 8, 1468, 2048 }, { 9, 1469, 2048 }, { 9, 1470, 2048 }, { 10, 1471, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2614 | { 5, 1472, 2048 }, { 6, 1473, 2048 }, { 6, 1474, 2048 }, { 7, 1475, 2048 }, { 6, 1476, 2048 }, { 7, 1477, 2048 }, { 7, 1478, 2048 }, { 8, 1479, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2615 | { 6, 1480, 2048 }, { 7, 1481, 2048 }, { 7, 1482, 2048 }, { 8, 1483, 2048 }, { 7, 1484, 2048 }, { 8, 1485, 2048 }, { 8, 1486, 2048 }, { 9, 1487, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2616 | { 6, 1488, 2048 }, { 7, 1489, 2048 }, { 7, 1490, 2048 }, { 8, 1491, 2048 }, { 7, 1492, 2048 }, { 8, 1493, 2048 }, { 8, 1494, 2048 }, { 9, 1495, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2617 | { 7, 1496, 2048 }, { 8, 1497, 2048 }, { 8, 1498, 2048 }, { 9, 1499, 2048 }, { 8, 1500, 2048 }, { 9, 1501, 2048 }, { 9, 1502, 2048 }, { 10, 1503, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2618 | { 6, 1504, 2048 }, { 7, 1505, 2048 }, { 7, 1506, 2048 }, { 8, 1507, 2048 }, { 7, 1508, 2048 }, { 8, 1509, 2048 }, { 8, 1510, 2048 }, { 9, 1511, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2619 | { 7, 1512, 2048 }, { 8, 1513, 2048 }, { 8, 1514, 2048 }, { 9, 1515, 2048 }, { 8, 1516, 2048 }, { 9, 1517, 2048 }, { 9, 1518, 2048 }, { 10, 1519, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2620 | { 7, 1520, 2048 }, { 8, 1521, 2048 }, { 8, 1522, 2048 }, { 9, 1523, 2048 }, { 8, 1524, 2048 }, { 9, 1525, 2048 }, { 9, 1526, 2048 }, { 10, 1527, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2621 | { 8, 1528, 2048 }, { 9, 1529, 2048 }, { 9, 1530, 2048 }, { 10, 1531, 2048 }, { 9, 1532, 2048 }, { 10, 1533, 2048 }, { 10, 1534, 2048 }, { 11, 1535, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2622 | { 3, 1536, 2048 }, { 4, 1537, 2048 }, { 4, 1538, 2048 }, { 5, 1539, 2048 }, { 4, 1540, 2048 }, { 5, 1541, 2048 }, { 5, 1542, 2048 }, { 6, 1543, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2623 | { 4, 1544, 2048 }, { 5, 1545, 2048 }, { 5, 1546, 2048 }, { 6, 1547, 2048 }, { 5, 1548, 2048 }, { 6, 1549, 2048 }, { 6, 1550, 2048 }, { 7, 1551, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2624 | { 4, 1552, 2048 }, { 5, 1553, 2048 }, { 5, 1554, 2048 }, { 6, 1555, 2048 }, { 5, 1556, 2048 }, { 6, 1557, 2048 }, { 6, 1558, 2048 }, { 7, 1559, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2625 | { 5, 1560, 2048 }, { 6, 1561, 2048 }, { 6, 1562, 2048 }, { 7, 1563, 2048 }, { 6, 1564, 2048 }, { 7, 1565, 2048 }, { 7, 1566, 2048 }, { 8, 1567, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2626 | { 4, 1568, 2048 }, { 5, 1569, 2048 }, { 5, 1570, 2048 }, { 6, 1571, 2048 }, { 5, 1572, 2048 }, { 6, 1573, 2048 }, { 6, 1574, 2048 }, { 7, 1575, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2627 | { 5, 1576, 2048 }, { 6, 1577, 2048 }, { 6, 1578, 2048 }, { 7, 1579, 2048 }, { 6, 1580, 2048 }, { 7, 1581, 2048 }, { 7, 1582, 2048 }, { 8, 1583, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2628 | { 5, 1584, 2048 }, { 6, 1585, 2048 }, { 6, 1586, 2048 }, { 7, 1587, 2048 }, { 6, 1588, 2048 }, { 7, 1589, 2048 }, { 7, 1590, 2048 }, { 8, 1591, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2629 | { 6, 1592, 2048 }, { 7, 1593, 2048 }, { 7, 1594, 2048 }, { 8, 1595, 2048 }, { 7, 1596, 2048 }, { 8, 1597, 2048 }, { 8, 1598, 2048 }, { 9, 1599, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2630 | { 4, 1600, 2048 }, { 5, 1601, 2048 }, { 5, 1602, 2048 }, { 6, 1603, 2048 }, { 5, 1604, 2048 }, { 6, 1605, 2048 }, { 6, 1606, 2048 }, { 7, 1607, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2631 | { 5, 1608, 2048 }, { 6, 1609, 2048 }, { 6, 1610, 2048 }, { 7, 1611, 2048 }, { 6, 1612, 2048 }, { 7, 1613, 2048 }, { 7, 1614, 2048 }, { 8, 1615, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2632 | { 5, 1616, 2048 }, { 6, 1617, 2048 }, { 6, 1618, 2048 }, { 7, 1619, 2048 }, { 6, 1620, 2048 }, { 7, 1621, 2048 }, { 7, 1622, 2048 }, { 8, 1623, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2633 | { 6, 1624, 2048 }, { 7, 1625, 2048 }, { 7, 1626, 2048 }, { 8, 1627, 2048 }, { 7, 1628, 2048 }, { 8, 1629, 2048 }, { 8, 1630, 2048 }, { 9, 1631, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2634 | { 5, 1632, 2048 }, { 6, 1633, 2048 }, { 6, 1634, 2048 }, { 7, 1635, 2048 }, { 6, 1636, 2048 }, { 7, 1637, 2048 }, { 7, 1638, 2048 }, { 8, 1639, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2635 | { 6, 1640, 2048 }, { 7, 1641, 2048 }, { 7, 1642, 2048 }, { 8, 1643, 2048 }, { 7, 1644, 2048 }, { 8, 1645, 2048 }, { 8, 1646, 2048 }, { 9, 1647, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2636 | { 6, 1648, 2048 }, { 7, 1649, 2048 }, { 7, 1650, 2048 }, { 8, 1651, 2048 }, { 7, 1652, 2048 }, { 8, 1653, 2048 }, { 8, 1654, 2048 }, { 9, 1655, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2637 | { 7, 1656, 2048 }, { 8, 1657, 2048 }, { 8, 1658, 2048 }, { 9, 1659, 2048 }, { 8, 1660, 2048 }, { 9, 1661, 2048 }, { 9, 1662, 2048 }, { 10, 1663, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2638 | { 4, 1664, 2048 }, { 5, 1665, 2048 }, { 5, 1666, 2048 }, { 6, 1667, 2048 }, { 5, 1668, 2048 }, { 6, 1669, 2048 }, { 6, 1670, 2048 }, { 7, 1671, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2639 | { 5, 1672, 2048 }, { 6, 1673, 2048 }, { 6, 1674, 2048 }, { 7, 1675, 2048 }, { 6, 1676, 2048 }, { 7, 1677, 2048 }, { 7, 1678, 2048 }, { 8, 1679, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2640 | { 5, 1680, 2048 }, { 6, 1681, 2048 }, { 6, 1682, 2048 }, { 7, 1683, 2048 }, { 6, 1684, 2048 }, { 7, 1685, 2048 }, { 7, 1686, 2048 }, { 8, 1687, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2641 | { 6, 1688, 2048 }, { 7, 1689, 2048 }, { 7, 1690, 2048 }, { 8, 1691, 2048 }, { 7, 1692, 2048 }, { 8, 1693, 2048 }, { 8, 1694, 2048 }, { 9, 1695, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2642 | { 5, 1696, 2048 }, { 6, 1697, 2048 }, { 6, 1698, 2048 }, { 7, 1699, 2048 }, { 6, 1700, 2048 }, { 7, 1701, 2048 }, { 7, 1702, 2048 }, { 8, 1703, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2643 | { 6, 1704, 2048 }, { 7, 1705, 2048 }, { 7, 1706, 2048 }, { 8, 1707, 2048 }, { 7, 1708, 2048 }, { 8, 1709, 2048 }, { 8, 1710, 2048 }, { 9, 1711, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2644 | { 6, 1712, 2048 }, { 7, 1713, 2048 }, { 7, 1714, 2048 }, { 8, 1715, 2048 }, { 7, 1716, 2048 }, { 8, 1717, 2048 }, { 8, 1718, 2048 }, { 9, 1719, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2645 | { 7, 1720, 2048 }, { 8, 1721, 2048 }, { 8, 1722, 2048 }, { 9, 1723, 2048 }, { 8, 1724, 2048 }, { 9, 1725, 2048 }, { 9, 1726, 2048 }, { 10, 1727, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2646 | { 5, 1728, 2048 }, { 6, 1729, 2048 }, { 6, 1730, 2048 }, { 7, 1731, 2048 }, { 6, 1732, 2048 }, { 7, 1733, 2048 }, { 7, 1734, 2048 }, { 8, 1735, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2647 | { 6, 1736, 2048 }, { 7, 1737, 2048 }, { 7, 1738, 2048 }, { 8, 1739, 2048 }, { 7, 1740, 2048 }, { 8, 1741, 2048 }, { 8, 1742, 2048 }, { 9, 1743, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2648 | { 6, 1744, 2048 }, { 7, 1745, 2048 }, { 7, 1746, 2048 }, { 8, 1747, 2048 }, { 7, 1748, 2048 }, { 8, 1749, 2048 }, { 8, 1750, 2048 }, { 9, 1751, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2649 | { 7, 1752, 2048 }, { 8, 1753, 2048 }, { 8, 1754, 2048 }, { 9, 1755, 2048 }, { 8, 1756, 2048 }, { 9, 1757, 2048 }, { 9, 1758, 2048 }, { 10, 1759, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2650 | { 6, 1760, 2048 }, { 7, 1761, 2048 }, { 7, 1762, 2048 }, { 8, 1763, 2048 }, { 7, 1764, 2048 }, { 8, 1765, 2048 }, { 8, 1766, 2048 }, { 9, 1767, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2651 | { 7, 1768, 2048 }, { 8, 1769, 2048 }, { 8, 1770, 2048 }, { 9, 1771, 2048 }, { 8, 1772, 2048 }, { 9, 1773, 2048 }, { 9, 1774, 2048 }, { 10, 1775, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2652 | { 7, 1776, 2048 }, { 8, 1777, 2048 }, { 8, 1778, 2048 }, { 9, 1779, 2048 }, { 8, 1780, 2048 }, { 9, 1781, 2048 }, { 9, 1782, 2048 }, { 10, 1783, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2653 | { 8, 1784, 2048 }, { 9, 1785, 2048 }, { 9, 1786, 2048 }, { 10, 1787, 2048 }, { 9, 1788, 2048 }, { 10, 1789, 2048 }, { 10, 1790, 2048 }, { 11, 1791, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2654 | { 4, 1792, 2048 }, { 5, 1793, 2048 }, { 5, 1794, 2048 }, { 6, 1795, 2048 }, { 5, 1796, 2048 }, { 6, 1797, 2048 }, { 6, 1798, 2048 }, { 7, 1799, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2655 | { 5, 1800, 2048 }, { 6, 1801, 2048 }, { 6, 1802, 2048 }, { 7, 1803, 2048 }, { 6, 1804, 2048 }, { 7, 1805, 2048 }, { 7, 1806, 2048 }, { 8, 1807, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2656 | { 5, 1808, 2048 }, { 6, 1809, 2048 }, { 6, 1810, 2048 }, { 7, 1811, 2048 }, { 6, 1812, 2048 }, { 7, 1813, 2048 }, { 7, 1814, 2048 }, { 8, 1815, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2657 | { 6, 1816, 2048 }, { 7, 1817, 2048 }, { 7, 1818, 2048 }, { 8, 1819, 2048 }, { 7, 1820, 2048 }, { 8, 1821, 2048 }, { 8, 1822, 2048 }, { 9, 1823, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2658 | { 5, 1824, 2048 }, { 6, 1825, 2048 }, { 6, 1826, 2048 }, { 7, 1827, 2048 }, { 6, 1828, 2048 }, { 7, 1829, 2048 }, { 7, 1830, 2048 }, { 8, 1831, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2659 | { 6, 1832, 2048 }, { 7, 1833, 2048 }, { 7, 1834, 2048 }, { 8, 1835, 2048 }, { 7, 1836, 2048 }, { 8, 1837, 2048 }, { 8, 1838, 2048 }, { 9, 1839, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2660 | { 6, 1840, 2048 }, { 7, 1841, 2048 }, { 7, 1842, 2048 }, { 8, 1843, 2048 }, { 7, 1844, 2048 }, { 8, 1845, 2048 }, { 8, 1846, 2048 }, { 9, 1847, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2661 | { 7, 1848, 2048 }, { 8, 1849, 2048 }, { 8, 1850, 2048 }, { 9, 1851, 2048 }, { 8, 1852, 2048 }, { 9, 1853, 2048 }, { 9, 1854, 2048 }, { 10, 1855, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2662 | { 5, 1856, 2048 }, { 6, 1857, 2048 }, { 6, 1858, 2048 }, { 7, 1859, 2048 }, { 6, 1860, 2048 }, { 7, 1861, 2048 }, { 7, 1862, 2048 }, { 8, 1863, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2663 | { 6, 1864, 2048 }, { 7, 1865, 2048 }, { 7, 1866, 2048 }, { 8, 1867, 2048 }, { 7, 1868, 2048 }, { 8, 1869, 2048 }, { 8, 1870, 2048 }, { 9, 1871, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2664 | { 6, 1872, 2048 }, { 7, 1873, 2048 }, { 7, 1874, 2048 }, { 8, 1875, 2048 }, { 7, 1876, 2048 }, { 8, 1877, 2048 }, { 8, 1878, 2048 }, { 9, 1879, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2665 | { 7, 1880, 2048 }, { 8, 1881, 2048 }, { 8, 1882, 2048 }, { 9, 1883, 2048 }, { 8, 1884, 2048 }, { 9, 1885, 2048 }, { 9, 1886, 2048 }, { 10, 1887, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2666 | { 6, 1888, 2048 }, { 7, 1889, 2048 }, { 7, 1890, 2048 }, { 8, 1891, 2048 }, { 7, 1892, 2048 }, { 8, 1893, 2048 }, { 8, 1894, 2048 }, { 9, 1895, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2667 | { 7, 1896, 2048 }, { 8, 1897, 2048 }, { 8, 1898, 2048 }, { 9, 1899, 2048 }, { 8, 1900, 2048 }, { 9, 1901, 2048 }, { 9, 1902, 2048 }, { 10, 1903, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2668 | { 7, 1904, 2048 }, { 8, 1905, 2048 }, { 8, 1906, 2048 }, { 9, 1907, 2048 }, { 8, 1908, 2048 }, { 9, 1909, 2048 }, { 9, 1910, 2048 }, { 10, 1911, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2669 | { 8, 1912, 2048 }, { 9, 1913, 2048 }, { 9, 1914, 2048 }, { 10, 1915, 2048 }, { 9, 1916, 2048 }, { 10, 1917, 2048 }, { 10, 1918, 2048 }, { 11, 1919, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2670 | { 5, 1920, 2048 }, { 6, 1921, 2048 }, { 6, 1922, 2048 }, { 7, 1923, 2048 }, { 6, 1924, 2048 }, { 7, 1925, 2048 }, { 7, 1926, 2048 }, { 8, 1927, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2671 | { 6, 1928, 2048 }, { 7, 1929, 2048 }, { 7, 1930, 2048 }, { 8, 1931, 2048 }, { 7, 1932, 2048 }, { 8, 1933, 2048 }, { 8, 1934, 2048 }, { 9, 1935, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2672 | { 6, 1936, 2048 }, { 7, 1937, 2048 }, { 7, 1938, 2048 }, { 8, 1939, 2048 }, { 7, 1940, 2048 }, { 8, 1941, 2048 }, { 8, 1942, 2048 }, { 9, 1943, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2673 | { 7, 1944, 2048 }, { 8, 1945, 2048 }, { 8, 1946, 2048 }, { 9, 1947, 2048 }, { 8, 1948, 2048 }, { 9, 1949, 2048 }, { 9, 1950, 2048 }, { 10, 1951, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2674 | { 6, 1952, 2048 }, { 7, 1953, 2048 }, { 7, 1954, 2048 }, { 8, 1955, 2048 }, { 7, 1956, 2048 }, { 8, 1957, 2048 }, { 8, 1958, 2048 }, { 9, 1959, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2675 | { 7, 1960, 2048 }, { 8, 1961, 2048 }, { 8, 1962, 2048 }, { 9, 1963, 2048 }, { 8, 1964, 2048 }, { 9, 1965, 2048 }, { 9, 1966, 2048 }, { 10, 1967, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2676 | { 7, 1968, 2048 }, { 8, 1969, 2048 }, { 8, 1970, 2048 }, { 9, 1971, 2048 }, { 8, 1972, 2048 }, { 9, 1973, 2048 }, { 9, 1974, 2048 }, { 10, 1975, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2677 | { 8, 1976, 2048 }, { 9, 1977, 2048 }, { 9, 1978, 2048 }, { 10, 1979, 2048 }, { 9, 1980, 2048 }, { 10, 1981, 2048 }, { 10, 1982, 2048 }, { 11, 1983, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2678 | { 6, 1984, 2048 }, { 7, 1985, 2048 }, { 7, 1986, 2048 }, { 8, 1987, 2048 }, { 7, 1988, 2048 }, { 8, 1989, 2048 }, { 8, 1990, 2048 }, { 9, 1991, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2679 | { 7, 1992, 2048 }, { 8, 1993, 2048 }, { 8, 1994, 2048 }, { 9, 1995, 2048 }, { 8, 1996, 2048 }, { 9, 1997, 2048 }, { 9, 1998, 2048 }, { 10, 1999, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2680 | { 7, 2000, 2048 }, { 8, 2001, 2048 }, { 8, 2002, 2048 }, { 9, 2003, 2048 }, { 8, 2004, 2048 }, { 9, 2005, 2048 }, { 9, 2006, 2048 }, { 10, 2007, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2681 | { 8, 2008, 2048 }, { 9, 2009, 2048 }, { 9, 2010, 2048 }, { 10, 2011, 2048 }, { 9, 2012, 2048 }, { 10, 2013, 2048 }, { 10, 2014, 2048 }, { 11, 2015, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2682 | { 7, 2016, 2048 }, { 8, 2017, 2048 }, { 8, 2018, 2048 }, { 9, 2019, 2048 }, { 8, 2020, 2048 }, { 9, 2021, 2048 }, { 9, 2022, 2048 }, { 10, 2023, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2683 | { 8, 2024, 2048 }, { 9, 2025, 2048 }, { 9, 2026, 2048 }, { 10, 2027, 2048 }, { 9, 2028, 2048 }, { 10, 2029, 2048 }, { 10, 2030, 2048 }, { 11, 2031, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2684 | { 8, 2032, 2048 }, { 9, 2033, 2048 }, { 9, 2034, 2048 }, { 10, 2035, 2048 }, { 9, 2036, 2048 }, { 10, 2037, 2048 }, { 10, 2038, 2048 }, { 11, 2039, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2685 | { 9, 2040, 2048 }, { 10, 2041, 2048 }, { 10, 2042, 2048 }, { 11, 2043, 2048 }, { 10, 2044, 2048 }, { 11, 2045, 2048 }, { 11, 2046, 2048 }, { 12, 2047, 2048 }, |
wolfSSL | 0:9d17e4342598 | 2686 | #endif |
wolfSSL | 0:9d17e4342598 | 2687 | #endif |
wolfSSL | 0:9d17e4342598 | 2688 | #endif |
wolfSSL | 0:9d17e4342598 | 2689 | #endif |
wolfSSL | 0:9d17e4342598 | 2690 | #endif |
wolfSSL | 0:9d17e4342598 | 2691 | #endif |
wolfSSL | 0:9d17e4342598 | 2692 | }; |
wolfSSL | 0:9d17e4342598 | 2693 | |
wolfSSL | 0:9d17e4342598 | 2694 | /* find a hole and free as required, return -1 if no hole found */ |
wolfSSL | 0:9d17e4342598 | 2695 | static int find_hole(void) |
wolfSSL | 0:9d17e4342598 | 2696 | { |
wolfSSL | 0:9d17e4342598 | 2697 | unsigned x; |
wolfSSL | 0:9d17e4342598 | 2698 | int y, z; |
wolfSSL | 0:9d17e4342598 | 2699 | for (z = -1, y = INT_MAX, x = 0; x < FP_ENTRIES; x++) { |
wolfSSL | 0:9d17e4342598 | 2700 | if (fp_cache[x].lru_count < y && fp_cache[x].lock == 0) { |
wolfSSL | 0:9d17e4342598 | 2701 | z = x; |
wolfSSL | 0:9d17e4342598 | 2702 | y = fp_cache[x].lru_count; |
wolfSSL | 0:9d17e4342598 | 2703 | } |
wolfSSL | 0:9d17e4342598 | 2704 | } |
wolfSSL | 0:9d17e4342598 | 2705 | |
wolfSSL | 0:9d17e4342598 | 2706 | /* decrease all */ |
wolfSSL | 0:9d17e4342598 | 2707 | for (x = 0; x < FP_ENTRIES; x++) { |
wolfSSL | 0:9d17e4342598 | 2708 | if (fp_cache[x].lru_count > 3) { |
wolfSSL | 0:9d17e4342598 | 2709 | --(fp_cache[x].lru_count); |
wolfSSL | 0:9d17e4342598 | 2710 | } |
wolfSSL | 0:9d17e4342598 | 2711 | } |
wolfSSL | 0:9d17e4342598 | 2712 | |
wolfSSL | 0:9d17e4342598 | 2713 | /* free entry z */ |
wolfSSL | 0:9d17e4342598 | 2714 | if (z >= 0 && fp_cache[z].g) { |
wolfSSL | 0:9d17e4342598 | 2715 | mp_clear(&fp_cache[z].mu); |
wolfSSL | 0:9d17e4342598 | 2716 | ecc_del_point(fp_cache[z].g); |
wolfSSL | 0:9d17e4342598 | 2717 | fp_cache[z].g = NULL; |
wolfSSL | 0:9d17e4342598 | 2718 | for (x = 0; x < (1U<<FP_LUT); x++) { |
wolfSSL | 0:9d17e4342598 | 2719 | ecc_del_point(fp_cache[z].LUT[x]); |
wolfSSL | 0:9d17e4342598 | 2720 | fp_cache[z].LUT[x] = NULL; |
wolfSSL | 0:9d17e4342598 | 2721 | } |
wolfSSL | 0:9d17e4342598 | 2722 | fp_cache[z].lru_count = 0; |
wolfSSL | 0:9d17e4342598 | 2723 | } |
wolfSSL | 0:9d17e4342598 | 2724 | return z; |
wolfSSL | 0:9d17e4342598 | 2725 | } |
wolfSSL | 0:9d17e4342598 | 2726 | |
wolfSSL | 0:9d17e4342598 | 2727 | /* determine if a base is already in the cache and if so, where */ |
wolfSSL | 0:9d17e4342598 | 2728 | static int find_base(ecc_point* g) |
wolfSSL | 0:9d17e4342598 | 2729 | { |
wolfSSL | 0:9d17e4342598 | 2730 | int x; |
wolfSSL | 0:9d17e4342598 | 2731 | for (x = 0; x < FP_ENTRIES; x++) { |
wolfSSL | 0:9d17e4342598 | 2732 | if (fp_cache[x].g != NULL && |
wolfSSL | 0:9d17e4342598 | 2733 | mp_cmp(&fp_cache[x].g->x, &g->x) == MP_EQ && |
wolfSSL | 0:9d17e4342598 | 2734 | mp_cmp(&fp_cache[x].g->y, &g->y) == MP_EQ && |
wolfSSL | 0:9d17e4342598 | 2735 | mp_cmp(&fp_cache[x].g->z, &g->z) == MP_EQ) { |
wolfSSL | 0:9d17e4342598 | 2736 | break; |
wolfSSL | 0:9d17e4342598 | 2737 | } |
wolfSSL | 0:9d17e4342598 | 2738 | } |
wolfSSL | 0:9d17e4342598 | 2739 | if (x == FP_ENTRIES) { |
wolfSSL | 0:9d17e4342598 | 2740 | x = -1; |
wolfSSL | 0:9d17e4342598 | 2741 | } |
wolfSSL | 0:9d17e4342598 | 2742 | return x; |
wolfSSL | 0:9d17e4342598 | 2743 | } |
wolfSSL | 0:9d17e4342598 | 2744 | |
wolfSSL | 0:9d17e4342598 | 2745 | /* add a new base to the cache */ |
wolfSSL | 0:9d17e4342598 | 2746 | static int add_entry(int idx, ecc_point *g) |
wolfSSL | 0:9d17e4342598 | 2747 | { |
wolfSSL | 0:9d17e4342598 | 2748 | unsigned x, y; |
wolfSSL | 0:9d17e4342598 | 2749 | |
wolfSSL | 0:9d17e4342598 | 2750 | /* allocate base and LUT */ |
wolfSSL | 0:9d17e4342598 | 2751 | fp_cache[idx].g = ecc_new_point(); |
wolfSSL | 0:9d17e4342598 | 2752 | if (fp_cache[idx].g == NULL) { |
wolfSSL | 0:9d17e4342598 | 2753 | return GEN_MEM_ERR; |
wolfSSL | 0:9d17e4342598 | 2754 | } |
wolfSSL | 0:9d17e4342598 | 2755 | |
wolfSSL | 0:9d17e4342598 | 2756 | /* copy x and y */ |
wolfSSL | 0:9d17e4342598 | 2757 | if ((mp_copy(&g->x, &fp_cache[idx].g->x) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 2758 | (mp_copy(&g->y, &fp_cache[idx].g->y) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 2759 | (mp_copy(&g->z, &fp_cache[idx].g->z) != MP_OKAY)) { |
wolfSSL | 0:9d17e4342598 | 2760 | ecc_del_point(fp_cache[idx].g); |
wolfSSL | 0:9d17e4342598 | 2761 | fp_cache[idx].g = NULL; |
wolfSSL | 0:9d17e4342598 | 2762 | return GEN_MEM_ERR; |
wolfSSL | 0:9d17e4342598 | 2763 | } |
wolfSSL | 0:9d17e4342598 | 2764 | |
wolfSSL | 0:9d17e4342598 | 2765 | for (x = 0; x < (1U<<FP_LUT); x++) { |
wolfSSL | 0:9d17e4342598 | 2766 | fp_cache[idx].LUT[x] = ecc_new_point(); |
wolfSSL | 0:9d17e4342598 | 2767 | if (fp_cache[idx].LUT[x] == NULL) { |
wolfSSL | 0:9d17e4342598 | 2768 | for (y = 0; y < x; y++) { |
wolfSSL | 0:9d17e4342598 | 2769 | ecc_del_point(fp_cache[idx].LUT[y]); |
wolfSSL | 0:9d17e4342598 | 2770 | fp_cache[idx].LUT[y] = NULL; |
wolfSSL | 0:9d17e4342598 | 2771 | } |
wolfSSL | 0:9d17e4342598 | 2772 | ecc_del_point(fp_cache[idx].g); |
wolfSSL | 0:9d17e4342598 | 2773 | fp_cache[idx].g = NULL; |
wolfSSL | 0:9d17e4342598 | 2774 | fp_cache[idx].lru_count = 0; |
wolfSSL | 0:9d17e4342598 | 2775 | return GEN_MEM_ERR; |
wolfSSL | 0:9d17e4342598 | 2776 | } |
wolfSSL | 0:9d17e4342598 | 2777 | } |
wolfSSL | 0:9d17e4342598 | 2778 | |
wolfSSL | 0:9d17e4342598 | 2779 | fp_cache[idx].lru_count = 0; |
wolfSSL | 0:9d17e4342598 | 2780 | |
wolfSSL | 0:9d17e4342598 | 2781 | return MP_OKAY; |
wolfSSL | 0:9d17e4342598 | 2782 | } |
wolfSSL | 0:9d17e4342598 | 2783 | |
wolfSSL | 0:9d17e4342598 | 2784 | /* build the LUT by spacing the bits of the input by #modulus/FP_LUT bits apart |
wolfSSL | 0:9d17e4342598 | 2785 | * |
wolfSSL | 0:9d17e4342598 | 2786 | * The algorithm builds patterns in increasing bit order by first making all |
wolfSSL | 0:9d17e4342598 | 2787 | * single bit input patterns, then all two bit input patterns and so on |
wolfSSL | 0:9d17e4342598 | 2788 | */ |
wolfSSL | 0:9d17e4342598 | 2789 | static int build_lut(int idx, mp_int* modulus, mp_digit* mp, mp_int* mu) |
wolfSSL | 0:9d17e4342598 | 2790 | { |
wolfSSL | 0:9d17e4342598 | 2791 | unsigned x, y, err, bitlen, lut_gap; |
wolfSSL | 0:9d17e4342598 | 2792 | mp_int tmp; |
wolfSSL | 0:9d17e4342598 | 2793 | |
wolfSSL | 0:9d17e4342598 | 2794 | if (mp_init(&tmp) != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2795 | return GEN_MEM_ERR; |
wolfSSL | 0:9d17e4342598 | 2796 | |
wolfSSL | 0:9d17e4342598 | 2797 | /* sanity check to make sure lut_order table is of correct size, |
wolfSSL | 0:9d17e4342598 | 2798 | should compile out to a NOP if true */ |
wolfSSL | 0:9d17e4342598 | 2799 | if ((sizeof(lut_orders) / sizeof(lut_orders[0])) < (1U<<FP_LUT)) { |
wolfSSL | 0:9d17e4342598 | 2800 | err = BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 2801 | } |
wolfSSL | 0:9d17e4342598 | 2802 | else { |
wolfSSL | 0:9d17e4342598 | 2803 | /* get bitlen and round up to next multiple of FP_LUT */ |
wolfSSL | 0:9d17e4342598 | 2804 | bitlen = mp_unsigned_bin_size(modulus) << 3; |
wolfSSL | 0:9d17e4342598 | 2805 | x = bitlen % FP_LUT; |
wolfSSL | 0:9d17e4342598 | 2806 | if (x) { |
wolfSSL | 0:9d17e4342598 | 2807 | bitlen += FP_LUT - x; |
wolfSSL | 0:9d17e4342598 | 2808 | } |
wolfSSL | 0:9d17e4342598 | 2809 | lut_gap = bitlen / FP_LUT; |
wolfSSL | 0:9d17e4342598 | 2810 | |
wolfSSL | 0:9d17e4342598 | 2811 | /* init the mu */ |
wolfSSL | 0:9d17e4342598 | 2812 | err = mp_init_copy(&fp_cache[idx].mu, mu); |
wolfSSL | 0:9d17e4342598 | 2813 | } |
wolfSSL | 0:9d17e4342598 | 2814 | |
wolfSSL | 0:9d17e4342598 | 2815 | /* copy base */ |
wolfSSL | 0:9d17e4342598 | 2816 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 2817 | if ((mp_mulmod(&fp_cache[idx].g->x, mu, modulus, |
wolfSSL | 0:9d17e4342598 | 2818 | &fp_cache[idx].LUT[1]->x) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 2819 | (mp_mulmod(&fp_cache[idx].g->y, mu, modulus, |
wolfSSL | 0:9d17e4342598 | 2820 | &fp_cache[idx].LUT[1]->y) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 2821 | (mp_mulmod(&fp_cache[idx].g->z, mu, modulus, |
wolfSSL | 0:9d17e4342598 | 2822 | &fp_cache[idx].LUT[1]->z) != MP_OKAY)) { |
wolfSSL | 0:9d17e4342598 | 2823 | err = MP_MULMOD_E; |
wolfSSL | 0:9d17e4342598 | 2824 | } |
wolfSSL | 0:9d17e4342598 | 2825 | } |
wolfSSL | 0:9d17e4342598 | 2826 | |
wolfSSL | 0:9d17e4342598 | 2827 | /* make all single bit entries */ |
wolfSSL | 0:9d17e4342598 | 2828 | for (x = 1; x < FP_LUT; x++) { |
wolfSSL | 0:9d17e4342598 | 2829 | if (err != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2830 | break; |
wolfSSL | 0:9d17e4342598 | 2831 | if ((mp_copy(&fp_cache[idx].LUT[1<<(x-1)]->x, |
wolfSSL | 0:9d17e4342598 | 2832 | &fp_cache[idx].LUT[1<<x]->x) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 2833 | (mp_copy(&fp_cache[idx].LUT[1<<(x-1)]->y, |
wolfSSL | 0:9d17e4342598 | 2834 | &fp_cache[idx].LUT[1<<x]->y) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 2835 | (mp_copy(&fp_cache[idx].LUT[1<<(x-1)]->z, |
wolfSSL | 0:9d17e4342598 | 2836 | &fp_cache[idx].LUT[1<<x]->z) != MP_OKAY)){ |
wolfSSL | 0:9d17e4342598 | 2837 | err = MP_INIT_E; |
wolfSSL | 0:9d17e4342598 | 2838 | break; |
wolfSSL | 0:9d17e4342598 | 2839 | } else { |
wolfSSL | 0:9d17e4342598 | 2840 | |
wolfSSL | 0:9d17e4342598 | 2841 | /* now double it bitlen/FP_LUT times */ |
wolfSSL | 0:9d17e4342598 | 2842 | for (y = 0; y < lut_gap; y++) { |
wolfSSL | 0:9d17e4342598 | 2843 | if ((err = ecc_projective_dbl_point(fp_cache[idx].LUT[1<<x], |
wolfSSL | 0:9d17e4342598 | 2844 | fp_cache[idx].LUT[1<<x], modulus, mp)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 2845 | break; |
wolfSSL | 0:9d17e4342598 | 2846 | } |
wolfSSL | 0:9d17e4342598 | 2847 | } |
wolfSSL | 0:9d17e4342598 | 2848 | } |
wolfSSL | 0:9d17e4342598 | 2849 | } |
wolfSSL | 0:9d17e4342598 | 2850 | |
wolfSSL | 0:9d17e4342598 | 2851 | /* now make all entries in increase order of hamming weight */ |
wolfSSL | 0:9d17e4342598 | 2852 | for (x = 2; x <= FP_LUT; x++) { |
wolfSSL | 0:9d17e4342598 | 2853 | if (err != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2854 | break; |
wolfSSL | 0:9d17e4342598 | 2855 | for (y = 0; y < (1UL<<FP_LUT); y++) { |
wolfSSL | 0:9d17e4342598 | 2856 | if (err != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2857 | break; |
wolfSSL | 0:9d17e4342598 | 2858 | if (lut_orders[y].ham != (int)x) continue; |
wolfSSL | 0:9d17e4342598 | 2859 | |
wolfSSL | 0:9d17e4342598 | 2860 | /* perform the add */ |
wolfSSL | 0:9d17e4342598 | 2861 | if ((err = ecc_projective_add_point( |
wolfSSL | 0:9d17e4342598 | 2862 | fp_cache[idx].LUT[lut_orders[y].terma], |
wolfSSL | 0:9d17e4342598 | 2863 | fp_cache[idx].LUT[lut_orders[y].termb], |
wolfSSL | 0:9d17e4342598 | 2864 | fp_cache[idx].LUT[y], modulus, mp)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 2865 | break; |
wolfSSL | 0:9d17e4342598 | 2866 | } |
wolfSSL | 0:9d17e4342598 | 2867 | } |
wolfSSL | 0:9d17e4342598 | 2868 | } |
wolfSSL | 0:9d17e4342598 | 2869 | |
wolfSSL | 0:9d17e4342598 | 2870 | /* now map all entries back to affine space to make point addition faster */ |
wolfSSL | 0:9d17e4342598 | 2871 | for (x = 1; x < (1UL<<FP_LUT); x++) { |
wolfSSL | 0:9d17e4342598 | 2872 | if (err != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2873 | break; |
wolfSSL | 0:9d17e4342598 | 2874 | |
wolfSSL | 0:9d17e4342598 | 2875 | /* convert z to normal from montgomery */ |
wolfSSL | 0:9d17e4342598 | 2876 | err = mp_montgomery_reduce(&fp_cache[idx].LUT[x]->z, modulus, *mp); |
wolfSSL | 0:9d17e4342598 | 2877 | |
wolfSSL | 0:9d17e4342598 | 2878 | /* invert it */ |
wolfSSL | 0:9d17e4342598 | 2879 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2880 | err = mp_invmod(&fp_cache[idx].LUT[x]->z, modulus, |
wolfSSL | 0:9d17e4342598 | 2881 | &fp_cache[idx].LUT[x]->z); |
wolfSSL | 0:9d17e4342598 | 2882 | |
wolfSSL | 0:9d17e4342598 | 2883 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2884 | /* now square it */ |
wolfSSL | 0:9d17e4342598 | 2885 | err = mp_sqrmod(&fp_cache[idx].LUT[x]->z, modulus, &tmp); |
wolfSSL | 0:9d17e4342598 | 2886 | |
wolfSSL | 0:9d17e4342598 | 2887 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2888 | /* fix x */ |
wolfSSL | 0:9d17e4342598 | 2889 | err = mp_mulmod(&fp_cache[idx].LUT[x]->x, &tmp, modulus, |
wolfSSL | 0:9d17e4342598 | 2890 | &fp_cache[idx].LUT[x]->x); |
wolfSSL | 0:9d17e4342598 | 2891 | |
wolfSSL | 0:9d17e4342598 | 2892 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2893 | /* get 1/z^3 */ |
wolfSSL | 0:9d17e4342598 | 2894 | err = mp_mulmod(&tmp, &fp_cache[idx].LUT[x]->z, modulus, &tmp); |
wolfSSL | 0:9d17e4342598 | 2895 | |
wolfSSL | 0:9d17e4342598 | 2896 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2897 | /* fix y */ |
wolfSSL | 0:9d17e4342598 | 2898 | err = mp_mulmod(&fp_cache[idx].LUT[x]->y, &tmp, modulus, |
wolfSSL | 0:9d17e4342598 | 2899 | &fp_cache[idx].LUT[x]->y); |
wolfSSL | 0:9d17e4342598 | 2900 | |
wolfSSL | 0:9d17e4342598 | 2901 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2902 | /* free z */ |
wolfSSL | 0:9d17e4342598 | 2903 | mp_clear(&fp_cache[idx].LUT[x]->z); |
wolfSSL | 0:9d17e4342598 | 2904 | } |
wolfSSL | 0:9d17e4342598 | 2905 | mp_clear(&tmp); |
wolfSSL | 0:9d17e4342598 | 2906 | |
wolfSSL | 0:9d17e4342598 | 2907 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2908 | return MP_OKAY; |
wolfSSL | 0:9d17e4342598 | 2909 | |
wolfSSL | 0:9d17e4342598 | 2910 | /* err cleanup */ |
wolfSSL | 0:9d17e4342598 | 2911 | for (y = 0; y < (1U<<FP_LUT); y++) { |
wolfSSL | 0:9d17e4342598 | 2912 | ecc_del_point(fp_cache[idx].LUT[y]); |
wolfSSL | 0:9d17e4342598 | 2913 | fp_cache[idx].LUT[y] = NULL; |
wolfSSL | 0:9d17e4342598 | 2914 | } |
wolfSSL | 0:9d17e4342598 | 2915 | ecc_del_point(fp_cache[idx].g); |
wolfSSL | 0:9d17e4342598 | 2916 | fp_cache[idx].g = NULL; |
wolfSSL | 0:9d17e4342598 | 2917 | fp_cache[idx].lru_count = 0; |
wolfSSL | 0:9d17e4342598 | 2918 | mp_clear(&fp_cache[idx].mu); |
wolfSSL | 0:9d17e4342598 | 2919 | mp_clear(&tmp); |
wolfSSL | 0:9d17e4342598 | 2920 | |
wolfSSL | 0:9d17e4342598 | 2921 | return err; |
wolfSSL | 0:9d17e4342598 | 2922 | } |
wolfSSL | 0:9d17e4342598 | 2923 | |
wolfSSL | 0:9d17e4342598 | 2924 | /* perform a fixed point ECC mulmod */ |
wolfSSL | 0:9d17e4342598 | 2925 | static int accel_fp_mul(int idx, mp_int* k, ecc_point *R, mp_int* modulus, |
wolfSSL | 0:9d17e4342598 | 2926 | mp_digit* mp, int map) |
wolfSSL | 0:9d17e4342598 | 2927 | { |
wolfSSL | 0:9d17e4342598 | 2928 | unsigned char kb[128]; |
wolfSSL | 0:9d17e4342598 | 2929 | int x; |
wolfSSL | 0:9d17e4342598 | 2930 | unsigned y, z, err, bitlen, bitpos, lut_gap, first; |
wolfSSL | 0:9d17e4342598 | 2931 | mp_int tk; |
wolfSSL | 0:9d17e4342598 | 2932 | |
wolfSSL | 0:9d17e4342598 | 2933 | if (mp_init(&tk) != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 2934 | return MP_INIT_E; |
wolfSSL | 0:9d17e4342598 | 2935 | |
wolfSSL | 0:9d17e4342598 | 2936 | /* if it's smaller than modulus we fine */ |
wolfSSL | 0:9d17e4342598 | 2937 | if (mp_unsigned_bin_size(k) > mp_unsigned_bin_size(modulus)) { |
wolfSSL | 0:9d17e4342598 | 2938 | mp_int order; |
wolfSSL | 0:9d17e4342598 | 2939 | if (mp_init(&order) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 2940 | mp_clear(&tk); |
wolfSSL | 0:9d17e4342598 | 2941 | return MP_INIT_E; |
wolfSSL | 0:9d17e4342598 | 2942 | } |
wolfSSL | 0:9d17e4342598 | 2943 | |
wolfSSL | 0:9d17e4342598 | 2944 | /* find order */ |
wolfSSL | 0:9d17e4342598 | 2945 | y = mp_unsigned_bin_size(modulus); |
wolfSSL | 0:9d17e4342598 | 2946 | for (x = 0; ecc_sets[x].size; x++) { |
wolfSSL | 0:9d17e4342598 | 2947 | if (y <= (unsigned)ecc_sets[x].size) break; |
wolfSSL | 0:9d17e4342598 | 2948 | } |
wolfSSL | 0:9d17e4342598 | 2949 | |
wolfSSL | 0:9d17e4342598 | 2950 | /* back off if we are on the 521 bit curve */ |
wolfSSL | 0:9d17e4342598 | 2951 | if (y == 66) --x; |
wolfSSL | 0:9d17e4342598 | 2952 | |
wolfSSL | 0:9d17e4342598 | 2953 | if ((err = mp_read_radix(&order, ecc_sets[x].order, 16)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 2954 | mp_clear(&order); |
wolfSSL | 0:9d17e4342598 | 2955 | mp_clear(&tk); |
wolfSSL | 0:9d17e4342598 | 2956 | return err; |
wolfSSL | 0:9d17e4342598 | 2957 | } |
wolfSSL | 0:9d17e4342598 | 2958 | |
wolfSSL | 0:9d17e4342598 | 2959 | /* k must be less than modulus */ |
wolfSSL | 0:9d17e4342598 | 2960 | if (mp_cmp(k, &order) != MP_LT) { |
wolfSSL | 0:9d17e4342598 | 2961 | if ((err = mp_mod(k, &order, &tk)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 2962 | mp_clear(&tk); |
wolfSSL | 0:9d17e4342598 | 2963 | mp_clear(&order); |
wolfSSL | 0:9d17e4342598 | 2964 | return err; |
wolfSSL | 0:9d17e4342598 | 2965 | } |
wolfSSL | 0:9d17e4342598 | 2966 | } else { |
wolfSSL | 0:9d17e4342598 | 2967 | mp_copy(k, &tk); |
wolfSSL | 0:9d17e4342598 | 2968 | } |
wolfSSL | 0:9d17e4342598 | 2969 | mp_clear(&order); |
wolfSSL | 0:9d17e4342598 | 2970 | } else { |
wolfSSL | 0:9d17e4342598 | 2971 | mp_copy(k, &tk); |
wolfSSL | 0:9d17e4342598 | 2972 | } |
wolfSSL | 0:9d17e4342598 | 2973 | |
wolfSSL | 0:9d17e4342598 | 2974 | /* get bitlen and round up to next multiple of FP_LUT */ |
wolfSSL | 0:9d17e4342598 | 2975 | bitlen = mp_unsigned_bin_size(modulus) << 3; |
wolfSSL | 0:9d17e4342598 | 2976 | x = bitlen % FP_LUT; |
wolfSSL | 0:9d17e4342598 | 2977 | if (x) { |
wolfSSL | 0:9d17e4342598 | 2978 | bitlen += FP_LUT - x; |
wolfSSL | 0:9d17e4342598 | 2979 | } |
wolfSSL | 0:9d17e4342598 | 2980 | lut_gap = bitlen / FP_LUT; |
wolfSSL | 0:9d17e4342598 | 2981 | |
wolfSSL | 0:9d17e4342598 | 2982 | /* get the k value */ |
wolfSSL | 0:9d17e4342598 | 2983 | if (mp_unsigned_bin_size(&tk) > (int)(sizeof(kb) - 2)) { |
wolfSSL | 0:9d17e4342598 | 2984 | mp_clear(&tk); |
wolfSSL | 0:9d17e4342598 | 2985 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 2986 | } |
wolfSSL | 0:9d17e4342598 | 2987 | |
wolfSSL | 0:9d17e4342598 | 2988 | /* store k */ |
wolfSSL | 0:9d17e4342598 | 2989 | XMEMSET(kb, 0, sizeof(kb)); |
wolfSSL | 0:9d17e4342598 | 2990 | if ((err = mp_to_unsigned_bin(&tk, kb)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 2991 | mp_clear(&tk); |
wolfSSL | 0:9d17e4342598 | 2992 | return err; |
wolfSSL | 0:9d17e4342598 | 2993 | } |
wolfSSL | 0:9d17e4342598 | 2994 | |
wolfSSL | 0:9d17e4342598 | 2995 | /* let's reverse kb so it's little endian */ |
wolfSSL | 0:9d17e4342598 | 2996 | x = 0; |
wolfSSL | 0:9d17e4342598 | 2997 | y = mp_unsigned_bin_size(&tk) - 1; |
wolfSSL | 0:9d17e4342598 | 2998 | mp_clear(&tk); |
wolfSSL | 0:9d17e4342598 | 2999 | |
wolfSSL | 0:9d17e4342598 | 3000 | while ((unsigned)x < y) { |
wolfSSL | 0:9d17e4342598 | 3001 | z = kb[x]; kb[x] = kb[y]; kb[y] = z; |
wolfSSL | 0:9d17e4342598 | 3002 | ++x; --y; |
wolfSSL | 0:9d17e4342598 | 3003 | } |
wolfSSL | 0:9d17e4342598 | 3004 | |
wolfSSL | 0:9d17e4342598 | 3005 | /* at this point we can start, yipee */ |
wolfSSL | 0:9d17e4342598 | 3006 | first = 1; |
wolfSSL | 0:9d17e4342598 | 3007 | for (x = lut_gap-1; x >= 0; x--) { |
wolfSSL | 0:9d17e4342598 | 3008 | /* extract FP_LUT bits from kb spread out by lut_gap bits and offset |
wolfSSL | 0:9d17e4342598 | 3009 | by x bits from the start */ |
wolfSSL | 0:9d17e4342598 | 3010 | bitpos = x; |
wolfSSL | 0:9d17e4342598 | 3011 | for (y = z = 0; y < FP_LUT; y++) { |
wolfSSL | 0:9d17e4342598 | 3012 | z |= ((kb[bitpos>>3] >> (bitpos&7)) & 1) << y; |
wolfSSL | 0:9d17e4342598 | 3013 | bitpos += lut_gap; /* it's y*lut_gap + x, but here we can avoid |
wolfSSL | 0:9d17e4342598 | 3014 | the mult in each loop */ |
wolfSSL | 0:9d17e4342598 | 3015 | } |
wolfSSL | 0:9d17e4342598 | 3016 | |
wolfSSL | 0:9d17e4342598 | 3017 | /* double if not first */ |
wolfSSL | 0:9d17e4342598 | 3018 | if (!first) { |
wolfSSL | 0:9d17e4342598 | 3019 | if ((err = ecc_projective_dbl_point(R, R, modulus, mp)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3020 | return err; |
wolfSSL | 0:9d17e4342598 | 3021 | } |
wolfSSL | 0:9d17e4342598 | 3022 | } |
wolfSSL | 0:9d17e4342598 | 3023 | |
wolfSSL | 0:9d17e4342598 | 3024 | /* add if not first, otherwise copy */ |
wolfSSL | 0:9d17e4342598 | 3025 | if (!first && z) { |
wolfSSL | 0:9d17e4342598 | 3026 | if ((err = ecc_projective_add_point(R, fp_cache[idx].LUT[z], R, |
wolfSSL | 0:9d17e4342598 | 3027 | modulus, mp)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3028 | return err; |
wolfSSL | 0:9d17e4342598 | 3029 | } |
wolfSSL | 0:9d17e4342598 | 3030 | } else if (z) { |
wolfSSL | 0:9d17e4342598 | 3031 | if ((mp_copy(&fp_cache[idx].LUT[z]->x, &R->x) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 3032 | (mp_copy(&fp_cache[idx].LUT[z]->y, &R->y) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 3033 | (mp_copy(&fp_cache[idx].mu, &R->z) != MP_OKAY)) { |
wolfSSL | 0:9d17e4342598 | 3034 | return GEN_MEM_ERR; |
wolfSSL | 0:9d17e4342598 | 3035 | } |
wolfSSL | 0:9d17e4342598 | 3036 | first = 0; |
wolfSSL | 0:9d17e4342598 | 3037 | } |
wolfSSL | 0:9d17e4342598 | 3038 | } |
wolfSSL | 0:9d17e4342598 | 3039 | z = 0; |
wolfSSL | 0:9d17e4342598 | 3040 | XMEMSET(kb, 0, sizeof(kb)); |
wolfSSL | 0:9d17e4342598 | 3041 | /* map R back from projective space */ |
wolfSSL | 0:9d17e4342598 | 3042 | if (map) { |
wolfSSL | 0:9d17e4342598 | 3043 | err = ecc_map(R, modulus, mp); |
wolfSSL | 0:9d17e4342598 | 3044 | } else { |
wolfSSL | 0:9d17e4342598 | 3045 | err = MP_OKAY; |
wolfSSL | 0:9d17e4342598 | 3046 | } |
wolfSSL | 0:9d17e4342598 | 3047 | |
wolfSSL | 0:9d17e4342598 | 3048 | return err; |
wolfSSL | 0:9d17e4342598 | 3049 | } |
wolfSSL | 0:9d17e4342598 | 3050 | |
wolfSSL | 0:9d17e4342598 | 3051 | #ifdef ECC_SHAMIR |
wolfSSL | 0:9d17e4342598 | 3052 | /* perform a fixed point ECC mulmod */ |
wolfSSL | 0:9d17e4342598 | 3053 | static int accel_fp_mul2add(int idx1, int idx2, |
wolfSSL | 0:9d17e4342598 | 3054 | mp_int* kA, mp_int* kB, |
wolfSSL | 0:9d17e4342598 | 3055 | ecc_point *R, mp_int* modulus, mp_digit* mp) |
wolfSSL | 0:9d17e4342598 | 3056 | { |
wolfSSL | 0:9d17e4342598 | 3057 | unsigned char kb[2][128]; |
wolfSSL | 0:9d17e4342598 | 3058 | int x; |
wolfSSL | 0:9d17e4342598 | 3059 | unsigned y, z, err, bitlen, bitpos, lut_gap, first, zA, zB; |
wolfSSL | 0:9d17e4342598 | 3060 | mp_int tka; |
wolfSSL | 0:9d17e4342598 | 3061 | mp_int tkb; |
wolfSSL | 0:9d17e4342598 | 3062 | mp_int order; |
wolfSSL | 0:9d17e4342598 | 3063 | |
wolfSSL | 0:9d17e4342598 | 3064 | if (mp_init_multi(&tka, &tkb, 0, 0, 0, 0) != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 3065 | return MP_INIT_E; |
wolfSSL | 0:9d17e4342598 | 3066 | |
wolfSSL | 0:9d17e4342598 | 3067 | /* if it's smaller than modulus we fine */ |
wolfSSL | 0:9d17e4342598 | 3068 | if (mp_unsigned_bin_size(kA) > mp_unsigned_bin_size(modulus)) { |
wolfSSL | 0:9d17e4342598 | 3069 | /* find order */ |
wolfSSL | 0:9d17e4342598 | 3070 | y = mp_unsigned_bin_size(modulus); |
wolfSSL | 0:9d17e4342598 | 3071 | for (x = 0; ecc_sets[x].size; x++) { |
wolfSSL | 0:9d17e4342598 | 3072 | if (y <= (unsigned)ecc_sets[x].size) break; |
wolfSSL | 0:9d17e4342598 | 3073 | } |
wolfSSL | 0:9d17e4342598 | 3074 | |
wolfSSL | 0:9d17e4342598 | 3075 | /* back off if we are on the 521 bit curve */ |
wolfSSL | 0:9d17e4342598 | 3076 | if (y == 66) --x; |
wolfSSL | 0:9d17e4342598 | 3077 | |
wolfSSL | 0:9d17e4342598 | 3078 | if ((err = mp_init(&order)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3079 | mp_clear(&tkb); |
wolfSSL | 0:9d17e4342598 | 3080 | mp_clear(&tka); |
wolfSSL | 0:9d17e4342598 | 3081 | return err; |
wolfSSL | 0:9d17e4342598 | 3082 | } |
wolfSSL | 0:9d17e4342598 | 3083 | if ((err = mp_read_radix(&order, ecc_sets[x].order, 16)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3084 | mp_clear(&tkb); |
wolfSSL | 0:9d17e4342598 | 3085 | mp_clear(&tka); |
wolfSSL | 0:9d17e4342598 | 3086 | mp_clear(&order); |
wolfSSL | 0:9d17e4342598 | 3087 | return err; |
wolfSSL | 0:9d17e4342598 | 3088 | } |
wolfSSL | 0:9d17e4342598 | 3089 | |
wolfSSL | 0:9d17e4342598 | 3090 | /* kA must be less than modulus */ |
wolfSSL | 0:9d17e4342598 | 3091 | if (mp_cmp(kA, &order) != MP_LT) { |
wolfSSL | 0:9d17e4342598 | 3092 | if ((err = mp_mod(kA, &order, &tka)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3093 | mp_clear(&tkb); |
wolfSSL | 0:9d17e4342598 | 3094 | mp_clear(&tka); |
wolfSSL | 0:9d17e4342598 | 3095 | mp_clear(&order); |
wolfSSL | 0:9d17e4342598 | 3096 | return err; |
wolfSSL | 0:9d17e4342598 | 3097 | } |
wolfSSL | 0:9d17e4342598 | 3098 | } else { |
wolfSSL | 0:9d17e4342598 | 3099 | mp_copy(kA, &tka); |
wolfSSL | 0:9d17e4342598 | 3100 | } |
wolfSSL | 0:9d17e4342598 | 3101 | mp_clear(&order); |
wolfSSL | 0:9d17e4342598 | 3102 | } else { |
wolfSSL | 0:9d17e4342598 | 3103 | mp_copy(kA, &tka); |
wolfSSL | 0:9d17e4342598 | 3104 | } |
wolfSSL | 0:9d17e4342598 | 3105 | |
wolfSSL | 0:9d17e4342598 | 3106 | /* if it's smaller than modulus we fine */ |
wolfSSL | 0:9d17e4342598 | 3107 | if (mp_unsigned_bin_size(kB) > mp_unsigned_bin_size(modulus)) { |
wolfSSL | 0:9d17e4342598 | 3108 | /* find order */ |
wolfSSL | 0:9d17e4342598 | 3109 | y = mp_unsigned_bin_size(modulus); |
wolfSSL | 0:9d17e4342598 | 3110 | for (x = 0; ecc_sets[x].size; x++) { |
wolfSSL | 0:9d17e4342598 | 3111 | if (y <= (unsigned)ecc_sets[x].size) break; |
wolfSSL | 0:9d17e4342598 | 3112 | } |
wolfSSL | 0:9d17e4342598 | 3113 | |
wolfSSL | 0:9d17e4342598 | 3114 | /* back off if we are on the 521 bit curve */ |
wolfSSL | 0:9d17e4342598 | 3115 | if (y == 66) --x; |
wolfSSL | 0:9d17e4342598 | 3116 | |
wolfSSL | 0:9d17e4342598 | 3117 | if ((err = mp_init(&order)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3118 | mp_clear(&tkb); |
wolfSSL | 0:9d17e4342598 | 3119 | mp_clear(&tka); |
wolfSSL | 0:9d17e4342598 | 3120 | return err; |
wolfSSL | 0:9d17e4342598 | 3121 | } |
wolfSSL | 0:9d17e4342598 | 3122 | if ((err = mp_read_radix(&order, ecc_sets[x].order, 16)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3123 | mp_clear(&tkb); |
wolfSSL | 0:9d17e4342598 | 3124 | mp_clear(&tka); |
wolfSSL | 0:9d17e4342598 | 3125 | mp_clear(&order); |
wolfSSL | 0:9d17e4342598 | 3126 | return err; |
wolfSSL | 0:9d17e4342598 | 3127 | } |
wolfSSL | 0:9d17e4342598 | 3128 | |
wolfSSL | 0:9d17e4342598 | 3129 | /* kB must be less than modulus */ |
wolfSSL | 0:9d17e4342598 | 3130 | if (mp_cmp(kB, &order) != MP_LT) { |
wolfSSL | 0:9d17e4342598 | 3131 | if ((err = mp_mod(kB, &order, &tkb)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3132 | mp_clear(&tkb); |
wolfSSL | 0:9d17e4342598 | 3133 | mp_clear(&tka); |
wolfSSL | 0:9d17e4342598 | 3134 | mp_clear(&order); |
wolfSSL | 0:9d17e4342598 | 3135 | return err; |
wolfSSL | 0:9d17e4342598 | 3136 | } |
wolfSSL | 0:9d17e4342598 | 3137 | } else { |
wolfSSL | 0:9d17e4342598 | 3138 | mp_copy(kB, &tkb); |
wolfSSL | 0:9d17e4342598 | 3139 | } |
wolfSSL | 0:9d17e4342598 | 3140 | mp_clear(&order); |
wolfSSL | 0:9d17e4342598 | 3141 | } else { |
wolfSSL | 0:9d17e4342598 | 3142 | mp_copy(kB, &tkb); |
wolfSSL | 0:9d17e4342598 | 3143 | } |
wolfSSL | 0:9d17e4342598 | 3144 | |
wolfSSL | 0:9d17e4342598 | 3145 | /* get bitlen and round up to next multiple of FP_LUT */ |
wolfSSL | 0:9d17e4342598 | 3146 | bitlen = mp_unsigned_bin_size(modulus) << 3; |
wolfSSL | 0:9d17e4342598 | 3147 | x = bitlen % FP_LUT; |
wolfSSL | 0:9d17e4342598 | 3148 | if (x) { |
wolfSSL | 0:9d17e4342598 | 3149 | bitlen += FP_LUT - x; |
wolfSSL | 0:9d17e4342598 | 3150 | } |
wolfSSL | 0:9d17e4342598 | 3151 | lut_gap = bitlen / FP_LUT; |
wolfSSL | 0:9d17e4342598 | 3152 | |
wolfSSL | 0:9d17e4342598 | 3153 | /* get the k value */ |
wolfSSL | 0:9d17e4342598 | 3154 | if ((mp_unsigned_bin_size(&tka) > (int)(sizeof(kb[0]) - 2)) || |
wolfSSL | 0:9d17e4342598 | 3155 | (mp_unsigned_bin_size(&tkb) > (int)(sizeof(kb[0]) - 2)) ) { |
wolfSSL | 0:9d17e4342598 | 3156 | mp_clear(&tka); |
wolfSSL | 0:9d17e4342598 | 3157 | mp_clear(&tkb); |
wolfSSL | 0:9d17e4342598 | 3158 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 3159 | } |
wolfSSL | 0:9d17e4342598 | 3160 | |
wolfSSL | 0:9d17e4342598 | 3161 | /* store k */ |
wolfSSL | 0:9d17e4342598 | 3162 | XMEMSET(kb, 0, sizeof(kb)); |
wolfSSL | 0:9d17e4342598 | 3163 | if ((err = mp_to_unsigned_bin(&tka, kb[0])) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3164 | mp_clear(&tka); |
wolfSSL | 0:9d17e4342598 | 3165 | mp_clear(&tkb); |
wolfSSL | 0:9d17e4342598 | 3166 | return err; |
wolfSSL | 0:9d17e4342598 | 3167 | } |
wolfSSL | 0:9d17e4342598 | 3168 | |
wolfSSL | 0:9d17e4342598 | 3169 | /* let's reverse kb so it's little endian */ |
wolfSSL | 0:9d17e4342598 | 3170 | x = 0; |
wolfSSL | 0:9d17e4342598 | 3171 | y = mp_unsigned_bin_size(&tka) - 1; |
wolfSSL | 0:9d17e4342598 | 3172 | mp_clear(&tka); |
wolfSSL | 0:9d17e4342598 | 3173 | while ((unsigned)x < y) { |
wolfSSL | 0:9d17e4342598 | 3174 | z = kb[0][x]; kb[0][x] = kb[0][y]; kb[0][y] = z; |
wolfSSL | 0:9d17e4342598 | 3175 | ++x; --y; |
wolfSSL | 0:9d17e4342598 | 3176 | } |
wolfSSL | 0:9d17e4342598 | 3177 | |
wolfSSL | 0:9d17e4342598 | 3178 | /* store b */ |
wolfSSL | 0:9d17e4342598 | 3179 | if ((err = mp_to_unsigned_bin(&tkb, kb[1])) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3180 | mp_clear(&tkb); |
wolfSSL | 0:9d17e4342598 | 3181 | return err; |
wolfSSL | 0:9d17e4342598 | 3182 | } |
wolfSSL | 0:9d17e4342598 | 3183 | |
wolfSSL | 0:9d17e4342598 | 3184 | x = 0; |
wolfSSL | 0:9d17e4342598 | 3185 | y = mp_unsigned_bin_size(&tkb) - 1; |
wolfSSL | 0:9d17e4342598 | 3186 | mp_clear(&tkb); |
wolfSSL | 0:9d17e4342598 | 3187 | while ((unsigned)x < y) { |
wolfSSL | 0:9d17e4342598 | 3188 | z = kb[1][x]; kb[1][x] = kb[1][y]; kb[1][y] = z; |
wolfSSL | 0:9d17e4342598 | 3189 | ++x; --y; |
wolfSSL | 0:9d17e4342598 | 3190 | } |
wolfSSL | 0:9d17e4342598 | 3191 | |
wolfSSL | 0:9d17e4342598 | 3192 | /* at this point we can start, yipee */ |
wolfSSL | 0:9d17e4342598 | 3193 | first = 1; |
wolfSSL | 0:9d17e4342598 | 3194 | for (x = lut_gap-1; x >= 0; x--) { |
wolfSSL | 0:9d17e4342598 | 3195 | /* extract FP_LUT bits from kb spread out by lut_gap bits and |
wolfSSL | 0:9d17e4342598 | 3196 | offset by x bits from the start */ |
wolfSSL | 0:9d17e4342598 | 3197 | bitpos = x; |
wolfSSL | 0:9d17e4342598 | 3198 | for (y = zA = zB = 0; y < FP_LUT; y++) { |
wolfSSL | 0:9d17e4342598 | 3199 | zA |= ((kb[0][bitpos>>3] >> (bitpos&7)) & 1) << y; |
wolfSSL | 0:9d17e4342598 | 3200 | zB |= ((kb[1][bitpos>>3] >> (bitpos&7)) & 1) << y; |
wolfSSL | 0:9d17e4342598 | 3201 | bitpos += lut_gap; /* it's y*lut_gap + x, but here we can avoid |
wolfSSL | 0:9d17e4342598 | 3202 | the mult in each loop */ |
wolfSSL | 0:9d17e4342598 | 3203 | } |
wolfSSL | 0:9d17e4342598 | 3204 | |
wolfSSL | 0:9d17e4342598 | 3205 | /* double if not first */ |
wolfSSL | 0:9d17e4342598 | 3206 | if (!first) { |
wolfSSL | 0:9d17e4342598 | 3207 | if ((err = ecc_projective_dbl_point(R, R, modulus, mp)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3208 | return err; |
wolfSSL | 0:9d17e4342598 | 3209 | } |
wolfSSL | 0:9d17e4342598 | 3210 | } |
wolfSSL | 0:9d17e4342598 | 3211 | |
wolfSSL | 0:9d17e4342598 | 3212 | /* add if not first, otherwise copy */ |
wolfSSL | 0:9d17e4342598 | 3213 | if (!first) { |
wolfSSL | 0:9d17e4342598 | 3214 | if (zA) { |
wolfSSL | 0:9d17e4342598 | 3215 | if ((err = ecc_projective_add_point(R, fp_cache[idx1].LUT[zA], |
wolfSSL | 0:9d17e4342598 | 3216 | R, modulus, mp)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3217 | return err; |
wolfSSL | 0:9d17e4342598 | 3218 | } |
wolfSSL | 0:9d17e4342598 | 3219 | } |
wolfSSL | 0:9d17e4342598 | 3220 | if (zB) { |
wolfSSL | 0:9d17e4342598 | 3221 | if ((err = ecc_projective_add_point(R, fp_cache[idx2].LUT[zB], |
wolfSSL | 0:9d17e4342598 | 3222 | R, modulus, mp)) != MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3223 | return err; |
wolfSSL | 0:9d17e4342598 | 3224 | } |
wolfSSL | 0:9d17e4342598 | 3225 | } |
wolfSSL | 0:9d17e4342598 | 3226 | } else { |
wolfSSL | 0:9d17e4342598 | 3227 | if (zA) { |
wolfSSL | 0:9d17e4342598 | 3228 | if ((mp_copy(&fp_cache[idx1].LUT[zA]->x, &R->x) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 3229 | (mp_copy(&fp_cache[idx1].LUT[zA]->y, &R->y) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 3230 | (mp_copy(&fp_cache[idx1].mu, &R->z) != MP_OKAY)) { |
wolfSSL | 0:9d17e4342598 | 3231 | return GEN_MEM_ERR; |
wolfSSL | 0:9d17e4342598 | 3232 | } |
wolfSSL | 0:9d17e4342598 | 3233 | first = 0; |
wolfSSL | 0:9d17e4342598 | 3234 | } |
wolfSSL | 0:9d17e4342598 | 3235 | if (zB && first == 0) { |
wolfSSL | 0:9d17e4342598 | 3236 | if (zB) { |
wolfSSL | 0:9d17e4342598 | 3237 | if ((err = ecc_projective_add_point(R, fp_cache[idx2].LUT[zB], |
wolfSSL | 0:9d17e4342598 | 3238 | R, modulus, mp)) != MP_OKAY){ |
wolfSSL | 0:9d17e4342598 | 3239 | return err; |
wolfSSL | 0:9d17e4342598 | 3240 | } |
wolfSSL | 0:9d17e4342598 | 3241 | } |
wolfSSL | 0:9d17e4342598 | 3242 | } else if (zB && first == 1) { |
wolfSSL | 0:9d17e4342598 | 3243 | if ((mp_copy(&fp_cache[idx2].LUT[zB]->x, &R->x) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 3244 | (mp_copy(&fp_cache[idx2].LUT[zB]->y, &R->y) != MP_OKAY) || |
wolfSSL | 0:9d17e4342598 | 3245 | (mp_copy(&fp_cache[idx2].mu, &R->z) != MP_OKAY)) { |
wolfSSL | 0:9d17e4342598 | 3246 | return GEN_MEM_ERR; |
wolfSSL | 0:9d17e4342598 | 3247 | } |
wolfSSL | 0:9d17e4342598 | 3248 | first = 0; |
wolfSSL | 0:9d17e4342598 | 3249 | } |
wolfSSL | 0:9d17e4342598 | 3250 | } |
wolfSSL | 0:9d17e4342598 | 3251 | } |
wolfSSL | 0:9d17e4342598 | 3252 | XMEMSET(kb, 0, sizeof(kb)); |
wolfSSL | 0:9d17e4342598 | 3253 | |
wolfSSL | 0:9d17e4342598 | 3254 | return ecc_map(R, modulus, mp); |
wolfSSL | 0:9d17e4342598 | 3255 | } |
wolfSSL | 0:9d17e4342598 | 3256 | |
wolfSSL | 0:9d17e4342598 | 3257 | /** ECC Fixed Point mulmod global |
wolfSSL | 0:9d17e4342598 | 3258 | Computes kA*A + kB*B = C using Shamir's Trick |
wolfSSL | 0:9d17e4342598 | 3259 | A First point to multiply |
wolfSSL | 0:9d17e4342598 | 3260 | kA What to multiple A by |
wolfSSL | 0:9d17e4342598 | 3261 | B Second point to multiply |
wolfSSL | 0:9d17e4342598 | 3262 | kB What to multiple B by |
wolfSSL | 0:9d17e4342598 | 3263 | C [out] Destination point (can overlap with A or B) |
wolfSSL | 0:9d17e4342598 | 3264 | modulus Modulus for curve |
wolfSSL | 0:9d17e4342598 | 3265 | return MP_OKAY on success |
wolfSSL | 0:9d17e4342598 | 3266 | */ |
wolfSSL | 0:9d17e4342598 | 3267 | int ecc_mul2add(ecc_point* A, mp_int* kA, |
wolfSSL | 0:9d17e4342598 | 3268 | ecc_point* B, mp_int* kB, |
wolfSSL | 0:9d17e4342598 | 3269 | ecc_point* C, mp_int* modulus) |
wolfSSL | 0:9d17e4342598 | 3270 | { |
wolfSSL | 0:9d17e4342598 | 3271 | int idx1 = -1, idx2 = -1, err = MP_OKAY, mpInit = 0; |
wolfSSL | 0:9d17e4342598 | 3272 | mp_digit mp; |
wolfSSL | 0:9d17e4342598 | 3273 | mp_int mu; |
wolfSSL | 0:9d17e4342598 | 3274 | |
wolfSSL | 0:9d17e4342598 | 3275 | err = mp_init(&mu); |
wolfSSL | 0:9d17e4342598 | 3276 | if (err != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 3277 | return err; |
wolfSSL | 0:9d17e4342598 | 3278 | |
wolfSSL | 0:9d17e4342598 | 3279 | #ifndef HAVE_THREAD_LS |
wolfSSL | 0:9d17e4342598 | 3280 | if (initMutex == 0) { |
wolfSSL | 0:9d17e4342598 | 3281 | InitMutex(&ecc_fp_lock); |
wolfSSL | 0:9d17e4342598 | 3282 | initMutex = 1; |
wolfSSL | 0:9d17e4342598 | 3283 | } |
wolfSSL | 0:9d17e4342598 | 3284 | if (LockMutex(&ecc_fp_lock) != 0) |
wolfSSL | 0:9d17e4342598 | 3285 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 3286 | #endif /* HAVE_THREAD_LS */ |
wolfSSL | 0:9d17e4342598 | 3287 | |
wolfSSL | 0:9d17e4342598 | 3288 | /* find point */ |
wolfSSL | 0:9d17e4342598 | 3289 | idx1 = find_base(A); |
wolfSSL | 0:9d17e4342598 | 3290 | |
wolfSSL | 0:9d17e4342598 | 3291 | /* no entry? */ |
wolfSSL | 0:9d17e4342598 | 3292 | if (idx1 == -1) { |
wolfSSL | 0:9d17e4342598 | 3293 | /* find hole and add it */ |
wolfSSL | 0:9d17e4342598 | 3294 | if ((idx1 = find_hole()) >= 0) { |
wolfSSL | 0:9d17e4342598 | 3295 | err = add_entry(idx1, A); |
wolfSSL | 0:9d17e4342598 | 3296 | } |
wolfSSL | 0:9d17e4342598 | 3297 | } |
wolfSSL | 0:9d17e4342598 | 3298 | if (err == MP_OKAY && idx1 != -1) { |
wolfSSL | 0:9d17e4342598 | 3299 | /* increment LRU */ |
wolfSSL | 0:9d17e4342598 | 3300 | ++(fp_cache[idx1].lru_count); |
wolfSSL | 0:9d17e4342598 | 3301 | } |
wolfSSL | 0:9d17e4342598 | 3302 | |
wolfSSL | 0:9d17e4342598 | 3303 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 3304 | /* find point */ |
wolfSSL | 0:9d17e4342598 | 3305 | idx2 = find_base(B); |
wolfSSL | 0:9d17e4342598 | 3306 | |
wolfSSL | 0:9d17e4342598 | 3307 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3308 | /* no entry? */ |
wolfSSL | 0:9d17e4342598 | 3309 | if (idx2 == -1) { |
wolfSSL | 0:9d17e4342598 | 3310 | /* find hole and add it */ |
wolfSSL | 0:9d17e4342598 | 3311 | if ((idx2 = find_hole()) >= 0) |
wolfSSL | 0:9d17e4342598 | 3312 | err = add_entry(idx2, B); |
wolfSSL | 0:9d17e4342598 | 3313 | } |
wolfSSL | 0:9d17e4342598 | 3314 | } |
wolfSSL | 0:9d17e4342598 | 3315 | |
wolfSSL | 0:9d17e4342598 | 3316 | if (err == MP_OKAY && idx2 != -1) { |
wolfSSL | 0:9d17e4342598 | 3317 | /* increment LRU */ |
wolfSSL | 0:9d17e4342598 | 3318 | ++(fp_cache[idx2].lru_count); |
wolfSSL | 0:9d17e4342598 | 3319 | } |
wolfSSL | 0:9d17e4342598 | 3320 | |
wolfSSL | 0:9d17e4342598 | 3321 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3322 | /* if it's 2 build the LUT, if it's higher just use the LUT */ |
wolfSSL | 0:9d17e4342598 | 3323 | if (idx1 >= 0 && fp_cache[idx1].lru_count == 2) { |
wolfSSL | 0:9d17e4342598 | 3324 | /* compute mp */ |
wolfSSL | 0:9d17e4342598 | 3325 | err = mp_montgomery_setup(modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 3326 | |
wolfSSL | 0:9d17e4342598 | 3327 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3328 | mpInit = 1; |
wolfSSL | 0:9d17e4342598 | 3329 | err = mp_montgomery_calc_normalization(&mu, modulus); |
wolfSSL | 0:9d17e4342598 | 3330 | } |
wolfSSL | 0:9d17e4342598 | 3331 | |
wolfSSL | 0:9d17e4342598 | 3332 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 3333 | /* build the LUT */ |
wolfSSL | 0:9d17e4342598 | 3334 | err = build_lut(idx1, modulus, &mp, &mu); |
wolfSSL | 0:9d17e4342598 | 3335 | } |
wolfSSL | 0:9d17e4342598 | 3336 | } |
wolfSSL | 0:9d17e4342598 | 3337 | |
wolfSSL | 0:9d17e4342598 | 3338 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3339 | /* if it's 2 build the LUT, if it's higher just use the LUT */ |
wolfSSL | 0:9d17e4342598 | 3340 | if (idx2 >= 0 && fp_cache[idx2].lru_count == 2) { |
wolfSSL | 0:9d17e4342598 | 3341 | if (mpInit == 0) { |
wolfSSL | 0:9d17e4342598 | 3342 | /* compute mp */ |
wolfSSL | 0:9d17e4342598 | 3343 | err = mp_montgomery_setup(modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 3344 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3345 | mpInit = 1; |
wolfSSL | 0:9d17e4342598 | 3346 | err = mp_montgomery_calc_normalization(&mu, modulus); |
wolfSSL | 0:9d17e4342598 | 3347 | } |
wolfSSL | 0:9d17e4342598 | 3348 | } |
wolfSSL | 0:9d17e4342598 | 3349 | |
wolfSSL | 0:9d17e4342598 | 3350 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 3351 | /* build the LUT */ |
wolfSSL | 0:9d17e4342598 | 3352 | err = build_lut(idx2, modulus, &mp, &mu); |
wolfSSL | 0:9d17e4342598 | 3353 | } |
wolfSSL | 0:9d17e4342598 | 3354 | } |
wolfSSL | 0:9d17e4342598 | 3355 | |
wolfSSL | 0:9d17e4342598 | 3356 | |
wolfSSL | 0:9d17e4342598 | 3357 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3358 | if (idx1 >=0 && idx2 >= 0 && fp_cache[idx1].lru_count >= 2 && |
wolfSSL | 0:9d17e4342598 | 3359 | fp_cache[idx2].lru_count >= 2) { |
wolfSSL | 0:9d17e4342598 | 3360 | if (mpInit == 0) { |
wolfSSL | 0:9d17e4342598 | 3361 | /* compute mp */ |
wolfSSL | 0:9d17e4342598 | 3362 | err = mp_montgomery_setup(modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 3363 | } |
wolfSSL | 0:9d17e4342598 | 3364 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 3365 | err = accel_fp_mul2add(idx1, idx2, kA, kB, C, modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 3366 | } else { |
wolfSSL | 0:9d17e4342598 | 3367 | err = normal_ecc_mul2add(A, kA, B, kB, C, modulus); |
wolfSSL | 0:9d17e4342598 | 3368 | } |
wolfSSL | 0:9d17e4342598 | 3369 | } |
wolfSSL | 0:9d17e4342598 | 3370 | |
wolfSSL | 0:9d17e4342598 | 3371 | #ifndef HAVE_THREAD_LS |
wolfSSL | 0:9d17e4342598 | 3372 | UnLockMutex(&ecc_fp_lock); |
wolfSSL | 0:9d17e4342598 | 3373 | #endif /* HAVE_THREAD_LS */ |
wolfSSL | 0:9d17e4342598 | 3374 | mp_clear(&mu); |
wolfSSL | 0:9d17e4342598 | 3375 | |
wolfSSL | 0:9d17e4342598 | 3376 | return err; |
wolfSSL | 0:9d17e4342598 | 3377 | } |
wolfSSL | 0:9d17e4342598 | 3378 | #endif |
wolfSSL | 0:9d17e4342598 | 3379 | |
wolfSSL | 0:9d17e4342598 | 3380 | /** ECC Fixed Point mulmod global |
wolfSSL | 0:9d17e4342598 | 3381 | k The multiplicand |
wolfSSL | 0:9d17e4342598 | 3382 | G Base point to multiply |
wolfSSL | 0:9d17e4342598 | 3383 | R [out] Destination of product |
wolfSSL | 0:9d17e4342598 | 3384 | modulus The modulus for the curve |
wolfSSL | 0:9d17e4342598 | 3385 | map [boolean] If non-zero maps the point back to affine co-ordinates, |
wolfSSL | 0:9d17e4342598 | 3386 | otherwise it's left in jacobian-montgomery form |
wolfSSL | 0:9d17e4342598 | 3387 | return MP_OKAY if successful |
wolfSSL | 0:9d17e4342598 | 3388 | */ |
wolfSSL | 0:9d17e4342598 | 3389 | int ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, |
wolfSSL | 0:9d17e4342598 | 3390 | int map) |
wolfSSL | 0:9d17e4342598 | 3391 | { |
wolfSSL | 0:9d17e4342598 | 3392 | int idx, err = MP_OKAY; |
wolfSSL | 0:9d17e4342598 | 3393 | mp_digit mp; |
wolfSSL | 0:9d17e4342598 | 3394 | mp_int mu; |
wolfSSL | 0:9d17e4342598 | 3395 | int mpSetup = 0; |
wolfSSL | 0:9d17e4342598 | 3396 | |
wolfSSL | 0:9d17e4342598 | 3397 | if (mp_init(&mu) != MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 3398 | return MP_INIT_E; |
wolfSSL | 0:9d17e4342598 | 3399 | |
wolfSSL | 0:9d17e4342598 | 3400 | #ifndef HAVE_THREAD_LS |
wolfSSL | 0:9d17e4342598 | 3401 | if (initMutex == 0) { |
wolfSSL | 0:9d17e4342598 | 3402 | InitMutex(&ecc_fp_lock); |
wolfSSL | 0:9d17e4342598 | 3403 | initMutex = 1; |
wolfSSL | 0:9d17e4342598 | 3404 | } |
wolfSSL | 0:9d17e4342598 | 3405 | |
wolfSSL | 0:9d17e4342598 | 3406 | if (LockMutex(&ecc_fp_lock) != 0) |
wolfSSL | 0:9d17e4342598 | 3407 | return BAD_MUTEX_E; |
wolfSSL | 0:9d17e4342598 | 3408 | #endif /* HAVE_THREAD_LS */ |
wolfSSL | 0:9d17e4342598 | 3409 | |
wolfSSL | 0:9d17e4342598 | 3410 | /* find point */ |
wolfSSL | 0:9d17e4342598 | 3411 | idx = find_base(G); |
wolfSSL | 0:9d17e4342598 | 3412 | |
wolfSSL | 0:9d17e4342598 | 3413 | /* no entry? */ |
wolfSSL | 0:9d17e4342598 | 3414 | if (idx == -1) { |
wolfSSL | 0:9d17e4342598 | 3415 | /* find hole and add it */ |
wolfSSL | 0:9d17e4342598 | 3416 | idx = find_hole(); |
wolfSSL | 0:9d17e4342598 | 3417 | |
wolfSSL | 0:9d17e4342598 | 3418 | if (idx >= 0) |
wolfSSL | 0:9d17e4342598 | 3419 | err = add_entry(idx, G); |
wolfSSL | 0:9d17e4342598 | 3420 | } |
wolfSSL | 0:9d17e4342598 | 3421 | if (err == MP_OKAY && idx != -1) { |
wolfSSL | 0:9d17e4342598 | 3422 | /* increment LRU */ |
wolfSSL | 0:9d17e4342598 | 3423 | ++(fp_cache[idx].lru_count); |
wolfSSL | 0:9d17e4342598 | 3424 | } |
wolfSSL | 0:9d17e4342598 | 3425 | |
wolfSSL | 0:9d17e4342598 | 3426 | |
wolfSSL | 0:9d17e4342598 | 3427 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3428 | /* if it's 2 build the LUT, if it's higher just use the LUT */ |
wolfSSL | 0:9d17e4342598 | 3429 | if (idx >= 0 && fp_cache[idx].lru_count == 2) { |
wolfSSL | 0:9d17e4342598 | 3430 | /* compute mp */ |
wolfSSL | 0:9d17e4342598 | 3431 | err = mp_montgomery_setup(modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 3432 | |
wolfSSL | 0:9d17e4342598 | 3433 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3434 | /* compute mu */ |
wolfSSL | 0:9d17e4342598 | 3435 | mpSetup = 1; |
wolfSSL | 0:9d17e4342598 | 3436 | err = mp_montgomery_calc_normalization(&mu, modulus); |
wolfSSL | 0:9d17e4342598 | 3437 | } |
wolfSSL | 0:9d17e4342598 | 3438 | |
wolfSSL | 0:9d17e4342598 | 3439 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 3440 | /* build the LUT */ |
wolfSSL | 0:9d17e4342598 | 3441 | err = build_lut(idx, modulus, &mp, &mu); |
wolfSSL | 0:9d17e4342598 | 3442 | } |
wolfSSL | 0:9d17e4342598 | 3443 | } |
wolfSSL | 0:9d17e4342598 | 3444 | |
wolfSSL | 0:9d17e4342598 | 3445 | if (err == MP_OKAY) { |
wolfSSL | 0:9d17e4342598 | 3446 | if (idx >= 0 && fp_cache[idx].lru_count >= 2) { |
wolfSSL | 0:9d17e4342598 | 3447 | if (mpSetup == 0) { |
wolfSSL | 0:9d17e4342598 | 3448 | /* compute mp */ |
wolfSSL | 0:9d17e4342598 | 3449 | err = mp_montgomery_setup(modulus, &mp); |
wolfSSL | 0:9d17e4342598 | 3450 | } |
wolfSSL | 0:9d17e4342598 | 3451 | if (err == MP_OKAY) |
wolfSSL | 0:9d17e4342598 | 3452 | err = accel_fp_mul(idx, k, R, modulus, &mp, map); |
wolfSSL | 0:9d17e4342598 | 3453 | } else { |
wolfSSL | 0:9d17e4342598 | 3454 | err = normal_ecc_mulmod(k, G, R, modulus, map); |
wolfSSL | 0:9d17e4342598 | 3455 | } |
wolfSSL | 0:9d17e4342598 | 3456 | } |
wolfSSL | 0:9d17e4342598 | 3457 | |
wolfSSL | 0:9d17e4342598 | 3458 | #ifndef HAVE_THREAD_LS |
wolfSSL | 0:9d17e4342598 | 3459 | UnLockMutex(&ecc_fp_lock); |
wolfSSL | 0:9d17e4342598 | 3460 | #endif /* HAVE_THREAD_LS */ |
wolfSSL | 0:9d17e4342598 | 3461 | mp_clear(&mu); |
wolfSSL | 0:9d17e4342598 | 3462 | |
wolfSSL | 0:9d17e4342598 | 3463 | return err; |
wolfSSL | 0:9d17e4342598 | 3464 | } |
wolfSSL | 0:9d17e4342598 | 3465 | |
wolfSSL | 0:9d17e4342598 | 3466 | /* helper function for freeing the cache ... |
wolfSSL | 0:9d17e4342598 | 3467 | must be called with the cache mutex locked */ |
wolfSSL | 0:9d17e4342598 | 3468 | static void ecc_fp_free_cache(void) |
wolfSSL | 0:9d17e4342598 | 3469 | { |
wolfSSL | 0:9d17e4342598 | 3470 | unsigned x, y; |
wolfSSL | 0:9d17e4342598 | 3471 | for (x = 0; x < FP_ENTRIES; x++) { |
wolfSSL | 0:9d17e4342598 | 3472 | if (fp_cache[x].g != NULL) { |
wolfSSL | 0:9d17e4342598 | 3473 | for (y = 0; y < (1U<<FP_LUT); y++) { |
wolfSSL | 0:9d17e4342598 | 3474 | ecc_del_point(fp_cache[x].LUT[y]); |
wolfSSL | 0:9d17e4342598 | 3475 | fp_cache[x].LUT[y] = NULL; |
wolfSSL | 0:9d17e4342598 | 3476 | } |
wolfSSL | 0:9d17e4342598 | 3477 | ecc_del_point(fp_cache[x].g); |
wolfSSL | 0:9d17e4342598 | 3478 | fp_cache[x].g = NULL; |
wolfSSL | 0:9d17e4342598 | 3479 | mp_clear(&fp_cache[x].mu); |
wolfSSL | 0:9d17e4342598 | 3480 | fp_cache[x].lru_count = 0; |
wolfSSL | 0:9d17e4342598 | 3481 | fp_cache[x].lock = 0; |
wolfSSL | 0:9d17e4342598 | 3482 | } |
wolfSSL | 0:9d17e4342598 | 3483 | } |
wolfSSL | 0:9d17e4342598 | 3484 | } |
wolfSSL | 0:9d17e4342598 | 3485 | |
wolfSSL | 0:9d17e4342598 | 3486 | /** Free the Fixed Point cache */ |
wolfSSL | 0:9d17e4342598 | 3487 | void ecc_fp_free(void) |
wolfSSL | 0:9d17e4342598 | 3488 | { |
wolfSSL | 0:9d17e4342598 | 3489 | #ifndef HAVE_THREAD_LS |
wolfSSL | 0:9d17e4342598 | 3490 | if (initMutex == 0) { |
wolfSSL | 0:9d17e4342598 | 3491 | InitMutex(&ecc_fp_lock); |
wolfSSL | 0:9d17e4342598 | 3492 | initMutex = 1; |
wolfSSL | 0:9d17e4342598 | 3493 | } |
wolfSSL | 0:9d17e4342598 | 3494 | |
wolfSSL | 0:9d17e4342598 | 3495 | if (LockMutex(&ecc_fp_lock) == 0) { |
wolfSSL | 0:9d17e4342598 | 3496 | #endif /* HAVE_THREAD_LS */ |
wolfSSL | 0:9d17e4342598 | 3497 | |
wolfSSL | 0:9d17e4342598 | 3498 | ecc_fp_free_cache(); |
wolfSSL | 0:9d17e4342598 | 3499 | |
wolfSSL | 0:9d17e4342598 | 3500 | #ifndef HAVE_THREAD_LS |
wolfSSL | 0:9d17e4342598 | 3501 | UnLockMutex(&ecc_fp_lock); |
wolfSSL | 0:9d17e4342598 | 3502 | FreeMutex(&ecc_fp_lock); |
wolfSSL | 0:9d17e4342598 | 3503 | initMutex = 0; |
wolfSSL | 0:9d17e4342598 | 3504 | } |
wolfSSL | 0:9d17e4342598 | 3505 | #endif /* HAVE_THREAD_LS */ |
wolfSSL | 0:9d17e4342598 | 3506 | } |
wolfSSL | 0:9d17e4342598 | 3507 | |
wolfSSL | 0:9d17e4342598 | 3508 | |
wolfSSL | 0:9d17e4342598 | 3509 | #endif /* FP_ECC */ |
wolfSSL | 0:9d17e4342598 | 3510 | |
wolfSSL | 0:9d17e4342598 | 3511 | #ifdef HAVE_ECC_ENCRYPT |
wolfSSL | 0:9d17e4342598 | 3512 | |
wolfSSL | 0:9d17e4342598 | 3513 | |
wolfSSL | 0:9d17e4342598 | 3514 | enum ecCliState { |
wolfSSL | 0:9d17e4342598 | 3515 | ecCLI_INIT = 1, |
wolfSSL | 0:9d17e4342598 | 3516 | ecCLI_SALT_GET = 2, |
wolfSSL | 0:9d17e4342598 | 3517 | ecCLI_SALT_SET = 3, |
wolfSSL | 0:9d17e4342598 | 3518 | ecCLI_SENT_REQ = 4, |
wolfSSL | 0:9d17e4342598 | 3519 | ecCLI_RECV_RESP = 5, |
wolfSSL | 0:9d17e4342598 | 3520 | ecCLI_BAD_STATE = 99 |
wolfSSL | 0:9d17e4342598 | 3521 | }; |
wolfSSL | 0:9d17e4342598 | 3522 | |
wolfSSL | 0:9d17e4342598 | 3523 | enum ecSrvState { |
wolfSSL | 0:9d17e4342598 | 3524 | ecSRV_INIT = 1, |
wolfSSL | 0:9d17e4342598 | 3525 | ecSRV_SALT_GET = 2, |
wolfSSL | 0:9d17e4342598 | 3526 | ecSRV_SALT_SET = 3, |
wolfSSL | 0:9d17e4342598 | 3527 | ecSRV_RECV_REQ = 4, |
wolfSSL | 0:9d17e4342598 | 3528 | ecSRV_SENT_RESP = 5, |
wolfSSL | 0:9d17e4342598 | 3529 | ecSRV_BAD_STATE = 99 |
wolfSSL | 0:9d17e4342598 | 3530 | }; |
wolfSSL | 0:9d17e4342598 | 3531 | |
wolfSSL | 0:9d17e4342598 | 3532 | |
wolfSSL | 0:9d17e4342598 | 3533 | struct ecEncCtx { |
wolfSSL | 0:9d17e4342598 | 3534 | byte* kdfSalt; /* optional salt for kdf */ |
wolfSSL | 0:9d17e4342598 | 3535 | byte* kdfInfo; /* optional info for kdf */ |
wolfSSL | 0:9d17e4342598 | 3536 | byte* macSalt; /* optional salt for mac */ |
wolfSSL | 0:9d17e4342598 | 3537 | word32 kdfSaltSz; /* size of kdfSalt */ |
wolfSSL | 0:9d17e4342598 | 3538 | word32 kdfInfoSz; /* size of kdfInfo */ |
wolfSSL | 0:9d17e4342598 | 3539 | word32 macSaltSz; /* size of macSalt */ |
wolfSSL | 0:9d17e4342598 | 3540 | byte clientSalt[EXCHANGE_SALT_SZ]; /* for msg exchange */ |
wolfSSL | 0:9d17e4342598 | 3541 | byte serverSalt[EXCHANGE_SALT_SZ]; /* for msg exchange */ |
wolfSSL | 0:9d17e4342598 | 3542 | byte encAlgo; /* which encryption type */ |
wolfSSL | 0:9d17e4342598 | 3543 | byte kdfAlgo; /* which key derivation function type */ |
wolfSSL | 0:9d17e4342598 | 3544 | byte macAlgo; /* which mac function type */ |
wolfSSL | 0:9d17e4342598 | 3545 | byte protocol; /* are we REQ_RESP client or server ? */ |
wolfSSL | 0:9d17e4342598 | 3546 | byte cliSt; /* protocol state, for sanity checks */ |
wolfSSL | 0:9d17e4342598 | 3547 | byte srvSt; /* protocol state, for sanity checks */ |
wolfSSL | 0:9d17e4342598 | 3548 | }; |
wolfSSL | 0:9d17e4342598 | 3549 | |
wolfSSL | 0:9d17e4342598 | 3550 | |
wolfSSL | 0:9d17e4342598 | 3551 | const byte* ecc_ctx_get_own_salt(ecEncCtx* ctx) |
wolfSSL | 0:9d17e4342598 | 3552 | { |
wolfSSL | 0:9d17e4342598 | 3553 | if (ctx == NULL || ctx->protocol == 0) |
wolfSSL | 0:9d17e4342598 | 3554 | return NULL; |
wolfSSL | 0:9d17e4342598 | 3555 | |
wolfSSL | 0:9d17e4342598 | 3556 | if (ctx->protocol == REQ_RESP_CLIENT) { |
wolfSSL | 0:9d17e4342598 | 3557 | if (ctx->cliSt == ecCLI_INIT) { |
wolfSSL | 0:9d17e4342598 | 3558 | ctx->cliSt = ecCLI_SALT_GET; |
wolfSSL | 0:9d17e4342598 | 3559 | return ctx->clientSalt; |
wolfSSL | 0:9d17e4342598 | 3560 | } |
wolfSSL | 0:9d17e4342598 | 3561 | else { |
wolfSSL | 0:9d17e4342598 | 3562 | ctx->cliSt = ecCLI_BAD_STATE; |
wolfSSL | 0:9d17e4342598 | 3563 | return NULL; |
wolfSSL | 0:9d17e4342598 | 3564 | } |
wolfSSL | 0:9d17e4342598 | 3565 | } |
wolfSSL | 0:9d17e4342598 | 3566 | else if (ctx->protocol == REQ_RESP_SERVER) { |
wolfSSL | 0:9d17e4342598 | 3567 | if (ctx->srvSt == ecSRV_INIT) { |
wolfSSL | 0:9d17e4342598 | 3568 | ctx->srvSt = ecSRV_SALT_GET; |
wolfSSL | 0:9d17e4342598 | 3569 | return ctx->serverSalt; |
wolfSSL | 0:9d17e4342598 | 3570 | } |
wolfSSL | 0:9d17e4342598 | 3571 | else { |
wolfSSL | 0:9d17e4342598 | 3572 | ctx->srvSt = ecSRV_BAD_STATE; |
wolfSSL | 0:9d17e4342598 | 3573 | return NULL; |
wolfSSL | 0:9d17e4342598 | 3574 | } |
wolfSSL | 0:9d17e4342598 | 3575 | } |
wolfSSL | 0:9d17e4342598 | 3576 | |
wolfSSL | 0:9d17e4342598 | 3577 | return NULL; |
wolfSSL | 0:9d17e4342598 | 3578 | } |
wolfSSL | 0:9d17e4342598 | 3579 | |
wolfSSL | 0:9d17e4342598 | 3580 | |
wolfSSL | 0:9d17e4342598 | 3581 | static const char* exchange_info = "Secure Message Exchange"; |
wolfSSL | 0:9d17e4342598 | 3582 | |
wolfSSL | 0:9d17e4342598 | 3583 | int ecc_ctx_set_peer_salt(ecEncCtx* ctx, const byte* salt) |
wolfSSL | 0:9d17e4342598 | 3584 | { |
wolfSSL | 0:9d17e4342598 | 3585 | byte tmp[EXCHANGE_SALT_SZ/2]; |
wolfSSL | 0:9d17e4342598 | 3586 | int halfSz = EXCHANGE_SALT_SZ/2; |
wolfSSL | 0:9d17e4342598 | 3587 | |
wolfSSL | 0:9d17e4342598 | 3588 | if (ctx == NULL || ctx->protocol == 0 || salt == NULL) |
wolfSSL | 0:9d17e4342598 | 3589 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3590 | |
wolfSSL | 0:9d17e4342598 | 3591 | if (ctx->protocol == REQ_RESP_CLIENT) { |
wolfSSL | 0:9d17e4342598 | 3592 | XMEMCPY(ctx->serverSalt, salt, EXCHANGE_SALT_SZ); |
wolfSSL | 0:9d17e4342598 | 3593 | if (ctx->cliSt == ecCLI_SALT_GET) |
wolfSSL | 0:9d17e4342598 | 3594 | ctx->cliSt = ecCLI_SALT_SET; |
wolfSSL | 0:9d17e4342598 | 3595 | else { |
wolfSSL | 0:9d17e4342598 | 3596 | ctx->cliSt = ecCLI_BAD_STATE; |
wolfSSL | 0:9d17e4342598 | 3597 | return BAD_ENC_STATE_E; |
wolfSSL | 0:9d17e4342598 | 3598 | } |
wolfSSL | 0:9d17e4342598 | 3599 | } |
wolfSSL | 0:9d17e4342598 | 3600 | else { |
wolfSSL | 0:9d17e4342598 | 3601 | XMEMCPY(ctx->clientSalt, salt, EXCHANGE_SALT_SZ); |
wolfSSL | 0:9d17e4342598 | 3602 | if (ctx->srvSt == ecSRV_SALT_GET) |
wolfSSL | 0:9d17e4342598 | 3603 | ctx->srvSt = ecSRV_SALT_SET; |
wolfSSL | 0:9d17e4342598 | 3604 | else { |
wolfSSL | 0:9d17e4342598 | 3605 | ctx->srvSt = ecSRV_BAD_STATE; |
wolfSSL | 0:9d17e4342598 | 3606 | return BAD_ENC_STATE_E; |
wolfSSL | 0:9d17e4342598 | 3607 | } |
wolfSSL | 0:9d17e4342598 | 3608 | } |
wolfSSL | 0:9d17e4342598 | 3609 | |
wolfSSL | 0:9d17e4342598 | 3610 | /* mix half and half */ |
wolfSSL | 0:9d17e4342598 | 3611 | /* tmp stores 2nd half of client before overwrite */ |
wolfSSL | 0:9d17e4342598 | 3612 | XMEMCPY(tmp, ctx->clientSalt + halfSz, halfSz); |
wolfSSL | 0:9d17e4342598 | 3613 | XMEMCPY(ctx->clientSalt + halfSz, ctx->serverSalt, halfSz); |
wolfSSL | 0:9d17e4342598 | 3614 | XMEMCPY(ctx->serverSalt, tmp, halfSz); |
wolfSSL | 0:9d17e4342598 | 3615 | |
wolfSSL | 0:9d17e4342598 | 3616 | ctx->kdfSalt = ctx->clientSalt; |
wolfSSL | 0:9d17e4342598 | 3617 | ctx->kdfSaltSz = EXCHANGE_SALT_SZ; |
wolfSSL | 0:9d17e4342598 | 3618 | |
wolfSSL | 0:9d17e4342598 | 3619 | ctx->macSalt = ctx->serverSalt; |
wolfSSL | 0:9d17e4342598 | 3620 | ctx->macSaltSz = EXCHANGE_SALT_SZ; |
wolfSSL | 0:9d17e4342598 | 3621 | |
wolfSSL | 0:9d17e4342598 | 3622 | ctx->kdfInfo = (byte*)exchange_info; |
wolfSSL | 0:9d17e4342598 | 3623 | ctx->kdfInfoSz = EXCHANGE_INFO_SZ; |
wolfSSL | 0:9d17e4342598 | 3624 | |
wolfSSL | 0:9d17e4342598 | 3625 | return 0; |
wolfSSL | 0:9d17e4342598 | 3626 | } |
wolfSSL | 0:9d17e4342598 | 3627 | |
wolfSSL | 0:9d17e4342598 | 3628 | |
wolfSSL | 0:9d17e4342598 | 3629 | static int ecc_ctx_set_salt(ecEncCtx* ctx, int flags, RNG* rng) |
wolfSSL | 0:9d17e4342598 | 3630 | { |
wolfSSL | 0:9d17e4342598 | 3631 | byte* saltBuffer = NULL; |
wolfSSL | 0:9d17e4342598 | 3632 | |
wolfSSL | 0:9d17e4342598 | 3633 | if (ctx == NULL || rng == NULL || flags == 0) |
wolfSSL | 0:9d17e4342598 | 3634 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3635 | |
wolfSSL | 0:9d17e4342598 | 3636 | saltBuffer = (flags == REQ_RESP_CLIENT) ? ctx->clientSalt : ctx->serverSalt; |
wolfSSL | 0:9d17e4342598 | 3637 | RNG_GenerateBlock(rng, saltBuffer, EXCHANGE_SALT_SZ); |
wolfSSL | 0:9d17e4342598 | 3638 | |
wolfSSL | 0:9d17e4342598 | 3639 | return 0; |
wolfSSL | 0:9d17e4342598 | 3640 | } |
wolfSSL | 0:9d17e4342598 | 3641 | |
wolfSSL | 0:9d17e4342598 | 3642 | |
wolfSSL | 0:9d17e4342598 | 3643 | static void ecc_ctx_init(ecEncCtx* ctx, int flags) |
wolfSSL | 0:9d17e4342598 | 3644 | { |
wolfSSL | 0:9d17e4342598 | 3645 | if (ctx) { |
wolfSSL | 0:9d17e4342598 | 3646 | XMEMSET(ctx, 0, sizeof(ecEncCtx)); |
wolfSSL | 0:9d17e4342598 | 3647 | |
wolfSSL | 0:9d17e4342598 | 3648 | ctx->encAlgo = ecAES_128_CBC; |
wolfSSL | 0:9d17e4342598 | 3649 | ctx->kdfAlgo = ecHKDF_SHA256; |
wolfSSL | 0:9d17e4342598 | 3650 | ctx->macAlgo = ecHMAC_SHA256; |
wolfSSL | 0:9d17e4342598 | 3651 | ctx->protocol = (byte)flags; |
wolfSSL | 0:9d17e4342598 | 3652 | |
wolfSSL | 0:9d17e4342598 | 3653 | if (flags == REQ_RESP_CLIENT) |
wolfSSL | 0:9d17e4342598 | 3654 | ctx->cliSt = ecCLI_INIT; |
wolfSSL | 0:9d17e4342598 | 3655 | if (flags == REQ_RESP_SERVER) |
wolfSSL | 0:9d17e4342598 | 3656 | ctx->srvSt = ecSRV_INIT; |
wolfSSL | 0:9d17e4342598 | 3657 | } |
wolfSSL | 0:9d17e4342598 | 3658 | } |
wolfSSL | 0:9d17e4342598 | 3659 | |
wolfSSL | 0:9d17e4342598 | 3660 | |
wolfSSL | 0:9d17e4342598 | 3661 | /* allow ecc context reset so user doesn't have to init/free for resue */ |
wolfSSL | 0:9d17e4342598 | 3662 | int ecc_ctx_reset(ecEncCtx* ctx, RNG* rng) |
wolfSSL | 0:9d17e4342598 | 3663 | { |
wolfSSL | 0:9d17e4342598 | 3664 | if (ctx == NULL || rng == NULL) |
wolfSSL | 0:9d17e4342598 | 3665 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3666 | |
wolfSSL | 0:9d17e4342598 | 3667 | ecc_ctx_init(ctx, ctx->protocol); |
wolfSSL | 0:9d17e4342598 | 3668 | return ecc_ctx_set_salt(ctx, ctx->protocol, rng); |
wolfSSL | 0:9d17e4342598 | 3669 | } |
wolfSSL | 0:9d17e4342598 | 3670 | |
wolfSSL | 0:9d17e4342598 | 3671 | |
wolfSSL | 0:9d17e4342598 | 3672 | /* alloc/init and set defaults, return new Context */ |
wolfSSL | 0:9d17e4342598 | 3673 | ecEncCtx* ecc_ctx_new(int flags, RNG* rng) |
wolfSSL | 0:9d17e4342598 | 3674 | { |
wolfSSL | 0:9d17e4342598 | 3675 | int ret = 0; |
wolfSSL | 0:9d17e4342598 | 3676 | ecEncCtx* ctx = (ecEncCtx*)XMALLOC(sizeof(ecEncCtx), 0, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 3677 | |
wolfSSL | 0:9d17e4342598 | 3678 | if (ctx) |
wolfSSL | 0:9d17e4342598 | 3679 | ctx->protocol = (byte)flags; |
wolfSSL | 0:9d17e4342598 | 3680 | |
wolfSSL | 0:9d17e4342598 | 3681 | ret = ecc_ctx_reset(ctx, rng); |
wolfSSL | 0:9d17e4342598 | 3682 | if (ret != 0) { |
wolfSSL | 0:9d17e4342598 | 3683 | ecc_ctx_free(ctx); |
wolfSSL | 0:9d17e4342598 | 3684 | ctx = NULL; |
wolfSSL | 0:9d17e4342598 | 3685 | } |
wolfSSL | 0:9d17e4342598 | 3686 | |
wolfSSL | 0:9d17e4342598 | 3687 | return ctx; |
wolfSSL | 0:9d17e4342598 | 3688 | } |
wolfSSL | 0:9d17e4342598 | 3689 | |
wolfSSL | 0:9d17e4342598 | 3690 | |
wolfSSL | 0:9d17e4342598 | 3691 | /* free any resources, clear any keys */ |
wolfSSL | 0:9d17e4342598 | 3692 | void ecc_ctx_free(ecEncCtx* ctx) |
wolfSSL | 0:9d17e4342598 | 3693 | { |
wolfSSL | 0:9d17e4342598 | 3694 | if (ctx) { |
wolfSSL | 0:9d17e4342598 | 3695 | XMEMSET(ctx, 0, sizeof(ecEncCtx)); |
wolfSSL | 0:9d17e4342598 | 3696 | XFREE(ctx, 0, DYNAMIC_TYPE_ECC); |
wolfSSL | 0:9d17e4342598 | 3697 | } |
wolfSSL | 0:9d17e4342598 | 3698 | } |
wolfSSL | 0:9d17e4342598 | 3699 | |
wolfSSL | 0:9d17e4342598 | 3700 | |
wolfSSL | 0:9d17e4342598 | 3701 | static int ecc_get_key_sizes(ecEncCtx* ctx, int* encKeySz, int* ivSz, |
wolfSSL | 0:9d17e4342598 | 3702 | int* keysLen, word32* digestSz, word32* blockSz) |
wolfSSL | 0:9d17e4342598 | 3703 | { |
wolfSSL | 0:9d17e4342598 | 3704 | if (ctx) { |
wolfSSL | 0:9d17e4342598 | 3705 | switch (ctx->encAlgo) { |
wolfSSL | 0:9d17e4342598 | 3706 | case ecAES_128_CBC: |
wolfSSL | 0:9d17e4342598 | 3707 | *encKeySz = KEY_SIZE_128; |
wolfSSL | 0:9d17e4342598 | 3708 | *ivSz = IV_SIZE_64; |
wolfSSL | 0:9d17e4342598 | 3709 | *blockSz = AES_BLOCK_SIZE; |
wolfSSL | 0:9d17e4342598 | 3710 | break; |
wolfSSL | 0:9d17e4342598 | 3711 | default: |
wolfSSL | 0:9d17e4342598 | 3712 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3713 | } |
wolfSSL | 0:9d17e4342598 | 3714 | |
wolfSSL | 0:9d17e4342598 | 3715 | switch (ctx->macAlgo) { |
wolfSSL | 0:9d17e4342598 | 3716 | case ecHMAC_SHA256: |
wolfSSL | 0:9d17e4342598 | 3717 | *digestSz = SHA256_DIGEST_SIZE; |
wolfSSL | 0:9d17e4342598 | 3718 | break; |
wolfSSL | 0:9d17e4342598 | 3719 | default: |
wolfSSL | 0:9d17e4342598 | 3720 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3721 | } |
wolfSSL | 0:9d17e4342598 | 3722 | } else |
wolfSSL | 0:9d17e4342598 | 3723 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3724 | |
wolfSSL | 0:9d17e4342598 | 3725 | *keysLen = *encKeySz + *ivSz + *digestSz; |
wolfSSL | 0:9d17e4342598 | 3726 | |
wolfSSL | 0:9d17e4342598 | 3727 | return 0; |
wolfSSL | 0:9d17e4342598 | 3728 | } |
wolfSSL | 0:9d17e4342598 | 3729 | |
wolfSSL | 0:9d17e4342598 | 3730 | |
wolfSSL | 0:9d17e4342598 | 3731 | /* ecc encrypt with shared secret run through kdf |
wolfSSL | 0:9d17e4342598 | 3732 | ctx holds non default algos and inputs |
wolfSSL | 0:9d17e4342598 | 3733 | msgSz should be the right size for encAlgo, i.e., already padded |
wolfSSL | 0:9d17e4342598 | 3734 | return 0 on success */ |
wolfSSL | 0:9d17e4342598 | 3735 | int ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, |
wolfSSL | 0:9d17e4342598 | 3736 | word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx) |
wolfSSL | 0:9d17e4342598 | 3737 | { |
wolfSSL | 0:9d17e4342598 | 3738 | int ret; |
wolfSSL | 0:9d17e4342598 | 3739 | word32 blockSz; |
wolfSSL | 0:9d17e4342598 | 3740 | word32 digestSz; |
wolfSSL | 0:9d17e4342598 | 3741 | ecEncCtx localCtx; |
wolfSSL | 0:9d17e4342598 | 3742 | byte sharedSecret[ECC_MAXSIZE]; /* 521 max size */ |
wolfSSL | 0:9d17e4342598 | 3743 | byte keys[ECC_BUFSIZE]; /* max size */ |
wolfSSL | 0:9d17e4342598 | 3744 | word32 sharedSz = sizeof(sharedSecret); |
wolfSSL | 0:9d17e4342598 | 3745 | int keysLen; |
wolfSSL | 0:9d17e4342598 | 3746 | int encKeySz; |
wolfSSL | 0:9d17e4342598 | 3747 | int ivSz; |
wolfSSL | 0:9d17e4342598 | 3748 | int offset = 0; /* keys offset if doing msg exchange */ |
wolfSSL | 0:9d17e4342598 | 3749 | byte* encKey; |
wolfSSL | 0:9d17e4342598 | 3750 | byte* encIv; |
wolfSSL | 0:9d17e4342598 | 3751 | byte* macKey; |
wolfSSL | 0:9d17e4342598 | 3752 | |
wolfSSL | 0:9d17e4342598 | 3753 | if (privKey == NULL || pubKey == NULL || msg == NULL || out == NULL || |
wolfSSL | 0:9d17e4342598 | 3754 | outSz == NULL) |
wolfSSL | 0:9d17e4342598 | 3755 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3756 | |
wolfSSL | 0:9d17e4342598 | 3757 | if (ctx == NULL) { /* use defaults */ |
wolfSSL | 0:9d17e4342598 | 3758 | ecc_ctx_init(&localCtx, 0); |
wolfSSL | 0:9d17e4342598 | 3759 | ctx = &localCtx; |
wolfSSL | 0:9d17e4342598 | 3760 | } |
wolfSSL | 0:9d17e4342598 | 3761 | |
wolfSSL | 0:9d17e4342598 | 3762 | ret = ecc_get_key_sizes(ctx, &encKeySz, &ivSz, &keysLen, &digestSz, |
wolfSSL | 0:9d17e4342598 | 3763 | &blockSz); |
wolfSSL | 0:9d17e4342598 | 3764 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3765 | return ret; |
wolfSSL | 0:9d17e4342598 | 3766 | |
wolfSSL | 0:9d17e4342598 | 3767 | if (ctx->protocol == REQ_RESP_SERVER) { |
wolfSSL | 0:9d17e4342598 | 3768 | offset = keysLen; |
wolfSSL | 0:9d17e4342598 | 3769 | keysLen *= 2; |
wolfSSL | 0:9d17e4342598 | 3770 | |
wolfSSL | 0:9d17e4342598 | 3771 | if (ctx->srvSt != ecSRV_RECV_REQ) |
wolfSSL | 0:9d17e4342598 | 3772 | return BAD_ENC_STATE_E; |
wolfSSL | 0:9d17e4342598 | 3773 | |
wolfSSL | 0:9d17e4342598 | 3774 | ctx->srvSt = ecSRV_BAD_STATE; /* we're done no more ops allowed */ |
wolfSSL | 0:9d17e4342598 | 3775 | } |
wolfSSL | 0:9d17e4342598 | 3776 | else if (ctx->protocol == REQ_RESP_CLIENT) { |
wolfSSL | 0:9d17e4342598 | 3777 | if (ctx->cliSt != ecCLI_SALT_SET) |
wolfSSL | 0:9d17e4342598 | 3778 | return BAD_ENC_STATE_E; |
wolfSSL | 0:9d17e4342598 | 3779 | |
wolfSSL | 0:9d17e4342598 | 3780 | ctx->cliSt = ecCLI_SENT_REQ; /* only do this once */ |
wolfSSL | 0:9d17e4342598 | 3781 | } |
wolfSSL | 0:9d17e4342598 | 3782 | |
wolfSSL | 0:9d17e4342598 | 3783 | if (keysLen > (int)sizeof(keys)) |
wolfSSL | 0:9d17e4342598 | 3784 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 3785 | |
wolfSSL | 0:9d17e4342598 | 3786 | if ( (msgSz%blockSz) != 0) |
wolfSSL | 0:9d17e4342598 | 3787 | return BAD_PADDING_E; |
wolfSSL | 0:9d17e4342598 | 3788 | |
wolfSSL | 0:9d17e4342598 | 3789 | if (*outSz < (msgSz + digestSz)) |
wolfSSL | 0:9d17e4342598 | 3790 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 3791 | |
wolfSSL | 0:9d17e4342598 | 3792 | ret = ecc_shared_secret(privKey, pubKey, sharedSecret, &sharedSz); |
wolfSSL | 0:9d17e4342598 | 3793 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3794 | return ret; |
wolfSSL | 0:9d17e4342598 | 3795 | |
wolfSSL | 0:9d17e4342598 | 3796 | switch (ctx->kdfAlgo) { |
wolfSSL | 0:9d17e4342598 | 3797 | case ecHKDF_SHA256 : |
wolfSSL | 0:9d17e4342598 | 3798 | ret = HKDF(SHA256, sharedSecret, sharedSz, ctx->kdfSalt, |
wolfSSL | 0:9d17e4342598 | 3799 | ctx->kdfSaltSz, ctx->kdfInfo, |
wolfSSL | 0:9d17e4342598 | 3800 | ctx->kdfInfoSz, keys, keysLen); |
wolfSSL | 0:9d17e4342598 | 3801 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3802 | return ret; |
wolfSSL | 0:9d17e4342598 | 3803 | break; |
wolfSSL | 0:9d17e4342598 | 3804 | |
wolfSSL | 0:9d17e4342598 | 3805 | default: |
wolfSSL | 0:9d17e4342598 | 3806 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3807 | } |
wolfSSL | 0:9d17e4342598 | 3808 | |
wolfSSL | 0:9d17e4342598 | 3809 | encKey = keys + offset; |
wolfSSL | 0:9d17e4342598 | 3810 | encIv = encKey + encKeySz; |
wolfSSL | 0:9d17e4342598 | 3811 | macKey = encKey + encKeySz + ivSz; |
wolfSSL | 0:9d17e4342598 | 3812 | |
wolfSSL | 0:9d17e4342598 | 3813 | switch (ctx->encAlgo) { |
wolfSSL | 0:9d17e4342598 | 3814 | case ecAES_128_CBC: |
wolfSSL | 0:9d17e4342598 | 3815 | { |
wolfSSL | 0:9d17e4342598 | 3816 | Aes aes; |
wolfSSL | 0:9d17e4342598 | 3817 | ret = AesSetKey(&aes, encKey,KEY_SIZE_128,encIv,AES_ENCRYPTION); |
wolfSSL | 0:9d17e4342598 | 3818 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3819 | return ret; |
wolfSSL | 0:9d17e4342598 | 3820 | ret = AesCbcEncrypt(&aes, out, msg, msgSz); |
wolfSSL | 0:9d17e4342598 | 3821 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3822 | return ret; |
wolfSSL | 0:9d17e4342598 | 3823 | } |
wolfSSL | 0:9d17e4342598 | 3824 | break; |
wolfSSL | 0:9d17e4342598 | 3825 | |
wolfSSL | 0:9d17e4342598 | 3826 | default: |
wolfSSL | 0:9d17e4342598 | 3827 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3828 | } |
wolfSSL | 0:9d17e4342598 | 3829 | |
wolfSSL | 0:9d17e4342598 | 3830 | switch (ctx->macAlgo) { |
wolfSSL | 0:9d17e4342598 | 3831 | case ecHMAC_SHA256: |
wolfSSL | 0:9d17e4342598 | 3832 | { |
wolfSSL | 0:9d17e4342598 | 3833 | Hmac hmac; |
wolfSSL | 0:9d17e4342598 | 3834 | ret = HmacSetKey(&hmac, SHA256, macKey, SHA256_DIGEST_SIZE); |
wolfSSL | 0:9d17e4342598 | 3835 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3836 | return ret; |
wolfSSL | 0:9d17e4342598 | 3837 | HmacUpdate(&hmac, out, msgSz); |
wolfSSL | 0:9d17e4342598 | 3838 | HmacUpdate(&hmac, ctx->macSalt, ctx->macSaltSz); |
wolfSSL | 0:9d17e4342598 | 3839 | HmacFinal(&hmac, out+msgSz); |
wolfSSL | 0:9d17e4342598 | 3840 | } |
wolfSSL | 0:9d17e4342598 | 3841 | break; |
wolfSSL | 0:9d17e4342598 | 3842 | |
wolfSSL | 0:9d17e4342598 | 3843 | default: |
wolfSSL | 0:9d17e4342598 | 3844 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3845 | } |
wolfSSL | 0:9d17e4342598 | 3846 | |
wolfSSL | 0:9d17e4342598 | 3847 | *outSz = msgSz + digestSz; |
wolfSSL | 0:9d17e4342598 | 3848 | |
wolfSSL | 0:9d17e4342598 | 3849 | return 0; |
wolfSSL | 0:9d17e4342598 | 3850 | } |
wolfSSL | 0:9d17e4342598 | 3851 | |
wolfSSL | 0:9d17e4342598 | 3852 | |
wolfSSL | 0:9d17e4342598 | 3853 | /* ecc decrypt with shared secret run through kdf |
wolfSSL | 0:9d17e4342598 | 3854 | ctx holds non default algos and inputs |
wolfSSL | 0:9d17e4342598 | 3855 | return 0 on success */ |
wolfSSL | 0:9d17e4342598 | 3856 | int ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg, |
wolfSSL | 0:9d17e4342598 | 3857 | word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx) |
wolfSSL | 0:9d17e4342598 | 3858 | { |
wolfSSL | 0:9d17e4342598 | 3859 | int ret; |
wolfSSL | 0:9d17e4342598 | 3860 | word32 blockSz; |
wolfSSL | 0:9d17e4342598 | 3861 | word32 digestSz; |
wolfSSL | 0:9d17e4342598 | 3862 | ecEncCtx localCtx; |
wolfSSL | 0:9d17e4342598 | 3863 | byte sharedSecret[ECC_MAXSIZE]; /* 521 max size */ |
wolfSSL | 0:9d17e4342598 | 3864 | byte keys[ECC_BUFSIZE]; /* max size */ |
wolfSSL | 0:9d17e4342598 | 3865 | word32 sharedSz = sizeof(sharedSecret); |
wolfSSL | 0:9d17e4342598 | 3866 | int keysLen; |
wolfSSL | 0:9d17e4342598 | 3867 | int encKeySz; |
wolfSSL | 0:9d17e4342598 | 3868 | int ivSz; |
wolfSSL | 0:9d17e4342598 | 3869 | int offset = 0; /* in case using msg exchange */ |
wolfSSL | 0:9d17e4342598 | 3870 | byte* encKey; |
wolfSSL | 0:9d17e4342598 | 3871 | byte* encIv; |
wolfSSL | 0:9d17e4342598 | 3872 | byte* macKey; |
wolfSSL | 0:9d17e4342598 | 3873 | |
wolfSSL | 0:9d17e4342598 | 3874 | if (privKey == NULL || pubKey == NULL || msg == NULL || out == NULL || |
wolfSSL | 0:9d17e4342598 | 3875 | outSz == NULL) |
wolfSSL | 0:9d17e4342598 | 3876 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3877 | |
wolfSSL | 0:9d17e4342598 | 3878 | if (ctx == NULL) { /* use defaults */ |
wolfSSL | 0:9d17e4342598 | 3879 | ecc_ctx_init(&localCtx, 0); |
wolfSSL | 0:9d17e4342598 | 3880 | ctx = &localCtx; |
wolfSSL | 0:9d17e4342598 | 3881 | } |
wolfSSL | 0:9d17e4342598 | 3882 | |
wolfSSL | 0:9d17e4342598 | 3883 | ret = ecc_get_key_sizes(ctx, &encKeySz, &ivSz, &keysLen, &digestSz, |
wolfSSL | 0:9d17e4342598 | 3884 | &blockSz); |
wolfSSL | 0:9d17e4342598 | 3885 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3886 | return ret; |
wolfSSL | 0:9d17e4342598 | 3887 | |
wolfSSL | 0:9d17e4342598 | 3888 | if (ctx->protocol == REQ_RESP_CLIENT) { |
wolfSSL | 0:9d17e4342598 | 3889 | offset = keysLen; |
wolfSSL | 0:9d17e4342598 | 3890 | keysLen *= 2; |
wolfSSL | 0:9d17e4342598 | 3891 | |
wolfSSL | 0:9d17e4342598 | 3892 | if (ctx->cliSt != ecCLI_SENT_REQ) |
wolfSSL | 0:9d17e4342598 | 3893 | return BAD_ENC_STATE_E; |
wolfSSL | 0:9d17e4342598 | 3894 | |
wolfSSL | 0:9d17e4342598 | 3895 | ctx->cliSt = ecSRV_BAD_STATE; /* we're done no more ops allowed */ |
wolfSSL | 0:9d17e4342598 | 3896 | } |
wolfSSL | 0:9d17e4342598 | 3897 | else if (ctx->protocol == REQ_RESP_SERVER) { |
wolfSSL | 0:9d17e4342598 | 3898 | if (ctx->srvSt != ecSRV_SALT_SET) |
wolfSSL | 0:9d17e4342598 | 3899 | return BAD_ENC_STATE_E; |
wolfSSL | 0:9d17e4342598 | 3900 | |
wolfSSL | 0:9d17e4342598 | 3901 | ctx->srvSt = ecSRV_RECV_REQ; /* only do this once */ |
wolfSSL | 0:9d17e4342598 | 3902 | } |
wolfSSL | 0:9d17e4342598 | 3903 | |
wolfSSL | 0:9d17e4342598 | 3904 | if (keysLen > (int)sizeof(keys)) |
wolfSSL | 0:9d17e4342598 | 3905 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 3906 | |
wolfSSL | 0:9d17e4342598 | 3907 | if ( ((msgSz-digestSz) % blockSz) != 0) |
wolfSSL | 0:9d17e4342598 | 3908 | return BAD_PADDING_E; |
wolfSSL | 0:9d17e4342598 | 3909 | |
wolfSSL | 0:9d17e4342598 | 3910 | if (*outSz < (msgSz - digestSz)) |
wolfSSL | 0:9d17e4342598 | 3911 | return BUFFER_E; |
wolfSSL | 0:9d17e4342598 | 3912 | |
wolfSSL | 0:9d17e4342598 | 3913 | ret = ecc_shared_secret(privKey, pubKey, sharedSecret, &sharedSz); |
wolfSSL | 0:9d17e4342598 | 3914 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3915 | return ret; |
wolfSSL | 0:9d17e4342598 | 3916 | |
wolfSSL | 0:9d17e4342598 | 3917 | switch (ctx->kdfAlgo) { |
wolfSSL | 0:9d17e4342598 | 3918 | case ecHKDF_SHA256 : |
wolfSSL | 0:9d17e4342598 | 3919 | ret = HKDF(SHA256, sharedSecret, sharedSz, ctx->kdfSalt, |
wolfSSL | 0:9d17e4342598 | 3920 | ctx->kdfSaltSz, ctx->kdfInfo, |
wolfSSL | 0:9d17e4342598 | 3921 | ctx->kdfInfoSz, keys, keysLen); |
wolfSSL | 0:9d17e4342598 | 3922 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3923 | return ret; |
wolfSSL | 0:9d17e4342598 | 3924 | break; |
wolfSSL | 0:9d17e4342598 | 3925 | |
wolfSSL | 0:9d17e4342598 | 3926 | default: |
wolfSSL | 0:9d17e4342598 | 3927 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3928 | } |
wolfSSL | 0:9d17e4342598 | 3929 | |
wolfSSL | 0:9d17e4342598 | 3930 | encKey = keys + offset; |
wolfSSL | 0:9d17e4342598 | 3931 | encIv = encKey + encKeySz; |
wolfSSL | 0:9d17e4342598 | 3932 | macKey = encKey + encKeySz + ivSz; |
wolfSSL | 0:9d17e4342598 | 3933 | |
wolfSSL | 0:9d17e4342598 | 3934 | switch (ctx->macAlgo) { |
wolfSSL | 0:9d17e4342598 | 3935 | case ecHMAC_SHA256: |
wolfSSL | 0:9d17e4342598 | 3936 | { |
wolfSSL | 0:9d17e4342598 | 3937 | byte verify[SHA256_DIGEST_SIZE]; |
wolfSSL | 0:9d17e4342598 | 3938 | Hmac hmac; |
wolfSSL | 0:9d17e4342598 | 3939 | ret = HmacSetKey(&hmac, SHA256, macKey, SHA256_DIGEST_SIZE); |
wolfSSL | 0:9d17e4342598 | 3940 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3941 | return ret; |
wolfSSL | 0:9d17e4342598 | 3942 | HmacUpdate(&hmac, msg, msgSz-digestSz); |
wolfSSL | 0:9d17e4342598 | 3943 | HmacUpdate(&hmac, ctx->macSalt, ctx->macSaltSz); |
wolfSSL | 0:9d17e4342598 | 3944 | HmacFinal(&hmac, verify); |
wolfSSL | 0:9d17e4342598 | 3945 | |
wolfSSL | 0:9d17e4342598 | 3946 | if (memcmp(verify, msg + msgSz - digestSz, digestSz) != 0) { |
wolfSSL | 0:9d17e4342598 | 3947 | return -1; |
wolfSSL | 0:9d17e4342598 | 3948 | } |
wolfSSL | 0:9d17e4342598 | 3949 | } |
wolfSSL | 0:9d17e4342598 | 3950 | break; |
wolfSSL | 0:9d17e4342598 | 3951 | |
wolfSSL | 0:9d17e4342598 | 3952 | default: |
wolfSSL | 0:9d17e4342598 | 3953 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3954 | } |
wolfSSL | 0:9d17e4342598 | 3955 | |
wolfSSL | 0:9d17e4342598 | 3956 | switch (ctx->encAlgo) { |
wolfSSL | 0:9d17e4342598 | 3957 | case ecAES_128_CBC: |
wolfSSL | 0:9d17e4342598 | 3958 | { |
wolfSSL | 0:9d17e4342598 | 3959 | Aes aes; |
wolfSSL | 0:9d17e4342598 | 3960 | ret = AesSetKey(&aes, encKey,KEY_SIZE_128,encIv,AES_DECRYPTION); |
wolfSSL | 0:9d17e4342598 | 3961 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3962 | return ret; |
wolfSSL | 0:9d17e4342598 | 3963 | ret = AesCbcDecrypt(&aes, out, msg, msgSz-digestSz); |
wolfSSL | 0:9d17e4342598 | 3964 | if (ret != 0) |
wolfSSL | 0:9d17e4342598 | 3965 | return ret; |
wolfSSL | 0:9d17e4342598 | 3966 | } |
wolfSSL | 0:9d17e4342598 | 3967 | break; |
wolfSSL | 0:9d17e4342598 | 3968 | |
wolfSSL | 0:9d17e4342598 | 3969 | default: |
wolfSSL | 0:9d17e4342598 | 3970 | return BAD_FUNC_ARG; |
wolfSSL | 0:9d17e4342598 | 3971 | } |
wolfSSL | 0:9d17e4342598 | 3972 | |
wolfSSL | 0:9d17e4342598 | 3973 | *outSz = msgSz - digestSz; |
wolfSSL | 0:9d17e4342598 | 3974 | |
wolfSSL | 0:9d17e4342598 | 3975 | return 0; |
wolfSSL | 0:9d17e4342598 | 3976 | } |
wolfSSL | 0:9d17e4342598 | 3977 | |
wolfSSL | 0:9d17e4342598 | 3978 | |
wolfSSL | 0:9d17e4342598 | 3979 | #endif /* HAVE_ECC_ENCRYPT */ |
wolfSSL | 0:9d17e4342598 | 3980 | |
wolfSSL | 0:9d17e4342598 | 3981 | #endif /* HAVE_ECC */ |