comparison libtomcrypt/src/pk/rsa/rsa_decrypt_key.c @ 1471:6dba84798cd5

Update to libtomcrypt 1.18.1, merged with Dropbear changes
author Matt Johnston <matt@ucc.asn.au>
date Fri, 09 Feb 2018 21:44:05 +0800
parents f849a5ca2efc
children
comparison
equal deleted inserted replaced
1470:8bba51a55704 1471:6dba84798cd5
3 * LibTomCrypt is a library that provides various cryptographic 3 * LibTomCrypt is a library that provides various cryptographic
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 *
9 * Tom St Denis, [email protected], http://libtom.org
10 */ 8 */
11 #include "tomcrypt.h" 9 #include "tomcrypt.h"
12 10
13 /** 11 /**
14 @file rsa_decrypt_key.c 12 @file rsa_decrypt_key.c
15 RSA LTC_PKCS #1 Decryption, Tom St Denis and Andreas Lange 13 RSA PKCS #1 Decryption, Tom St Denis and Andreas Lange
16 */ 14 */
17 15
18 #ifdef LTC_MRSA 16 #ifdef LTC_MRSA
19 17
20 /** 18 /**
21 LTC_PKCS #1 decrypt then v1.5 or OAEP depad 19 PKCS #1 decrypt then v1.5 or OAEP depad
22 @param in The ciphertext 20 @param in The ciphertext
23 @param inlen The length of the ciphertext (octets) 21 @param inlen The length of the ciphertext (octets)
24 @param out [out] The plaintext 22 @param out [out] The plaintext
25 @param outlen [in/out] The max size and resulting size of the plaintext (octets) 23 @param outlen [in/out] The max size and resulting size of the plaintext (octets)
26 @param lparam The system "lparam" value 24 @param lparam The system "lparam" value
27 @param lparamlen The length of the lparam value (octets) 25 @param lparamlen The length of the lparam value (octets)
28 @param hash_idx The index of the hash desired 26 @param hash_idx The index of the hash desired
29 @param padding Type of padding (LTC_LTC_PKCS_1_OAEP or LTC_LTC_PKCS_1_V1_5) 27 @param padding Type of padding (LTC_PKCS_1_OAEP or LTC_PKCS_1_V1_5)
30 @param stat [out] Result of the decryption, 1==valid, 0==invalid 28 @param stat [out] Result of the decryption, 1==valid, 0==invalid
31 @param key The corresponding private RSA key 29 @param key The corresponding private RSA key
32 @return CRYPT_OK if succcessul (even if invalid) 30 @return CRYPT_OK if succcessul (even if invalid)
33 */ 31 */
34 int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen, 32 int rsa_decrypt_key_ex(const unsigned char *in, unsigned long inlen,
49 /* default to invalid */ 47 /* default to invalid */
50 *stat = 0; 48 *stat = 0;
51 49
52 /* valid padding? */ 50 /* valid padding? */
53 51
54 if ((padding != LTC_LTC_PKCS_1_V1_5) && 52 if ((padding != LTC_PKCS_1_V1_5) &&
55 (padding != LTC_LTC_PKCS_1_OAEP)) { 53 (padding != LTC_PKCS_1_OAEP)) {
56 return CRYPT_PK_INVALID_PADDING; 54 return CRYPT_PK_INVALID_PADDING;
57 } 55 }
58 56
59 if (padding == LTC_LTC_PKCS_1_OAEP) { 57 if (padding == LTC_PKCS_1_OAEP) {
60 /* valid hash ? */ 58 /* valid hash ? */
61 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { 59 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
62 return err; 60 return err;
63 } 61 }
64 } 62 }
83 if ((err = ltc_mp.rsa_me(in, inlen, tmp, &x, PK_PRIVATE, key)) != CRYPT_OK) { 81 if ((err = ltc_mp.rsa_me(in, inlen, tmp, &x, PK_PRIVATE, key)) != CRYPT_OK) {
84 XFREE(tmp); 82 XFREE(tmp);
85 return err; 83 return err;
86 } 84 }
87 85
88 if (padding == LTC_LTC_PKCS_1_OAEP) { 86 if (padding == LTC_PKCS_1_OAEP) {
89 /* now OAEP decode the packet */ 87 /* now OAEP decode the packet */
90 err = pkcs_1_oaep_decode(tmp, x, lparam, lparamlen, modulus_bitlen, hash_idx, 88 err = pkcs_1_oaep_decode(tmp, x, lparam, lparamlen, modulus_bitlen, hash_idx,
91 out, outlen, stat); 89 out, outlen, stat);
92 } else { 90 } else {
93 /* now LTC_PKCS #1 v1.5 depad the packet */ 91 /* now PKCS #1 v1.5 depad the packet */
94 err = pkcs_1_v1_5_decode(tmp, x, LTC_LTC_PKCS_1_EME, modulus_bitlen, out, outlen, stat); 92 err = pkcs_1_v1_5_decode(tmp, x, LTC_PKCS_1_EME, modulus_bitlen, out, outlen, stat);
95 } 93 }
96 94
97 XFREE(tmp); 95 XFREE(tmp);
98 return err; 96 return err;
99 } 97 }
100 98
101 #endif /* LTC_MRSA */ 99 #endif /* LTC_MRSA */
102 100
103 /* $Source$ */ 101 /* ref: $Format:%D$ */
104 /* $Revision$ */ 102 /* git commit: $Format:%H$ */
105 /* $Date$ */ 103 /* commit time: $Format:%ai$ */