X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=openssl.c;fp=openssl.c;h=acf1120dd139aeb121a1533108f0f07b24dc6e61;hb=c9d82ed7bf01e5fb21e530ba819915a984e9efc4;hp=495d83c2bae0671a7f7d9f0e75a89900bfb4cecb;hpb=bfa89349d869e27dbe3467236ba269bca0a6f148;p=paraslash.git diff --git a/openssl.c b/openssl.c index 495d83c2..acf1120d 100644 --- a/openssl.c +++ b/openssl.c @@ -310,15 +310,22 @@ out: } int apc_pub_encrypt(struct asymmetric_key *pub, unsigned char *inbuf, - unsigned len, unsigned char *outbuf) + unsigned len, unsigned char **outbuf) { int ret, flen = len; /* RSA_public_encrypt expects a signed int */ + *outbuf = NULL; if (flen < 0) return -E_ENCRYPT; - ret = RSA_public_encrypt(flen, inbuf, outbuf, pub->rsa, + *outbuf = alloc(RSA_size(pub->rsa)); + ret = RSA_public_encrypt(flen, inbuf, *outbuf, pub->rsa, RSA_PKCS1_OAEP_PADDING); - return ret < 0? -E_ENCRYPT : ret; + if (ret < 0) { + free(*outbuf); + *outbuf = NULL; + return -E_ENCRYPT; + } + return ret; } struct stream_cipher {