summaryrefslogtreecommitdiff
path: root/ssh-rsa.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-03-29 00:31:20 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-03-29 00:31:20 +0000
commit425fb02f20671c332af7b718d1c0e797ad0699eb (patch)
tree66a4ac12032a214bcff2d979e97f6915917e08f3 /ssh-rsa.c
parentd09fcf5f6e6905ee2f04b81b6ad97e6d244f5c2a (diff)
- markus@cvs.openbsd.org 2001/03/27 10:34:08
[ssh-rsa.c sshd.c] use EVP_get_digestbynid, reorder some calls and fix missing free.
Diffstat (limited to 'ssh-rsa.c')
-rw-r--r--ssh-rsa.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/ssh-rsa.c b/ssh-rsa.c
index 9de0e7b0..a2153bd1 100644
--- a/ssh-rsa.c
+++ b/ssh-rsa.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: ssh-rsa.c,v 1.6 2001/02/08 19:30:52 itojun Exp $");
+RCSID("$OpenBSD: ssh-rsa.c,v 1.7 2001/03/27 10:34:08 markus Exp $");
#include <openssl/evp.h>
#include <openssl/err.h>
@@ -42,27 +42,32 @@ ssh_rsa_sign(
u_char **sigp, int *lenp,
u_char *data, int datalen)
{
- EVP_MD *evp_md = EVP_sha1();
+ const EVP_MD *evp_md;
EVP_MD_CTX md;
u_char *digest, *sig, *ret;
u_int slen, dlen, len;
- int ok;
+ int ok, nid;
Buffer b;
if (key == NULL || key->type != KEY_RSA || key->rsa == NULL) {
error("ssh_rsa_sign: no RSA key");
return -1;
}
- slen = RSA_size(key->rsa);
- sig = xmalloc(slen);
-
+ nid = NID_sha1;
+ if ((evp_md = EVP_get_digestbynid(nid)) == NULL) {
+ error("ssh_rsa_sign: EVP_get_digestbynid %d failed", nid);
+ return -1;
+ }
dlen = evp_md->md_size;
digest = xmalloc(dlen);
EVP_DigestInit(&md, evp_md);
EVP_DigestUpdate(&md, data, datalen);
EVP_DigestFinal(&md, digest, NULL);
- ok = RSA_sign(NID_sha1, digest, dlen, sig, &len, key->rsa);
+ slen = RSA_size(key->rsa);
+ sig = xmalloc(slen);
+
+ ok = RSA_sign(nid, digest, dlen, sig, &len, key->rsa);
memset(digest, 'd', dlen);
xfree(digest);
@@ -108,13 +113,12 @@ ssh_rsa_verify(
u_char *data, int datalen)
{
Buffer b;
- EVP_MD *evp_md = EVP_sha1();
+ const EVP_MD *evp_md;
EVP_MD_CTX md;
char *ktype;
u_char *sigblob, *digest;
u_int len, dlen;
- int rlen;
- int ret;
+ int rlen, ret, nid;
if (key == NULL || key->type != KEY_RSA || key->rsa == NULL) {
error("ssh_rsa_verify: no RSA key");
@@ -139,17 +143,23 @@ ssh_rsa_verify(
rlen = buffer_len(&b);
buffer_free(&b);
if(rlen != 0) {
+ xfree(sigblob);
error("ssh_rsa_verify: remaining bytes in signature %d", rlen);
return -1;
}
-
+ nid = NID_sha1;
+ if ((evp_md = EVP_get_digestbynid(nid)) == NULL) {
+ xfree(sigblob);
+ error("ssh_rsa_verify: EVP_get_digestbynid %d failed", nid);
+ return -1;
+ }
dlen = evp_md->md_size;
digest = xmalloc(dlen);
EVP_DigestInit(&md, evp_md);
EVP_DigestUpdate(&md, data, datalen);
EVP_DigestFinal(&md, digest, NULL);
- ret = RSA_verify(NID_sha1, digest, dlen, sigblob, len, key->rsa);
+ ret = RSA_verify(nid, digest, dlen, sigblob, len, key->rsa);
memset(digest, 'd', dlen);
xfree(digest);
memset(sigblob, 's', len);