diff options
| author | Erwin Pawliczek <pawliczekerwin@gmail.com> | 2026-10-25 22:44:29 -0500 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2026-11-12 17:35:33 +0800 |
| commit | cd65eaf17841ac76f93a0c0806215cbd0e1cd980 (patch) | |
| tree | 080911f7c9bbae9e672de50f8104ecd1b8083769 /crypto | |
| parent | 99f506c86bf8b6909564fff64eeaa64dec5996b9 (diff) | |
| download | linux-next-cd65eaf17841ac76f93a0c0806215cbd0e1cd980.tar.gz linux-next-cd65eaf17841ac76f93a0c0806215cbd0e1cd980.zip | |
crypto: ecc - Randomize the initial Z in ecc_make_pub_key()
ecc_make_pub_key() calls ecc_point_mult() without an initial Z, so the
final Z, and therefore the input to vli_mod_inv(), is a deterministic
function of the private key. vli_mod_inv() is not constant time, so
key generation leaks information about the private key through its
running time.
crypto_ecdh_shared_secret() already passes a random initial Z, which
blinds the inversion input. Do the same in ecc_make_pub_key().
Key generation is used in the kernel by Bluetooth SMP and TPM2 HMAC
sessions, which generate ephemeral P-256 keys.
crypto_kpp_generate_public_key(), KVM guest on an i7-1165G7 (median
over 4 boots of the best of 9 runs of 300 calls):
P-256: 744.9 us -> 753.2 us (+1.1%; within noise)
P-384: 1674.2 us -> 1651.6 us (-1.4%; within noise)
Suggested-by: Ignat Korchagin <ignat@linux.win>
Signed-off-by: Erwin Pawliczek <pawliczekerwin@gmail.com>
Reviewed-by: Ignat Korchagin <ignat@linux.win>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
| -rw-r--r-- | crypto/ecc.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/crypto/ecc.c b/crypto/ecc.c index c7366eb7ce1f..6696bf0d90a6 100644 --- a/crypto/ecc.c +++ b/crypto/ecc.c @@ -1614,20 +1614,26 @@ int ecc_make_pub_key(unsigned int curve_id, unsigned int ndigits, { int ret = 0; struct ecc_point *pk; + u64 rand_z[ECC_MAX_DIGITS]; + unsigned int nbytes; const struct ecc_curve *curve = ecc_get_curve(curve_id); - if (!private_key) { + if (!private_key || ndigits > ARRAY_SIZE(rand_z)) { ret = -EINVAL; goto out; } + nbytes = ndigits << ECC_DIGITS_TO_BYTES_SHIFT; + + get_random_bytes(rand_z, nbytes); + pk = ecc_alloc_point(ndigits); if (!pk) { ret = -ENOMEM; goto out; } - ecc_point_mult(pk, &curve->g, private_key, NULL, curve, ndigits); + ecc_point_mult(pk, &curve->g, private_key, rand_z, curve, ndigits); /* SP800-56A rev 3 5.6.2.1.3 key check */ if (ecc_is_pubkey_valid_full(curve, pk)) { @@ -1641,6 +1647,7 @@ int ecc_make_pub_key(unsigned int curve_id, unsigned int ndigits, err_free_point: ecc_free_point(pk); out: + memzero_explicit(rand_z, sizeof(rand_z)); return ret; } EXPORT_SYMBOL(ecc_make_pub_key); |
