comparison rsa_decrypt_key.c @ 15:6362d3854bb4 libtomcrypt-orig

0.96 release of LibTomCrypt
author Matt Johnston <matt@ucc.asn.au>
date Tue, 15 Jun 2004 14:07:21 +0000
parents
children 5d99163f7e32
comparison
equal deleted inserted replaced
3:7faae8f46238 15:6362d3854bb4
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
2 *
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
5 *
6 * The library is free for all purposes without any express
7 * guarantee it works.
8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org
10 */
11
12 #include "mycrypt.h"
13
14 #ifdef MRSA
15
16 /* 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,
22 rsa_key *key)
23 {
24 unsigned long modulus_bitlen, modulus_bytelen, x;
25 int err;
26
27 _ARGCHK(outkey != NULL);
28 _ARGCHK(keylen != NULL);
29 _ARGCHK(key != NULL);
30 _ARGCHK(res != NULL);
31
32 /* valid hash ? */
33 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
34 return err;
35 }
36
37 /* get modulus len in bits */
38 modulus_bitlen = mp_count_bits(&(key->N));
39
40 /* outlen must be at least the size of the modulus */
41 modulus_bytelen = mp_unsigned_bin_size(&(key->N));
42 if (modulus_bytelen != inlen) {
43 return CRYPT_INVALID_PACKET;
44 }
45
46 /* rsa decode the packet */
47 x = *keylen;
48 if ((err = rsa_exptmod(in, inlen, outkey, &x, PK_PRIVATE, prng, prng_idx, key)) != CRYPT_OK) {
49 return err;
50 }
51
52 /* now OAEP decode the packet */
53 return pkcs_1_oaep_decode(outkey, x, lparam, lparamlen, modulus_bitlen, hash_idx,
54 outkey, keylen, res);
55 }
56
57 #endif /* MRSA */
58
59
60
61