Index: openssl/crypto/rsa/rsa_oaep.c |
=================================================================== |
--- openssl/crypto/rsa/rsa_oaep.c (revision 105093) |
+++ openssl/crypto/rsa/rsa_oaep.c (working copy) |
@@ -28,7 +28,7 @@ |
#include <openssl/rand.h> |
#include <openssl/sha.h> |
-int MGF1(unsigned char *mask, long len, |
+static int MGF1(unsigned char *mask, long len, |
const unsigned char *seed, long seedlen); |
int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, |
@@ -76,11 +76,13 @@ |
return 0; |
} |
- MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH); |
+ if (MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH) < 0) |
+ return 0; |
for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++) |
db[i] ^= dbmask[i]; |
- MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH); |
+ if (MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH) < 0) |
+ return 0; |
for (i = 0; i < SHA_DIGEST_LENGTH; i++) |
seed[i] ^= seedmask[i]; |
@@ -133,11 +135,13 @@ |
maskeddb = padded_from + SHA_DIGEST_LENGTH; |
- MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen); |
+ if (MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen)) |
+ return -1; |
for (i = 0; i < SHA_DIGEST_LENGTH; i++) |
seed[i] ^= padded_from[i]; |
- MGF1(db, dblen, seed, SHA_DIGEST_LENGTH); |
+ if (MGF1(db, dblen, seed, SHA_DIGEST_LENGTH)) |
+ return -1; |
for (i = 0; i < dblen; i++) |
db[i] ^= maskeddb[i]; |
@@ -185,35 +189,44 @@ |
EVP_MD_CTX c; |
unsigned char md[EVP_MAX_MD_SIZE]; |
int mdlen; |
+ int rv = -1; |
EVP_MD_CTX_init(&c); |
- mdlen = M_EVP_MD_size(dgst); |
+ mdlen = EVP_MD_size(dgst); |
+ if (mdlen < 0) |
+ goto err; |
for (i = 0; outlen < len; i++) |
{ |
cnt[0] = (unsigned char)((i >> 24) & 255); |
cnt[1] = (unsigned char)((i >> 16) & 255); |
cnt[2] = (unsigned char)((i >> 8)) & 255; |
cnt[3] = (unsigned char)(i & 255); |
- EVP_DigestInit_ex(&c,dgst, NULL); |
- EVP_DigestUpdate(&c, seed, seedlen); |
- EVP_DigestUpdate(&c, cnt, 4); |
+ if (!EVP_DigestInit_ex(&c,dgst, NULL) |
+ || !EVP_DigestUpdate(&c, seed, seedlen) |
+ || !EVP_DigestUpdate(&c, cnt, 4)) |
+ goto err; |
if (outlen + mdlen <= len) |
{ |
- EVP_DigestFinal_ex(&c, mask + outlen, NULL); |
+ if (!EVP_DigestFinal_ex(&c, mask + outlen, NULL)) |
+ goto err; |
outlen += mdlen; |
} |
else |
{ |
- EVP_DigestFinal_ex(&c, md, NULL); |
+ if (!EVP_DigestFinal_ex(&c, md, NULL)) |
+ goto err; |
memcpy(mask + outlen, md, len - outlen); |
outlen = len; |
} |
} |
+ rv = 0; |
+ err: |
EVP_MD_CTX_cleanup(&c); |
- return 0; |
+ return rv; |
} |
-int MGF1(unsigned char *mask, long len, const unsigned char *seed, long seedlen) |
+static int MGF1(unsigned char *mask, long len, const unsigned char *seed, |
+ long seedlen) |
{ |
return PKCS1_MGF1(mask, len, seed, seedlen, EVP_sha1()); |
} |