]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Separate src and dst arguments for _rsa_blind and _rsa_unblind.
authorNiels Möller <nisse@lysator.liu.se>
Sun, 13 Sep 2015 06:35:48 +0000 (08:35 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Sun, 13 Sep 2015 06:35:48 +0000 (08:35 +0200)
ChangeLog
rsa-blind.c
rsa-decrypt-tr.c
rsa-pkcs1-sign-tr.c
rsa.h

index 250e905d17261693940e9713d90a0e63f4fd28b5..5f0c17ac5906f1f81d24ef2116901b8b4928fd9a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-09-13  Niels Möller  <nisse@lysator.liu.se>
+
+       * rsa-blind.c (_rsa_blind, _rsa_unblind): Separate source and
+       destination arguments. Updated callers.
+
 2015-09-07  Niels Möller  <nisse@lysator.liu.se>
 
        * testsuite/rsa-sign-tr-test.c: Drop include of nettle-internal.h.
index 7662f5034a80fb1ef19be73e506beeef70385f49..746ef8638b0ca592bdab841d8f83e92e8ea56b6d 100644 (file)
 
 #include "bignum.h"
 
-/* Blinds the c, by computing c *= r^e (mod n), for a random r. Also
+/* Blinds m, by computing c = m r^e (mod n), for a random r. Also
    returns the inverse (ri), for use by rsa_unblind. */
 void
 _rsa_blind (const struct rsa_public_key *pub,
            void *random_ctx, nettle_random_func *random,
-           mpz_t c, mpz_t ri)
+           mpz_t c, mpz_t ri, const mpz_t m)
 {
   mpz_t r;
 
   mpz_init(r);
 
-  /* c = c*(r^e)
+  /* c = m*(r^e)
    * ri = r^(-1)
    */
   do 
@@ -62,16 +62,17 @@ _rsa_blind (const struct rsa_public_key *pub,
 
   /* c = c*(r^e) mod n */
   mpz_powm(r, r, pub->e, pub->n);
-  mpz_mul(c, c, r);
+  mpz_mul(c, m, r);
   mpz_fdiv_r(c, c, pub->n);
 
   mpz_clear(r);
 }
 
-/* c *= ri mod n */
+/* m = c ri mod n */
 void
-_rsa_unblind (const struct rsa_public_key *pub, mpz_t c, const mpz_t ri)
+_rsa_unblind (const struct rsa_public_key *pub,
+             mpz_t m, const mpz_t ri, const mpz_t c)
 {
-  mpz_mul(c, c, ri);
-  mpz_fdiv_r(c, c, pub->n);
+  mpz_mul(m, c, ri);
+  mpz_fdiv_r(m, m, pub->n);
 }
index e28bee796f6d53a0fdc2ca32f52d03242545c49c..d28badd6c076cadfde303aba82fe48e9417ad41a 100644 (file)
@@ -54,9 +54,9 @@ rsa_decrypt_tr(const struct rsa_public_key *pub,
   mpz_init_set(m, gibberish);
   mpz_init (ri);
 
-  _rsa_blind (pub, random_ctx, random, m, ri);
+  _rsa_blind (pub, random_ctx, random, m, ri, m);
   rsa_compute_root(key, m, m);
-  _rsa_unblind (pub, m, ri);
+  _rsa_unblind (pub, m, ri, m);
   mpz_clear (ri);
 
   res = pkcs1_decrypt (key->size, m, length, message);
index f2b3e45d8ae9e488f18d4818d9e529061dca1843..896d410788a540d174b2ef94addc5ddf18ee0317 100644 (file)
@@ -75,7 +75,7 @@ rsa_pkcs1_sign_tr(const struct rsa_public_key *pub,
     {
       mpz_init (ri);
 
-      _rsa_blind (pub, random_ctx, random, m, ri);
+      _rsa_blind (pub, random_ctx, random, m, ri, m);
       rsa_compute_root(key, s, m);
 
       if (rsa_verify_res(pub, s, m) == 0)
@@ -86,7 +86,7 @@ rsa_pkcs1_sign_tr(const struct rsa_public_key *pub,
       else
         ret = 1;
 
-      _rsa_unblind (pub, s, ri);
+      _rsa_unblind (pub, s, ri, s);
       mpz_clear (ri);
     }
   else
diff --git a/rsa.h b/rsa.h
index 44d4af94920e0e2ed258739defb1f46227ff5c41..eeaeaaee199a738c7574753828a365fe687ab1fb 100644 (file)
--- a/rsa.h
+++ b/rsa.h
@@ -416,9 +416,10 @@ _rsa_check_size(mpz_t n);
 void
 _rsa_blind (const struct rsa_public_key *pub,
            void *random_ctx, nettle_random_func *random,
-           mpz_t c, mpz_t ri);
+           mpz_t c, mpz_t ri, const mpz_t m);
 void
-_rsa_unblind (const struct rsa_public_key *pub, mpz_t c, const mpz_t ri);
+_rsa_unblind (const struct rsa_public_key *pub,
+             mpz_t m, const mpz_t ri, const mpz_t c);
 
 #ifdef __cplusplus
 }