]> andersk Git - openssh.git/blobdiff - key.c
- markus@cvs.openbsd.org 2003/06/24 08:23:46
[openssh.git] / key.c
diff --git a/key.c b/key.c
index 51902ea257fa3b26310d0e09742462f7c81ff955..b101e1b271c763b2467bc3bad5d5b04027e677d4 100644 (file)
--- a/key.c
+++ b/key.c
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include "includes.h"
-RCSID("$OpenBSD: key.c,v 1.42 2002/03/18 17:23:31 markus Exp $");
+RCSID("$OpenBSD: key.c,v 1.53 2003/06/24 08:23:46 markus Exp $");
 
 #include <openssl/evp.h>
 
 #include "xmalloc.h"
 #include "key.h"
 #include "rsa.h"
-#include "ssh-dss.h"
-#include "ssh-rsa.h"
 #include "uuencode.h"
 #include "buffer.h"
 #include "bufaux.h"
@@ -89,6 +87,7 @@ key_new(int type)
        }
        return k;
 }
+
 Key *
 key_new_private(int type)
 {
@@ -120,6 +119,7 @@ key_new_private(int type)
        }
        return k;
 }
+
 void
 key_free(Key *k)
 {
@@ -169,7 +169,7 @@ key_equal(Key *a, Key *b)
        return 0;
 }
 
-static u_char*
+u_char*
 key_fingerprint_raw(Key *k, enum fp_type dgst_type, u_int *dgst_raw_length)
 {
        const EVP_MD *md = NULL;
@@ -225,8 +225,8 @@ key_fingerprint_raw(Key *k, enum fp_type dgst_type, u_int *dgst_raw_length)
        return retval;
 }
 
-static char*
-key_fingerprint_hex(u_chardgst_raw, u_int dgst_raw_len)
+static char *
+key_fingerprint_hex(u_char *dgst_raw, u_int dgst_raw_len)
 {
        char *retval;
        int i;
@@ -242,8 +242,8 @@ key_fingerprint_hex(u_char* dgst_raw, u_int dgst_raw_len)
        return retval;
 }
 
-static char*
-key_fingerprint_bubblebabble(u_chardgst_raw, u_int dgst_raw_len)
+static char *
+key_fingerprint_bubblebabble(u_char *dgst_raw, u_int dgst_raw_len)
 {
        char vowels[] = { 'a', 'e', 'i', 'o', 'u', 'y' };
        char consonants[] = { 'b', 'c', 'd', 'f', 'g', 'h', 'k', 'l', 'm',
@@ -289,7 +289,7 @@ key_fingerprint_bubblebabble(u_char* dgst_raw, u_int dgst_raw_len)
        return retval;
 }
 
-char*
+char *
 key_fingerprint(Key *k, enum fp_type dgst_type, enum fp_rep dgst_rep)
 {
        char *retval = NULL;
@@ -359,6 +359,7 @@ read_bignum(char **cpp, BIGNUM * value)
        *cpp = cp;
        return 1;
 }
+
 static int
 write_bignum(FILE *f, BIGNUM *num)
 {
@@ -407,14 +408,14 @@ key_read(Key *ret, char **cpp)
        case KEY_DSA:
                space = strchr(cp, ' ');
                if (space == NULL) {
-                       debug3("key_read: no space");
+                       debug3("key_read: missing whitespace");
                        return -1;
                }
                *space = '\0';
                type = key_type_from_name(cp);
                *space = ' ';
                if (type == KEY_UNSPEC) {
-                       debug3("key_read: no key found");
+                       debug3("key_read: missing keytype");
                        return -1;
                }
                cp = space+1;
@@ -437,7 +438,7 @@ key_read(Key *ret, char **cpp)
                        xfree(blob);
                        return -1;
                }
-               k = key_from_blob(blob, n);
+               k = key_from_blob(blob, (u_int)n);
                xfree(blob);
                if (k == NULL) {
                        error("key_read: key_from_blob %s failed", cp);
@@ -485,12 +486,14 @@ key_read(Key *ret, char **cpp)
        }
        return success;
 }
+
 int
 key_write(Key *key, FILE *f)
 {
        int n, success = 0;
        u_int len, bits = 0;
-       u_char *blob, *uu;
+       u_char *blob;
+       char *uu;
 
        if (key->type == KEY_RSA1 && key->rsa != NULL) {
                /* size of modulus 'n' */
@@ -516,6 +519,7 @@ key_write(Key *key, FILE *f)
        }
        return success;
 }
+
 char *
 key_type(Key *k)
 {
@@ -532,6 +536,7 @@ key_type(Key *k)
        }
        return "unknown";
 }
+
 char *
 key_ssh_name(Key *k)
 {
@@ -545,6 +550,7 @@ key_ssh_name(Key *k)
        }
        return "ssh-unknown";
 }
+
 u_int
 key_size(Key *k)
 {
@@ -668,7 +674,7 @@ key_names_valid2(const char *names)
 }
 
 Key *
-key_from_blob(u_char *blob, int blen)
+key_from_blob(u_char *blob, u_int blen)
 {
        Buffer b;
        char *ktype;
@@ -722,7 +728,6 @@ key_to_blob(Key *key, u_char **blobp, u_int *lenp)
 {
        Buffer b;
        int len;
-       u_char *buf;
 
        if (key == NULL) {
                error("key_to_blob: key == NULL");
@@ -748,14 +753,14 @@ key_to_blob(Key *key, u_char **blobp, u_int *lenp)
                return 0;
        }
        len = buffer_len(&b);
-       buf = xmalloc(len);
-       memcpy(buf, buffer_ptr(&b), len);
-       memset(buffer_ptr(&b), 0, len);
-       buffer_free(&b);
        if (lenp != NULL)
                *lenp = len;
-       if (blobp != NULL)
-               *blobp = buf;
+       if (blobp != NULL) {
+               *blobp = xmalloc(len);
+               memcpy(*blobp, buffer_ptr(&b), len);
+       }
+       memset(buffer_ptr(&b), 0, len);
+       buffer_free(&b);
        return len;
 }
 
@@ -779,6 +784,10 @@ key_sign(
        }
 }
 
+/*
+ * key_verify returns 1 for a correct signature, 0 for an incorrect signature
+ * and -1 on error.
+ */
 int
 key_verify(
     Key *key,
@@ -803,12 +812,11 @@ key_verify(
 }
 
 /* Converts a private to a public key */
-
 Key *
 key_demote(Key *k)
 {
        Key *pk;
-       
+
        pk = xmalloc(sizeof(*pk));
        pk->type = k->type;
        pk->flags = k->flags;
This page took 0.274698 seconds and 4 git commands to generate.