Fix leak of secrecy in ecdh_compute_key()
authorDr. Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Sat, 15 Oct 2016 22:53:33 +0000 (00:53 +0200)
committerMatt Caswell <matt@openssl.org>
Tue, 25 Oct 2016 21:07:39 +0000 (22:07 +0100)
A temporary buffer containing g^xy was not cleared in ecdh_compute_key()
before freeing it, so the shared secret was leaked in memory.

Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(cherry picked from commit 0e4690165b4beb6777b747b0aeb1646a301f41d9)

crypto/ecdh/ech_ossl.c

index d448b19a528f2974d9a5255916705300a0703633..2d14252dcee139eb42110c0974f80d01903fd158 100644 (file)
@@ -202,7 +202,9 @@ static int ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
         BN_CTX_end(ctx);
     if (ctx)
         BN_CTX_free(ctx);
-    if (buf)
+    if (buf) {
+        OPENSSL_cleanse(buf, buflen);
         OPENSSL_free(buf);
+    }
     return (ret);
 }