EVP_PKEY & EC_KEY: Make EC EVP_PKEY_CTX parameter ctrls / setters more available
authorRichard Levitte <levitte@openssl.org>
Tue, 1 Dec 2020 18:21:04 +0000 (19:21 +0100)
committerRichard Levitte <levitte@openssl.org>
Wed, 16 Dec 2020 10:56:38 +0000 (11:56 +0100)
EVP_PKEY_CTX_set_ec_ functions were only available when EC was enabled
('no-ec' not configured).  However, that makes it impossible to use
these functions with an engine or a provider that happens to implement
EC_KEY.  This change solves that problem by shuffling these functions
to more appropriate places.

Partially fixes #13550

squash! EVP_PKEY & EC_KEY: Make EC EVP_PKEY_CTX parameter ctrls / setters more available

By consequence, there are a number of places where we can remove the
check of OPENSSL_NO_EC.  This requires some re-arrangements of
internal tables to translate between numeric identities and names.

Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13589)

crypto/ec/build.info
crypto/ec/ec_curve.c
crypto/evp/build.info
crypto/evp/ec_ctrl.c [moved from crypto/ec/ec_ctrl.c with 99% similarity]
crypto/evp/ec_support.c [new file with mode: 0644]
crypto/evp/p_lib.c
crypto/evp/pmeth_lib.c
include/crypto/ec.h
include/openssl/ec.h

index 63512565bac99e384e03fcc25dc90aeeab84f845..fff3ab1e1cdaea98b7abae473f0bad1f1ab68b02 100644 (file)
@@ -57,7 +57,7 @@ IF[{- !$disabled{'ec_nistp_64_gcc_128'} -}]
 ENDIF
 
 SOURCE[../../libcrypto]=$COMMON ec_ameth.c ec_pmeth.c ecx_meth.c ecx_key.c \
-                        ec_err.c eck_prn.c ec_ctrl.c
+                        ec_err.c eck_prn.c
 SOURCE[../../providers/libfips.a]=$COMMON
 
 # Implementations are now spread across several libraries, so the defines
index 051d3fe18165e55e644e04122f0403195d567b80..2fedaf04905779d4401e39accf0875d2950ffd84 100644 (file)
@@ -21,7 +21,6 @@
 #include <openssl/objects.h>
 #include <openssl/opensslconf.h>
 #include "internal/nelem.h"
-#include "e_os.h" /* strcasecmp required by windows */
 
 typedef struct {
     int field_type,             /* either NID_X9_62_prime_field or
@@ -2818,7 +2817,6 @@ static const struct {
 #endif /* OPENSSL_NO_SM2 */
 
 typedef struct _ec_list_element_st {
-    const char *name;
     int nid;
     const EC_CURVE_DATA *data;
     const EC_METHOD *(*meth) (void);
@@ -2829,7 +2827,7 @@ typedef struct _ec_list_element_st {
 static const ec_list_element curve_list[] = {
     /* prime field curves */
     /* secg curves */
-    {"secp224r1", NID_secp224r1, &_EC_NIST_PRIME_224.h,
+    {NID_secp224r1, &_EC_NIST_PRIME_224.h,
 # if !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
      EC_GFp_nistp224_method,
 # else
@@ -2837,7 +2835,7 @@ static const ec_list_element curve_list[] = {
 # endif
      "NIST/SECG curve over a 224 bit prime field"},
     /* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */
-    {"secp384r1", NID_secp384r1, &_EC_NIST_PRIME_384.h,
+    {NID_secp384r1, &_EC_NIST_PRIME_384.h,
 # if defined(S390X_EC_ASM)
      EC_GFp_s390x_nistp384_method,
 # else
@@ -2845,7 +2843,7 @@ static const ec_list_element curve_list[] = {
 # endif
      "NIST/SECG curve over a 384 bit prime field"},
 
-    {"secp521r1", NID_secp521r1, &_EC_NIST_PRIME_521.h,
+    {NID_secp521r1, &_EC_NIST_PRIME_521.h,
 # if defined(S390X_EC_ASM)
      EC_GFp_s390x_nistp521_method,
 # elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
@@ -2856,9 +2854,9 @@ static const ec_list_element curve_list[] = {
      "NIST/SECG curve over a 521 bit prime field"},
 
     /* X9.62 curves */
-    {"prime192v1", NID_X9_62_prime192v1, &_EC_NIST_PRIME_192.h, 0,
+    {NID_X9_62_prime192v1, &_EC_NIST_PRIME_192.h, 0,
      "NIST/X9.62/SECG curve over a 192 bit prime field"},
-    {"prime256v1", NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,
+    {NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,
 # if defined(ECP_NISTZ256_ASM)
      EC_GFp_nistz256_method,
 # elif defined(S390X_EC_ASM)
@@ -2873,25 +2871,25 @@ static const ec_list_element curve_list[] = {
 # ifndef OPENSSL_NO_EC2M
     /* characteristic two field curves */
     /* NIST/SECG curves */
-    {"sect163k1", NID_sect163k1, &_EC_NIST_CHAR2_163K.h, 0,
+    {NID_sect163k1, &_EC_NIST_CHAR2_163K.h, 0,
      "NIST/SECG/WTLS curve over a 163 bit binary field"},
-    {"sect163r2", NID_sect163r2, &_EC_NIST_CHAR2_163B.h, 0,
+    {NID_sect163r2, &_EC_NIST_CHAR2_163B.h, 0,
      "NIST/SECG curve over a 163 bit binary field"},
-    {"sect233k1", NID_sect233k1, &_EC_NIST_CHAR2_233K.h, 0,
+    {NID_sect233k1, &_EC_NIST_CHAR2_233K.h, 0,
      "NIST/SECG/WTLS curve over a 233 bit binary field"},
-    {"sect233r1", NID_sect233r1, &_EC_NIST_CHAR2_233B.h, 0,
+    {NID_sect233r1, &_EC_NIST_CHAR2_233B.h, 0,
      "NIST/SECG/WTLS curve over a 233 bit binary field"},
-    {"sect283k1", NID_sect283k1, &_EC_NIST_CHAR2_283K.h, 0,
+    {NID_sect283k1, &_EC_NIST_CHAR2_283K.h, 0,
      "NIST/SECG curve over a 283 bit binary field"},
-    {"sect283r1", NID_sect283r1, &_EC_NIST_CHAR2_283B.h, 0,
+    {NID_sect283r1, &_EC_NIST_CHAR2_283B.h, 0,
      "NIST/SECG curve over a 283 bit binary field"},
-    {"sect409k1", NID_sect409k1, &_EC_NIST_CHAR2_409K.h, 0,
+    {NID_sect409k1, &_EC_NIST_CHAR2_409K.h, 0,
      "NIST/SECG curve over a 409 bit binary field"},
-    {"sect409r1", NID_sect409r1, &_EC_NIST_CHAR2_409B.h, 0,
+    {NID_sect409r1, &_EC_NIST_CHAR2_409B.h, 0,
      "NIST/SECG curve over a 409 bit binary field"},
-    {"sect571k1", NID_sect571k1, &_EC_NIST_CHAR2_571K.h, 0,
+    {NID_sect571k1, &_EC_NIST_CHAR2_571K.h, 0,
      "NIST/SECG curve over a 571 bit binary field"},
-    {"sect571r1", NID_sect571r1, &_EC_NIST_CHAR2_571B.h, 0,
+    {NID_sect571r1, &_EC_NIST_CHAR2_571B.h, 0,
      "NIST/SECG curve over a 571 bit binary field"},
 # endif
 };
@@ -2901,43 +2899,43 @@ static const ec_list_element curve_list[] = {
 static const ec_list_element curve_list[] = {
     /* prime field curves */
     /* secg curves */
-    {"secp112r1", NID_secp112r1, &_EC_SECG_PRIME_112R1.h, 0,
+    {NID_secp112r1, &_EC_SECG_PRIME_112R1.h, 0,
      "SECG/WTLS curve over a 112 bit prime field"},
-    {"secp112r2", NID_secp112r2, &_EC_SECG_PRIME_112R2.h, 0,
+    {NID_secp112r2, &_EC_SECG_PRIME_112R2.h, 0,
      "SECG curve over a 112 bit prime field"},
-    {"secp128r1", NID_secp128r1, &_EC_SECG_PRIME_128R1.h, 0,
+    {NID_secp128r1, &_EC_SECG_PRIME_128R1.h, 0,
      "SECG curve over a 128 bit prime field"},
-    {"secp128r2", NID_secp128r2, &_EC_SECG_PRIME_128R2.h, 0,
+    {NID_secp128r2, &_EC_SECG_PRIME_128R2.h, 0,
      "SECG curve over a 128 bit prime field"},
-    {"secp160k1", NID_secp160k1, &_EC_SECG_PRIME_160K1.h, 0,
+    {NID_secp160k1, &_EC_SECG_PRIME_160K1.h, 0,
      "SECG curve over a 160 bit prime field"},
-    {"secp160r1", NID_secp160r1, &_EC_SECG_PRIME_160R1.h, 0,
+    {NID_secp160r1, &_EC_SECG_PRIME_160R1.h, 0,
      "SECG curve over a 160 bit prime field"},
-    {"secp160r2", NID_secp160r2, &_EC_SECG_PRIME_160R2.h, 0,
+    {NID_secp160r2, &_EC_SECG_PRIME_160R2.h, 0,
      "SECG/WTLS curve over a 160 bit prime field"},
     /* SECG secp192r1 is the same as X9.62 prime192v1 and hence omitted */
-    {"secp192k1", NID_secp192k1, &_EC_SECG_PRIME_192K1.h, 0,
+    {NID_secp192k1, &_EC_SECG_PRIME_192K1.h, 0,
      "SECG curve over a 192 bit prime field"},
-    {"secp224k1", NID_secp224k1, &_EC_SECG_PRIME_224K1.h, 0,
+    {NID_secp224k1, &_EC_SECG_PRIME_224K1.h, 0,
      "SECG curve over a 224 bit prime field"},
 # ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
-    {"secp224r1", NID_secp224r1, &_EC_NIST_PRIME_224.h, EC_GFp_nistp224_method,
+    {NID_secp224r1, &_EC_NIST_PRIME_224.h, EC_GFp_nistp224_method,
      "NIST/SECG curve over a 224 bit prime field"},
 # else
-    {"secp224r1", NID_secp224r1, &_EC_NIST_PRIME_224.h, 0,
+    {NID_secp224r1, &_EC_NIST_PRIME_224.h, 0,
      "NIST/SECG curve over a 224 bit prime field"},
 # endif
-    {"secp256k1", NID_secp256k1, &_EC_SECG_PRIME_256K1.h, 0,
+    {NID_secp256k1, &_EC_SECG_PRIME_256K1.h, 0,
      "SECG curve over a 256 bit prime field"},
     /* SECG secp256r1 is the same as X9.62 prime256v1 and hence omitted */
-    {"secp384r1", NID_secp384r1, &_EC_NIST_PRIME_384.h,
+    {NID_secp384r1, &_EC_NIST_PRIME_384.h,
 # if defined(S390X_EC_ASM)
      EC_GFp_s390x_nistp384_method,
 # else
      0,
 # endif
      "NIST/SECG curve over a 384 bit prime field"},
-    {"secp521r1", NID_secp521r1, &_EC_NIST_PRIME_521.h,
+    {NID_secp521r1, &_EC_NIST_PRIME_521.h,
 # if defined(S390X_EC_ASM)
      EC_GFp_s390x_nistp521_method,
 # elif !defined(OPENSSL_NO_EC_NISTP_64_GCC_128)
@@ -2947,19 +2945,19 @@ static const ec_list_element curve_list[] = {
 # endif
      "NIST/SECG curve over a 521 bit prime field"},
     /* X9.62 curves */
-    {"prime192v1", NID_X9_62_prime192v1, &_EC_NIST_PRIME_192.h, 0,
+    {NID_X9_62_prime192v1, &_EC_NIST_PRIME_192.h, 0,
      "NIST/X9.62/SECG curve over a 192 bit prime field"},
-    {"prime192v2", NID_X9_62_prime192v2, &_EC_X9_62_PRIME_192V2.h, 0,
+    {NID_X9_62_prime192v2, &_EC_X9_62_PRIME_192V2.h, 0,
      "X9.62 curve over a 192 bit prime field"},
-    {"prime192v3", NID_X9_62_prime192v3, &_EC_X9_62_PRIME_192V3.h, 0,
+    {NID_X9_62_prime192v3, &_EC_X9_62_PRIME_192V3.h, 0,
      "X9.62 curve over a 192 bit prime field"},
-    {"prime239v1", NID_X9_62_prime239v1, &_EC_X9_62_PRIME_239V1.h, 0,
+    {NID_X9_62_prime239v1, &_EC_X9_62_PRIME_239V1.h, 0,
      "X9.62 curve over a 239 bit prime field"},
-    {"prime239v2", NID_X9_62_prime239v2, &_EC_X9_62_PRIME_239V2.h, 0,
+    {NID_X9_62_prime239v2, &_EC_X9_62_PRIME_239V2.h, 0,
      "X9.62 curve over a 239 bit prime field"},
-    {"prime239v3", NID_X9_62_prime239v3, &_EC_X9_62_PRIME_239V3.h, 0,
+    {NID_X9_62_prime239v3, &_EC_X9_62_PRIME_239V3.h, 0,
      "X9.62 curve over a 239 bit prime field"},
-    {"prime256v1", NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,
+    {NID_X9_62_prime256v1, &_EC_X9_62_PRIME_256V1.h,
 # if defined(ECP_NISTZ256_ASM)
      EC_GFp_nistz256_method,
 # elif defined(S390X_EC_ASM)
@@ -2973,144 +2971,144 @@ static const ec_list_element curve_list[] = {
 # ifndef OPENSSL_NO_EC2M
     /* characteristic two field curves */
     /* NIST/SECG curves */
-    {"sect113r1", NID_sect113r1, &_EC_SECG_CHAR2_113R1.h, 0,
+    {NID_sect113r1, &_EC_SECG_CHAR2_113R1.h, 0,
      "SECG curve over a 113 bit binary field"},
-    {"sect113r2", NID_sect113r2, &_EC_SECG_CHAR2_113R2.h, 0,
+    {NID_sect113r2, &_EC_SECG_CHAR2_113R2.h, 0,
      "SECG curve over a 113 bit binary field"},
-    { "sect131r1", NID_sect131r1, &_EC_SECG_CHAR2_131R1.h, 0,
+    {NID_sect131r1, &_EC_SECG_CHAR2_131R1.h, 0,
      "SECG/WTLS curve over a 131 bit binary field"},
-    { "sect131r2", NID_sect131r2, &_EC_SECG_CHAR2_131R2.h, 0,
+    {NID_sect131r2, &_EC_SECG_CHAR2_131R2.h, 0,
      "SECG curve over a 131 bit binary field"},
-    {"sect163k1", NID_sect163k1, &_EC_NIST_CHAR2_163K.h, 0,
+    {NID_sect163k1, &_EC_NIST_CHAR2_163K.h, 0,
      "NIST/SECG/WTLS curve over a 163 bit binary field"},
-    {"sect163r1", NID_sect163r1, &_EC_SECG_CHAR2_163R1.h, 0,
+    {NID_sect163r1, &_EC_SECG_CHAR2_163R1.h, 0,
      "SECG curve over a 163 bit binary field"},
-    {"sect163r2", NID_sect163r2, &_EC_NIST_CHAR2_163B.h, 0,
+    {NID_sect163r2, &_EC_NIST_CHAR2_163B.h, 0,
      "NIST/SECG curve over a 163 bit binary field"},
-    {"sect193r1", NID_sect193r1, &_EC_SECG_CHAR2_193R1.h, 0,
+    {NID_sect193r1, &_EC_SECG_CHAR2_193R1.h, 0,
      "SECG curve over a 193 bit binary field"},
-    {"sect193r2", NID_sect193r2, &_EC_SECG_CHAR2_193R2.h, 0,
+    {NID_sect193r2, &_EC_SECG_CHAR2_193R2.h, 0,
      "SECG curve over a 193 bit binary field"},
-    {"sect233k1", NID_sect233k1, &_EC_NIST_CHAR2_233K.h, 0,
+    {NID_sect233k1, &_EC_NIST_CHAR2_233K.h, 0,
      "NIST/SECG/WTLS curve over a 233 bit binary field"},
-    {"sect233r1", NID_sect233r1, &_EC_NIST_CHAR2_233B.h, 0,
+    {NID_sect233r1, &_EC_NIST_CHAR2_233B.h, 0,
      "NIST/SECG/WTLS curve over a 233 bit binary field"},
-    {"sect239k1", NID_sect239k1, &_EC_SECG_CHAR2_239K1.h, 0,
+    {NID_sect239k1, &_EC_SECG_CHAR2_239K1.h, 0,
      "SECG curve over a 239 bit binary field"},
-    {"sect283k1", NID_sect283k1, &_EC_NIST_CHAR2_283K.h, 0,
+    {NID_sect283k1, &_EC_NIST_CHAR2_283K.h, 0,
      "NIST/SECG curve over a 283 bit binary field"},
-    {"sect283r1", NID_sect283r1, &_EC_NIST_CHAR2_283B.h, 0,
+    {NID_sect283r1, &_EC_NIST_CHAR2_283B.h, 0,
      "NIST/SECG curve over a 283 bit binary field"},
-    {"sect409k1", NID_sect409k1, &_EC_NIST_CHAR2_409K.h, 0,
+    {NID_sect409k1, &_EC_NIST_CHAR2_409K.h, 0,
      "NIST/SECG curve over a 409 bit binary field"},
-    {"sect409r1", NID_sect409r1, &_EC_NIST_CHAR2_409B.h, 0,
+    {NID_sect409r1, &_EC_NIST_CHAR2_409B.h, 0,
      "NIST/SECG curve over a 409 bit binary field"},
-    {"sect571k1", NID_sect571k1, &_EC_NIST_CHAR2_571K.h, 0,
+    {NID_sect571k1, &_EC_NIST_CHAR2_571K.h, 0,
      "NIST/SECG curve over a 571 bit binary field"},
-    {"sect571r1", NID_sect571r1, &_EC_NIST_CHAR2_571B.h, 0,
+    {NID_sect571r1, &_EC_NIST_CHAR2_571B.h, 0,
      "NIST/SECG curve over a 571 bit binary field"},
     /* X9.62 curves */
-    {"c2pnb163v1", NID_X9_62_c2pnb163v1, &_EC_X9_62_CHAR2_163V1.h, 0,
+    {NID_X9_62_c2pnb163v1, &_EC_X9_62_CHAR2_163V1.h, 0,
      "X9.62 curve over a 163 bit binary field"},
-    {"c2pnb163v2", NID_X9_62_c2pnb163v2, &_EC_X9_62_CHAR2_163V2.h, 0,
+    {NID_X9_62_c2pnb163v2, &_EC_X9_62_CHAR2_163V2.h, 0,
      "X9.62 curve over a 163 bit binary field"},
-    {"c2pnb163v3", NID_X9_62_c2pnb163v3, &_EC_X9_62_CHAR2_163V3.h, 0,
+    {NID_X9_62_c2pnb163v3, &_EC_X9_62_CHAR2_163V3.h, 0,
      "X9.62 curve over a 163 bit binary field"},
-    {"c2pnb176v1", NID_X9_62_c2pnb176v1, &_EC_X9_62_CHAR2_176V1.h, 0,
+    {NID_X9_62_c2pnb176v1, &_EC_X9_62_CHAR2_176V1.h, 0,
      "X9.62 curve over a 176 bit binary field"},
-    {"c2tnb191v1", NID_X9_62_c2tnb191v1, &_EC_X9_62_CHAR2_191V1.h, 0,
+    {NID_X9_62_c2tnb191v1, &_EC_X9_62_CHAR2_191V1.h, 0,
      "X9.62 curve over a 191 bit binary field"},
-    {"c2tnb191v2", NID_X9_62_c2tnb191v2, &_EC_X9_62_CHAR2_191V2.h, 0,
+    {NID_X9_62_c2tnb191v2, &_EC_X9_62_CHAR2_191V2.h, 0,
      "X9.62 curve over a 191 bit binary field"},
-    {"c2tnb191v3", NID_X9_62_c2tnb191v3, &_EC_X9_62_CHAR2_191V3.h, 0,
+    {NID_X9_62_c2tnb191v3, &_EC_X9_62_CHAR2_191V3.h, 0,
      "X9.62 curve over a 191 bit binary field"},
-    {"c2pnb208w1", NID_X9_62_c2pnb208w1, &_EC_X9_62_CHAR2_208W1.h, 0,
+    {NID_X9_62_c2pnb208w1, &_EC_X9_62_CHAR2_208W1.h, 0,
      "X9.62 curve over a 208 bit binary field"},
-    {"c2tnb239v1", NID_X9_62_c2tnb239v1, &_EC_X9_62_CHAR2_239V1.h, 0,
+    {NID_X9_62_c2tnb239v1, &_EC_X9_62_CHAR2_239V1.h, 0,
      "X9.62 curve over a 239 bit binary field"},
-    {"c2tnb239v2", NID_X9_62_c2tnb239v2, &_EC_X9_62_CHAR2_239V2.h, 0,
+    {NID_X9_62_c2tnb239v2, &_EC_X9_62_CHAR2_239V2.h, 0,
      "X9.62 curve over a 239 bit binary field"},
-    {"c2tnb239v3", NID_X9_62_c2tnb239v3, &_EC_X9_62_CHAR2_239V3.h, 0,
+    {NID_X9_62_c2tnb239v3, &_EC_X9_62_CHAR2_239V3.h, 0,
      "X9.62 curve over a 239 bit binary field"},
-    {"c2pnb272w1", NID_X9_62_c2pnb272w1, &_EC_X9_62_CHAR2_272W1.h, 0,
+    {NID_X9_62_c2pnb272w1, &_EC_X9_62_CHAR2_272W1.h, 0,
      "X9.62 curve over a 272 bit binary field"},
-    {"c2pnb304w1", NID_X9_62_c2pnb304w1, &_EC_X9_62_CHAR2_304W1.h, 0,
+    {NID_X9_62_c2pnb304w1, &_EC_X9_62_CHAR2_304W1.h, 0,
      "X9.62 curve over a 304 bit binary field"},
-    {"c2tnb359v1", NID_X9_62_c2tnb359v1, &_EC_X9_62_CHAR2_359V1.h, 0,
+    {NID_X9_62_c2tnb359v1, &_EC_X9_62_CHAR2_359V1.h, 0,
      "X9.62 curve over a 359 bit binary field"},
-    {"c2pnb368w1", NID_X9_62_c2pnb368w1, &_EC_X9_62_CHAR2_368W1.h, 0,
+    {NID_X9_62_c2pnb368w1, &_EC_X9_62_CHAR2_368W1.h, 0,
      "X9.62 curve over a 368 bit binary field"},
-    {"c2tnb431r1", NID_X9_62_c2tnb431r1, &_EC_X9_62_CHAR2_431R1.h, 0,
+    {NID_X9_62_c2tnb431r1, &_EC_X9_62_CHAR2_431R1.h, 0,
      "X9.62 curve over a 431 bit binary field"},
     /*
      * the WAP/WTLS curves [unlike SECG, spec has its own OIDs for curves
      * from X9.62]
      */
-    {"wap-wsg-idm-ecid-wtls1", NID_wap_wsg_idm_ecid_wtls1, &_EC_WTLS_1.h, 0,
+    {NID_wap_wsg_idm_ecid_wtls1, &_EC_WTLS_1.h, 0,
      "WTLS curve over a 113 bit binary field"},
-    {"wap-wsg-idm-ecid-wtls3", NID_wap_wsg_idm_ecid_wtls3, &_EC_NIST_CHAR2_163K.h, 0,
+    {NID_wap_wsg_idm_ecid_wtls3, &_EC_NIST_CHAR2_163K.h, 0,
      "NIST/SECG/WTLS curve over a 163 bit binary field"},
-    {"wap-wsg-idm-ecid-wtls4", NID_wap_wsg_idm_ecid_wtls4, &_EC_SECG_CHAR2_113R1.h, 0,
+    {NID_wap_wsg_idm_ecid_wtls4, &_EC_SECG_CHAR2_113R1.h, 0,
      "SECG curve over a 113 bit binary field"},
-    {"wap-wsg-idm-ecid-wtls5", NID_wap_wsg_idm_ecid_wtls5, &_EC_X9_62_CHAR2_163V1.h, 0,
+    {NID_wap_wsg_idm_ecid_wtls5, &_EC_X9_62_CHAR2_163V1.h, 0,
      "X9.62 curve over a 163 bit binary field"},
 # endif
-    {"wap-wsg-idm-ecid-wtls6", NID_wap_wsg_idm_ecid_wtls6, &_EC_SECG_PRIME_112R1.h, 0,
+    {NID_wap_wsg_idm_ecid_wtls6, &_EC_SECG_PRIME_112R1.h, 0,
      "SECG/WTLS curve over a 112 bit prime field"},
-    {"wap-wsg-idm-ecid-wtls7", NID_wap_wsg_idm_ecid_wtls7, &_EC_SECG_PRIME_160R2.h, 0,
+    {NID_wap_wsg_idm_ecid_wtls7, &_EC_SECG_PRIME_160R2.h, 0,
      "SECG/WTLS curve over a 160 bit prime field"},
-    {"wap-wsg-idm-ecid-wtls8", NID_wap_wsg_idm_ecid_wtls8, &_EC_WTLS_8.h, 0,
+    {NID_wap_wsg_idm_ecid_wtls8, &_EC_WTLS_8.h, 0,
      "WTLS curve over a 112 bit prime field"},
-    {"wap-wsg-idm-ecid-wtls9", NID_wap_wsg_idm_ecid_wtls9, &_EC_WTLS_9.h, 0,
+    {NID_wap_wsg_idm_ecid_wtls9, &_EC_WTLS_9.h, 0,
      "WTLS curve over a 160 bit prime field"},
 # ifndef OPENSSL_NO_EC2M
-    {"wap-wsg-idm-ecid-wtls10", NID_wap_wsg_idm_ecid_wtls10, &_EC_NIST_CHAR2_233K.h, 0,
+    {NID_wap_wsg_idm_ecid_wtls10, &_EC_NIST_CHAR2_233K.h, 0,
      "NIST/SECG/WTLS curve over a 233 bit binary field"},
-    {"wap-wsg-idm-ecid-wtls11", NID_wap_wsg_idm_ecid_wtls11, &_EC_NIST_CHAR2_233B.h, 0,
+    {NID_wap_wsg_idm_ecid_wtls11, &_EC_NIST_CHAR2_233B.h, 0,
      "NIST/SECG/WTLS curve over a 233 bit binary field"},
 # endif
-    {"wap-wsg-idm-ecid-wtls12", NID_wap_wsg_idm_ecid_wtls12, &_EC_WTLS_12.h, 0,
+    {NID_wap_wsg_idm_ecid_wtls12, &_EC_WTLS_12.h, 0,
      "WTLS curve over a 224 bit prime field"},
 # ifndef OPENSSL_NO_EC2M
     /* IPSec curves */
-    {"Oakley-EC2N-3", NID_ipsec3, &_EC_IPSEC_155_ID3.h, 0,
+    {NID_ipsec3, &_EC_IPSEC_155_ID3.h, 0,
      "\n\tIPSec/IKE/Oakley curve #3 over a 155 bit binary field.\n"
      "\tNot suitable for ECDSA.\n\tQuestionable extension field!"},
-    {"Oakley-EC2N-4", NID_ipsec4, &_EC_IPSEC_185_ID4.h, 0,
+    {NID_ipsec4, &_EC_IPSEC_185_ID4.h, 0,
      "\n\tIPSec/IKE/Oakley curve #4 over a 185 bit binary field.\n"
      "\tNot suitable for ECDSA.\n\tQuestionable extension field!"},
 # endif
     /* brainpool curves */
-    {"brainpoolP160r1", NID_brainpoolP160r1, &_EC_brainpoolP160r1.h, 0,
+    {NID_brainpoolP160r1, &_EC_brainpoolP160r1.h, 0,
      "RFC 5639 curve over a 160 bit prime field"},
-    {"brainpoolP160t1", NID_brainpoolP160t1, &_EC_brainpoolP160t1.h, 0,
+    {NID_brainpoolP160t1, &_EC_brainpoolP160t1.h, 0,
      "RFC 5639 curve over a 160 bit prime field"},
-    {"brainpoolP192r1", NID_brainpoolP192r1, &_EC_brainpoolP192r1.h, 0,
+    {NID_brainpoolP192r1, &_EC_brainpoolP192r1.h, 0,
      "RFC 5639 curve over a 192 bit prime field"},
-    {"brainpoolP192t1", NID_brainpoolP192t1, &_EC_brainpoolP192t1.h, 0,
+    {NID_brainpoolP192t1, &_EC_brainpoolP192t1.h, 0,
      "RFC 5639 curve over a 192 bit prime field"},
-    {"brainpoolP224r1", NID_brainpoolP224r1, &_EC_brainpoolP224r1.h, 0,
+    {NID_brainpoolP224r1, &_EC_brainpoolP224r1.h, 0,
      "RFC 5639 curve over a 224 bit prime field"},
-    {"brainpoolP224t1", NID_brainpoolP224t1, &_EC_brainpoolP224t1.h, 0,
+    {NID_brainpoolP224t1, &_EC_brainpoolP224t1.h, 0,
      "RFC 5639 curve over a 224 bit prime field"},
-    {"brainpoolP256r1", NID_brainpoolP256r1, &_EC_brainpoolP256r1.h, 0,
+    {NID_brainpoolP256r1, &_EC_brainpoolP256r1.h, 0,
      "RFC 5639 curve over a 256 bit prime field"},
-    {"brainpoolP256t1", NID_brainpoolP256t1, &_EC_brainpoolP256t1.h, 0,
+    {NID_brainpoolP256t1, &_EC_brainpoolP256t1.h, 0,
      "RFC 5639 curve over a 256 bit prime field"},
-    {"brainpoolP320r1", NID_brainpoolP320r1, &_EC_brainpoolP320r1.h, 0,
+    {NID_brainpoolP320r1, &_EC_brainpoolP320r1.h, 0,
      "RFC 5639 curve over a 320 bit prime field"},
-    {"brainpoolP320t1", NID_brainpoolP320t1, &_EC_brainpoolP320t1.h, 0,
+    {NID_brainpoolP320t1, &_EC_brainpoolP320t1.h, 0,
      "RFC 5639 curve over a 320 bit prime field"},
-    {"brainpoolP384r1", NID_brainpoolP384r1, &_EC_brainpoolP384r1.h, 0,
+    {NID_brainpoolP384r1, &_EC_brainpoolP384r1.h, 0,
      "RFC 5639 curve over a 384 bit prime field"},
-    {"brainpoolP384t1", NID_brainpoolP384t1, &_EC_brainpoolP384t1.h, 0,
+    {NID_brainpoolP384t1, &_EC_brainpoolP384t1.h, 0,
      "RFC 5639 curve over a 384 bit prime field"},
-    {"brainpoolP512r1", NID_brainpoolP512r1, &_EC_brainpoolP512r1.h, 0,
+    {NID_brainpoolP512r1, &_EC_brainpoolP512r1.h, 0,
      "RFC 5639 curve over a 512 bit prime field"},
-    {"brainpoolP512t1", NID_brainpoolP512t1, &_EC_brainpoolP512t1.h, 0,
+    {NID_brainpoolP512t1, &_EC_brainpoolP512t1.h, 0,
      "RFC 5639 curve over a 512 bit prime field"},
 # ifndef OPENSSL_NO_SM2
-    {"SM2", NID_sm2, &_EC_sm2p256v1.h, 0,
+    {NID_sm2, &_EC_sm2p256v1.h, 0,
      "SM2 curve over a 256 bit prime field"},
 # endif
 };
@@ -3132,54 +3130,6 @@ static const ec_list_element *ec_curve_nid2curve(int nid)
     return NULL;
 }
 
-static const ec_list_element *ec_curve_name2curve(const char *name)
-{
-    size_t i;
-
-    for (i = 0; i < curve_list_length; i++) {
-        if (strcasecmp(curve_list[i].name, name) == 0)
-            return &curve_list[i];
-    }
-    return NULL;
-}
-
-const char *ec_curve_nid2name(int nid)
-{
-    /*
-     * TODO(3.0) Figure out if we should try to find the nid with
-     * EC_curve_nid2nist() first, i.e. make it a priority to return
-     * NIST names if there is one for the NID.  This is related to
-     * the TODO comment in ec_curve_name2nid().
-     */
-    const ec_list_element *curve = ec_curve_nid2curve(nid);
-
-    if (curve != NULL)
-        return curve->name;
-    return NULL;
-}
-
-int ec_curve_name2nid(const char *name)
-{
-    const ec_list_element *curve = NULL;
-    int nid;
-
-    if ((nid = EC_curve_nist2nid(name)) != NID_undef)
-        return nid;
-
-#ifndef FIPS_MODULE
-    /*
-     * TODO(3.0) Figure out if we can use other names than the NIST names
-     * ("B-163", "K-163" & "P-192") in the FIPS module, or if other names
-     * are allowed as well as long as they lead to the same curve data.
-     * If only the NIST names are allowed in the FIPS module, we should
-     * move '#endif' to just before 'return NID_undef'.
-     */
-#endif
-    if ((curve = ec_curve_name2curve(name)) != NULL)
-        return curve->nid;
-    return NID_undef;
-}
-
 static EC_GROUP *ec_group_new_from_data(OSSL_LIB_CTX *libctx,
                                         const char *propq,
                                         const ec_list_element curve)
@@ -3334,49 +3284,14 @@ size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems)
     return curve_list_length;
 }
 
-/* Functions to translate between common NIST curve names and NIDs */
-
-typedef struct {
-    const char *name;           /* NIST Name of curve */
-    int nid;                    /* Curve NID */
-} EC_NIST_NAME;
-
-static EC_NIST_NAME nist_curves[] = {
-    {"B-163", NID_sect163r2},
-    {"B-233", NID_sect233r1},
-    {"B-283", NID_sect283r1},
-    {"B-409", NID_sect409r1},
-    {"B-571", NID_sect571r1},
-    {"K-163", NID_sect163k1},
-    {"K-233", NID_sect233k1},
-    {"K-283", NID_sect283k1},
-    {"K-409", NID_sect409k1},
-    {"K-571", NID_sect571k1},
-    {"P-192", NID_X9_62_prime192v1},
-    {"P-224", NID_secp224r1},
-    {"P-256", NID_X9_62_prime256v1},
-    {"P-384", NID_secp384r1},
-    {"P-521", NID_secp521r1}
-};
-
 const char *EC_curve_nid2nist(int nid)
 {
-    size_t i;
-    for (i = 0; i < OSSL_NELEM(nist_curves); i++) {
-        if (nist_curves[i].nid == nid)
-            return nist_curves[i].name;
-    }
-    return NULL;
+    return ec_curve_nid2nist_int(nid);
 }
 
 int EC_curve_nist2nid(const char *name)
 {
-    size_t i;
-    for (i = 0; i < OSSL_NELEM(nist_curves); i++) {
-        if (strcmp(nist_curves[i].name, name) == 0)
-            return nist_curves[i].nid;
-    }
-    return NID_undef;
+    return ec_curve_nist2nid_int(name);
 }
 
 #define NUM_BN_FIELDS 6
index 8ee6e70c061b91bbd9772f6163fe049447d86f18..4b3057873fbc57f76068628e16fb8eb2aeb1cf5c 100644 (file)
@@ -2,7 +2,7 @@ LIBS=../../libcrypto
 $COMMON=digest.c evp_enc.c evp_lib.c evp_fetch.c cmeth_lib.c evp_utils.c \
         mac_lib.c mac_meth.c keymgmt_meth.c keymgmt_lib.c kdf_lib.c kdf_meth.c \
         m_sigver.c pmeth_lib.c signature.c p_lib.c pmeth_gn.c exchange.c \
-        pmeth_check.c evp_rand.c asymcipher.c kem.c dh_support.c
+        pmeth_check.c evp_rand.c asymcipher.c kem.c dh_support.c ec_support.c
 
 SOURCE[../../libcrypto]=$COMMON\
         encode.c evp_key.c evp_cnf.c \
@@ -19,7 +19,7 @@ SOURCE[../../libcrypto]=$COMMON\
 
 # Diverse type specific ctrl functions.  They are kinda sorta legacy, kinda
 # sorta not.
-SOURCE[../../libcrypto]=dh_ctrl.c dsa_ctrl.c
+SOURCE[../../libcrypto]=dh_ctrl.c dsa_ctrl.c ec_ctrl.c
 
 IF[{- !$disabled{'deprecated-3.0'} -}]
   SOURCE[../../libcrypto]=p_enc.c p_dec.c
similarity index 99%
rename from crypto/ec/ec_ctrl.c
rename to crypto/evp/ec_ctrl.c
index 1465af2becee03065518b44e47c86bc1f4a385ad..541d8549d49e2c8da375fd9bde468b65df131846 100644 (file)
@@ -9,13 +9,11 @@
 
 #include <string.h>
 
-#include <openssl/err.h>
-#include <openssl/opensslv.h>
-
 #include <openssl/core_names.h>
+#include <openssl/err.h>
+#include <openssl/ec.h>
 #include "crypto/evp.h"
-
-#include "ec_local.h"
+#include "crypto/ec.h"
 
 /*
  * This file is meant to contain functions to provide EVP_PKEY support for EC
diff --git a/crypto/evp/ec_support.c b/crypto/evp/ec_support.c
new file mode 100644 (file)
index 0000000..7afd307
--- /dev/null
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#include <string.h>
+#include <openssl/ec.h>
+#include "crypto/ec.h"
+#include "e_os.h" /* strcasecmp required by windows */
+
+typedef struct ec_name2nid_st {
+    const char *name;
+    int nid;
+} EC_NAME2NID;
+
+static const EC_NAME2NID curve_list[] = {
+    /* prime field curves */
+    /* secg curves */
+    {"secp112r1", NID_secp112r1 },
+    {"secp112r2", NID_secp112r2 },
+    {"secp128r1", NID_secp128r1 },
+    {"secp128r2", NID_secp128r2 },
+    {"secp160k1", NID_secp160k1 },
+    {"secp160r1", NID_secp160r1 },
+    {"secp160r2", NID_secp160r2 },
+    {"secp192k1", NID_secp192k1 },
+    {"secp224k1", NID_secp224k1 },
+    {"secp224r1", NID_secp224r1 },
+    {"secp256k1", NID_secp256k1 },
+    {"secp384r1", NID_secp384r1 },
+    {"secp521r1", NID_secp521r1 },
+    /* X9.62 curves */
+    {"prime192v1", NID_X9_62_prime192v1 },
+    {"prime192v2", NID_X9_62_prime192v2 },
+    {"prime192v3", NID_X9_62_prime192v3 },
+    {"prime239v1", NID_X9_62_prime239v1 },
+    {"prime239v2", NID_X9_62_prime239v2 },
+    {"prime239v3", NID_X9_62_prime239v3 },
+    {"prime256v1", NID_X9_62_prime256v1 },
+    /* characteristic two field curves */
+    /* NIST/SECG curves */
+    {"sect113r1", NID_sect113r1 },
+    {"sect113r2", NID_sect113r2 },
+    {"sect131r1", NID_sect131r1 },
+    {"sect131r2", NID_sect131r2 },
+    {"sect163k1", NID_sect163k1 },
+    {"sect163r1", NID_sect163r1 },
+    {"sect163r2", NID_sect163r2 },
+    {"sect193r1", NID_sect193r1 },
+    {"sect193r2", NID_sect193r2 },
+    {"sect233k1", NID_sect233k1 },
+    {"sect233r1", NID_sect233r1 },
+    {"sect239k1", NID_sect239k1 },
+    {"sect283k1", NID_sect283k1 },
+    {"sect283r1", NID_sect283r1 },
+    {"sect409k1", NID_sect409k1 },
+    {"sect409r1", NID_sect409r1 },
+    {"sect571k1", NID_sect571k1 },
+    {"sect571r1", NID_sect571r1 },
+    /* X9.62 curves */
+    {"c2pnb163v1", NID_X9_62_c2pnb163v1 },
+    {"c2pnb163v2", NID_X9_62_c2pnb163v2 },
+    {"c2pnb163v3", NID_X9_62_c2pnb163v3 },
+    {"c2pnb176v1", NID_X9_62_c2pnb176v1 },
+    {"c2tnb191v1", NID_X9_62_c2tnb191v1 },
+    {"c2tnb191v2", NID_X9_62_c2tnb191v2 },
+    {"c2tnb191v3", NID_X9_62_c2tnb191v3 },
+    {"c2pnb208w1", NID_X9_62_c2pnb208w1 },
+    {"c2tnb239v1", NID_X9_62_c2tnb239v1 },
+    {"c2tnb239v2", NID_X9_62_c2tnb239v2 },
+    {"c2tnb239v3", NID_X9_62_c2tnb239v3 },
+    {"c2pnb272w1", NID_X9_62_c2pnb272w1 },
+    {"c2pnb304w1", NID_X9_62_c2pnb304w1 },
+    {"c2tnb359v1", NID_X9_62_c2tnb359v1 },
+    {"c2pnb368w1", NID_X9_62_c2pnb368w1 },
+    {"c2tnb431r1", NID_X9_62_c2tnb431r1 },
+    /*
+     * the WAP/WTLS curves [unlike SECG, spec has its own OIDs for curves
+     * from X9.62]
+     */
+    {"wap-wsg-idm-ecid-wtls1", NID_wap_wsg_idm_ecid_wtls1 },
+    {"wap-wsg-idm-ecid-wtls3", NID_wap_wsg_idm_ecid_wtls3 },
+    {"wap-wsg-idm-ecid-wtls4", NID_wap_wsg_idm_ecid_wtls4 },
+    {"wap-wsg-idm-ecid-wtls5", NID_wap_wsg_idm_ecid_wtls5 },
+    {"wap-wsg-idm-ecid-wtls6", NID_wap_wsg_idm_ecid_wtls6 },
+    {"wap-wsg-idm-ecid-wtls7", NID_wap_wsg_idm_ecid_wtls7 },
+    {"wap-wsg-idm-ecid-wtls8", NID_wap_wsg_idm_ecid_wtls8 },
+    {"wap-wsg-idm-ecid-wtls9", NID_wap_wsg_idm_ecid_wtls9 },
+    {"wap-wsg-idm-ecid-wtls10", NID_wap_wsg_idm_ecid_wtls10 },
+    {"wap-wsg-idm-ecid-wtls11", NID_wap_wsg_idm_ecid_wtls11 },
+    {"wap-wsg-idm-ecid-wtls12", NID_wap_wsg_idm_ecid_wtls12 },
+    /* IPSec curves */
+    {"Oakley-EC2N-3", NID_ipsec3 },
+    {"Oakley-EC2N-4", NID_ipsec4 },
+    /* brainpool curves */
+    {"brainpoolP160r1", NID_brainpoolP160r1 },
+    {"brainpoolP160t1", NID_brainpoolP160t1 },
+    {"brainpoolP192r1", NID_brainpoolP192r1 },
+    {"brainpoolP192t1", NID_brainpoolP192t1 },
+    {"brainpoolP224r1", NID_brainpoolP224r1 },
+    {"brainpoolP224t1", NID_brainpoolP224t1 },
+    {"brainpoolP256r1", NID_brainpoolP256r1 },
+    {"brainpoolP256t1", NID_brainpoolP256t1 },
+    {"brainpoolP320r1", NID_brainpoolP320r1 },
+    {"brainpoolP320t1", NID_brainpoolP320t1 },
+    {"brainpoolP384r1", NID_brainpoolP384r1 },
+    {"brainpoolP384t1", NID_brainpoolP384t1 },
+    {"brainpoolP512r1", NID_brainpoolP512r1 },
+    {"brainpoolP512t1", NID_brainpoolP512t1 },
+    /* SM2 curve */
+    {"SM2", NID_sm2 },
+};
+
+const char *ec_curve_nid2name(int nid)
+{
+    size_t i;
+
+    if (nid <= 0)
+        return NULL;
+
+    /*
+     * TODO(3.0) Figure out if we should try to find the nid with
+     * EC_curve_nid2nist() first, i.e. make it a priority to return
+     * NIST names if there is one for the NID.  This is related to
+     * the TODO comment in ec_curve_name2nid().
+     */
+
+    for (i = 0; i < OSSL_NELEM(curve_list); i++) {
+        if (curve_list[i].nid == nid)
+            return curve_list[i].name;
+    }
+    return NULL;
+}
+
+int ec_curve_name2nid(const char *name)
+{
+    size_t i;
+    int nid;
+
+    if (name != NULL) {
+        if ((nid = ec_curve_nist2nid_int(name)) != NID_undef)
+            return nid;
+
+        for (i = 0; i < OSSL_NELEM(curve_list); i++) {
+            if (strcasecmp(curve_list[i].name, name) == 0)
+                return curve_list[i].nid;
+        }
+    }
+
+    return NID_undef;
+}
+
+/* Functions to translate between common NIST curve names and NIDs */
+
+static const EC_NAME2NID nist_curves[] = {
+    {"B-163", NID_sect163r2},
+    {"B-233", NID_sect233r1},
+    {"B-283", NID_sect283r1},
+    {"B-409", NID_sect409r1},
+    {"B-571", NID_sect571r1},
+    {"K-163", NID_sect163k1},
+    {"K-233", NID_sect233k1},
+    {"K-283", NID_sect283k1},
+    {"K-409", NID_sect409k1},
+    {"K-571", NID_sect571k1},
+    {"P-192", NID_X9_62_prime192v1},
+    {"P-224", NID_secp224r1},
+    {"P-256", NID_X9_62_prime256v1},
+    {"P-384", NID_secp384r1},
+    {"P-521", NID_secp521r1}
+};
+
+const char *ec_curve_nid2nist_int(int nid)
+{
+    size_t i;
+    for (i = 0; i < OSSL_NELEM(nist_curves); i++) {
+        if (nist_curves[i].nid == nid)
+            return nist_curves[i].name;
+    }
+    return NULL;
+}
+
+int ec_curve_nist2nid_int(const char *name)
+{
+    size_t i;
+    for (i = 0; i < OSSL_NELEM(nist_curves); i++) {
+        if (strcmp(nist_curves[i].name, name) == 0)
+            return nist_curves[i].nid;
+    }
+    return NID_undef;
+}
index 434bd0b61b76b1c4275178e7a12834d451a1f626..326c58c8aa51e7b8f3696dbb13552bba15a917ed 100644 (file)
@@ -35,6 +35,7 @@
 #include "internal/ffc.h"
 #include "crypto/asn1.h"
 #include "crypto/evp.h"
+#include "crypto/ec.h"
 #include "crypto/ecx.h"
 #include "internal/provider.h"
 #include "evp_local.h"
index 58ca1d1d933a9d493d310ac9ee001fc8f450c48a..3823855008494983fae1f4929f8dcd36c5e799fa 100644 (file)
@@ -1278,7 +1278,6 @@ static int legacy_ctrl_to_param(EVP_PKEY_CTX *ctx, int keytype, int optype,
         }
     }
 # endif
-# ifndef OPENSSL_NO_EC
     if (keytype == EVP_PKEY_EC) {
         switch (cmd) {
         case EVP_PKEY_CTRL_EC_PARAM_ENC:
@@ -1314,7 +1313,6 @@ static int legacy_ctrl_to_param(EVP_PKEY_CTX *ctx, int keytype, int optype,
             return EVP_PKEY_CTX_set0_ecdh_kdf_ukm(ctx, p2, p1);
         }
     }
-# endif
     if (keytype == EVP_PKEY_RSA) {
         switch (cmd) {
         case EVP_PKEY_CTRL_RSA_OAEP_MD:
@@ -1572,7 +1570,6 @@ static int legacy_ctrl_str_to_param(EVP_PKEY_CTX *ctx, const char *name,
             ossl_ffc_named_group_get_name(ossl_ffc_uid_to_dh_named_group(num));
     } else if (strcmp(name, "dh_pad") == 0)
         name = OSSL_EXCHANGE_PARAM_PAD;
-# ifndef OPENSSL_NO_EC
     else if (strcmp(name, "ec_paramgen_curve") == 0)
         name = OSSL_PKEY_PARAM_GROUP_NAME;
     else if (strcmp(name, "ecdh_cofactor_mode") == 0)
@@ -1581,7 +1578,6 @@ static int legacy_ctrl_str_to_param(EVP_PKEY_CTX *ctx, const char *name,
         name = OSSL_EXCHANGE_PARAM_KDF_DIGEST;
     else if (strcmp(name, "ec_param_enc") == 0)
         name = OSSL_PKEY_PARAM_EC_ENCODING;
-# endif
     else if (strcmp(name, "N") == 0)
         name = OSSL_KDF_PARAM_SCRYPT_N;
 
index ffd5f1907185abdeb88ae07338279247bcc32f00..451a3751a147422a4dabfbedada7b67eebc13508 100644 (file)
 #ifndef OSSL_CRYPTO_EC_H
 # define OSSL_CRYPTO_EC_H
 # include <openssl/opensslconf.h>
+# include <openssl/evp.h>
+
+const char *ec_curve_nid2name(int nid);
+int ec_curve_name2nid(const char *name);
+const char *ec_curve_nid2nist_int(int nid);
+int ec_curve_nist2nid_int(const char *name);
+int evp_pkey_ctx_set_ec_param_enc_prov(EVP_PKEY_CTX *ctx, int param_enc);
 
 # ifndef OPENSSL_NO_EC
 #  include <openssl/core.h>
@@ -54,8 +61,6 @@ int ec_key_private_check(const EC_KEY *eckey);
 int ec_key_pairwise_check(const EC_KEY *eckey, BN_CTX *ctx);
 OSSL_LIB_CTX *ec_key_get_libctx(const EC_KEY *eckey);
 const char *ec_key_get0_propq(const EC_KEY *eckey);
-const char *ec_curve_nid2name(int nid);
-int ec_curve_name2nid(const char *name);
 
 /* Backend support */
 int ec_group_todata(const EC_GROUP *group, OSSL_PARAM_BLD *tmpl,
@@ -68,7 +73,5 @@ int ec_key_otherparams_fromdata(EC_KEY *ec, const OSSL_PARAM params[]);
 int ec_set_ecdh_cofactor_mode(EC_KEY *ec, int mode);
 int ec_encoding_name2id(const char *name);
 
-int evp_pkey_ctx_set_ec_param_enc_prov(EVP_PKEY_CTX *ctx, int param_enc);
-
 # endif /* OPENSSL_NO_EC */
 #endif
index 2933d7503a1bb04cd106a63fe920408b7f63dc29..1f01c09fb23e94eeea8e01e53c2f967d61075cd9 100644 (file)
 # endif
 
 # include <openssl/opensslconf.h>
+# include <openssl/types.h>
+
+# ifdef  __cplusplus
+extern "C" {
+# endif
+
+/* Values for EVP_PKEY_CTX_set_ec_param_enc() */
+# define OPENSSL_EC_EXPLICIT_CURVE  0x000
+# define OPENSSL_EC_NAMED_CURVE     0x001
+
+int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid);
+int EVP_PKEY_CTX_set_ec_param_enc(EVP_PKEY_CTX *ctx, int param_enc);
+int EVP_PKEY_CTX_set_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx, int cofactor_mode);
+int EVP_PKEY_CTX_get_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx);
+
+int EVP_PKEY_CTX_set_ecdh_kdf_type(EVP_PKEY_CTX *ctx, int kdf);
+int EVP_PKEY_CTX_get_ecdh_kdf_type(EVP_PKEY_CTX *ctx);
+
+int EVP_PKEY_CTX_set_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
+int EVP_PKEY_CTX_get_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD **md);
+
+int EVP_PKEY_CTX_set_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int len);
+int EVP_PKEY_CTX_get_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int *len);
+
+int EVP_PKEY_CTX_set0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char *ukm,
+                                   int len);
+int EVP_PKEY_CTX_get0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char **ukm);
+
+# define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID    (EVP_PKEY_ALG_CTRL + 1)
+# define EVP_PKEY_CTRL_EC_PARAM_ENC             (EVP_PKEY_ALG_CTRL + 2)
+# define EVP_PKEY_CTRL_EC_ECDH_COFACTOR         (EVP_PKEY_ALG_CTRL + 3)
+# define EVP_PKEY_CTRL_EC_KDF_TYPE              (EVP_PKEY_ALG_CTRL + 4)
+# define EVP_PKEY_CTRL_EC_KDF_MD                (EVP_PKEY_ALG_CTRL + 5)
+# define EVP_PKEY_CTRL_GET_EC_KDF_MD            (EVP_PKEY_ALG_CTRL + 6)
+# define EVP_PKEY_CTRL_EC_KDF_OUTLEN            (EVP_PKEY_ALG_CTRL + 7)
+# define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN        (EVP_PKEY_ALG_CTRL + 8)
+# define EVP_PKEY_CTRL_EC_KDF_UKM               (EVP_PKEY_ALG_CTRL + 9)
+# define EVP_PKEY_CTRL_GET_EC_KDF_UKM           (EVP_PKEY_ALG_CTRL + 10)
+
+/* KDF types */
+# define EVP_PKEY_ECDH_KDF_NONE                      1
+# define EVP_PKEY_ECDH_KDF_X9_63                     2
+/*
+ * The old name for EVP_PKEY_ECDH_KDF_X9_63
+ *  The ECDH KDF specification has been mistakenly attributed to ANSI X9.62,
+ *  it is actually specified in ANSI X9.63.
+ *  This identifier is retained for backwards compatibility
+ */
+# define EVP_PKEY_ECDH_KDF_X9_62   EVP_PKEY_ECDH_KDF_X9_63
 
 # ifndef OPENSSL_NO_EC
 #  include <openssl/asn1.h>
@@ -26,9 +75,6 @@
 #   include <openssl/bn.h>
 #  endif
 #  include <openssl/ecerr.h>
-#  ifdef  __cplusplus
-extern "C" {
-#  endif
 
 #  ifndef OPENSSL_ECC_MAX_FIELD_BITS
 #   define OPENSSL_ECC_MAX_FIELD_BITS 661
@@ -847,9 +893,6 @@ int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
                                    unsigned int *k2, unsigned int *k3);
 #  endif
 
-#  define OPENSSL_EC_EXPLICIT_CURVE  0x000
-#  define OPENSSL_EC_NAMED_CURVE     0x001
-
 EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
 int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
 
@@ -1478,47 +1521,8 @@ DEPRECATEDIN_3_0(void EC_KEY_METHOD_get_verify
 #   endif
 #  endif
 
-int EVP_PKEY_CTX_set_ec_paramgen_curve_nid(EVP_PKEY_CTX *ctx, int nid);
-int EVP_PKEY_CTX_set_ec_param_enc(EVP_PKEY_CTX *ctx, int param_enc);
-int EVP_PKEY_CTX_set_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx, int cofactor_mode);
-int EVP_PKEY_CTX_get_ecdh_cofactor_mode(EVP_PKEY_CTX *ctx);
-
-int EVP_PKEY_CTX_set_ecdh_kdf_type(EVP_PKEY_CTX *ctx, int kdf);
-int EVP_PKEY_CTX_get_ecdh_kdf_type(EVP_PKEY_CTX *ctx);
-
-int EVP_PKEY_CTX_set_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
-int EVP_PKEY_CTX_get_ecdh_kdf_md(EVP_PKEY_CTX *ctx, const EVP_MD **md);
-
-int EVP_PKEY_CTX_set_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int len);
-int EVP_PKEY_CTX_get_ecdh_kdf_outlen(EVP_PKEY_CTX *ctx, int *len);
-
-int EVP_PKEY_CTX_set0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char *ukm,
-                                   int len);
-int EVP_PKEY_CTX_get0_ecdh_kdf_ukm(EVP_PKEY_CTX *ctx, unsigned char **ukm);
-
-#  define EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID         (EVP_PKEY_ALG_CTRL + 1)
-#  define EVP_PKEY_CTRL_EC_PARAM_ENC                  (EVP_PKEY_ALG_CTRL + 2)
-#  define EVP_PKEY_CTRL_EC_ECDH_COFACTOR              (EVP_PKEY_ALG_CTRL + 3)
-#  define EVP_PKEY_CTRL_EC_KDF_TYPE                   (EVP_PKEY_ALG_CTRL + 4)
-#  define EVP_PKEY_CTRL_EC_KDF_MD                     (EVP_PKEY_ALG_CTRL + 5)
-#  define EVP_PKEY_CTRL_GET_EC_KDF_MD                 (EVP_PKEY_ALG_CTRL + 6)
-#  define EVP_PKEY_CTRL_EC_KDF_OUTLEN                 (EVP_PKEY_ALG_CTRL + 7)
-#  define EVP_PKEY_CTRL_GET_EC_KDF_OUTLEN             (EVP_PKEY_ALG_CTRL + 8)
-#  define EVP_PKEY_CTRL_EC_KDF_UKM                    (EVP_PKEY_ALG_CTRL + 9)
-#  define EVP_PKEY_CTRL_GET_EC_KDF_UKM                (EVP_PKEY_ALG_CTRL + 10)
-
-/* KDF types */
-#  define EVP_PKEY_ECDH_KDF_NONE                      1
-#  define EVP_PKEY_ECDH_KDF_X9_63                     2
-/** The old name for EVP_PKEY_ECDH_KDF_X9_63
- *  The ECDH KDF specification has been mistakingly attributed to ANSI X9.62,
- *  it is actually specified in ANSI X9.63.
- *  This identifier is retained for backwards compatibility
- */
-#  define EVP_PKEY_ECDH_KDF_X9_62   EVP_PKEY_ECDH_KDF_X9_63
-
-#  ifdef  __cplusplus
+# endif
+# ifdef  __cplusplus
 }
-#  endif
 # endif
 #endif