[PATCH] cipher: Fix memory leaks for EdDSA.

Tianjia Zhang tianjia.zhang at linux.alibaba.com
Mon May 17 04:47:29 CEST 2021


* cipher/ecc-eddsa.c (_gcry_ecc_eddsa_genkey): Initialize point Q when used.
--

Signed-off-by: Tianjia Zhang <tianjia.zhang at linux.alibaba.com>
---
 cipher/ecc-eddsa.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/cipher/ecc-eddsa.c b/cipher/ecc-eddsa.c
index 2025cbca..fedf5ad6 100644
--- a/cipher/ecc-eddsa.c
+++ b/cipher/ecc-eddsa.c
@@ -598,8 +598,6 @@ _gcry_ecc_eddsa_genkey (mpi_ec_t ec, int flags)
   size_t dlen;
   unsigned char *hash_d = NULL;
 
-  point_init (&Q);
-
   if ((flags & PUBKEY_FLAG_TRANSIENT_KEY))
     random_level = GCRY_STRONG_RANDOM;
   else
@@ -625,16 +623,14 @@ _gcry_ecc_eddsa_genkey (mpi_ec_t ec, int flags)
   ec->d = _gcry_mpi_set_opaque (NULL, dbuf, dlen*8);
   rc = _gcry_ecc_eddsa_compute_h_d (&hash_d, ec);
   if (rc)
-    {
-      point_free (&Q);
-      goto leave;
-    }
+    goto leave;
 
   _gcry_mpi_set_buffer (a, hash_d, b, 0);
   xfree (hash_d);
   /* log_printmpi ("ecgen         a", a); */
 
   /* Compute Q.  */
+  point_init (&Q);
   _gcry_mpi_ec_mul_point (&Q, a, ec->G, ec);
   if (DBG_CIPHER)
     log_printpnt ("ecgen      pk", &Q, ec);
-- 
2.19.1.3.ge56e4f7




More information about the Gcrypt-devel mailing list