comparison libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_encode.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 /*! \file pkcs_1_v1_5_encode.c 13 /*! \file pkcs_1_v1_5_encode.c
14 * 14 *
15 * PKCS #1 v1.5 Padding (Andreas Lange) 15 * LTC_PKCS #1 v1.5 Padding (Andreas Lange)
16 */ 16 */
17 17
18 #ifdef PKCS_1 18 #ifdef LTC_PKCS_1
19 19
20 /*! \brief PKCS #1 v1.5 encode. 20 /*! \brief LTC_PKCS #1 v1.5 encode.
21 * 21 *
22 * \param msg The data to encode 22 * \param msg The data to encode
23 * \param msglen The length of the data to encode (octets) 23 * \param msglen The length of the data to encode (octets)
24 * \param block_type Block type to use in padding (\sa ltc_pkcs_1_v1_5_blocks) 24 * \param block_type Block type to use in padding (\sa ltc_pkcs_1_v1_5_blocks)
25 * \param modulus_bitlen The bit length of the RSA modulus 25 * \param modulus_bitlen The bit length of the RSA modulus
26 * \param prng An active PRNG state (only for LTC_PKCS_1_EME) 26 * \param prng An active PRNG state (only for LTC_LTC_PKCS_1_EME)
27 * \param prng_idx The index of the PRNG desired (only for LTC_PKCS_1_EME) 27 * \param prng_idx The index of the PRNG desired (only for LTC_LTC_PKCS_1_EME)
28 * \param out [out] The destination for the encoded data 28 * \param out [out] The destination for the encoded data
29 * \param outlen [in/out] The max size and resulting size of the encoded data 29 * \param outlen [in/out] The max size and resulting size of the encoded data
30 * 30 *
31 * \return CRYPT_OK if successful 31 * \return CRYPT_OK if successful
32 */ 32 */
42 unsigned long modulus_len, ps_len, i; 42 unsigned long modulus_len, ps_len, i;
43 unsigned char *ps; 43 unsigned char *ps;
44 int result; 44 int result;
45 45
46 /* valid block_type? */ 46 /* valid block_type? */
47 if ((block_type != LTC_PKCS_1_EMSA) && 47 if ((block_type != LTC_LTC_PKCS_1_EMSA) &&
48 (block_type != LTC_PKCS_1_EME)) { 48 (block_type != LTC_LTC_PKCS_1_EME)) {
49 return CRYPT_PK_INVALID_PADDING; 49 return CRYPT_PK_INVALID_PADDING;
50 } 50 }
51 51
52 if (block_type == LTC_PKCS_1_EME) { /* encryption padding, we need a valid PRNG */ 52 if (block_type == LTC_LTC_PKCS_1_EME) { /* encryption padding, we need a valid PRNG */
53 if ((result = prng_is_valid(prng_idx)) != CRYPT_OK) { 53 if ((result = prng_is_valid(prng_idx)) != CRYPT_OK) {
54 return result; 54 return result;
55 } 55 }
56 } 56 }
57 57
70 70
71 /* generate an octets string PS */ 71 /* generate an octets string PS */
72 ps = &out[2]; 72 ps = &out[2];
73 ps_len = modulus_len - msglen - 3; 73 ps_len = modulus_len - msglen - 3;
74 74
75 if (block_type == LTC_PKCS_1_EME) { 75 if (block_type == LTC_LTC_PKCS_1_EME) {
76 /* now choose a random ps */ 76 /* now choose a random ps */
77 if (prng_descriptor[prng_idx].read(ps, ps_len, prng) != ps_len) { 77 if (prng_descriptor[prng_idx].read(ps, ps_len, prng) != ps_len) {
78 result = CRYPT_ERROR_READPRNG; 78 result = CRYPT_ERROR_READPRNG;
79 goto bail; 79 goto bail;
80 } 80 }
102 result = CRYPT_OK; 102 result = CRYPT_OK;
103 bail: 103 bail:
104 return result; 104 return result;
105 } /* pkcs_1_v1_5_encode */ 105 } /* pkcs_1_v1_5_encode */
106 106
107 #endif /* #ifdef PKCS_1 */ 107 #endif /* #ifdef LTC_PKCS_1 */
108 108
109 /* $Source: /cvs/libtom/libtomcrypt/src/pk/pkcs1/pkcs_1_v1_5_encode.c,v $ */ 109 /* $Source$ */
110 /* $Revision: 1.2 $ */ 110 /* $Revision$ */
111 /* $Date: 2006/11/01 09:12:06 $ */ 111 /* $Date$ */