diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-05-23 21:19:48 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2010-06-03 19:54:53 +0200 |
commit | bab8c93bf9501e0eece9d99b491987c83b998e26 (patch) | |
tree | ef223bf13227b371e3f7fdff93e2a260635a8eed /lib/gnutls_pk.c | |
parent | 805694523f9cead85dcf221f5f715527e2b15ffc (diff) | |
download | gnutls-bab8c93bf9501e0eece9d99b491987c83b998e26.tar.gz |
Common code for calculation of RSA exp1 and exp2. Also update the openpgp
code to calculate those values.
Diffstat (limited to 'lib/gnutls_pk.c')
-rw-r--r-- | lib/gnutls_pk.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/gnutls_pk.c b/lib/gnutls_pk.c index 77d1434b79..982186550c 100644 --- a/lib/gnutls_pk.c +++ b/lib/gnutls_pk.c @@ -609,3 +609,39 @@ gnutls_pk_params_release (gnutls_pk_params_st * p) _gnutls_mpi_release (&p->params[i]); } } + +int _gnutls_calc_rsa_exp(bigint_t* params, unsigned int params_size) +{ +int ret; +bigint_t tmp = _gnutls_mpi_alloc_like(params[0]); + + if (params_size < RSA_PRIVATE_PARAMS) + { + gnutls_assert(); + return GNUTLS_E_INTERNAL_ERROR; + } + + if (tmp == NULL) + { + gnutls_assert (); + return GNUTLS_E_MEMORY_ERROR; + } + + /* [6] = d % p-1, [7] = d % q-1 */ + _gnutls_mpi_sub_ui(tmp, params[3], 1); + params[6] = _gnutls_mpi_mod(params[2]/*d*/, tmp); + + _gnutls_mpi_sub_ui(tmp, params[4], 1); + params[7] = _gnutls_mpi_mod(params[2]/*d*/, tmp); + + _gnutls_mpi_release(&tmp); + + if (params[7] == NULL || params[6] == NULL) + { + gnutls_assert (); + return GNUTLS_E_MEMORY_ERROR; + } + + return 0; +} + |