[Pkg-gnupg-commit] [gnupg1] 14/30: rsa: Reduce secmem pressure.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Aug 2 06:35:09 UTC 2017


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg1.

commit 1b1f44846b5f21a80ed101f2284ce5f6e8849ee7
Author: NIIBE Yutaka <gniibe at fsij.org>
Date:   Fri Jul 7 21:51:42 2017 +0900

    rsa: Reduce secmem pressure.
    
    * cipher/rsa.c (secret): Don't keep secmem.
    
    Signed-off-by: NIIBE Yutaka <gniibe at fsij.org>
---
 cipher/rsa.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/cipher/rsa.c b/cipher/rsa.c
index 84a1af0..51b7640 100644
--- a/cipher/rsa.c
+++ b/cipher/rsa.c
@@ -341,22 +341,29 @@ secret(MPI output, MPI input, RSA_secret_key *skey )
     mpi_set_highbit (rr, rr_nbits - 1);
     mpi_sub_ui( h, skey->p, 1  );
     mpi_mul ( D_blind, h, rr );
+    mpi_free ( rr );
     mpi_fdiv_r( h, skey->d, h );
     mpi_add ( D_blind, D_blind, h );
+    mpi_free ( h );
     mpi_powm ( m1, input, D_blind, skey->p );
 
+    h = mpi_alloc_secure (nlimbs);
+    rr = mpi_alloc_secure ( (rr_nbits + BITS_PER_MPI_LIMB-1)/BITS_PER_MPI_LIMB );
+
     /* d_blind = (d mod (q-1)) + (q-1) * r            */
     /* m2 = c ^ d_blind mod q */
     randomize_mpi (rr, rr_nbits, 0);
     mpi_set_highbit (rr, rr_nbits - 1);
     mpi_sub_ui( h, skey->q, 1  );
     mpi_mul ( D_blind, h, rr );
+    mpi_free ( rr );
     mpi_fdiv_r( h, skey->d, h );
     mpi_add ( D_blind, D_blind, h );
+    mpi_free ( h );
     mpi_powm ( m2, input, D_blind, skey->q );
 
-    mpi_free ( rr );
     mpi_free ( D_blind );
+    h = mpi_alloc_secure (nlimbs);
 
     /* h = u * ( m2 - m1 ) mod q */
     mpi_sub( h, m2, m1 );

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg1.git



More information about the Pkg-gnupg-commit mailing list