[PATCH] ecc: store EdDSA session key in secure memory
Regarding the function _gcry_ecc_eddsa_sign (cipher/ecc-eddsa.c), I am
wondering why the long-term secret key 'a' is stored in secure memory,
whereas the derived session key 'r' is not. This seems particularly
important in the case of EdDSA as the function _gcry_mpi_ec_mul_point
(mpi/ec.c) attempts to provide side-channel protection by using constant
time operations for scalars residing in secure memory.
As far as I understand from Bernstein et al.
(http://cr.yp.to/papers.html#ed25519), an attacker who learns 'r' from
side-channel observation during the signing process can easily recover
'a' as follows:
Given a valid signature (R,S) for message m, public key pk, point G and
hash function H,
S = r + a * H(encodepoint(R) + encodepoint(pk) + m) mod n
=> a = (S - r) / H(encodepoint(R) + encodepoint(pk) + m) mod n
Or am I missing something here? If not, I included a simple patch below.
From dbc810e1a75559413e610d3913796559de792677 Mon Sep 17 00:00:00 2001
From: Jo Van Bulck <[hidden email]>
Date: Thu, 19 Jan 2017 17:00:15 +0100
Subject: [PATCH 1/1] ecc: store EdDSA session key in secure memory.
* cipher/ecc-eddsa.c (_gcry_ecc_eddsa_sign): use mpi_snew to allocate
An attacker who learns the EdDSA session key from side-channel
observation during the signing process, can easily revover the long-
term secret key. Storing the session key in secure memory ensures that
constant time point operations are used in the MPI library.
Signed-off-by: Jo Van Bulck <[hidden email]>
cipher/ecc-eddsa.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/cipher/ecc-eddsa.c b/cipher/ecc-eddsa.c
index f91f848..813e030 100644
@@ -603,7 +603,7 @@ _gcry_ecc_eddsa_sign (gcry_mpi_t input,
a = mpi_snew (0);
x = mpi_new (0);
y = mpi_new (0);
- r = mpi_new (0);
+ r = mpi_snew (0);
ctx = _gcry_mpi_ec_p_internal_new (skey->E.model, skey->E.dialect, 0,
skey->E.p, skey->E.a, skey->E.b);
b = (ctx->nbits+7)/8;