summaryrefslogtreecommitdiffstats
path: root/crypto/ec
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2021-02-17 13:00:34 +1000
committerShane Lontis <shane.lontis@oracle.com>2021-02-22 13:31:31 +1000
commit4718326a46ad460fefc5cc240a8599af4b5993c7 (patch)
treebe4beed6f52122d46ebba91baf9fb59ba586f918 /crypto/ec
parent681618cfc18b4f01f2c07e823308d30f6f47504b (diff)
Add EVP_PKEY_public_check_quick.
Adding the EVP_PKEY_param_check_quick() reminded me that there are also partial checks for public keys as part of SP800-56A for FFC (DH named safe prime groups) and ECC. The code was mainly already there and just needed to be plumbed into the validate methods. Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14206)
Diffstat (limited to 'crypto/ec')
-rw-r--r--crypto/ec/ec_key.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c
index ec0b6bda85..30c524726d 100644
--- a/crypto/ec/ec_key.c
+++ b/crypto/ec/ec_key.c
@@ -442,15 +442,11 @@ err:
}
/*
- * ECC Key validation as specified in SP800-56A R3.
- * Section 5.6.2.3.3 ECC Full Public-Key Validation.
+ * ECC Partial Public-Key Validation as specified in SP800-56A R3
+ * Section 5.6.2.3.4 ECC Partial Public-Key Validation Routine.
*/
-int ec_key_public_check(const EC_KEY *eckey, BN_CTX *ctx)
+int ec_key_public_check_quick(const EC_KEY *eckey, BN_CTX *ctx)
{
- int ret = 0;
- EC_POINT *point = NULL;
- const BIGNUM *order = NULL;
-
if (eckey == NULL || eckey->group == NULL || eckey->pub_key == NULL) {
ERR_raise(ERR_LIB_EC, ERR_R_PASSED_NULL_PARAMETER);
return 0;
@@ -462,21 +458,36 @@ int ec_key_public_check(const EC_KEY *eckey, BN_CTX *ctx)
return 0;
}
- point = EC_POINT_new(eckey->group);
- if (point == NULL)
- return 0;
-
/* 5.6.2.3.3 (Step 2) Test if the public key is in range */
if (!ec_key_public_range_check(ctx, eckey)) {
ERR_raise(ERR_LIB_EC, EC_R_COORDINATES_OUT_OF_RANGE);
- goto err;
+ return 0;
}
/* 5.6.2.3.3 (Step 3) is the pub_key on the elliptic curve */
if (EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx) <= 0) {
ERR_raise(ERR_LIB_EC, EC_R_POINT_IS_NOT_ON_CURVE);
- goto err;
+ return 0;
}
+ return 1;
+}
+
+/*
+ * ECC Key validation as specified in SP800-56A R3.
+ * Section 5.6.2.3.3 ECC Full Public-Key Validation Routine.
+ */
+int ec_key_public_check(const EC_KEY *eckey, BN_CTX *ctx)
+{
+ int ret = 0;
+ EC_POINT *point = NULL;
+ const BIGNUM *order = NULL;
+
+ if (!ec_key_public_check_quick(eckey, ctx))
+ return 0;
+
+ point = EC_POINT_new(eckey->group);
+ if (point == NULL)
+ return 0;
order = eckey->group->order;
if (BN_is_zero(order)) {