diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2009-06-26 22:52:18 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2009-06-26 22:52:18 +0000 |
commit | 167d2a14117a950e5107427808fcfe7449177068 (patch) | |
tree | f50e494dbaef3d1aa0ed8678d5900c2ab5a86a56 /crypto | |
parent | 3f4802a14ea070a26917223b6f93bd35097740d9 (diff) |
PR: 1961
Submitted by: Martin Gerbershagen <martin.gerbershagen@nsn.com>
Approved by: steve@openssl.org
Avoid memory leak if RAND_bytes() fails.
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/rsa/rsa_oaep.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/crypto/rsa/rsa_oaep.c b/crypto/rsa/rsa_oaep.c index 4d30c9d2d3..697d577977 100644 --- a/crypto/rsa/rsa_oaep.c +++ b/crypto/rsa/rsa_oaep.c @@ -52,17 +52,6 @@ int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, return 0; } - dbmask = OPENSSL_malloc(emlen - SHA_DIGEST_LENGTH); - if (dbmask == NULL) - { - RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); - return 0; - } - - to[0] = 0; - seed = to + 1; - db = to + SHA_DIGEST_LENGTH + 1; - EVP_Digest((void *)param, plen, db, NULL, EVP_sha1(), NULL); memset(db + SHA_DIGEST_LENGTH, 0, emlen - flen - 2 * SHA_DIGEST_LENGTH - 1); @@ -76,6 +65,17 @@ int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, 20); #endif + to[0] = 0; + seed = to + 1; + db = to + SHA_DIGEST_LENGTH + 1; + + dbmask = OPENSSL_malloc(emlen - SHA_DIGEST_LENGTH); + if (dbmask == NULL) + { + RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); + return 0; + } + MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH); for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++) db[i] ^= dbmask[i]; |