]> andersk Git - openssh.git/blobdiff - key.c
- (dtucker) Wrap use of IPPROTO_IPV6 in an ifdef for platforms that don't
[openssh.git] / key.c
diff --git a/key.c b/key.c
index 80ce855d867679b78f80f5ecfccb14f4583b53f3..f2edf6d5d56f725c8a3a1b72d7a7e39b86f2d44a 100644 (file)
--- a/key.c
+++ b/key.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key.c,v 1.71 2008/06/11 23:02:22 otto Exp $ */
+/* $OpenBSD: key.c,v 1.81 2009/12/11 18:16:33 markus Exp $ */
 /*
  * read_bignum():
  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -11,6 +11,7 @@
  *
  *
  * Copyright (c) 2000, 2001 Markus Friedl.  All rights reserved.
+ * Copyright (c) 2008 Alexander von Gernler.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -173,6 +174,7 @@ key_equal(const Key *a, const Key *b)
        default:
                fatal("key_equal: bad key type %d", a->type);
        }
+       /* NOTREACHED */
 }
 
 u_char*
@@ -319,21 +321,29 @@ key_fingerprint_bubblebabble(u_char *dgst_raw, u_int dgst_raw_len)
  * Graphs are not unambiguous, because circles in graphs can be
  * walked in either direction.
  */
-#define        FLDSIZE_Y        8
-#define        FLDSIZE_X       FLDSIZE_Y * 2
+
+/*
+ * Field sizes for the random art.  Have to be odd, so the starting point
+ * can be in the exact middle of the picture, and FLDBASE should be >=8 .
+ * Else pictures would be too dense, and drawing the frame would
+ * fail, too, because the key type would not fit in anymore.
+ */
+#define        FLDBASE         8
+#define        FLDSIZE_Y       (FLDBASE + 1)
+#define        FLDSIZE_X       (FLDBASE * 2 + 1)
 static char *
-key_fingerprint_randomart(u_char *dgst_raw, u_int dgst_raw_len)
+key_fingerprint_randomart(u_char *dgst_raw, u_int dgst_raw_len, const Key *k)
 {
        /*
         * Chars to be used after each other every time the worm
         * intersects with itself.  Matter of taste.
         */
-       char    *augmentation_string = " .o+=*BOX@%&#/^";
+       char    *augmentation_string = " .o+=*BOX@%&#/^SE";
        char    *retval, *p;
        u_char   field[FLDSIZE_X][FLDSIZE_Y];
        u_int    i, b;
        int      x, y;
-       size_t   len = strlen(augmentation_string);
+       size_t   len = strlen(augmentation_string) - 1;
 
        retval = xcalloc(1, (FLDSIZE_X + 3) * (FLDSIZE_Y + 2));
 
@@ -341,7 +351,6 @@ key_fingerprint_randomart(u_char *dgst_raw, u_int dgst_raw_len)
        memset(field, 0, FLDSIZE_X * FLDSIZE_Y * sizeof(char));
        x = FLDSIZE_X / 2;
        y = FLDSIZE_Y / 2;
-       field[x][y] = 1;
 
        /* process raw key */
        for (i = 0; i < dgst_raw_len; i++) {
@@ -360,17 +369,22 @@ key_fingerprint_randomart(u_char *dgst_raw, u_int dgst_raw_len)
                        y = MIN(y, FLDSIZE_Y - 1);
 
                        /* augment the field */
-                       field[x][y]++;
+                       if (field[x][y] < len - 2)
+                               field[x][y]++;
                        input = input >> 2;
                }
        }
 
+       /* mark starting point and end point*/
+       field[FLDSIZE_X / 2][FLDSIZE_Y / 2] = len - 1;
+       field[x][y] = len;
+
        /* fill in retval */
-       p = retval;
+       snprintf(retval, FLDSIZE_X, "+--[%4s %4u]", key_type(k), key_size(k));
+       p = strchr(retval, '\0');
 
        /* output upper border */
-       *p++ = '+';
-       for (i = 0; i < FLDSIZE_X; i++)
+       for (i = p - retval - 1; i < FLDSIZE_X; i++)
                *p++ = '-';
        *p++ = '+';
        *p++ = '\n';
@@ -379,7 +393,7 @@ key_fingerprint_randomart(u_char *dgst_raw, u_int dgst_raw_len)
        for (y = 0; y < FLDSIZE_Y; y++) {
                *p++ = '|';
                for (x = 0; x < FLDSIZE_X; x++)
-                       *p++ = augmentation_string[MIN(field[x][y], len - 1)];
+                       *p++ = augmentation_string[MIN(field[x][y], len)];
                *p++ = '|';
                *p++ = '\n';
        }
@@ -411,10 +425,10 @@ key_fingerprint(const Key *k, enum fp_type dgst_type, enum fp_rep dgst_rep)
                retval = key_fingerprint_bubblebabble(dgst_raw, dgst_raw_len);
                break;
        case SSH_FP_RANDOMART:
-               retval = key_fingerprint_randomart(dgst_raw, dgst_raw_len);
+               retval = key_fingerprint_randomart(dgst_raw, dgst_raw_len, k);
                break;
        default:
-               fatal("key_fingerprint_ex: bad digest representation %d",
+               fatal("key_fingerprint: bad digest representation %d",
                    dgst_rep);
                break;
        }
@@ -671,7 +685,7 @@ rsa_generate_private_key(u_int bits)
 {
        RSA *private;
 
-       private = RSA_generate_key(bits, 35, NULL, NULL);
+       private = RSA_generate_key(bits, RSA_F4, NULL, NULL);
        if (private == NULL)
                fatal("rsa_generate_private_key: key generation failed.");
        return private;
This page took 0.709238 seconds and 4 git commands to generate.