diff options
author | djm@openbsd.org <djm@openbsd.org> | 2019-01-21 09:49:37 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2019-01-21 21:46:05 +1100 |
commit | f3ebaffd8714be31d4345f90af64992de4b3bba2 (patch) | |
tree | d0a73c727dc9aaf21842426908581531f4a7d741 /kexc25519.c | |
parent | 9d1a9771d0ad3a83af733bf3d2650b53f43c269f (diff) |
upstream: fix all-zero check in kexc25519_shared_key
from markus@ ok djm@
OpenBSD-Commit-ID: 60b1d364e0d9d34d1d1ef1620cb92e36cf06712d
Diffstat (limited to 'kexc25519.c')
-rw-r--r-- | kexc25519.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/kexc25519.c b/kexc25519.c index 712dd523d..acddcab37 100644 --- a/kexc25519.c +++ b/kexc25519.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: kexc25519.c,v 1.11 2018/12/27 03:25:25 djm Exp $ */ | 1 | /* $OpenBSD: kexc25519.c,v 1.12 2019/01/21 09:49:37 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001, 2013 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2001, 2013 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2010 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2010 Damien Miller. All rights reserved. |
@@ -64,14 +64,16 @@ kexc25519_shared_key(const u_char key[CURVE25519_SIZE], | |||
64 | const u_char pub[CURVE25519_SIZE], struct sshbuf *out) | 64 | const u_char pub[CURVE25519_SIZE], struct sshbuf *out) |
65 | { | 65 | { |
66 | u_char shared_key[CURVE25519_SIZE]; | 66 | u_char shared_key[CURVE25519_SIZE]; |
67 | u_char zero[CURVE25519_SIZE]; | ||
67 | int r; | 68 | int r; |
68 | 69 | ||
69 | /* Check for all-zero public key */ | 70 | crypto_scalarmult_curve25519(shared_key, key, pub); |
70 | explicit_bzero(shared_key, CURVE25519_SIZE); | 71 | |
71 | if (timingsafe_bcmp(pub, shared_key, CURVE25519_SIZE) == 0) | 72 | /* Check for all-zero shared secret */ |
73 | explicit_bzero(zero, CURVE25519_SIZE); | ||
74 | if (timingsafe_bcmp(zero, shared_key, CURVE25519_SIZE) == 0) | ||
72 | return SSH_ERR_KEY_INVALID_EC_VALUE; | 75 | return SSH_ERR_KEY_INVALID_EC_VALUE; |
73 | 76 | ||
74 | crypto_scalarmult_curve25519(shared_key, key, pub); | ||
75 | #ifdef DEBUG_KEXECDH | 77 | #ifdef DEBUG_KEXECDH |
76 | dump_digest("shared secret", shared_key, CURVE25519_SIZE); | 78 | dump_digest("shared secret", shared_key, CURVE25519_SIZE); |
77 | #endif | 79 | #endif |