diff options
-rw-r--r-- | ssh-rsa.c | 21 |
1 files changed, 6 insertions, 15 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh-rsa.c,v 1.64 2017/12/18 23:14:34 djm Exp $ */ | 1 | /* $OpenBSD: ssh-rsa.c,v 1.65 2018/02/07 05:17:56 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org> | 3 | * Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org> |
4 | * | 4 | * |
@@ -120,7 +120,7 @@ ssh_rsa_sign(const struct sshkey *key, u_char **sigp, size_t *lenp, | |||
120 | const u_char *data, size_t datalen, const char *alg_ident) | 120 | const u_char *data, size_t datalen, const char *alg_ident) |
121 | { | 121 | { |
122 | u_char digest[SSH_DIGEST_MAX_LENGTH], *sig = NULL; | 122 | u_char digest[SSH_DIGEST_MAX_LENGTH], *sig = NULL; |
123 | size_t slen; | 123 | size_t slen = 0; |
124 | u_int dlen, len; | 124 | u_int dlen, len; |
125 | int nid, hash_alg, ret = SSH_ERR_INTERNAL_ERROR; | 125 | int nid, hash_alg, ret = SSH_ERR_INTERNAL_ERROR; |
126 | struct sshbuf *b = NULL; | 126 | struct sshbuf *b = NULL; |
@@ -189,10 +189,7 @@ ssh_rsa_sign(const struct sshkey *key, u_char **sigp, size_t *lenp, | |||
189 | ret = 0; | 189 | ret = 0; |
190 | out: | 190 | out: |
191 | explicit_bzero(digest, sizeof(digest)); | 191 | explicit_bzero(digest, sizeof(digest)); |
192 | if (sig != NULL) { | 192 | freezero(sig, slen); |
193 | explicit_bzero(sig, slen); | ||
194 | free(sig); | ||
195 | } | ||
196 | sshbuf_free(b); | 193 | sshbuf_free(b); |
197 | return ret; | 194 | return ret; |
198 | } | 195 | } |
@@ -204,7 +201,7 @@ ssh_rsa_verify(const struct sshkey *key, | |||
204 | { | 201 | { |
205 | char *sigtype = NULL; | 202 | char *sigtype = NULL; |
206 | int hash_alg, ret = SSH_ERR_INTERNAL_ERROR; | 203 | int hash_alg, ret = SSH_ERR_INTERNAL_ERROR; |
207 | size_t len, diff, modlen, dlen; | 204 | size_t len = 0, diff, modlen, dlen; |
208 | struct sshbuf *b = NULL; | 205 | struct sshbuf *b = NULL; |
209 | u_char digest[SSH_DIGEST_MAX_LENGTH], *osigblob, *sigblob = NULL; | 206 | u_char digest[SSH_DIGEST_MAX_LENGTH], *osigblob, *sigblob = NULL; |
210 | 207 | ||
@@ -269,10 +266,7 @@ ssh_rsa_verify(const struct sshkey *key, | |||
269 | ret = openssh_RSA_verify(hash_alg, digest, dlen, sigblob, len, | 266 | ret = openssh_RSA_verify(hash_alg, digest, dlen, sigblob, len, |
270 | key->rsa); | 267 | key->rsa); |
271 | out: | 268 | out: |
272 | if (sigblob != NULL) { | 269 | freezero(sigblob, len); |
273 | explicit_bzero(sigblob, len); | ||
274 | free(sigblob); | ||
275 | } | ||
276 | free(sigtype); | 270 | free(sigtype); |
277 | sshbuf_free(b); | 271 | sshbuf_free(b); |
278 | explicit_bzero(digest, sizeof(digest)); | 272 | explicit_bzero(digest, sizeof(digest)); |
@@ -394,10 +388,7 @@ openssh_RSA_verify(int hash_alg, u_char *hash, size_t hashlen, | |||
394 | } | 388 | } |
395 | ret = 0; | 389 | ret = 0; |
396 | done: | 390 | done: |
397 | if (decrypted) { | 391 | freezero(decrypted, rsasize); |
398 | explicit_bzero(decrypted, rsasize); | ||
399 | free(decrypted); | ||
400 | } | ||
401 | return ret; | 392 | return ret; |
402 | } | 393 | } |
403 | #endif /* WITH_OPENSSL */ | 394 | #endif /* WITH_OPENSSL */ |