diff --git a/rsa-decrypt-tr.c b/rsa-decrypt-tr.c index 4705137..33ea3d5 100644 --- a/rsa-decrypt-tr.c +++ b/rsa-decrypt-tr.c @@ -47,7 +47,7 @@ rsa_decrypt_tr(const struct rsa_public_key *pub, mpz_init (ri); _rsa_blind (pub, random_ctx, random, m, ri); - rsa_compute_root(key, m, m); + rsa_compute_root_ar(pub, key, m, m); _rsa_unblind (pub, m, ri); mpz_clear (ri); diff --git a/rsa-pkcs1-sign-tr.c b/rsa-pkcs1-sign-tr.c index 16de2f9..31417c5 100644 --- a/rsa-pkcs1-sign-tr.c +++ b/rsa-pkcs1-sign-tr.c @@ -45,7 +45,7 @@ rsa_pkcs1_sign_tr(const struct rsa_public_key *pub, mpz_init (ri); _rsa_blind (pub, random_ctx, random, s, ri); - rsa_compute_root(key, s, s); + rsa_compute_root_ar(pub, key, s, s); _rsa_unblind (pub, s, ri); mpz_clear (ri); diff --git a/rsa-sign.c b/rsa-sign.c index 56adda3..cc80faa 100644 --- a/rsa-sign.c +++ b/rsa-sign.c @@ -78,13 +78,20 @@ rsa_private_key_prepare(struct rsa_private_key *key) /* Computing an rsa root. */ void -rsa_compute_root(const struct rsa_private_key *key, - mpz_t x, const mpz_t m) +rsa_compute_root_ar(const struct rsa_public_key *pub, + const struct rsa_private_key *key, + mpz_t x, const mpz_t _m) { mpz_t xp; /* modulo p */ mpz_t xq; /* modulo q */ + mpz_t m; /* m=_m mod n */ + + mpz_init(xp); mpz_init(xq); mpz_init(m); - mpz_init(xp); mpz_init(xq); + if (pub != NULL) + mpz_fdiv_r(m, _m, pub->n); + else + mpz_set(m, _m); /* Compute xq = m^d % q = (m%q)^b % q */ mpz_fdiv_r(xq, m, key->q); @@ -132,5 +139,12 @@ rsa_compute_root(const struct rsa_private_key *key, mpz_mul(x, key->q, xp); mpz_add(x, x, xq); - mpz_clear(xp); mpz_clear(xq); + mpz_clear(xp); mpz_clear(xq); mpz_clear(m); +} + +void +rsa_compute_root(const struct rsa_private_key *key, + mpz_t x, const mpz_t m) +{ + return rsa_compute_root_ar(NULL, key, x, m); } diff --git a/rsa.h b/rsa.h index 38455a7..34c0992 100644 --- a/rsa.h +++ b/rsa.h @@ -67,6 +67,7 @@ extern "C" { #define rsa_decrypt nettle_rsa_decrypt #define rsa_decrypt_tr nettle_rsa_decrypt_tr #define rsa_compute_root nettle_rsa_compute_root +#define rsa_compute_root_ar nettle_rsa_compute_root_ar #define rsa_generate_keypair nettle_rsa_generate_keypair #define rsa_keypair_to_sexp nettle_rsa_keypair_to_sexp #define rsa_keypair_from_sexp_alist nettle_rsa_keypair_from_sexp_alist @@ -307,6 +308,12 @@ void rsa_compute_root(const struct rsa_private_key *key, mpz_t x, const mpz_t m); +/* The acoustic resistant version: http://www.cs.tau.ac.il/~tromer/acoustic/ */ +void +rsa_compute_root_ar(const struct rsa_public_key *pub, + const struct rsa_private_key *key, + mpz_t x, const mpz_t m); + /* Key generation */