[ssh-dss.c ssh-rsa.c]
     use static EVP_MAX_MD_SIZE buffers for EVP_DigestFinal; ok stevesk@
     don't use evp_md->md_size, it's not public.
This commit is contained in:
Damien Miller 2002-02-05 11:53:43 +11:00
parent 3a8262ffcc
commit c516e928cd
3 changed files with 19 additions and 27 deletions

View File

@ -10,6 +10,10 @@
- markus@cvs.openbsd.org 2002/01/25 21:00:24 - markus@cvs.openbsd.org 2002/01/25 21:00:24
[sshconnect2.c] [sshconnect2.c]
unused include unused include
- markus@cvs.openbsd.org 2002/01/25 21:42:11
[ssh-dss.c ssh-rsa.c]
use static EVP_MAX_MD_SIZE buffers for EVP_DigestFinal; ok stevesk@
don't use evp_md->md_size, it's not public.
20020130 20020130
- (djm) Delay PRNG seeding until we need it in ssh-keygen, from markus@ - (djm) Delay PRNG seeding until we need it in ssh-keygen, from markus@
@ -7412,4 +7416,4 @@
- Wrote replacements for strlcpy and mkdtemp - Wrote replacements for strlcpy and mkdtemp
- Released 1.0pre1 - Released 1.0pre1
$Id: ChangeLog,v 1.1801 2002/02/05 00:53:15 djm Exp $ $Id: ChangeLog,v 1.1802 2002/02/05 00:53:43 djm Exp $

View File

@ -23,7 +23,7 @@
*/ */
#include "includes.h" #include "includes.h"
RCSID("$OpenBSD: ssh-dss.c,v 1.11 2001/12/27 18:22:16 markus Exp $"); RCSID("$OpenBSD: ssh-dss.c,v 1.12 2002/01/25 21:42:11 markus Exp $");
#include <openssl/bn.h> #include <openssl/bn.h>
#include <openssl/evp.h> #include <openssl/evp.h>
@ -48,7 +48,7 @@ ssh_dss_sign(
DSA_SIG *sig; DSA_SIG *sig;
EVP_MD *evp_md = EVP_sha1(); EVP_MD *evp_md = EVP_sha1();
EVP_MD_CTX md; EVP_MD_CTX md;
u_char *digest, *ret, sigblob[SIGBLOB_LEN]; u_char *ret, digest[EVP_MAX_MD_SIZE], sigblob[SIGBLOB_LEN];
u_int rlen, slen, len, dlen; u_int rlen, slen, len, dlen;
Buffer b; Buffer b;
@ -56,16 +56,13 @@ ssh_dss_sign(
error("ssh_dss_sign: no DSA key"); error("ssh_dss_sign: no DSA key");
return -1; return -1;
} }
dlen = evp_md->md_size;
digest = xmalloc(dlen);
EVP_DigestInit(&md, evp_md); EVP_DigestInit(&md, evp_md);
EVP_DigestUpdate(&md, data, datalen); EVP_DigestUpdate(&md, data, datalen);
EVP_DigestFinal(&md, digest, NULL); EVP_DigestFinal(&md, digest, &dlen);
sig = DSA_do_sign(digest, dlen, key->dsa); sig = DSA_do_sign(digest, dlen, key->dsa);
memset(digest, 'd', sizeof(digest));
memset(digest, 0, dlen);
xfree(digest);
if (sig == NULL) { if (sig == NULL) {
error("ssh_dss_sign: sign failed"); error("ssh_dss_sign: sign failed");
return -1; return -1;
@ -115,7 +112,7 @@ ssh_dss_verify(
DSA_SIG *sig; DSA_SIG *sig;
EVP_MD *evp_md = EVP_sha1(); EVP_MD *evp_md = EVP_sha1();
EVP_MD_CTX md; EVP_MD_CTX md;
u_char *digest, *sigblob; u_char digest[EVP_MAX_MD_SIZE], *sigblob;
u_int len, dlen; u_int len, dlen;
int rlen, ret; int rlen, ret;
Buffer b; Buffer b;
@ -173,16 +170,13 @@ ssh_dss_verify(
} }
/* sha1 the data */ /* sha1 the data */
dlen = evp_md->md_size;
digest = xmalloc(dlen);
EVP_DigestInit(&md, evp_md); EVP_DigestInit(&md, evp_md);
EVP_DigestUpdate(&md, data, datalen); EVP_DigestUpdate(&md, data, datalen);
EVP_DigestFinal(&md, digest, NULL); EVP_DigestFinal(&md, digest, &dlen);
ret = DSA_do_verify(digest, dlen, sig, key->dsa); ret = DSA_do_verify(digest, dlen, sig, key->dsa);
memset(digest, 'd', sizeof(digest));
memset(digest, 0, dlen);
xfree(digest);
DSA_SIG_free(sig); DSA_SIG_free(sig);
debug("ssh_dss_verify: signature %s", debug("ssh_dss_verify: signature %s",

View File

@ -23,7 +23,7 @@
*/ */
#include "includes.h" #include "includes.h"
RCSID("$OpenBSD: ssh-rsa.c,v 1.14 2001/12/05 10:06:12 deraadt Exp $"); RCSID("$OpenBSD: ssh-rsa.c,v 1.15 2002/01/25 21:42:11 markus Exp $");
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/err.h> #include <openssl/err.h>
@ -45,7 +45,7 @@ ssh_rsa_sign(
{ {
const EVP_MD *evp_md; const EVP_MD *evp_md;
EVP_MD_CTX md; EVP_MD_CTX md;
u_char *digest, *sig, *ret; u_char digest[EVP_MAX_MD_SIZE], *sig, *ret;
u_int slen, dlen, len; u_int slen, dlen, len;
int ok, nid; int ok, nid;
Buffer b; Buffer b;
@ -63,18 +63,15 @@ ssh_rsa_sign(
error("ssh_rsa_sign: EVP_get_digestbynid %d failed", nid); error("ssh_rsa_sign: EVP_get_digestbynid %d failed", nid);
return -1; return -1;
} }
dlen = evp_md->md_size;
digest = xmalloc(dlen);
EVP_DigestInit(&md, evp_md); EVP_DigestInit(&md, evp_md);
EVP_DigestUpdate(&md, data, datalen); EVP_DigestUpdate(&md, data, datalen);
EVP_DigestFinal(&md, digest, NULL); EVP_DigestFinal(&md, digest, &dlen);
slen = RSA_size(key->rsa); slen = RSA_size(key->rsa);
sig = xmalloc(slen); sig = xmalloc(slen);
ok = RSA_sign(nid, digest, dlen, sig, &len, key->rsa); ok = RSA_sign(nid, digest, dlen, sig, &len, key->rsa);
memset(digest, 'd', dlen); memset(digest, 'd', sizeof(digest));
xfree(digest);
if (ok != 1) { if (ok != 1) {
int ecode = ERR_get_error(); int ecode = ERR_get_error();
@ -120,7 +117,7 @@ ssh_rsa_verify(
const EVP_MD *evp_md; const EVP_MD *evp_md;
EVP_MD_CTX md; EVP_MD_CTX md;
char *ktype; char *ktype;
u_char *sigblob, *digest; u_char digest[EVP_MAX_MD_SIZE], *sigblob;
u_int len, dlen; u_int len, dlen;
int rlen, ret, nid; int rlen, ret, nid;
@ -161,15 +158,12 @@ ssh_rsa_verify(
xfree(sigblob); xfree(sigblob);
return -1; return -1;
} }
dlen = evp_md->md_size;
digest = xmalloc(dlen);
EVP_DigestInit(&md, evp_md); EVP_DigestInit(&md, evp_md);
EVP_DigestUpdate(&md, data, datalen); EVP_DigestUpdate(&md, data, datalen);
EVP_DigestFinal(&md, digest, NULL); EVP_DigestFinal(&md, digest, &dlen);
ret = RSA_verify(nid, digest, dlen, sigblob, len, key->rsa); ret = RSA_verify(nid, digest, dlen, sigblob, len, key->rsa);
memset(digest, 'd', dlen); memset(digest, 'd', sizeof(digest));
xfree(digest);
memset(sigblob, 's', len); memset(sigblob, 's', len);
xfree(sigblob); xfree(sigblob);
if (ret == 0) { if (ret == 0) {