wolfSSL 3.11.1 for TLS1.3 beta
Fork of wolfSSL by
wolfssl/openssl/ec.h@13:80fb167dafdf, 2017-05-30 (annotated)
- Committer:
- wolfSSL
- Date:
- Tue May 30 06:16:19 2017 +0000
- Revision:
- 13:80fb167dafdf
- Parent:
- 11:cee25a834751
wolfSSL 3.11.1: TLS1.3 Beta
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wolfSSL | 11:cee25a834751 | 1 | /* ec.h for openssl */ |
wolfSSL | 11:cee25a834751 | 2 | |
wolfSSL | 11:cee25a834751 | 3 | #ifndef WOLFSSL_EC_H_ |
wolfSSL | 11:cee25a834751 | 4 | #define WOLFSSL_EC_H_ |
wolfSSL | 11:cee25a834751 | 5 | |
wolfSSL | 11:cee25a834751 | 6 | #include <wolfssl/openssl/bn.h> |
wolfSSL | 11:cee25a834751 | 7 | #include <wolfssl/wolfcrypt/ecc.h> |
wolfSSL | 11:cee25a834751 | 8 | |
wolfSSL | 11:cee25a834751 | 9 | #ifdef __cplusplus |
wolfSSL | 11:cee25a834751 | 10 | extern "C" { |
wolfSSL | 11:cee25a834751 | 11 | #endif |
wolfSSL | 11:cee25a834751 | 12 | |
wolfSSL | 11:cee25a834751 | 13 | /* Map OpenSSL NID value */ |
wolfSSL | 11:cee25a834751 | 14 | enum { |
wolfSSL | 11:cee25a834751 | 15 | POINT_CONVERSION_UNCOMPRESSED = 4, |
wolfSSL | 11:cee25a834751 | 16 | |
wolfSSL | 11:cee25a834751 | 17 | #ifdef HAVE_ECC |
wolfSSL | 11:cee25a834751 | 18 | /* Use ecc_curve_type enum values for NID */ |
wolfSSL | 11:cee25a834751 | 19 | NID_X9_62_prime192v1 = ECC_SECP192R1, |
wolfSSL | 11:cee25a834751 | 20 | NID_X9_62_prime256v1 = ECC_SECP256R1, |
wolfSSL | 11:cee25a834751 | 21 | NID_secp112r1 = ECC_SECP112R1, |
wolfSSL | 11:cee25a834751 | 22 | NID_secp112r2 = ECC_SECP112R2, |
wolfSSL | 11:cee25a834751 | 23 | NID_secp128r1 = ECC_SECP128R1, |
wolfSSL | 11:cee25a834751 | 24 | NID_secp128r2 = ECC_SECP128R2, |
wolfSSL | 11:cee25a834751 | 25 | NID_secp160r1 = ECC_SECP160R1, |
wolfSSL | 11:cee25a834751 | 26 | NID_secp160r2 = ECC_SECP160R2, |
wolfSSL | 11:cee25a834751 | 27 | NID_secp224r1 = ECC_SECP224R1, |
wolfSSL | 11:cee25a834751 | 28 | NID_secp384r1 = ECC_SECP384R1, |
wolfSSL | 11:cee25a834751 | 29 | NID_secp521r1 = ECC_SECP521R1, |
wolfSSL | 11:cee25a834751 | 30 | NID_secp160k1 = ECC_SECP160K1, |
wolfSSL | 11:cee25a834751 | 31 | NID_secp192k1 = ECC_SECP192K1, |
wolfSSL | 11:cee25a834751 | 32 | NID_secp224k1 = ECC_SECP224K1, |
wolfSSL | 11:cee25a834751 | 33 | NID_secp256k1 = ECC_SECP256K1, |
wolfSSL | 11:cee25a834751 | 34 | NID_brainpoolP160r1 = ECC_BRAINPOOLP160R1, |
wolfSSL | 11:cee25a834751 | 35 | NID_brainpoolP192r1 = ECC_BRAINPOOLP192R1, |
wolfSSL | 11:cee25a834751 | 36 | NID_brainpoolP224r1 = ECC_BRAINPOOLP224R1, |
wolfSSL | 11:cee25a834751 | 37 | NID_brainpoolP256r1 = ECC_BRAINPOOLP256R1, |
wolfSSL | 11:cee25a834751 | 38 | NID_brainpoolP320r1 = ECC_BRAINPOOLP320R1, |
wolfSSL | 11:cee25a834751 | 39 | NID_brainpoolP384r1 = ECC_BRAINPOOLP384R1, |
wolfSSL | 11:cee25a834751 | 40 | NID_brainpoolP512r1 = ECC_BRAINPOOLP512R1, |
wolfSSL | 11:cee25a834751 | 41 | #endif |
wolfSSL | 11:cee25a834751 | 42 | |
wolfSSL | 11:cee25a834751 | 43 | OPENSSL_EC_NAMED_CURVE = 0x001 |
wolfSSL | 11:cee25a834751 | 44 | }; |
wolfSSL | 11:cee25a834751 | 45 | |
wolfSSL | 11:cee25a834751 | 46 | #ifndef WOLFSSL_EC_TYPE_DEFINED /* guard on redeclaration */ |
wolfSSL | 11:cee25a834751 | 47 | typedef struct WOLFSSL_EC_KEY WOLFSSL_EC_KEY; |
wolfSSL | 11:cee25a834751 | 48 | typedef struct WOLFSSL_EC_POINT WOLFSSL_EC_POINT; |
wolfSSL | 11:cee25a834751 | 49 | typedef struct WOLFSSL_EC_GROUP WOLFSSL_EC_GROUP; |
wolfSSL | 11:cee25a834751 | 50 | #define WOLFSSL_EC_TYPE_DEFINED |
wolfSSL | 11:cee25a834751 | 51 | #endif |
wolfSSL | 11:cee25a834751 | 52 | |
wolfSSL | 11:cee25a834751 | 53 | typedef WOLFSSL_EC_KEY EC_KEY; |
wolfSSL | 11:cee25a834751 | 54 | typedef WOLFSSL_EC_GROUP EC_GROUP; |
wolfSSL | 11:cee25a834751 | 55 | typedef WOLFSSL_EC_POINT EC_POINT; |
wolfSSL | 11:cee25a834751 | 56 | |
wolfSSL | 11:cee25a834751 | 57 | struct WOLFSSL_EC_POINT { |
wolfSSL | 11:cee25a834751 | 58 | WOLFSSL_BIGNUM *X; |
wolfSSL | 11:cee25a834751 | 59 | WOLFSSL_BIGNUM *Y; |
wolfSSL | 11:cee25a834751 | 60 | WOLFSSL_BIGNUM *Z; |
wolfSSL | 11:cee25a834751 | 61 | |
wolfSSL | 11:cee25a834751 | 62 | void* internal; /* our ECC point */ |
wolfSSL | 11:cee25a834751 | 63 | char inSet; /* internal set from external ? */ |
wolfSSL | 11:cee25a834751 | 64 | char exSet; /* external set from internal ? */ |
wolfSSL | 11:cee25a834751 | 65 | }; |
wolfSSL | 11:cee25a834751 | 66 | |
wolfSSL | 11:cee25a834751 | 67 | struct WOLFSSL_EC_GROUP { |
wolfSSL | 11:cee25a834751 | 68 | int curve_idx; /* index of curve, used by WolfSSL as reference */ |
wolfSSL | 11:cee25a834751 | 69 | int curve_nid; /* NID of curve, used by OpenSSL/OpenSSH as reference */ |
wolfSSL | 11:cee25a834751 | 70 | int curve_oid; /* OID of curve, used by OpenSSL/OpenSSH as reference */ |
wolfSSL | 11:cee25a834751 | 71 | }; |
wolfSSL | 11:cee25a834751 | 72 | |
wolfSSL | 11:cee25a834751 | 73 | struct WOLFSSL_EC_KEY { |
wolfSSL | 11:cee25a834751 | 74 | WOLFSSL_EC_GROUP *group; |
wolfSSL | 11:cee25a834751 | 75 | WOLFSSL_EC_POINT *pub_key; |
wolfSSL | 11:cee25a834751 | 76 | WOLFSSL_BIGNUM *priv_key; |
wolfSSL | 11:cee25a834751 | 77 | |
wolfSSL | 11:cee25a834751 | 78 | void* internal; /* our ECC Key */ |
wolfSSL | 11:cee25a834751 | 79 | char inSet; /* internal set from external ? */ |
wolfSSL | 11:cee25a834751 | 80 | char exSet; /* external set from internal ? */ |
wolfSSL | 11:cee25a834751 | 81 | }; |
wolfSSL | 11:cee25a834751 | 82 | |
wolfSSL | 11:cee25a834751 | 83 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 84 | int wolfSSL_ECPoint_i2d(const WOLFSSL_EC_GROUP *curve, |
wolfSSL | 11:cee25a834751 | 85 | const WOLFSSL_EC_POINT *p, |
wolfSSL | 11:cee25a834751 | 86 | unsigned char *out, unsigned int *len); |
wolfSSL | 11:cee25a834751 | 87 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 88 | int wolfSSL_ECPoint_d2i(unsigned char *in, unsigned int len, |
wolfSSL | 11:cee25a834751 | 89 | const WOLFSSL_EC_GROUP *curve, WOLFSSL_EC_POINT *p); |
wolfSSL | 11:cee25a834751 | 90 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 91 | int wolfSSL_EC_KEY_LoadDer(WOLFSSL_EC_KEY* key, |
wolfSSL | 11:cee25a834751 | 92 | const unsigned char* der, int derSz); |
wolfSSL | 11:cee25a834751 | 93 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 94 | void wolfSSL_EC_KEY_free(WOLFSSL_EC_KEY *key); |
wolfSSL | 11:cee25a834751 | 95 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 96 | WOLFSSL_EC_POINT *wolfSSL_EC_KEY_get0_public_key(const WOLFSSL_EC_KEY *key); |
wolfSSL | 11:cee25a834751 | 97 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 98 | const WOLFSSL_EC_GROUP *wolfSSL_EC_KEY_get0_group(const WOLFSSL_EC_KEY *key); |
wolfSSL | 11:cee25a834751 | 99 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 100 | int wolfSSL_EC_KEY_set_private_key(WOLFSSL_EC_KEY *key, |
wolfSSL | 11:cee25a834751 | 101 | const WOLFSSL_BIGNUM *priv_key); |
wolfSSL | 11:cee25a834751 | 102 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 103 | WOLFSSL_BIGNUM *wolfSSL_EC_KEY_get0_private_key(const WOLFSSL_EC_KEY *key); |
wolfSSL | 11:cee25a834751 | 104 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 105 | WOLFSSL_EC_KEY *wolfSSL_EC_KEY_new_by_curve_name(int nid); |
wolfSSL | 11:cee25a834751 | 106 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 107 | WOLFSSL_EC_KEY *wolfSSL_EC_KEY_new(void); |
wolfSSL | 11:cee25a834751 | 108 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 109 | int wolfSSL_EC_KEY_set_group(WOLFSSL_EC_KEY *key, WOLFSSL_EC_GROUP *group); |
wolfSSL | 11:cee25a834751 | 110 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 111 | int wolfSSL_EC_KEY_generate_key(WOLFSSL_EC_KEY *key); |
wolfSSL | 11:cee25a834751 | 112 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 113 | void wolfSSL_EC_KEY_set_asn1_flag(WOLFSSL_EC_KEY *key, int asn1_flag); |
wolfSSL | 11:cee25a834751 | 114 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 115 | int wolfSSL_EC_KEY_set_public_key(WOLFSSL_EC_KEY *key, |
wolfSSL | 11:cee25a834751 | 116 | const WOLFSSL_EC_POINT *pub); |
wolfSSL | 11:cee25a834751 | 117 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 118 | void wolfSSL_EC_GROUP_set_asn1_flag(WOLFSSL_EC_GROUP *group, int flag); |
wolfSSL | 11:cee25a834751 | 119 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 120 | WOLFSSL_EC_GROUP *wolfSSL_EC_GROUP_new_by_curve_name(int nid); |
wolfSSL | 11:cee25a834751 | 121 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 122 | int wolfSSL_EC_GROUP_cmp(const WOLFSSL_EC_GROUP *a, const WOLFSSL_EC_GROUP *b, |
wolfSSL | 11:cee25a834751 | 123 | WOLFSSL_BN_CTX *ctx); |
wolfSSL | 11:cee25a834751 | 124 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 125 | int wolfSSL_EC_GROUP_get_curve_name(const WOLFSSL_EC_GROUP *group); |
wolfSSL | 11:cee25a834751 | 126 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 127 | int wolfSSL_EC_GROUP_get_degree(const WOLFSSL_EC_GROUP *group); |
wolfSSL | 11:cee25a834751 | 128 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 129 | int wolfSSL_EC_GROUP_get_order(const WOLFSSL_EC_GROUP *group, |
wolfSSL | 11:cee25a834751 | 130 | WOLFSSL_BIGNUM *order, WOLFSSL_BN_CTX *ctx); |
wolfSSL | 11:cee25a834751 | 131 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 132 | void wolfSSL_EC_GROUP_free(WOLFSSL_EC_GROUP *group); |
wolfSSL | 11:cee25a834751 | 133 | #if defined(DEBUG_WOLFSSL) && !defined(NO_FILESYSTEM) |
wolfSSL | 11:cee25a834751 | 134 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 135 | void wolfssl_EC_POINT_dump(const char *msg, const WOLFSSL_EC_POINT *p); |
wolfSSL | 11:cee25a834751 | 136 | #endif |
wolfSSL | 11:cee25a834751 | 137 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 138 | WOLFSSL_EC_POINT *wolfSSL_EC_POINT_new(const WOLFSSL_EC_GROUP *group); |
wolfSSL | 11:cee25a834751 | 139 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 140 | int wolfSSL_EC_POINT_get_affine_coordinates_GFp(const WOLFSSL_EC_GROUP *group, |
wolfSSL | 11:cee25a834751 | 141 | const WOLFSSL_EC_POINT *p, |
wolfSSL | 11:cee25a834751 | 142 | WOLFSSL_BIGNUM *x, |
wolfSSL | 11:cee25a834751 | 143 | WOLFSSL_BIGNUM *y, |
wolfSSL | 11:cee25a834751 | 144 | WOLFSSL_BN_CTX *ctx); |
wolfSSL | 11:cee25a834751 | 145 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 146 | int wolfSSL_EC_POINT_mul(const WOLFSSL_EC_GROUP *group, WOLFSSL_EC_POINT *r, |
wolfSSL | 11:cee25a834751 | 147 | const WOLFSSL_BIGNUM *n, |
wolfSSL | 11:cee25a834751 | 148 | const WOLFSSL_EC_POINT *q, const WOLFSSL_BIGNUM *m, |
wolfSSL | 11:cee25a834751 | 149 | WOLFSSL_BN_CTX *ctx); |
wolfSSL | 11:cee25a834751 | 150 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 151 | void wolfSSL_EC_POINT_clear_free(WOLFSSL_EC_POINT *point); |
wolfSSL | 11:cee25a834751 | 152 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 153 | int wolfSSL_EC_POINT_cmp(const WOLFSSL_EC_GROUP *group, |
wolfSSL | 11:cee25a834751 | 154 | const WOLFSSL_EC_POINT *a, const WOLFSSL_EC_POINT *b, |
wolfSSL | 11:cee25a834751 | 155 | WOLFSSL_BN_CTX *ctx); |
wolfSSL | 11:cee25a834751 | 156 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 157 | void wolfSSL_EC_POINT_free(WOLFSSL_EC_POINT *point); |
wolfSSL | 11:cee25a834751 | 158 | WOLFSSL_API |
wolfSSL | 11:cee25a834751 | 159 | int wolfSSL_EC_POINT_is_at_infinity(const WOLFSSL_EC_GROUP *group, |
wolfSSL | 11:cee25a834751 | 160 | const WOLFSSL_EC_POINT *a); |
wolfSSL | 11:cee25a834751 | 161 | |
wolfSSL | 11:cee25a834751 | 162 | #define EC_KEY_free wolfSSL_EC_KEY_free |
wolfSSL | 11:cee25a834751 | 163 | #define EC_KEY_get0_public_key wolfSSL_EC_KEY_get0_public_key |
wolfSSL | 11:cee25a834751 | 164 | #define EC_KEY_get0_group wolfSSL_EC_KEY_get0_group |
wolfSSL | 11:cee25a834751 | 165 | #define EC_KEY_set_private_key wolfSSL_EC_KEY_set_private_key |
wolfSSL | 11:cee25a834751 | 166 | #define EC_KEY_get0_private_key wolfSSL_EC_KEY_get0_private_key |
wolfSSL | 11:cee25a834751 | 167 | #define EC_KEY_new_by_curve_name wolfSSL_EC_KEY_new_by_curve_name |
wolfSSL | 11:cee25a834751 | 168 | #define EC_KEY_set_group wolfSSL_EC_KEY_set_group |
wolfSSL | 11:cee25a834751 | 169 | #define EC_KEY_generate_key wolfSSL_EC_KEY_generate_key |
wolfSSL | 11:cee25a834751 | 170 | #define EC_KEY_set_asn1_flag wolfSSL_EC_KEY_set_asn1_flag |
wolfSSL | 11:cee25a834751 | 171 | #define EC_KEY_set_public_key wolfSSL_EC_KEY_set_public_key |
wolfSSL | 11:cee25a834751 | 172 | #define EC_KEY_new wolfSSL_EC_KEY_new |
wolfSSL | 11:cee25a834751 | 173 | |
wolfSSL | 11:cee25a834751 | 174 | #define EC_GROUP_set_asn1_flag wolfSSL_EC_GROUP_set_asn1_flag |
wolfSSL | 11:cee25a834751 | 175 | #define EC_GROUP_new_by_curve_name wolfSSL_EC_GROUP_new_by_curve_name |
wolfSSL | 11:cee25a834751 | 176 | #define EC_GROUP_cmp wolfSSL_EC_GROUP_cmp |
wolfSSL | 11:cee25a834751 | 177 | #define EC_GROUP_get_curve_name wolfSSL_EC_GROUP_get_curve_name |
wolfSSL | 11:cee25a834751 | 178 | #define EC_GROUP_get_degree wolfSSL_EC_GROUP_get_degree |
wolfSSL | 11:cee25a834751 | 179 | #define EC_GROUP_get_order wolfSSL_EC_GROUP_get_order |
wolfSSL | 11:cee25a834751 | 180 | #define EC_GROUP_free wolfSSL_EC_GROUP_free |
wolfSSL | 11:cee25a834751 | 181 | |
wolfSSL | 11:cee25a834751 | 182 | #define EC_POINT_new wolfSSL_EC_POINT_new |
wolfSSL | 11:cee25a834751 | 183 | #define EC_POINT_get_affine_coordinates_GFp \ |
wolfSSL | 11:cee25a834751 | 184 | wolfSSL_EC_POINT_get_affine_coordinates_GFp |
wolfSSL | 11:cee25a834751 | 185 | #define EC_POINT_mul wolfSSL_EC_POINT_mul |
wolfSSL | 11:cee25a834751 | 186 | #define EC_POINT_clear_free wolfSSL_EC_POINT_clear_free |
wolfSSL | 11:cee25a834751 | 187 | #define EC_POINT_cmp wolfSSL_EC_POINT_cmp |
wolfSSL | 11:cee25a834751 | 188 | #define EC_POINT_free wolfSSL_EC_POINT_free |
wolfSSL | 11:cee25a834751 | 189 | #define EC_POINT_is_at_infinity wolfSSL_EC_POINT_is_at_infinity |
wolfSSL | 11:cee25a834751 | 190 | |
wolfSSL | 11:cee25a834751 | 191 | #ifdef __cplusplus |
wolfSSL | 11:cee25a834751 | 192 | } /* extern "C" */ |
wolfSSL | 11:cee25a834751 | 193 | #endif |
wolfSSL | 11:cee25a834751 | 194 | |
wolfSSL | 11:cee25a834751 | 195 | #endif /* header */ |
wolfSSL | 11:cee25a834751 | 196 |