summaryrefslogtreecommitdiffstats
path: root/crypto/openssh/key.c
diff options
context:
space:
mode:
authorkris <kris@FreeBSD.org>2000-09-10 08:31:17 +0000
committerkris <kris@FreeBSD.org>2000-09-10 08:31:17 +0000
commit0ca2bdc2f755d323cf97966ca69c4d32b283070a (patch)
treec42b17e610c0f98d5a0dda76cbd9035109d60303 /crypto/openssh/key.c
parent3639dd9acea182e29b2d59915fbb97029217d9b2 (diff)
downloadFreeBSD-src-0ca2bdc2f755d323cf97966ca69c4d32b283070a.zip
FreeBSD-src-0ca2bdc2f755d323cf97966ca69c4d32b283070a.tar.gz
Initial import of OpenSSH post-2.2.0 snapshot dated 2000-09-09
Diffstat (limited to 'crypto/openssh/key.c')
-rw-r--r--crypto/openssh/key.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/crypto/openssh/key.c b/crypto/openssh/key.c
index d474f85..f7df0bb 100644
--- a/crypto/openssh/key.c
+++ b/crypto/openssh/key.c
@@ -1,4 +1,14 @@
/*
+ * read_bignum():
+ * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
+ *
+ * As far as I am concerned, the code I have written for this software
+ * can be used freely for any purpose. Any derived versions of this
+ * software must be clearly marked as such, and if the derived work is
+ * incompatible with the protocol description in the RFC file, it must be
+ * called by a name other than "ssh" or "Secure Shell".
+ *
+ *
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -9,11 +19,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Markus Friedl.
- * 4. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -26,10 +31,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/*
- * read_bignum():
- * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
- */
#include "includes.h"
#include "ssh.h"
@@ -41,6 +42,8 @@
#include "dsa.h"
#include "uuencode.h"
+RCSID("$OpenBSD: key.c,v 1.11 2000/09/07 20:27:51 deraadt Exp $");
+
#define SSH_DSS "ssh-dss"
Key *
@@ -121,8 +124,6 @@ key_equal(Key *a, Key *b)
return 0;
}
-#define FPRINT "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x"
-
/*
* Generate key fingerprint in ascii format.
* Based on ideas and code from Bjoern Groenvall <bg@sics.se>
@@ -130,7 +131,7 @@ key_equal(Key *a, Key *b)
char *
key_fingerprint(Key *k)
{
- static char retval[80];
+ static char retval[(EVP_MAX_MD_SIZE+1)*3];
unsigned char *blob = NULL;
int len = 0;
int nlen, elen;
@@ -151,15 +152,22 @@ key_fingerprint(Key *k)
fatal("key_fingerprint: bad key type %d", k->type);
break;
}
+ retval[0] = '\0';
+
if (blob != NULL) {
- unsigned char d[16];
- EVP_MD_CTX md;
- EVP_DigestInit(&md, EVP_md5());
- EVP_DigestUpdate(&md, blob, len);
- EVP_DigestFinal(&md, d, NULL);
- snprintf(retval, sizeof(retval), FPRINT,
- d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7],
- d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
+ int i;
+ unsigned char digest[EVP_MAX_MD_SIZE];
+ EVP_MD *md = EVP_md5();
+ EVP_MD_CTX ctx;
+ EVP_DigestInit(&ctx, md);
+ EVP_DigestUpdate(&ctx, blob, len);
+ EVP_DigestFinal(&ctx, digest, NULL);
+ for(i = 0; i < md->md_size; i++) {
+ char hex[4];
+ snprintf(hex, sizeof(hex), "%02x:", digest[i]);
+ strlcat(retval, hex, sizeof(retval));
+ }
+ retval[strlen(retval) - 1] = '\0';
memset(blob, 0, len);
xfree(blob);
}
@@ -328,3 +336,15 @@ key_type(Key *k)
}
return "unknown";
}
+unsigned int
+key_size(Key *k){
+ switch (k->type) {
+ case KEY_RSA:
+ return BN_num_bits(k->rsa->n);
+ break;
+ case KEY_DSA:
+ return BN_num_bits(k->dsa->p);
+ break;
+ }
+ return 0;
+}
OpenPOWER on IntegriCloud