diff options
author | Damien Miller <djm@mindrot.org> | 1999-11-09 10:35:52 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 1999-11-09 10:35:52 +1100 |
commit | da217a02796934a87ace9e0859ab4af8be1893ce (patch) | |
tree | a5f3eab4e630a01283d54de6aebf2dbaf2d8df5a /rsa.c | |
parent | c7b38ceed6030484c61c71ea9fafaca6b34a297e (diff) |
- Merged OpenBSD CVS changes:
- [rsa.c] bugfix: use correct size for memset()
- [sshconnect.c] warn if announced size of modulus 'n' != real size
Diffstat (limited to 'rsa.c')
-rw-r--r-- | rsa.c | 38 |
1 files changed, 17 insertions, 21 deletions
@@ -35,7 +35,7 @@ Description of the RSA algorithm can be found e.g. from the following sources: | |||
35 | */ | 35 | */ |
36 | 36 | ||
37 | #include "includes.h" | 37 | #include "includes.h" |
38 | RCSID("$Id: rsa.c,v 1.2 1999/11/08 04:30:59 damien Exp $"); | 38 | RCSID("$Id: rsa.c,v 1.3 1999/11/08 23:35:52 damien Exp $"); |
39 | 39 | ||
40 | #include "rsa.h" | 40 | #include "rsa.h" |
41 | #include "ssh.h" | 41 | #include "ssh.h" |
@@ -110,28 +110,26 @@ void | |||
110 | rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA* key) | 110 | rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA* key) |
111 | { | 111 | { |
112 | char *inbuf, *outbuf; | 112 | char *inbuf, *outbuf; |
113 | int in_len; | 113 | int len, ilen, olen; |
114 | int out_len; | ||
115 | int len; | ||
116 | 114 | ||
117 | if (BN_num_bits(key->e) < 2 || !BN_is_odd(key->e)) | 115 | if (BN_num_bits(key->e) < 2 || !BN_is_odd(key->e)) |
118 | fatal("rsa_public_encrypt() exponent too small or not odd"); | 116 | fatal("rsa_public_encrypt() exponent too small or not odd"); |
119 | 117 | ||
120 | out_len = BN_num_bytes(key->n); | 118 | olen = BN_num_bytes(key->n); |
121 | outbuf = xmalloc(out_len); | 119 | outbuf = xmalloc(olen); |
122 | 120 | ||
123 | in_len = BN_num_bytes(in); | 121 | ilen = BN_num_bytes(in); |
124 | inbuf = xmalloc(in_len); | 122 | inbuf = xmalloc(ilen); |
125 | BN_bn2bin(in, inbuf); | 123 | BN_bn2bin(in, inbuf); |
126 | 124 | ||
127 | if ((len = RSA_public_encrypt(in_len, inbuf, outbuf, key, | 125 | if ((len = RSA_public_encrypt(ilen, inbuf, outbuf, key, |
128 | RSA_PKCS1_PADDING)) <= 0) | 126 | RSA_PKCS1_PADDING)) <= 0) |
129 | fatal("rsa_public_encrypt() failed"); | 127 | fatal("rsa_public_encrypt() failed"); |
130 | 128 | ||
131 | BN_bin2bn(outbuf, len, out); | 129 | BN_bin2bn(outbuf, len, out); |
132 | 130 | ||
133 | memset(outbuf, 0, out_len); | 131 | memset(outbuf, 0, olen); |
134 | memset(inbuf, 0, in_len); | 132 | memset(inbuf, 0, ilen); |
135 | xfree(outbuf); | 133 | xfree(outbuf); |
136 | xfree(inbuf); | 134 | xfree(inbuf); |
137 | } | 135 | } |
@@ -140,25 +138,23 @@ void | |||
140 | rsa_private_decrypt(BIGNUM *out, BIGNUM *in, RSA *key) | 138 | rsa_private_decrypt(BIGNUM *out, BIGNUM *in, RSA *key) |
141 | { | 139 | { |
142 | char *inbuf, *outbuf; | 140 | char *inbuf, *outbuf; |
143 | int in_len; | 141 | int len, ilen, olen; |
144 | int out_len; | ||
145 | int len; | ||
146 | 142 | ||
147 | out_len = BN_num_bytes(key->n); | 143 | olen = BN_num_bytes(key->n); |
148 | outbuf = xmalloc(out_len); | 144 | outbuf = xmalloc(olen); |
149 | 145 | ||
150 | in_len = BN_num_bytes(in); | 146 | ilen = BN_num_bytes(in); |
151 | inbuf = xmalloc(in_len); | 147 | inbuf = xmalloc(ilen); |
152 | BN_bn2bin(in, inbuf); | 148 | BN_bn2bin(in, inbuf); |
153 | 149 | ||
154 | if ((len = RSA_private_decrypt(in_len, inbuf, outbuf, key, | 150 | if ((len = RSA_private_decrypt(ilen, inbuf, outbuf, key, |
155 | RSA_SSLV23_PADDING)) <= 0) | 151 | RSA_SSLV23_PADDING)) <= 0) |
156 | fatal("rsa_private_decrypt() failed"); | 152 | fatal("rsa_private_decrypt() failed"); |
157 | 153 | ||
158 | BN_bin2bn(outbuf, len, out); | 154 | BN_bin2bn(outbuf, len, out); |
159 | 155 | ||
160 | memset(outbuf, 0, out_len); | 156 | memset(outbuf, 0, olen); |
161 | memset(inbuf, 0, in_len); | 157 | memset(inbuf, 0, ilen); |
162 | xfree(outbuf); | 158 | xfree(outbuf); |
163 | xfree(inbuf); | 159 | xfree(inbuf); |
164 | } | 160 | } |