1
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
3
* LibTomCrypt is a library that provides various cryptographic
4
* algorithms in a highly modular and flexible manner.
6
* The library is free for all purposes without any express
9
* Tom St Denis, tomstdenis@iahu.ca, http://libtomcrypt.org
16
/* (PKCS #1 v2.0) decrypt then OAEP depad */
17
int rsa_decrypt_key(const unsigned char *in, unsigned long inlen,
18
unsigned char *outkey, unsigned long *keylen,
19
const unsigned char *lparam, unsigned long lparamlen,
20
prng_state *prng, int prng_idx,
21
int hash_idx, int *res,
24
unsigned long modulus_bitlen, modulus_bytelen, x;
28
_ARGCHK(outkey != NULL);
29
_ARGCHK(keylen != NULL);
33
/* default to invalid */
36
/* valid hash/prng ? */
37
if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) {
40
if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
44
/* get modulus len in bits */
45
modulus_bitlen = mp_count_bits(&(key->N));
47
/* outlen must be at least the size of the modulus */
48
modulus_bytelen = mp_unsigned_bin_size(&(key->N));
49
if (modulus_bytelen != inlen) {
50
return CRYPT_INVALID_PACKET;
59
/* rsa decode the packet */
61
if ((err = rsa_exptmod(in, inlen, tmp, &x, PK_PRIVATE, prng, prng_idx, key)) != CRYPT_OK) {
66
/* now OAEP decode the packet */
67
err = pkcs_1_oaep_decode(tmp, x, lparam, lparamlen, modulus_bitlen, hash_idx,