summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rsa
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/rsa')
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c2
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c20
2 files changed, 14 insertions, 8 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
index c5eaeeae6b..7c941885f0 100644
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ b/src/lib/libcrypto/rsa/rsa_eay.c
@@ -675,7 +675,7 @@ static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
675 rsa->_method_mod_n)) goto err; 675 rsa->_method_mod_n)) goto err;
676 676
677 if ((padding == RSA_X931_PADDING) && ((ret->d[0] & 0xf) != 12)) 677 if ((padding == RSA_X931_PADDING) && ((ret->d[0] & 0xf) != 12))
678 BN_sub(ret, rsa->n, ret); 678 if (!BN_sub(ret, rsa->n, ret)) goto err;
679 679
680 p=buf; 680 p=buf;
681 i=BN_bn2bin(ret,p); 681 i=BN_bn2bin(ret,p);
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c
index e238d10e5c..18d307ea9e 100644
--- a/src/lib/libcrypto/rsa/rsa_oaep.c
+++ b/src/lib/libcrypto/rsa/rsa_oaep.c
@@ -189,34 +189,40 @@ int PKCS1_MGF1(unsigned char *mask, long len,
189 EVP_MD_CTX c; 189 EVP_MD_CTX c;
190 unsigned char md[EVP_MAX_MD_SIZE]; 190 unsigned char md[EVP_MAX_MD_SIZE];
191 int mdlen; 191 int mdlen;
192 int rv = -1;
192 193
193 EVP_MD_CTX_init(&c); 194 EVP_MD_CTX_init(&c);
194 mdlen = EVP_MD_size(dgst); 195 mdlen = EVP_MD_size(dgst);
195 if (mdlen < 0) 196 if (mdlen < 0)
196 return -1; 197 goto err;
197 for (i = 0; outlen < len; i++) 198 for (i = 0; outlen < len; i++)
198 { 199 {
199 cnt[0] = (unsigned char)((i >> 24) & 255); 200 cnt[0] = (unsigned char)((i >> 24) & 255);
200 cnt[1] = (unsigned char)((i >> 16) & 255); 201 cnt[1] = (unsigned char)((i >> 16) & 255);
201 cnt[2] = (unsigned char)((i >> 8)) & 255; 202 cnt[2] = (unsigned char)((i >> 8)) & 255;
202 cnt[3] = (unsigned char)(i & 255); 203 cnt[3] = (unsigned char)(i & 255);
203 EVP_DigestInit_ex(&c,dgst, NULL); 204 if (!EVP_DigestInit_ex(&c,dgst, NULL)
204 EVP_DigestUpdate(&c, seed, seedlen); 205 || !EVP_DigestUpdate(&c, seed, seedlen)
205 EVP_DigestUpdate(&c, cnt, 4); 206 || !EVP_DigestUpdate(&c, cnt, 4))
207 goto err;
206 if (outlen + mdlen <= len) 208 if (outlen + mdlen <= len)
207 { 209 {
208 EVP_DigestFinal_ex(&c, mask + outlen, NULL); 210 if (!EVP_DigestFinal_ex(&c, mask + outlen, NULL))
211 goto err;
209 outlen += mdlen; 212 outlen += mdlen;
210 } 213 }
211 else 214 else
212 { 215 {
213 EVP_DigestFinal_ex(&c, md, NULL); 216 if (!EVP_DigestFinal_ex(&c, md, NULL))
217 goto err;
214 memcpy(mask + outlen, md, len - outlen); 218 memcpy(mask + outlen, md, len - outlen);
215 outlen = len; 219 outlen = len;
216 } 220 }
217 } 221 }
222 rv = 0;
223 err:
218 EVP_MD_CTX_cleanup(&c); 224 EVP_MD_CTX_cleanup(&c);
219 return 0; 225 return rv;
220 } 226 }
221 227
222static int MGF1(unsigned char *mask, long len, const unsigned char *seed, 228static int MGF1(unsigned char *mask, long len, const unsigned char *seed,