]> andersk Git - openssh.git/blobdiff - ssh-dss.c
- dtucker@cvs.openbsd.org 2010/01/09 11:17:56
[openssh.git] / ssh-dss.c
index dbf8465bae54612d6160c2f7e7fff0f06f4b0d01..51a06e98fe270a3e0faf5957a82657a761c879a5 100644 (file)
--- a/ssh-dss.c
+++ b/ssh-dss.c
@@ -1,3 +1,4 @@
+/* $OpenBSD: ssh-dss.c,v 1.24 2006/11/06 21:25:28 markus Exp $ */
 /*
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
  *
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: ssh-dss.c,v 1.15 2002/06/23 03:30:17 deraadt Exp $");
+
+#include <sys/types.h>
 
 #include <openssl/bn.h>
 #include <openssl/evp.h>
 
+#include <stdarg.h>
+#include <string.h>
+
 #include "xmalloc.h"
 #include "buffer.h"
-#include "bufaux.h"
 #include "compat.h"
 #include "log.h"
 #include "key.h"
-#include "ssh-dss.h"
 
 #define INTBLOB_LEN    20
 #define SIGBLOB_LEN    (2*INTBLOB_LEN)
 
 int
-ssh_dss_sign(Key *key, u_char **sigp, u_int *lenp,
-    u_char *data, u_int datalen)
+ssh_dss_sign(const Key *key, u_char **sigp, u_int *lenp,
+    const u_char *data, u_int datalen)
 {
        DSA_SIG *sig;
        const EVP_MD *evp_md = EVP_sha1();
        EVP_MD_CTX md;
-       u_char *ret, digest[EVP_MAX_MD_SIZE], sigblob[SIGBLOB_LEN];
+       u_char digest[EVP_MAX_MD_SIZE], sigblob[SIGBLOB_LEN];
        u_int rlen, slen, len, dlen;
        Buffer b;
 
@@ -79,31 +82,31 @@ ssh_dss_sign(Key *key, u_char **sigp, u_int *lenp,
        DSA_SIG_free(sig);
 
        if (datafellows & SSH_BUG_SIGBLOB) {
-               ret = xmalloc(SIGBLOB_LEN);
-               memcpy(ret, sigblob, SIGBLOB_LEN);
                if (lenp != NULL)
                        *lenp = SIGBLOB_LEN;
-               if (sigp != NULL)
-                       *sigp = ret;
+               if (sigp != NULL) {
+                       *sigp = xmalloc(SIGBLOB_LEN);
+                       memcpy(*sigp, sigblob, SIGBLOB_LEN);
+               }
        } else {
                /* ietf-drafts */
                buffer_init(&b);
                buffer_put_cstring(&b, "ssh-dss");
                buffer_put_string(&b, sigblob, SIGBLOB_LEN);
                len = buffer_len(&b);
-               ret = xmalloc(len);
-               memcpy(ret, buffer_ptr(&b), len);
-               buffer_free(&b);
                if (lenp != NULL)
                        *lenp = len;
-               if (sigp != NULL)
-                       *sigp = ret;
+               if (sigp != NULL) {
+                       *sigp = xmalloc(len);
+                       memcpy(*sigp, buffer_ptr(&b), len);
+               }
+               buffer_free(&b);
        }
        return 0;
 }
 int
-ssh_dss_verify(Key *key, u_char *signature, u_int signaturelen,
-    u_char *data, u_int datalen)
+ssh_dss_verify(const Key *key, const u_char *signature, u_int signaturelen,
+    const u_char *data, u_int datalen)
 {
        DSA_SIG *sig;
        const EVP_MD *evp_md = EVP_sha1();
@@ -120,7 +123,8 @@ ssh_dss_verify(Key *key, u_char *signature, u_int signaturelen,
 
        /* fetch signature */
        if (datafellows & SSH_BUG_SIGBLOB) {
-               sigblob = signature;
+               sigblob = xmalloc(signaturelen);
+               memcpy(sigblob, signature, signaturelen);
                len = signaturelen;
        } else {
                /* ietf-drafts */
@@ -157,13 +161,13 @@ ssh_dss_verify(Key *key, u_char *signature, u_int signaturelen,
                fatal("ssh_dss_verify: BN_new failed");
        if ((sig->s = BN_new()) == NULL)
                fatal("ssh_dss_verify: BN_new failed");
-       BN_bin2bn(sigblob, INTBLOB_LEN, sig->r);
-       BN_bin2bn(sigblob+ INTBLOB_LEN, INTBLOB_LEN, sig->s);
+       if ((BN_bin2bn(sigblob, INTBLOB_LEN, sig->r) == NULL) ||
+           (BN_bin2bn(sigblob+ INTBLOB_LEN, INTBLOB_LEN, sig->s) == NULL))
+               fatal("ssh_dss_verify: BN_bin2bn failed");
 
-       if (!(datafellows & SSH_BUG_SIGBLOB)) {
-               memset(sigblob, 0, len);
-               xfree(sigblob);
-       }
+       /* clean up */
+       memset(sigblob, 0, len);
+       xfree(sigblob);
 
        /* sha1 the data */
        EVP_DigestInit(&md, evp_md);
This page took 0.076721 seconds and 4 git commands to generate.