wolfSSL SSL/TLS library, support up to TLS1.3

Dependents:   CyaSSL-Twitter-OAuth4Tw Example-client-tls-cert TwitterReader TweetTest ... more

Committer:
wolfSSL
Date:
Tue Aug 22 10:48:22 2017 +0000
Revision:
13:f67a6c6013ca
wolfSSL3.12.0 with TLS1.3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 13:f67a6c6013ca 1 /* ecc.h
wolfSSL 13:f67a6c6013ca 2 *
wolfSSL 13:f67a6c6013ca 3 * Copyright (C) 2006-2016 wolfSSL Inc.
wolfSSL 13:f67a6c6013ca 4 *
wolfSSL 13:f67a6c6013ca 5 * This file is part of wolfSSL.
wolfSSL 13:f67a6c6013ca 6 *
wolfSSL 13:f67a6c6013ca 7 * wolfSSL is free software; you can redistribute it and/or modify
wolfSSL 13:f67a6c6013ca 8 * it under the terms of the GNU General Public License as published by
wolfSSL 13:f67a6c6013ca 9 * the Free Software Foundation; either version 2 of the License, or
wolfSSL 13:f67a6c6013ca 10 * (at your option) any later version.
wolfSSL 13:f67a6c6013ca 11 *
wolfSSL 13:f67a6c6013ca 12 * wolfSSL is distributed in the hope that it will be useful,
wolfSSL 13:f67a6c6013ca 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wolfSSL 13:f67a6c6013ca 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wolfSSL 13:f67a6c6013ca 15 * GNU General Public License for more details.
wolfSSL 13:f67a6c6013ca 16 *
wolfSSL 13:f67a6c6013ca 17 * You should have received a copy of the GNU General Public License
wolfSSL 13:f67a6c6013ca 18 * along with this program; if not, write to the Free Software
wolfSSL 13:f67a6c6013ca 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
wolfSSL 13:f67a6c6013ca 20 */
wolfSSL 13:f67a6c6013ca 21
wolfSSL 13:f67a6c6013ca 22
wolfSSL 13:f67a6c6013ca 23 #ifndef WOLF_CRYPT_ECC_H
wolfSSL 13:f67a6c6013ca 24 #define WOLF_CRYPT_ECC_H
wolfSSL 13:f67a6c6013ca 25
wolfSSL 13:f67a6c6013ca 26 #include <wolfssl/wolfcrypt/types.h>
wolfSSL 13:f67a6c6013ca 27
wolfSSL 13:f67a6c6013ca 28 #ifdef HAVE_ECC
wolfSSL 13:f67a6c6013ca 29
wolfSSL 13:f67a6c6013ca 30 #include <wolfssl/wolfcrypt/integer.h>
wolfSSL 13:f67a6c6013ca 31 #include <wolfssl/wolfcrypt/random.h>
wolfSSL 13:f67a6c6013ca 32
wolfSSL 13:f67a6c6013ca 33 #ifdef HAVE_X963_KDF
wolfSSL 13:f67a6c6013ca 34 #include <wolfssl/wolfcrypt/hash.h>
wolfSSL 13:f67a6c6013ca 35 #endif
wolfSSL 13:f67a6c6013ca 36
wolfSSL 13:f67a6c6013ca 37 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 13:f67a6c6013ca 38 #include <wolfssl/wolfcrypt/async.h>
wolfSSL 13:f67a6c6013ca 39 #ifdef WOLFSSL_CERT_GEN
wolfSSL 13:f67a6c6013ca 40 #include <wolfssl/wolfcrypt/asn.h>
wolfSSL 13:f67a6c6013ca 41 #endif
wolfSSL 13:f67a6c6013ca 42 #endif
wolfSSL 13:f67a6c6013ca 43
wolfSSL 13:f67a6c6013ca 44 #ifdef WOLFSSL_ATECC508A
wolfSSL 13:f67a6c6013ca 45 #include <wolfssl/wolfcrypt/port/atmel/atmel.h>
wolfSSL 13:f67a6c6013ca 46 #endif /* WOLFSSL_ATECC508A */
wolfSSL 13:f67a6c6013ca 47
wolfSSL 13:f67a6c6013ca 48
wolfSSL 13:f67a6c6013ca 49 #ifdef __cplusplus
wolfSSL 13:f67a6c6013ca 50 extern "C" {
wolfSSL 13:f67a6c6013ca 51 #endif
wolfSSL 13:f67a6c6013ca 52
wolfSSL 13:f67a6c6013ca 53
wolfSSL 13:f67a6c6013ca 54 /* Enable curve B parameter if needed */
wolfSSL 13:f67a6c6013ca 55 #if defined(HAVE_COMP_KEY) || defined(ECC_CACHE_CURVE)
wolfSSL 13:f67a6c6013ca 56 #ifndef USE_ECC_B_PARAM /* Allow someone to force enable */
wolfSSL 13:f67a6c6013ca 57 #define USE_ECC_B_PARAM
wolfSSL 13:f67a6c6013ca 58 #endif
wolfSSL 13:f67a6c6013ca 59 #endif
wolfSSL 13:f67a6c6013ca 60
wolfSSL 13:f67a6c6013ca 61
wolfSSL 13:f67a6c6013ca 62 /* Use this as the key->idx if a custom ecc_set is used for key->dp */
wolfSSL 13:f67a6c6013ca 63 #define ECC_CUSTOM_IDX (-1)
wolfSSL 13:f67a6c6013ca 64
wolfSSL 13:f67a6c6013ca 65
wolfSSL 13:f67a6c6013ca 66 /* Determine max ECC bits based on enabled curves */
wolfSSL 13:f67a6c6013ca 67 #if defined(HAVE_ECC521) || defined(HAVE_ALL_CURVES)
wolfSSL 13:f67a6c6013ca 68 #define MAX_ECC_BITS 521
wolfSSL 13:f67a6c6013ca 69 #elif defined(HAVE_ECC512)
wolfSSL 13:f67a6c6013ca 70 #define MAX_ECC_BITS 512
wolfSSL 13:f67a6c6013ca 71 #elif defined(HAVE_ECC384)
wolfSSL 13:f67a6c6013ca 72 #define MAX_ECC_BITS 384
wolfSSL 13:f67a6c6013ca 73 #elif defined(HAVE_ECC320)
wolfSSL 13:f67a6c6013ca 74 #define MAX_ECC_BITS 320
wolfSSL 13:f67a6c6013ca 75 #elif defined(HAVE_ECC239)
wolfSSL 13:f67a6c6013ca 76 #define MAX_ECC_BITS 239
wolfSSL 13:f67a6c6013ca 77 #elif defined(HAVE_ECC224)
wolfSSL 13:f67a6c6013ca 78 #define MAX_ECC_BITS 224
wolfSSL 13:f67a6c6013ca 79 #elif !defined(NO_ECC256)
wolfSSL 13:f67a6c6013ca 80 #define MAX_ECC_BITS 256
wolfSSL 13:f67a6c6013ca 81 #elif defined(HAVE_ECC192)
wolfSSL 13:f67a6c6013ca 82 #define MAX_ECC_BITS 192
wolfSSL 13:f67a6c6013ca 83 #elif defined(HAVE_ECC160)
wolfSSL 13:f67a6c6013ca 84 #define MAX_ECC_BITS 160
wolfSSL 13:f67a6c6013ca 85 #elif defined(HAVE_ECC128)
wolfSSL 13:f67a6c6013ca 86 #define MAX_ECC_BITS 128
wolfSSL 13:f67a6c6013ca 87 #elif defined(HAVE_ECC112)
wolfSSL 13:f67a6c6013ca 88 #define MAX_ECC_BITS 112
wolfSSL 13:f67a6c6013ca 89 #endif
wolfSSL 13:f67a6c6013ca 90
wolfSSL 13:f67a6c6013ca 91 /* calculate max ECC bytes */
wolfSSL 13:f67a6c6013ca 92 #if ((MAX_ECC_BITS * 2) % 8) == 0
wolfSSL 13:f67a6c6013ca 93 #define MAX_ECC_BYTES (MAX_ECC_BITS / 8)
wolfSSL 13:f67a6c6013ca 94 #else
wolfSSL 13:f67a6c6013ca 95 /* add byte if not aligned */
wolfSSL 13:f67a6c6013ca 96 #define MAX_ECC_BYTES ((MAX_ECC_BITS / 8) + 1)
wolfSSL 13:f67a6c6013ca 97 #endif
wolfSSL 13:f67a6c6013ca 98
wolfSSL 13:f67a6c6013ca 99
wolfSSL 13:f67a6c6013ca 100 enum {
wolfSSL 13:f67a6c6013ca 101 ECC_PUBLICKEY = 1,
wolfSSL 13:f67a6c6013ca 102 ECC_PRIVATEKEY = 2,
wolfSSL 13:f67a6c6013ca 103 ECC_MAXNAME = 16, /* MAX CURVE NAME LENGTH */
wolfSSL 13:f67a6c6013ca 104 SIG_HEADER_SZ = 6, /* ECC signature header size */
wolfSSL 13:f67a6c6013ca 105 ECC_BUFSIZE = 256, /* for exported keys temp buffer */
wolfSSL 13:f67a6c6013ca 106 ECC_MINSIZE = 20, /* MIN Private Key size */
wolfSSL 13:f67a6c6013ca 107 ECC_MAXSIZE = 66, /* MAX Private Key size */
wolfSSL 13:f67a6c6013ca 108 ECC_MAXSIZE_GEN = 74, /* MAX Buffer size required when generating ECC keys*/
wolfSSL 13:f67a6c6013ca 109 ECC_MAX_PAD_SZ = 4, /* ECC maximum padding size */
wolfSSL 13:f67a6c6013ca 110 ECC_MAX_OID_LEN = 16,
wolfSSL 13:f67a6c6013ca 111 ECC_MAX_SIG_SIZE= ((MAX_ECC_BYTES * 2) + ECC_MAX_PAD_SZ + SIG_HEADER_SZ)
wolfSSL 13:f67a6c6013ca 112 };
wolfSSL 13:f67a6c6013ca 113
wolfSSL 13:f67a6c6013ca 114 /* Curve Types */
wolfSSL 13:f67a6c6013ca 115 typedef enum ecc_curve_id {
wolfSSL 13:f67a6c6013ca 116 ECC_CURVE_INVALID = -1,
wolfSSL 13:f67a6c6013ca 117 ECC_CURVE_DEF = 0, /* NIST or SECP */
wolfSSL 13:f67a6c6013ca 118
wolfSSL 13:f67a6c6013ca 119 /* NIST Prime Curves */
wolfSSL 13:f67a6c6013ca 120 ECC_SECP192R1,
wolfSSL 13:f67a6c6013ca 121 ECC_PRIME192V2,
wolfSSL 13:f67a6c6013ca 122 ECC_PRIME192V3,
wolfSSL 13:f67a6c6013ca 123 ECC_PRIME239V1,
wolfSSL 13:f67a6c6013ca 124 ECC_PRIME239V2,
wolfSSL 13:f67a6c6013ca 125 ECC_PRIME239V3,
wolfSSL 13:f67a6c6013ca 126 ECC_SECP256R1,
wolfSSL 13:f67a6c6013ca 127
wolfSSL 13:f67a6c6013ca 128 /* SECP Curves */
wolfSSL 13:f67a6c6013ca 129 ECC_SECP112R1,
wolfSSL 13:f67a6c6013ca 130 ECC_SECP112R2,
wolfSSL 13:f67a6c6013ca 131 ECC_SECP128R1,
wolfSSL 13:f67a6c6013ca 132 ECC_SECP128R2,
wolfSSL 13:f67a6c6013ca 133 ECC_SECP160R1,
wolfSSL 13:f67a6c6013ca 134 ECC_SECP160R2,
wolfSSL 13:f67a6c6013ca 135 ECC_SECP224R1,
wolfSSL 13:f67a6c6013ca 136 ECC_SECP384R1,
wolfSSL 13:f67a6c6013ca 137 ECC_SECP521R1,
wolfSSL 13:f67a6c6013ca 138
wolfSSL 13:f67a6c6013ca 139 /* Koblitz */
wolfSSL 13:f67a6c6013ca 140 ECC_SECP160K1,
wolfSSL 13:f67a6c6013ca 141 ECC_SECP192K1,
wolfSSL 13:f67a6c6013ca 142 ECC_SECP224K1,
wolfSSL 13:f67a6c6013ca 143 ECC_SECP256K1,
wolfSSL 13:f67a6c6013ca 144
wolfSSL 13:f67a6c6013ca 145 /* Brainpool Curves */
wolfSSL 13:f67a6c6013ca 146 ECC_BRAINPOOLP160R1,
wolfSSL 13:f67a6c6013ca 147 ECC_BRAINPOOLP192R1,
wolfSSL 13:f67a6c6013ca 148 ECC_BRAINPOOLP224R1,
wolfSSL 13:f67a6c6013ca 149 ECC_BRAINPOOLP256R1,
wolfSSL 13:f67a6c6013ca 150 ECC_BRAINPOOLP320R1,
wolfSSL 13:f67a6c6013ca 151 ECC_BRAINPOOLP384R1,
wolfSSL 13:f67a6c6013ca 152 ECC_BRAINPOOLP512R1,
wolfSSL 13:f67a6c6013ca 153
wolfSSL 13:f67a6c6013ca 154 /* Twisted Edwards Curves */
wolfSSL 13:f67a6c6013ca 155 #ifdef HAVE_CURVE25519
wolfSSL 13:f67a6c6013ca 156 ECC_X25519,
wolfSSL 13:f67a6c6013ca 157 #endif
wolfSSL 13:f67a6c6013ca 158 #ifdef HAVE_X448
wolfSSL 13:f67a6c6013ca 159 ECC_X448,
wolfSSL 13:f67a6c6013ca 160 #endif
wolfSSL 13:f67a6c6013ca 161
wolfSSL 13:f67a6c6013ca 162 #ifdef WOLFSSL_CUSTOM_CURVES
wolfSSL 13:f67a6c6013ca 163 ECC_CURVE_CUSTOM,
wolfSSL 13:f67a6c6013ca 164 #endif
wolfSSL 13:f67a6c6013ca 165 } ecc_curve_id;
wolfSSL 13:f67a6c6013ca 166
wolfSSL 13:f67a6c6013ca 167 #ifdef HAVE_OID_ENCODING
wolfSSL 13:f67a6c6013ca 168 typedef word16 ecc_oid_t;
wolfSSL 13:f67a6c6013ca 169 #else
wolfSSL 13:f67a6c6013ca 170 typedef byte ecc_oid_t;
wolfSSL 13:f67a6c6013ca 171 /* OID encoded with ASN scheme:
wolfSSL 13:f67a6c6013ca 172 first element = (oid[0] * 40) + oid[1]
wolfSSL 13:f67a6c6013ca 173 if any element > 127 then MSB 0x80 indicates additional byte */
wolfSSL 13:f67a6c6013ca 174 #endif
wolfSSL 13:f67a6c6013ca 175
wolfSSL 13:f67a6c6013ca 176 /* ECC set type defined a GF(p) curve */
wolfSSL 13:f67a6c6013ca 177 typedef struct ecc_set_type {
wolfSSL 13:f67a6c6013ca 178 int size; /* The size of the curve in octets */
wolfSSL 13:f67a6c6013ca 179 int id; /* id of this curve */
wolfSSL 13:f67a6c6013ca 180 const char* name; /* name of this curve */
wolfSSL 13:f67a6c6013ca 181 const char* prime; /* prime that defines the field, curve is in (hex) */
wolfSSL 13:f67a6c6013ca 182 const char* Af; /* fields A param (hex) */
wolfSSL 13:f67a6c6013ca 183 const char* Bf; /* fields B param (hex) */
wolfSSL 13:f67a6c6013ca 184 const char* order; /* order of the curve (hex) */
wolfSSL 13:f67a6c6013ca 185 const char* Gx; /* x coordinate of the base point on curve (hex) */
wolfSSL 13:f67a6c6013ca 186 const char* Gy; /* y coordinate of the base point on curve (hex) */
wolfSSL 13:f67a6c6013ca 187 const ecc_oid_t* oid;
wolfSSL 13:f67a6c6013ca 188 word32 oidSz;
wolfSSL 13:f67a6c6013ca 189 word32 oidSum; /* sum of encoded OID bytes */
wolfSSL 13:f67a6c6013ca 190 int cofactor;
wolfSSL 13:f67a6c6013ca 191 } ecc_set_type;
wolfSSL 13:f67a6c6013ca 192
wolfSSL 13:f67a6c6013ca 193
wolfSSL 13:f67a6c6013ca 194 #ifdef ALT_ECC_SIZE
wolfSSL 13:f67a6c6013ca 195
wolfSSL 13:f67a6c6013ca 196 /* Note on ALT_ECC_SIZE:
wolfSSL 13:f67a6c6013ca 197 * The fast math code uses an array of a fixed size to store the big integers.
wolfSSL 13:f67a6c6013ca 198 * By default, the array is big enough for RSA keys. There is a size,
wolfSSL 13:f67a6c6013ca 199 * FP_MAX_BITS which can be used to make the array smaller when one wants ECC
wolfSSL 13:f67a6c6013ca 200 * but not RSA. Some people want fast math sized for both RSA and ECC, where
wolfSSL 13:f67a6c6013ca 201 * ECC won't use as much as RSA. The flag ALT_ECC_SIZE switches in an alternate
wolfSSL 13:f67a6c6013ca 202 * ecc_point structure that uses an alternate fp_int that has a shorter array
wolfSSL 13:f67a6c6013ca 203 * of fp_digits.
wolfSSL 13:f67a6c6013ca 204 *
wolfSSL 13:f67a6c6013ca 205 * Now, without ALT_ECC_SIZE, the ecc_point has three single item arrays of
wolfSSL 13:f67a6c6013ca 206 * mp_ints for the components of the point. With ALT_ECC_SIZE, the components
wolfSSL 13:f67a6c6013ca 207 * of the point are pointers that are set to each of a three item array of
wolfSSL 13:f67a6c6013ca 208 * alt_fp_ints. While an mp_int will have 4096 bits of digit inside the
wolfSSL 13:f67a6c6013ca 209 * structure, the alt_fp_int will only have 528 bits. A size value was added
wolfSSL 13:f67a6c6013ca 210 * in the ALT case, as well, and is set by mp_init() and alt_fp_init(). The
wolfSSL 13:f67a6c6013ca 211 * functions fp_zero() and fp_copy() use the size parameter. An int needs to
wolfSSL 13:f67a6c6013ca 212 * be initialized before using it instead of just fp_zeroing it, the init will
wolfSSL 13:f67a6c6013ca 213 * call zero. FP_MAX_BITS_ECC defaults to 528, but can be set to change the
wolfSSL 13:f67a6c6013ca 214 * number of bits used in the alternate FP_INT.
wolfSSL 13:f67a6c6013ca 215 *
wolfSSL 13:f67a6c6013ca 216 * Do not enable ALT_ECC_SIZE and disable fast math in the configuration.
wolfSSL 13:f67a6c6013ca 217 */
wolfSSL 13:f67a6c6013ca 218
wolfSSL 13:f67a6c6013ca 219 #ifndef USE_FAST_MATH
wolfSSL 13:f67a6c6013ca 220 #error USE_FAST_MATH must be defined to use ALT_ECC_SIZE
wolfSSL 13:f67a6c6013ca 221 #endif
wolfSSL 13:f67a6c6013ca 222
wolfSSL 13:f67a6c6013ca 223 /* determine max bits required for ECC math */
wolfSSL 13:f67a6c6013ca 224 #ifndef FP_MAX_BITS_ECC
wolfSSL 13:f67a6c6013ca 225 /* check alignment */
wolfSSL 13:f67a6c6013ca 226 #if ((MAX_ECC_BITS * 2) % DIGIT_BIT) == 0
wolfSSL 13:f67a6c6013ca 227 /* max bits is double */
wolfSSL 13:f67a6c6013ca 228 #define FP_MAX_BITS_ECC (MAX_ECC_BITS * 2)
wolfSSL 13:f67a6c6013ca 229 #else
wolfSSL 13:f67a6c6013ca 230 /* max bits is doubled, plus one digit of fudge */
wolfSSL 13:f67a6c6013ca 231 #define FP_MAX_BITS_ECC ((MAX_ECC_BITS * 2) + DIGIT_BIT)
wolfSSL 13:f67a6c6013ca 232 #endif
wolfSSL 13:f67a6c6013ca 233 #else
wolfSSL 13:f67a6c6013ca 234 /* verify alignment */
wolfSSL 13:f67a6c6013ca 235 #if FP_MAX_BITS_ECC % CHAR_BIT
wolfSSL 13:f67a6c6013ca 236 #error FP_MAX_BITS_ECC must be a multiple of CHAR_BIT
wolfSSL 13:f67a6c6013ca 237 #endif
wolfSSL 13:f67a6c6013ca 238 #endif
wolfSSL 13:f67a6c6013ca 239
wolfSSL 13:f67a6c6013ca 240 /* determine buffer size */
wolfSSL 13:f67a6c6013ca 241 #define FP_SIZE_ECC (FP_MAX_BITS_ECC/DIGIT_BIT)
wolfSSL 13:f67a6c6013ca 242
wolfSSL 13:f67a6c6013ca 243
wolfSSL 13:f67a6c6013ca 244 /* This needs to match the size of the fp_int struct, except the
wolfSSL 13:f67a6c6013ca 245 * fp_digit array will be shorter. */
wolfSSL 13:f67a6c6013ca 246 typedef struct alt_fp_int {
wolfSSL 13:f67a6c6013ca 247 int used, sign, size;
wolfSSL 13:f67a6c6013ca 248 fp_digit dp[FP_SIZE_ECC];
wolfSSL 13:f67a6c6013ca 249 } alt_fp_int;
wolfSSL 13:f67a6c6013ca 250 #endif /* ALT_ECC_SIZE */
wolfSSL 13:f67a6c6013ca 251
wolfSSL 13:f67a6c6013ca 252
wolfSSL 13:f67a6c6013ca 253 /* A point on an ECC curve, stored in Jacbobian format such that (x,y,z) =>
wolfSSL 13:f67a6c6013ca 254 (x/z^2, y/z^3, 1) when interpreted as affine */
wolfSSL 13:f67a6c6013ca 255 typedef struct {
wolfSSL 13:f67a6c6013ca 256 #ifndef ALT_ECC_SIZE
wolfSSL 13:f67a6c6013ca 257 mp_int x[1]; /* The x coordinate */
wolfSSL 13:f67a6c6013ca 258 mp_int y[1]; /* The y coordinate */
wolfSSL 13:f67a6c6013ca 259 mp_int z[1]; /* The z coordinate */
wolfSSL 13:f67a6c6013ca 260 #else
wolfSSL 13:f67a6c6013ca 261 mp_int* x; /* The x coordinate */
wolfSSL 13:f67a6c6013ca 262 mp_int* y; /* The y coordinate */
wolfSSL 13:f67a6c6013ca 263 mp_int* z; /* The z coordinate */
wolfSSL 13:f67a6c6013ca 264 alt_fp_int xyz[3];
wolfSSL 13:f67a6c6013ca 265 #endif
wolfSSL 13:f67a6c6013ca 266 } ecc_point;
wolfSSL 13:f67a6c6013ca 267
wolfSSL 13:f67a6c6013ca 268 /* ECC Flags */
wolfSSL 13:f67a6c6013ca 269 enum {
wolfSSL 13:f67a6c6013ca 270 WC_ECC_FLAG_NONE = 0x00,
wolfSSL 13:f67a6c6013ca 271 #ifdef HAVE_ECC_CDH
wolfSSL 13:f67a6c6013ca 272 WC_ECC_FLAG_COFACTOR = 0x01,
wolfSSL 13:f67a6c6013ca 273 #endif
wolfSSL 13:f67a6c6013ca 274 };
wolfSSL 13:f67a6c6013ca 275
wolfSSL 13:f67a6c6013ca 276 /* An ECC Key */
wolfSSL 13:f67a6c6013ca 277 struct ecc_key {
wolfSSL 13:f67a6c6013ca 278 int type; /* Public or Private */
wolfSSL 13:f67a6c6013ca 279 int idx; /* Index into the ecc_sets[] for the parameters of
wolfSSL 13:f67a6c6013ca 280 this curve if -1, this key is using user supplied
wolfSSL 13:f67a6c6013ca 281 curve in dp */
wolfSSL 13:f67a6c6013ca 282 int state;
wolfSSL 13:f67a6c6013ca 283 word32 flags;
wolfSSL 13:f67a6c6013ca 284 const ecc_set_type* dp; /* domain parameters, either points to NIST
wolfSSL 13:f67a6c6013ca 285 curves (idx >= 0) or user supplied */
wolfSSL 13:f67a6c6013ca 286 void* heap; /* heap hint */
wolfSSL 13:f67a6c6013ca 287 #ifdef WOLFSSL_ATECC508A
wolfSSL 13:f67a6c6013ca 288 int slot; /* Key Slot Number (-1 unknown) */
wolfSSL 13:f67a6c6013ca 289 byte pubkey[PUB_KEY_SIZE];
wolfSSL 13:f67a6c6013ca 290 #else
wolfSSL 13:f67a6c6013ca 291 ecc_point pubkey; /* public key */
wolfSSL 13:f67a6c6013ca 292 mp_int k; /* private key */
wolfSSL 13:f67a6c6013ca 293 #endif
wolfSSL 13:f67a6c6013ca 294 #ifdef WOLFSSL_ASYNC_CRYPT
wolfSSL 13:f67a6c6013ca 295 mp_int* r; /* sign/verify temps */
wolfSSL 13:f67a6c6013ca 296 mp_int* s;
wolfSSL 13:f67a6c6013ca 297 WC_ASYNC_DEV asyncDev;
wolfSSL 13:f67a6c6013ca 298 #ifdef WOLFSSL_CERT_GEN
wolfSSL 13:f67a6c6013ca 299 CertSignCtx certSignCtx; /* context info for cert sign (MakeSignature) */
wolfSSL 13:f67a6c6013ca 300 #endif
wolfSSL 13:f67a6c6013ca 301 #endif /* WOLFSSL_ASYNC_CRYPT */
wolfSSL 13:f67a6c6013ca 302 };
wolfSSL 13:f67a6c6013ca 303
wolfSSL 13:f67a6c6013ca 304 #ifndef WC_ECCKEY_TYPE_DEFINED
wolfSSL 13:f67a6c6013ca 305 typedef struct ecc_key ecc_key;
wolfSSL 13:f67a6c6013ca 306 #define WC_ECCKEY_TYPE_DEFINED
wolfSSL 13:f67a6c6013ca 307 #endif
wolfSSL 13:f67a6c6013ca 308
wolfSSL 13:f67a6c6013ca 309
wolfSSL 13:f67a6c6013ca 310 /* ECC predefined curve sets */
wolfSSL 13:f67a6c6013ca 311 extern const ecc_set_type ecc_sets[];
wolfSSL 13:f67a6c6013ca 312
wolfSSL 13:f67a6c6013ca 313 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 314 const char* wc_ecc_get_name(int curve_id);
wolfSSL 13:f67a6c6013ca 315
wolfSSL 13:f67a6c6013ca 316 #ifndef WOLFSSL_ATECC508A
wolfSSL 13:f67a6c6013ca 317
wolfSSL 13:f67a6c6013ca 318 #ifdef WOLFSSL_PUBLIC_ECC_ADD_DBL
wolfSSL 13:f67a6c6013ca 319 #define ECC_API WOLFSSL_API
wolfSSL 13:f67a6c6013ca 320 #else
wolfSSL 13:f67a6c6013ca 321 #define ECC_API WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 322 #endif
wolfSSL 13:f67a6c6013ca 323
wolfSSL 13:f67a6c6013ca 324 ECC_API int ecc_map(ecc_point*, mp_int*, mp_digit);
wolfSSL 13:f67a6c6013ca 325 ECC_API int ecc_projective_add_point(ecc_point* P, ecc_point* Q, ecc_point* R,
wolfSSL 13:f67a6c6013ca 326 mp_int* a, mp_int* modulus, mp_digit mp);
wolfSSL 13:f67a6c6013ca 327 ECC_API int ecc_projective_dbl_point(ecc_point* P, ecc_point* R, mp_int* a,
wolfSSL 13:f67a6c6013ca 328 mp_int* modulus, mp_digit mp);
wolfSSL 13:f67a6c6013ca 329
wolfSSL 13:f67a6c6013ca 330 #endif
wolfSSL 13:f67a6c6013ca 331
wolfSSL 13:f67a6c6013ca 332 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 333 int wc_ecc_make_key(WC_RNG* rng, int keysize, ecc_key* key);
wolfSSL 13:f67a6c6013ca 334 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 335 int wc_ecc_make_key_ex(WC_RNG* rng, int keysize, ecc_key* key,
wolfSSL 13:f67a6c6013ca 336 int curve_id);
wolfSSL 13:f67a6c6013ca 337 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 338 int wc_ecc_check_key(ecc_key* key);
wolfSSL 13:f67a6c6013ca 339 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 340 int wc_ecc_is_point(ecc_point* ecp, mp_int* a, mp_int* b, mp_int* prime);
wolfSSL 13:f67a6c6013ca 341
wolfSSL 13:f67a6c6013ca 342 #ifdef HAVE_ECC_DHE
wolfSSL 13:f67a6c6013ca 343 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 344 int wc_ecc_shared_secret(ecc_key* private_key, ecc_key* public_key, byte* out,
wolfSSL 13:f67a6c6013ca 345 word32* outlen);
wolfSSL 13:f67a6c6013ca 346 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 347 int wc_ecc_shared_secret_gen(ecc_key* private_key, ecc_point* point,
wolfSSL 13:f67a6c6013ca 348 byte* out, word32 *outlen);
wolfSSL 13:f67a6c6013ca 349 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 350 int wc_ecc_shared_secret_ex(ecc_key* private_key, ecc_point* point,
wolfSSL 13:f67a6c6013ca 351 byte* out, word32 *outlen);
wolfSSL 13:f67a6c6013ca 352 #define wc_ecc_shared_secret_ssh wc_ecc_shared_secret_ex /* For backwards compat */
wolfSSL 13:f67a6c6013ca 353 #endif /* HAVE_ECC_DHE */
wolfSSL 13:f67a6c6013ca 354
wolfSSL 13:f67a6c6013ca 355 #ifdef HAVE_ECC_SIGN
wolfSSL 13:f67a6c6013ca 356 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 357 int wc_ecc_sign_hash(const byte* in, word32 inlen, byte* out, word32 *outlen,
wolfSSL 13:f67a6c6013ca 358 WC_RNG* rng, ecc_key* key);
wolfSSL 13:f67a6c6013ca 359 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 360 int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng,
wolfSSL 13:f67a6c6013ca 361 ecc_key* key, mp_int *r, mp_int *s);
wolfSSL 13:f67a6c6013ca 362 #endif /* HAVE_ECC_SIGN */
wolfSSL 13:f67a6c6013ca 363
wolfSSL 13:f67a6c6013ca 364 #ifdef HAVE_ECC_VERIFY
wolfSSL 13:f67a6c6013ca 365 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 366 int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash,
wolfSSL 13:f67a6c6013ca 367 word32 hashlen, int* stat, ecc_key* key);
wolfSSL 13:f67a6c6013ca 368 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 369 int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
wolfSSL 13:f67a6c6013ca 370 word32 hashlen, int* stat, ecc_key* key);
wolfSSL 13:f67a6c6013ca 371 #endif /* HAVE_ECC_VERIFY */
wolfSSL 13:f67a6c6013ca 372
wolfSSL 13:f67a6c6013ca 373 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 374 int wc_ecc_init(ecc_key* key);
wolfSSL 13:f67a6c6013ca 375 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 376 int wc_ecc_init_ex(ecc_key* key, void* heap, int devId);
wolfSSL 13:f67a6c6013ca 377 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 378 void wc_ecc_free(ecc_key* key);
wolfSSL 13:f67a6c6013ca 379 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 380 int wc_ecc_set_flags(ecc_key* key, word32 flags);
wolfSSL 13:f67a6c6013ca 381 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 382 void wc_ecc_fp_free(void);
wolfSSL 13:f67a6c6013ca 383
wolfSSL 13:f67a6c6013ca 384 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 385 int wc_ecc_set_curve(ecc_key* key, int keysize, int curve_id);
wolfSSL 13:f67a6c6013ca 386
wolfSSL 13:f67a6c6013ca 387 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 388 int wc_ecc_is_valid_idx(int n);
wolfSSL 13:f67a6c6013ca 389 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 390 int wc_ecc_get_curve_idx(int curve_id);
wolfSSL 13:f67a6c6013ca 391 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 392 int wc_ecc_get_curve_id(int curve_idx);
wolfSSL 13:f67a6c6013ca 393 #define wc_ecc_get_curve_name_from_id wc_ecc_get_name
wolfSSL 13:f67a6c6013ca 394 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 395 int wc_ecc_get_curve_size_from_id(int curve_id);
wolfSSL 13:f67a6c6013ca 396
wolfSSL 13:f67a6c6013ca 397 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 398 int wc_ecc_get_curve_idx_from_name(const char* curveName);
wolfSSL 13:f67a6c6013ca 399 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 400 int wc_ecc_get_curve_size_from_name(const char* curveName);
wolfSSL 13:f67a6c6013ca 401 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 402 int wc_ecc_get_curve_id_from_name(const char* curveName);
wolfSSL 13:f67a6c6013ca 403 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 404 int wc_ecc_get_curve_id_from_params(int fieldSize,
wolfSSL 13:f67a6c6013ca 405 const byte* prime, word32 primeSz, const byte* Af, word32 AfSz,
wolfSSL 13:f67a6c6013ca 406 const byte* Bf, word32 BfSz, const byte* order, word32 orderSz,
wolfSSL 13:f67a6c6013ca 407 const byte* Gx, word32 GxSz, const byte* Gy, word32 GySz, int cofactor);
wolfSSL 13:f67a6c6013ca 408
wolfSSL 13:f67a6c6013ca 409 #ifndef WOLFSSL_ATECC508A
wolfSSL 13:f67a6c6013ca 410
wolfSSL 13:f67a6c6013ca 411 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 412 ecc_point* wc_ecc_new_point(void);
wolfSSL 13:f67a6c6013ca 413 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 414 ecc_point* wc_ecc_new_point_h(void* h);
wolfSSL 13:f67a6c6013ca 415 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 416 void wc_ecc_del_point(ecc_point* p);
wolfSSL 13:f67a6c6013ca 417 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 418 void wc_ecc_del_point_h(ecc_point* p, void* h);
wolfSSL 13:f67a6c6013ca 419 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 420 int wc_ecc_copy_point(ecc_point* p, ecc_point *r);
wolfSSL 13:f67a6c6013ca 421 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 422 int wc_ecc_cmp_point(ecc_point* a, ecc_point *b);
wolfSSL 13:f67a6c6013ca 423 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 424 int wc_ecc_point_is_at_infinity(ecc_point *p);
wolfSSL 13:f67a6c6013ca 425 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 426 int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R,
wolfSSL 13:f67a6c6013ca 427 mp_int* a, mp_int* modulus, int map);
wolfSSL 13:f67a6c6013ca 428 WOLFSSL_LOCAL
wolfSSL 13:f67a6c6013ca 429 int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R,
wolfSSL 13:f67a6c6013ca 430 mp_int* a, mp_int* modulus, int map, void* heap);
wolfSSL 13:f67a6c6013ca 431 #endif /* !WOLFSSL_ATECC508A */
wolfSSL 13:f67a6c6013ca 432
wolfSSL 13:f67a6c6013ca 433
wolfSSL 13:f67a6c6013ca 434 #ifdef HAVE_ECC_KEY_EXPORT
wolfSSL 13:f67a6c6013ca 435 /* ASN key helpers */
wolfSSL 13:f67a6c6013ca 436 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 437 int wc_ecc_export_x963(ecc_key*, byte* out, word32* outLen);
wolfSSL 13:f67a6c6013ca 438 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 439 int wc_ecc_export_x963_ex(ecc_key*, byte* out, word32* outLen, int compressed);
wolfSSL 13:f67a6c6013ca 440 /* extended functionality with compressed option */
wolfSSL 13:f67a6c6013ca 441 #endif /* HAVE_ECC_KEY_EXPORT */
wolfSSL 13:f67a6c6013ca 442
wolfSSL 13:f67a6c6013ca 443 #ifdef HAVE_ECC_KEY_IMPORT
wolfSSL 13:f67a6c6013ca 444 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 445 int wc_ecc_import_x963(const byte* in, word32 inLen, ecc_key* key);
wolfSSL 13:f67a6c6013ca 446 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 447 int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
wolfSSL 13:f67a6c6013ca 448 int curve_id);
wolfSSL 13:f67a6c6013ca 449 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 450 int wc_ecc_import_private_key(const byte* priv, word32 privSz, const byte* pub,
wolfSSL 13:f67a6c6013ca 451 word32 pubSz, ecc_key* key);
wolfSSL 13:f67a6c6013ca 452 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 453 int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
wolfSSL 13:f67a6c6013ca 454 const byte* pub, word32 pubSz, ecc_key* key, int curve_id);
wolfSSL 13:f67a6c6013ca 455 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 456 int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen);
wolfSSL 13:f67a6c6013ca 457 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 458 int wc_ecc_sig_to_rs(const byte* sig, word32 sigLen, byte* r, word32* rLen,
wolfSSL 13:f67a6c6013ca 459 byte* s, word32* sLen);
wolfSSL 13:f67a6c6013ca 460 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 461 int wc_ecc_import_raw(ecc_key* key, const char* qx, const char* qy,
wolfSSL 13:f67a6c6013ca 462 const char* d, const char* curveName);
wolfSSL 13:f67a6c6013ca 463 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 464 int wc_ecc_import_raw_ex(ecc_key* key, const char* qx, const char* qy,
wolfSSL 13:f67a6c6013ca 465 const char* d, int curve_id);
wolfSSL 13:f67a6c6013ca 466 #endif /* HAVE_ECC_KEY_IMPORT */
wolfSSL 13:f67a6c6013ca 467
wolfSSL 13:f67a6c6013ca 468 #ifdef HAVE_ECC_KEY_EXPORT
wolfSSL 13:f67a6c6013ca 469 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 470 int wc_ecc_export_private_only(ecc_key* key, byte* out, word32* outLen);
wolfSSL 13:f67a6c6013ca 471 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 472 int wc_ecc_export_public_raw(ecc_key* key, byte* qx, word32* qxLen,
wolfSSL 13:f67a6c6013ca 473 byte* qy, word32* qyLen);
wolfSSL 13:f67a6c6013ca 474 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 475 int wc_ecc_export_private_raw(ecc_key* key, byte* qx, word32* qxLen,
wolfSSL 13:f67a6c6013ca 476 byte* qy, word32* qyLen, byte* d, word32* dLen);
wolfSSL 13:f67a6c6013ca 477 #endif /* HAVE_ECC_KEY_EXPORT */
wolfSSL 13:f67a6c6013ca 478
wolfSSL 13:f67a6c6013ca 479 #ifdef HAVE_ECC_KEY_EXPORT
wolfSSL 13:f67a6c6013ca 480
wolfSSL 13:f67a6c6013ca 481 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 482 int wc_ecc_export_point_der(const int curve_idx, ecc_point* point,
wolfSSL 13:f67a6c6013ca 483 byte* out, word32* outLen);
wolfSSL 13:f67a6c6013ca 484 #endif /* HAVE_ECC_KEY_EXPORT */
wolfSSL 13:f67a6c6013ca 485
wolfSSL 13:f67a6c6013ca 486
wolfSSL 13:f67a6c6013ca 487 #ifdef HAVE_ECC_KEY_IMPORT
wolfSSL 13:f67a6c6013ca 488 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 489 int wc_ecc_import_point_der(byte* in, word32 inLen, const int curve_idx,
wolfSSL 13:f67a6c6013ca 490 ecc_point* point);
wolfSSL 13:f67a6c6013ca 491 #endif /* HAVE_ECC_KEY_IMPORT */
wolfSSL 13:f67a6c6013ca 492
wolfSSL 13:f67a6c6013ca 493 /* size helper */
wolfSSL 13:f67a6c6013ca 494 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 495 int wc_ecc_size(ecc_key* key);
wolfSSL 13:f67a6c6013ca 496 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 497 int wc_ecc_sig_size(ecc_key* key);
wolfSSL 13:f67a6c6013ca 498
wolfSSL 13:f67a6c6013ca 499 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 500 int wc_ecc_get_oid(word32 oidSum, const byte** oid, word32* oidSz);
wolfSSL 13:f67a6c6013ca 501
wolfSSL 13:f67a6c6013ca 502 #ifdef WOLFSSL_CUSTOM_CURVES
wolfSSL 13:f67a6c6013ca 503 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 504 int wc_ecc_set_custom_curve(ecc_key* key, const ecc_set_type* dp);
wolfSSL 13:f67a6c6013ca 505 #endif
wolfSSL 13:f67a6c6013ca 506
wolfSSL 13:f67a6c6013ca 507 #ifdef HAVE_ECC_ENCRYPT
wolfSSL 13:f67a6c6013ca 508 /* ecc encrypt */
wolfSSL 13:f67a6c6013ca 509
wolfSSL 13:f67a6c6013ca 510 enum ecEncAlgo {
wolfSSL 13:f67a6c6013ca 511 ecAES_128_CBC = 1, /* default */
wolfSSL 13:f67a6c6013ca 512 ecAES_256_CBC = 2
wolfSSL 13:f67a6c6013ca 513 };
wolfSSL 13:f67a6c6013ca 514
wolfSSL 13:f67a6c6013ca 515 enum ecKdfAlgo {
wolfSSL 13:f67a6c6013ca 516 ecHKDF_SHA256 = 1, /* default */
wolfSSL 13:f67a6c6013ca 517 ecHKDF_SHA1 = 2
wolfSSL 13:f67a6c6013ca 518 };
wolfSSL 13:f67a6c6013ca 519
wolfSSL 13:f67a6c6013ca 520 enum ecMacAlgo {
wolfSSL 13:f67a6c6013ca 521 ecHMAC_SHA256 = 1, /* default */
wolfSSL 13:f67a6c6013ca 522 ecHMAC_SHA1 = 2
wolfSSL 13:f67a6c6013ca 523 };
wolfSSL 13:f67a6c6013ca 524
wolfSSL 13:f67a6c6013ca 525 enum {
wolfSSL 13:f67a6c6013ca 526 KEY_SIZE_128 = 16,
wolfSSL 13:f67a6c6013ca 527 KEY_SIZE_256 = 32,
wolfSSL 13:f67a6c6013ca 528 IV_SIZE_64 = 8,
wolfSSL 13:f67a6c6013ca 529 IV_SIZE_128 = 16,
wolfSSL 13:f67a6c6013ca 530 EXCHANGE_SALT_SZ = 16,
wolfSSL 13:f67a6c6013ca 531 EXCHANGE_INFO_SZ = 23
wolfSSL 13:f67a6c6013ca 532 };
wolfSSL 13:f67a6c6013ca 533
wolfSSL 13:f67a6c6013ca 534 enum ecFlags {
wolfSSL 13:f67a6c6013ca 535 REQ_RESP_CLIENT = 1,
wolfSSL 13:f67a6c6013ca 536 REQ_RESP_SERVER = 2
wolfSSL 13:f67a6c6013ca 537 };
wolfSSL 13:f67a6c6013ca 538
wolfSSL 13:f67a6c6013ca 539
wolfSSL 13:f67a6c6013ca 540 typedef struct ecEncCtx ecEncCtx;
wolfSSL 13:f67a6c6013ca 541
wolfSSL 13:f67a6c6013ca 542 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 543 ecEncCtx* wc_ecc_ctx_new(int flags, WC_RNG* rng);
wolfSSL 13:f67a6c6013ca 544 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 545 ecEncCtx* wc_ecc_ctx_new_ex(int flags, WC_RNG* rng, void* heap);
wolfSSL 13:f67a6c6013ca 546 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 547 void wc_ecc_ctx_free(ecEncCtx*);
wolfSSL 13:f67a6c6013ca 548 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 549 int wc_ecc_ctx_reset(ecEncCtx*, WC_RNG*); /* reset for use again w/o alloc/free */
wolfSSL 13:f67a6c6013ca 550
wolfSSL 13:f67a6c6013ca 551 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 552 const byte* wc_ecc_ctx_get_own_salt(ecEncCtx*);
wolfSSL 13:f67a6c6013ca 553 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 554 int wc_ecc_ctx_set_peer_salt(ecEncCtx*, const byte* salt);
wolfSSL 13:f67a6c6013ca 555 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 556 int wc_ecc_ctx_set_info(ecEncCtx*, const byte* info, int sz);
wolfSSL 13:f67a6c6013ca 557
wolfSSL 13:f67a6c6013ca 558 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 559 int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
wolfSSL 13:f67a6c6013ca 560 word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx);
wolfSSL 13:f67a6c6013ca 561 WOLFSSL_API
wolfSSL 13:f67a6c6013ca 562 int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
wolfSSL 13:f67a6c6013ca 563 word32 msgSz, byte* out, word32* outSz, ecEncCtx* ctx);
wolfSSL 13:f67a6c6013ca 564
wolfSSL 13:f67a6c6013ca 565 #endif /* HAVE_ECC_ENCRYPT */
wolfSSL 13:f67a6c6013ca 566
wolfSSL 13:f67a6c6013ca 567 #ifdef HAVE_X963_KDF
wolfSSL 13:f67a6c6013ca 568 WOLFSSL_API int wc_X963_KDF(enum wc_HashType type, const byte* secret,
wolfSSL 13:f67a6c6013ca 569 word32 secretSz, const byte* sinfo, word32 sinfoSz,
wolfSSL 13:f67a6c6013ca 570 byte* out, word32 outSz);
wolfSSL 13:f67a6c6013ca 571 #endif
wolfSSL 13:f67a6c6013ca 572
wolfSSL 13:f67a6c6013ca 573 #ifdef ECC_CACHE_CURVE
wolfSSL 13:f67a6c6013ca 574 WOLFSSL_API int wc_ecc_curve_cache_init(void);
wolfSSL 13:f67a6c6013ca 575 WOLFSSL_API void wc_ecc_curve_cache_free(void);
wolfSSL 13:f67a6c6013ca 576 #endif
wolfSSL 13:f67a6c6013ca 577
wolfSSL 13:f67a6c6013ca 578
wolfSSL 13:f67a6c6013ca 579 #ifdef __cplusplus
wolfSSL 13:f67a6c6013ca 580 } /* extern "C" */
wolfSSL 13:f67a6c6013ca 581 #endif
wolfSSL 13:f67a6c6013ca 582
wolfSSL 13:f67a6c6013ca 583 #endif /* HAVE_ECC */
wolfSSL 13:f67a6c6013ca 584 #endif /* WOLF_CRYPT_ECC_H */
wolfSSL 13:f67a6c6013ca 585