+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.
#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
/* 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);
}
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);
{
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)
else
ret = 1;
- _rsa_unblind (pub, s, ri);
+ _rsa_unblind (pub, s, ri, s);
mpz_clear (ri);
}
else
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
}