Skip to content

Commit

Permalink
crypto: ecdh - check validity of Z before export
Browse files Browse the repository at this point in the history
SP800-56A rev3 section 5.7.1.2 step 2 mandates that the validity of the
calculated shared secret is verified before the data is returned to the
caller. Thus, the export function and the validity check functions are
reversed. In addition, the sensitive variables of priv and rand_z are
zeroized.

Signed-off-by: Stephan Mueller <[email protected]>
Reviewed-by: Vitaly Chikunov <[email protected]>
Acked-by: Neil Horman <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
smuellerDD authored and herbertx committed Jul 31, 2020
1 parent ef19f82 commit e7d2b41
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crypto/ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1495,11 +1495,16 @@ int crypto_ecdh_shared_secret(unsigned int curve_id, unsigned int ndigits,

ecc_point_mult(product, pk, priv, rand_z, curve, ndigits);

ecc_swap_digits(product->x, secret, ndigits);

if (ecc_point_is_zero(product))
if (ecc_point_is_zero(product)) {
ret = -EFAULT;
goto err_validity;
}

ecc_swap_digits(product->x, secret, ndigits);

err_validity:
memzero_explicit(priv, sizeof(priv));
memzero_explicit(rand_z, sizeof(rand_z));
ecc_free_point(product);
err_alloc_product:
ecc_free_point(pk);
Expand Down

0 comments on commit e7d2b41

Please sign in to comment.