aboutsummaryrefslogtreecommitdiff
path: root/crypto/openssh/ssh-rsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssh/ssh-rsa.c')
-rw-r--r--crypto/openssh/ssh-rsa.c47
1 files changed, 24 insertions, 23 deletions
diff --git a/crypto/openssh/ssh-rsa.c b/crypto/openssh/ssh-rsa.c
index b502ddb6e0dc..8e79d4e1d310 100644
--- a/crypto/openssh/ssh-rsa.c
+++ b/crypto/openssh/ssh-rsa.c
@@ -23,7 +23,7 @@
*/
#include "includes.h"
-RCSID("$OpenBSD: ssh-rsa.c,v 1.8 2001/03/27 10:57:00 markus Exp $");
+RCSID("$OpenBSD: ssh-rsa.c,v 1.16 2002/02/24 19:14:59 markus Exp $");
#include <openssl/evp.h>
#include <openssl/err.h>
@@ -40,12 +40,12 @@ RCSID("$OpenBSD: ssh-rsa.c,v 1.8 2001/03/27 10:57:00 markus Exp $");
int
ssh_rsa_sign(
Key *key,
- u_char **sigp, int *lenp,
- u_char *data, int datalen)
+ u_char **sigp, u_int *lenp,
+ u_char *data, u_int datalen)
{
const EVP_MD *evp_md;
EVP_MD_CTX md;
- u_char *digest, *sig, *ret;
+ u_char digest[EVP_MAX_MD_SIZE], *sig, *ret;
u_int slen, dlen, len;
int ok, nid;
Buffer b;
@@ -54,23 +54,24 @@ ssh_rsa_sign(
error("ssh_rsa_sign: no RSA key");
return -1;
}
+ if (datafellows & SSH_BUG_SIGBLOB) {
+ error("ssh_rsa_sign: SSH_BUG_SIGBLOB not supported");
+ return -1;
+ }
nid = (datafellows & SSH_BUG_RSASIGMD5) ? NID_md5 : 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);
+ EVP_DigestFinal(&md, digest, &dlen);
slen = RSA_size(key->rsa);
sig = xmalloc(slen);
ok = RSA_sign(nid, digest, dlen, sig, &len, key->rsa);
- memset(digest, 'd', dlen);
- xfree(digest);
+ memset(digest, 'd', sizeof(digest));
if (ok != 1) {
int ecode = ERR_get_error();
@@ -103,21 +104,20 @@ ssh_rsa_sign(
*lenp = len;
if (sigp != NULL)
*sigp = ret;
- debug2("ssh_rsa_sign: done");
return 0;
}
int
ssh_rsa_verify(
Key *key,
- u_char *signature, int signaturelen,
- u_char *data, int datalen)
+ u_char *signature, u_int signaturelen,
+ u_char *data, u_int datalen)
{
Buffer b;
const EVP_MD *evp_md;
EVP_MD_CTX md;
char *ktype;
- u_char *sigblob, *digest;
+ u_char digest[EVP_MAX_MD_SIZE], *sigblob;
u_int len, dlen;
int rlen, ret, nid;
@@ -125,13 +125,17 @@ ssh_rsa_verify(
error("ssh_rsa_verify: no RSA key");
return -1;
}
+ if (datafellows & SSH_BUG_SIGBLOB) {
+ error("ssh_rsa_verify: SSH_BUG_SIGBLOB not supported");
+ return -1;
+ }
if (BN_num_bits(key->rsa->n) < 768) {
error("ssh_rsa_verify: n too small: %d bits",
BN_num_bits(key->rsa->n));
return -1;
}
buffer_init(&b);
- buffer_append(&b, (char *) signature, signaturelen);
+ buffer_append(&b, signature, signaturelen);
ktype = buffer_get_string(&b, NULL);
if (strcmp("ssh-rsa", ktype) != 0) {
error("ssh_rsa_verify: cannot handle type %s", ktype);
@@ -140,29 +144,26 @@ ssh_rsa_verify(
return -1;
}
xfree(ktype);
- sigblob = (u_char *)buffer_get_string(&b, &len);
+ sigblob = buffer_get_string(&b, &len);
rlen = buffer_len(&b);
buffer_free(&b);
- if(rlen != 0) {
- xfree(sigblob);
+ if (rlen != 0) {
error("ssh_rsa_verify: remaining bytes in signature %d", rlen);
+ xfree(sigblob);
return -1;
}
nid = (datafellows & SSH_BUG_RSASIGMD5) ? NID_md5 : NID_sha1;
if ((evp_md = EVP_get_digestbynid(nid)) == NULL) {
- xfree(sigblob);
error("ssh_rsa_verify: EVP_get_digestbynid %d failed", nid);
+ xfree(sigblob);
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);
+ EVP_DigestFinal(&md, digest, &dlen);
ret = RSA_verify(nid, digest, dlen, sigblob, len, key->rsa);
- memset(digest, 'd', dlen);
- xfree(digest);
+ memset(digest, 'd', sizeof(digest));
memset(sigblob, 's', len);
xfree(sigblob);
if (ret == 0) {