Mercurial > dropbear
comparison libtomcrypt/src/pk/rsa/rsa_sign_hash.c @ 1437:871b18fd7065 fuzz
merge from main (libtommath/libtomcrypt/curve25510-donna updates)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 24 Jun 2017 22:51:45 +0800 |
parents | f849a5ca2efc |
children | 6dba84798cd5 |
comparison
equal
deleted
inserted
replaced
1432:41dca1e5ea34 | 1437:871b18fd7065 |
---|---|
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_sign_hash.c | 14 @file rsa_sign_hash.c |
15 RSA PKCS #1 v1.5 and v2 PSS sign hash, Tom St Denis and Andreas Lange | 15 RSA LTC_PKCS #1 v1.5 and v2 PSS sign hash, Tom St Denis and Andreas Lange |
16 */ | 16 */ |
17 | 17 |
18 #ifdef MRSA | 18 #ifdef LTC_MRSA |
19 | 19 |
20 /** | 20 /** |
21 PKCS #1 pad then sign | 21 LTC_PKCS #1 pad then sign |
22 @param in The hash to sign | 22 @param in The hash to sign |
23 @param inlen The length of the hash to sign (octets) | 23 @param inlen The length of the hash to sign (octets) |
24 @param out [out] The signature | 24 @param out [out] The signature |
25 @param outlen [in/out] The max size and resulting size of the signature | 25 @param outlen [in/out] The max size and resulting size of the signature |
26 @param padding Type of padding (LTC_PKCS_1_PSS or LTC_PKCS_1_V1_5) | 26 @param padding Type of padding (LTC_LTC_PKCS_1_PSS or LTC_LTC_PKCS_1_V1_5) |
27 @param prng An active PRNG state | 27 @param prng An active PRNG state |
28 @param prng_idx The index of the PRNG desired | 28 @param prng_idx The index of the PRNG desired |
29 @param hash_idx The index of the hash desired | 29 @param hash_idx The index of the hash desired |
30 @param saltlen The length of the salt desired (octets) | 30 @param saltlen The length of the salt desired (octets) |
31 @param key The private RSA key to use | 31 @param key The private RSA key to use |
45 LTC_ARGCHK(out != NULL); | 45 LTC_ARGCHK(out != NULL); |
46 LTC_ARGCHK(outlen != NULL); | 46 LTC_ARGCHK(outlen != NULL); |
47 LTC_ARGCHK(key != NULL); | 47 LTC_ARGCHK(key != NULL); |
48 | 48 |
49 /* valid padding? */ | 49 /* valid padding? */ |
50 if ((padding != LTC_PKCS_1_V1_5) && (padding != LTC_PKCS_1_PSS)) { | 50 if ((padding != LTC_LTC_PKCS_1_V1_5) && (padding != LTC_LTC_PKCS_1_PSS)) { |
51 return CRYPT_PK_INVALID_PADDING; | 51 return CRYPT_PK_INVALID_PADDING; |
52 } | 52 } |
53 | 53 |
54 if (padding == LTC_PKCS_1_PSS) { | 54 if (padding == LTC_LTC_PKCS_1_PSS) { |
55 /* valid prng and hash ? */ | 55 /* valid prng and hash ? */ |
56 if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) { | 56 if ((err = prng_is_valid(prng_idx)) != CRYPT_OK) { |
57 return err; | 57 return err; |
58 } | 58 } |
59 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { | 59 if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) { |
69 if (modulus_bytelen > *outlen) { | 69 if (modulus_bytelen > *outlen) { |
70 *outlen = modulus_bytelen; | 70 *outlen = modulus_bytelen; |
71 return CRYPT_BUFFER_OVERFLOW; | 71 return CRYPT_BUFFER_OVERFLOW; |
72 } | 72 } |
73 | 73 |
74 if (padding == LTC_PKCS_1_PSS) { | 74 if (padding == LTC_LTC_PKCS_1_PSS) { |
75 /* PSS pad the key */ | 75 /* PSS pad the key */ |
76 x = *outlen; | 76 x = *outlen; |
77 if ((err = pkcs_1_pss_encode(in, inlen, saltlen, prng, prng_idx, | 77 if ((err = pkcs_1_pss_encode(in, inlen, saltlen, prng, prng_idx, |
78 hash_idx, modulus_bitlen, out, &x)) != CRYPT_OK) { | 78 hash_idx, modulus_bitlen, out, &x)) != CRYPT_OK) { |
79 return err; | 79 return err; |
80 } | 80 } |
81 } else { | 81 } else { |
82 /* PKCS #1 v1.5 pad the hash */ | 82 /* LTC_PKCS #1 v1.5 pad the hash */ |
83 unsigned char *tmpin; | 83 unsigned char *tmpin; |
84 ltc_asn1_list digestinfo[2], siginfo[2]; | 84 ltc_asn1_list digestinfo[2], siginfo[2]; |
85 | 85 |
86 /* not all hashes have OIDs... so sad */ | 86 /* not all hashes have OIDs... so sad */ |
87 if (hash_descriptor[hash_idx].OIDlen == 0) { | 87 if (hash_descriptor[hash_idx].OIDlen == 0) { |
112 XFREE(tmpin); | 112 XFREE(tmpin); |
113 return err; | 113 return err; |
114 } | 114 } |
115 | 115 |
116 x = *outlen; | 116 x = *outlen; |
117 if ((err = pkcs_1_v1_5_encode(tmpin, y, LTC_PKCS_1_EMSA, | 117 if ((err = pkcs_1_v1_5_encode(tmpin, y, LTC_LTC_PKCS_1_EMSA, |
118 modulus_bitlen, NULL, 0, | 118 modulus_bitlen, NULL, 0, |
119 out, &x)) != CRYPT_OK) { | 119 out, &x)) != CRYPT_OK) { |
120 XFREE(tmpin); | 120 XFREE(tmpin); |
121 return err; | 121 return err; |
122 } | 122 } |
125 | 125 |
126 /* RSA encode it */ | 126 /* RSA encode it */ |
127 return ltc_mp.rsa_me(out, x, out, outlen, PK_PRIVATE, key); | 127 return ltc_mp.rsa_me(out, x, out, outlen, PK_PRIVATE, key); |
128 } | 128 } |
129 | 129 |
130 #endif /* MRSA */ | 130 #endif /* LTC_MRSA */ |
131 | 131 |
132 /* $Source: /cvs/libtom/libtomcrypt/src/pk/rsa/rsa_sign_hash.c,v $ */ | 132 /* $Source$ */ |
133 /* $Revision: 1.9 $ */ | 133 /* $Revision$ */ |
134 /* $Date: 2006/11/09 23:15:39 $ */ | 134 /* $Date$ */ |