diff options
| author | tb <> | 2026-06-08 12:08:08 +0000 |
|---|---|---|
| committer | tb <> | 2026-06-08 12:08:08 +0000 |
| commit | 216081b6fcc8cc105c5d67cd7feba13e79c0658d (patch) | |
| tree | 3d64560a4b6927f8fa95d4fb35fe874ac9bf8e69 /src | |
| parent | 47439108a83a3142292d6cdb68f3f053aafc733c (diff) | |
| download | openbsd-216081b6fcc8cc105c5d67cd7feba13e79c0658d.tar.gz openbsd-216081b6fcc8cc105c5d67cd7feba13e79c0658d.tar.bz2 openbsd-216081b6fcc8cc105c5d67cd7feba13e79c0658d.zip | |
Add a point at infinity check to ecdh_compute_key()
While we already check that the peer's public point is on the curve and
will reject the point at infinity when getting the affine coordinates,
doing this earlier avoids doing work with the private key in a clearly
invalid case.
Suggested by Lucca Hirschi et al.
[An EC_KEY_check_key() call was also suggested but this is a bit expensive
and punishes callers that do that or equivalent already (e.g. ssh)]
ok jsing kenjiro
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/ecdh/ecdh.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/lib/libcrypto/ecdh/ecdh.c b/src/lib/libcrypto/ecdh/ecdh.c index f970db7750..51b409a5dd 100644 --- a/src/lib/libcrypto/ecdh/ecdh.c +++ b/src/lib/libcrypto/ecdh/ecdh.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ecdh.c,v 1.13 2026/03/18 08:02:40 tb Exp $ */ | 1 | /* $OpenBSD: ecdh.c,v 1.14 2026/06/08 12:08:08 tb Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | 3 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
| 4 | * | 4 | * |
| @@ -169,6 +169,9 @@ ec_key_ecdh_compute_key(unsigned char **out, size_t *out_len, | |||
| 169 | if ((group = EC_KEY_get0_group(ecdh)) == NULL) | 169 | if ((group = EC_KEY_get0_group(ecdh)) == NULL) |
| 170 | goto err; | 170 | goto err; |
| 171 | 171 | ||
| 172 | if (EC_POINT_is_at_infinity(group, pub_key)) | ||
| 173 | goto err; | ||
| 174 | |||
| 172 | if (EC_POINT_is_on_curve(group, pub_key, ctx) <= 0) | 175 | if (EC_POINT_is_on_curve(group, pub_key, ctx) <= 0) |
| 173 | goto err; | 176 | goto err; |
| 174 | 177 | ||
