Skip to content

Commit 6914dd5

Browse files
smuellerDDherbertx
authored andcommitted
crypto: ecc - SP800-56A rev 3 local public key validation
After the generation of a local public key, SP800-56A rev 3 section 5.6.2.1.3 mandates a validation of that key with a full validation compliant to section 5.6.2.3.3. Only if the full validation passes, the key is allowed to be used. The patch adds the full key validation compliant to 5.6.2.3.3 and performs the required check on the generated public key. Signed-off-by: Stephan Mueller <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 2ed5ba6 commit 6914dd5

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

crypto/ecc.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,9 @@ int ecc_make_pub_key(unsigned int curve_id, unsigned int ndigits,
14041404
}
14051405

14061406
ecc_point_mult(pk, &curve->g, priv, NULL, curve, ndigits);
1407-
if (ecc_point_is_zero(pk)) {
1407+
1408+
/* SP800-56A rev 3 5.6.2.1.3 key check */
1409+
if (ecc_is_pubkey_valid_full(curve, pk)) {
14081410
ret = -EAGAIN;
14091411
goto err_free_point;
14101412
}
@@ -1452,6 +1454,33 @@ int ecc_is_pubkey_valid_partial(const struct ecc_curve *curve,
14521454
}
14531455
EXPORT_SYMBOL(ecc_is_pubkey_valid_partial);
14541456

1457+
/* SP800-56A section 5.6.2.3.3 full verification */
1458+
int ecc_is_pubkey_valid_full(const struct ecc_curve *curve,
1459+
struct ecc_point *pk)
1460+
{
1461+
struct ecc_point *nQ;
1462+
1463+
/* Checks 1 through 3 */
1464+
int ret = ecc_is_pubkey_valid_partial(curve, pk);
1465+
1466+
if (ret)
1467+
return ret;
1468+
1469+
/* Check 4: Verify that nQ is the zero point. */
1470+
nQ = ecc_alloc_point(pk->ndigits);
1471+
if (!nQ)
1472+
return -ENOMEM;
1473+
1474+
ecc_point_mult(nQ, pk, curve->n, NULL, curve, pk->ndigits);
1475+
if (!ecc_point_is_zero(nQ))
1476+
ret = -EINVAL;
1477+
1478+
ecc_free_point(nQ);
1479+
1480+
return ret;
1481+
}
1482+
EXPORT_SYMBOL(ecc_is_pubkey_valid_full);
1483+
14551484
int crypto_ecdh_shared_secret(unsigned int curve_id, unsigned int ndigits,
14561485
const u64 *private_key, const u64 *public_key,
14571486
u64 *secret)

crypto/ecc.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,20 @@ int crypto_ecdh_shared_secret(unsigned int curve_id, unsigned int ndigits,
147147
int ecc_is_pubkey_valid_partial(const struct ecc_curve *curve,
148148
struct ecc_point *pk);
149149

150+
/**
151+
* ecc_is_pubkey_valid_full() - Full public key validation
152+
*
153+
* @curve: elliptic curve domain parameters
154+
* @pk: public key as a point
155+
*
156+
* Valdiate public key according to SP800-56A section 5.6.2.3.3 ECC Full
157+
* Public-Key Validation Routine.
158+
*
159+
* Return: 0 if validation is successful, -EINVAL if validation is failed.
160+
*/
161+
int ecc_is_pubkey_valid_full(const struct ecc_curve *curve,
162+
struct ecc_point *pk);
163+
150164
/**
151165
* vli_is_zero() - Determine is vli is zero
152166
*

0 commit comments

Comments
 (0)