summaryrefslogtreecommitdiff
path: root/cipher/ecc.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2017-08-25 18:13:28 +0900
committerWerner Koch <wk@gnupg.org>2017-08-27 09:08:50 +0200
commitbf76acbf0da6b0f245e491bec12c0f0a1b5be7c9 (patch)
tree48b590dc58ed543ddb8cb5331e6d7b2f99fdaba1 /cipher/ecc.c
parent5417a29336426d310c3e012b148bcb20ef9ca85c (diff)
downloadlibgcrypt-bf76acbf0da6b0f245e491bec12c0f0a1b5be7c9.tar.gz
ecc: Add input validation for X25519.
* cipher/ecc.c (ecc_decrypt_raw): Add input validation. * mpi/ec.c (ec_p_init): Use scratch buffer for bad points. (_gcry_mpi_ec_bad_point): New. -- Following is the paper describing the attack: May the Fourth Be With You: A Microarchitectural Side Channel Attack on Real-World Applications of Curve25519 by Daniel Genkin, Luke Valenta, and Yuval Yarom In the current implementation, we do output checking and it results an error for those bad points. However, when attacked, the computation will done with leak of private key, even it will results errors. To mitigate leak, we added input validation. Note that we only list bad points with MSB=0. By X25519, MSB is always cleared. In future, we should implement constant-time field computation. Then, this input validation could be removed, if performance is important and we are sure for no leak. CVE-id: CVE-2017-0379 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'cipher/ecc.c')
-rw-r--r--cipher/ecc.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/cipher/ecc.c b/cipher/ecc.c
index e25bf095..4e3e5b1a 100644
--- a/cipher/ecc.c
+++ b/cipher/ecc.c
@@ -1628,9 +1628,22 @@ ecc_decrypt_raw (gcry_sexp_t *r_plain, gcry_sexp_t s_data, gcry_sexp_t keyparms)
if (DBG_CIPHER)
log_printpnt ("ecc_decrypt kG", &kG, NULL);
- if (!(flags & PUBKEY_FLAG_DJB_TWEAK)
+ if ((flags & PUBKEY_FLAG_DJB_TWEAK))
+ {
/* For X25519, by its definition, validation should not be done. */
- && !_gcry_mpi_ec_curve_point (&kG, ec))
+ /* (Instead, we do output check.)
+ *
+ * However, to mitigate secret key leak from our implementation,
+ * we also do input validation here. For constant-time
+ * implementation, we can remove this input validation.
+ */
+ if (_gcry_mpi_ec_bad_point (&kG, ec))
+ {
+ rc = GPG_ERR_INV_DATA;
+ goto leave;
+ }
+ }
+ else if (!_gcry_mpi_ec_curve_point (&kG, ec))
{
rc = GPG_ERR_INV_DATA;
goto leave;