From da217a02796934a87ace9e0859ab4af8be1893ce Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Tue, 9 Nov 1999 10:35:52 +1100 Subject: - Merged OpenBSD CVS changes: - [rsa.c] bugfix: use correct size for memset() - [sshconnect.c] warn if announced size of modulus 'n' != real size --- rsa.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'rsa.c') diff --git a/rsa.c b/rsa.c index 6845fab9d..61e53759d 100644 --- a/rsa.c +++ b/rsa.c @@ -35,7 +35,7 @@ Description of the RSA algorithm can be found e.g. from the following sources: */ #include "includes.h" -RCSID("$Id: rsa.c,v 1.2 1999/11/08 04:30:59 damien Exp $"); +RCSID("$Id: rsa.c,v 1.3 1999/11/08 23:35:52 damien Exp $"); #include "rsa.h" #include "ssh.h" @@ -110,28 +110,26 @@ void rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA* key) { char *inbuf, *outbuf; - int in_len; - int out_len; - int len; + int len, ilen, olen; if (BN_num_bits(key->e) < 2 || !BN_is_odd(key->e)) fatal("rsa_public_encrypt() exponent too small or not odd"); - out_len = BN_num_bytes(key->n); - outbuf = xmalloc(out_len); + olen = BN_num_bytes(key->n); + outbuf = xmalloc(olen); - in_len = BN_num_bytes(in); - inbuf = xmalloc(in_len); + ilen = BN_num_bytes(in); + inbuf = xmalloc(ilen); BN_bn2bin(in, inbuf); - if ((len = RSA_public_encrypt(in_len, inbuf, outbuf, key, + if ((len = RSA_public_encrypt(ilen, inbuf, outbuf, key, RSA_PKCS1_PADDING)) <= 0) fatal("rsa_public_encrypt() failed"); BN_bin2bn(outbuf, len, out); - memset(outbuf, 0, out_len); - memset(inbuf, 0, in_len); + memset(outbuf, 0, olen); + memset(inbuf, 0, ilen); xfree(outbuf); xfree(inbuf); } @@ -140,25 +138,23 @@ void rsa_private_decrypt(BIGNUM *out, BIGNUM *in, RSA *key) { char *inbuf, *outbuf; - int in_len; - int out_len; - int len; + int len, ilen, olen; - out_len = BN_num_bytes(key->n); - outbuf = xmalloc(out_len); + olen = BN_num_bytes(key->n); + outbuf = xmalloc(olen); - in_len = BN_num_bytes(in); - inbuf = xmalloc(in_len); + ilen = BN_num_bytes(in); + inbuf = xmalloc(ilen); BN_bn2bin(in, inbuf); - if ((len = RSA_private_decrypt(in_len, inbuf, outbuf, key, + if ((len = RSA_private_decrypt(ilen, inbuf, outbuf, key, RSA_SSLV23_PADDING)) <= 0) fatal("rsa_private_decrypt() failed"); BN_bin2bn(outbuf, len, out); - memset(outbuf, 0, out_len); - memset(inbuf, 0, in_len); + memset(outbuf, 0, olen); + memset(inbuf, 0, ilen); xfree(outbuf); xfree(inbuf); } -- cgit v1.2.3