comparison libtomcrypt/src/pk/rsa/rsa_decrypt_key.c @ 1439:8d24733026c5 coverity

merge
author Matt Johnston <matt@ucc.asn.au>
date Sat, 24 Jun 2017 23:33:16 +0800
parents f849a5ca2efc
children 6dba84798cd5
comparison
equal deleted inserted replaced
1400:238a439670f5 1439:8d24733026c5
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.com 9 * Tom St Denis, [email protected], http://libtom.org
10 */ 10 */
11 #include "tomcrypt.h" 11 #include "tomcrypt.h"
12 12
13 /** 13 /**
14 @file rsa_decrypt_key.c 14 @file rsa_decrypt_key.c
15 RSA PKCS #1 Decryption, Tom St Denis and Andreas Lange 15 RSA LTC_PKCS #1 Decryption, Tom St Denis and Andreas Lange
16 */ 16 */
17 17
18 #ifdef MRSA 18 #ifdef LTC_MRSA
19 19
20 /** 20 /**
21 PKCS #1 decrypt then v1.5 or OAEP depad 21 LTC_PKCS #1 decrypt then v1.5 or OAEP depad
22 @param in The ciphertext 22 @param in The ciphertext
23 @param inlen The length of the ciphertext (octets) 23 @param inlen The length of the ciphertext (octets)
24 @param out [out] The plaintext 24 @param out [out] The plaintext
25 @param outlen [in/out] The max size and resulting size of the plaintext (octets) 25 @param outlen [in/out] The max size and resulting size of the plaintext (octets)
26 @param lparam The system "lparam" value 26 @param lparam The system "lparam" value
27 @param lparamlen The length of the lparam value (octets) 27 @param lparamlen The length of the lparam value (octets)
28 @param hash_idx The index of the hash desired 28 @param hash_idx The index of the hash desired
29 @param padding Type of padding (LTC_PKCS_1_OAEP or LTC_PKCS_1_V1_5) 29 @param padding Type of padding (LTC_LTC_PKCS_1_OAEP or LTC_LTC_PKCS_1_V1_5)
30 @param stat [out] Result of the decryption, 1==valid, 0==invalid 30 @param stat [out] Result of the decryption, 1==valid, 0==invalid
31 @param key The corresponding private RSA key 31 @param key The corresponding private RSA key
32 @return CRYPT_OK if succcessul (even if invalid) 32 @return CRYPT_OK if succcessul (even if invalid)
33 */ 33 */
34 int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen, 34 int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen,
49 /* default to invalid */ 49 /* default to invalid */
50 *stat = 0; 50 *stat = 0;
51 51
52 /* valid padding? */ 52 /* valid padding? */
53 53
54 if ((padding != LTC_PKCS_1_V1_5) && 54 if ((padding != LTC_LTC_PKCS_1_V1_5) &&
55 (padding != LTC_PKCS_1_OAEP)) { 55 (padding != LTC_LTC_PKCS_1_OAEP)) {
56 return CRYPT_PK_INVALID_PADDING; 56 return CRYPT_PK_INVALID_PADDING;
57 } 57 }
58 58
59 if (padding == LTC_PKCS_1_OAEP) { 59 if (padding == LTC_LTC_PKCS_1_OAEP) {
60 /* valid hash ? */ 60 /* valid hash ? */
61 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { 61 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
62 return err; 62 return err;
63 } 63 }
64 } 64 }
83 if ((err = ltc_mp.rsa_me(in, inlen, tmp, &x, PK_PRIVATE, key)) != CRYPT_OK) { 83 if ((err = ltc_mp.rsa_me(in, inlen, tmp, &x, PK_PRIVATE, key)) != CRYPT_OK) {
84 XFREE(tmp); 84 XFREE(tmp);
85 return err; 85 return err;
86 } 86 }
87 87
88 if (padding == LTC_PKCS_1_OAEP) { 88 if (padding == LTC_LTC_PKCS_1_OAEP) {
89 /* now OAEP decode the packet */ 89 /* now OAEP decode the packet */
90 err = pkcs_1_oaep_decode(tmp, x, lparam, lparamlen, modulus_bitlen, hash_idx, 90 err = pkcs_1_oaep_decode(tmp, x, lparam, lparamlen, modulus_bitlen, hash_idx,
91 out, outlen, stat); 91 out, outlen, stat);
92 } else { 92 } else {
93 /* now PKCS #1 v1.5 depad the packet */ 93 /* now LTC_PKCS #1 v1.5 depad the packet */
94 err = pkcs_1_v1_5_decode(tmp, x, LTC_PKCS_1_EME, modulus_bitlen, out, outlen, stat); 94 err = pkcs_1_v1_5_decode(tmp, x, LTC_LTC_PKCS_1_EME, modulus_bitlen, out, outlen, stat);
95 } 95 }
96 96
97 XFREE(tmp); 97 XFREE(tmp);
98 return err; 98 return err;
99 } 99 }
100 100
101 #endif /* MRSA */ 101 #endif /* LTC_MRSA */
102 102
103 /* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_decrypt_key.c,v $ */ 103 /* $Source$ */
104 /* $Revision: 1.8 $ */ 104 /* $Revision$ */
105 /* $Date: 2006/11/01 09:18:22 $ */ 105 /* $Date$ */