X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=sshrsa.c;h=e565a64ac791ff7be104a17f27814f4962f32fc7;hb=7fd8915ce9dabd124ee10374c33449ad912b607c;hp=3adccfbef1d43eb9fc0787b7e7537ca26d60488a;hpb=bcfcb169efab1587a7cebcffff9efbf9ccac8ce8;p=PuTTY.git diff --git a/sshrsa.c b/sshrsa.c index 3adccfbe..e565a64a 100644 --- a/sshrsa.c +++ b/sshrsa.c @@ -565,7 +565,8 @@ static Bignum getmp(const char **data, int *datalen) static void rsa2_freekey(void *key); /* forward reference */ -static void *rsa2_newkey(const char *data, int len) +static void *rsa2_newkey(const struct ssh_signkey *self, + const char *data, int len) { const char *p; int slen; @@ -685,13 +686,14 @@ static unsigned char *rsa2_private_blob(void *key, int *len) return blob; } -static void *rsa2_createkey(const unsigned char *pub_blob, int pub_len, +static void *rsa2_createkey(const struct ssh_signkey *self, + const unsigned char *pub_blob, int pub_len, const unsigned char *priv_blob, int priv_len) { struct RSAKey *rsa; const char *pb = (const char *) priv_blob; - rsa = rsa2_newkey((char *) pub_blob, pub_len); + rsa = rsa2_newkey(self, (char *) pub_blob, pub_len); rsa->private_exponent = getmp(&pb, &priv_len); rsa->p = getmp(&pb, &priv_len); rsa->q = getmp(&pb, &priv_len); @@ -705,7 +707,8 @@ static void *rsa2_createkey(const unsigned char *pub_blob, int pub_len, return rsa; } -static void *rsa2_openssh_createkey(const unsigned char **blob, int *len) +static void *rsa2_openssh_createkey(const struct ssh_signkey *self, + const unsigned char **blob, int *len) { const char **b = (const char **) blob; struct RSAKey *rsa; @@ -763,53 +766,21 @@ static int rsa2_openssh_fmtkey(void *key, unsigned char *blob, int len) return bloblen; } -static int rsa2_pubkey_bits(const void *blob, int len) +static int rsa2_pubkey_bits(const struct ssh_signkey *self, + const void *blob, int len) { struct RSAKey *rsa; int ret; - rsa = rsa2_newkey((const char *) blob, len); + rsa = rsa2_newkey(self, (const char *) blob, len); + if (!rsa) + return -1; ret = bignum_bitcount(rsa->modulus); rsa2_freekey(rsa); return ret; } -static char *rsa2_fingerprint(void *key) -{ - struct RSAKey *rsa = (struct RSAKey *) key; - struct MD5Context md5c; - unsigned char digest[16], lenbuf[4]; - char buffer[16 * 3 + 40]; - char *ret; - int numlen, i; - - MD5Init(&md5c); - MD5Update(&md5c, (unsigned char *)"\0\0\0\7ssh-rsa", 11); - -#define ADD_BIGNUM(bignum) \ - numlen = (bignum_bitcount(bignum)+8)/8; \ - PUT_32BIT(lenbuf, numlen); MD5Update(&md5c, lenbuf, 4); \ - for (i = numlen; i-- ;) { \ - unsigned char c = bignum_byte(bignum, i); \ - MD5Update(&md5c, &c, 1); \ - } - ADD_BIGNUM(rsa->exponent); - ADD_BIGNUM(rsa->modulus); -#undef ADD_BIGNUM - - MD5Final(digest, &md5c); - - sprintf(buffer, "ssh-rsa %d ", bignum_bitcount(rsa->modulus)); - for (i = 0; i < 16; i++) - sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "", - digest[i]); - ret = snewn(strlen(buffer) + 1, char); - if (ret) - strcpy(ret, buffer); - return ret; -} - /* * This is the magic ASN.1/DER prefix that goes in the decoded * signature, between the string of FFs and the actual SHA hash @@ -945,16 +916,16 @@ const struct ssh_signkey ssh_rsa = { rsa2_openssh_fmtkey, 6 /* n,e,d,iqmp,q,p */, rsa2_pubkey_bits, - rsa2_fingerprint, rsa2_verifysig, rsa2_sign, "ssh-rsa", - "rsa2" + "rsa2", + NULL, }; void *ssh_rsakex_newkey(char *data, int len) { - return rsa2_newkey(data, len); + return rsa2_newkey(&ssh_rsa, data, len); } void ssh_rsakex_freekey(void *key) @@ -1089,11 +1060,11 @@ void ssh_rsakex_encrypt(const struct ssh_hash *h, unsigned char *in, int inlen, } static const struct ssh_kex ssh_rsa_kex_sha1 = { - "rsa1024-sha1", NULL, KEXTYPE_RSA, NULL, NULL, 0, 0, &ssh_sha1 + "rsa1024-sha1", NULL, KEXTYPE_RSA, &ssh_sha1, NULL, }; static const struct ssh_kex ssh_rsa_kex_sha256 = { - "rsa2048-sha256", NULL, KEXTYPE_RSA, NULL, NULL, 0, 0, &ssh_sha256 + "rsa2048-sha256", NULL, KEXTYPE_RSA, &ssh_sha256, NULL, }; static const struct ssh_kex *const rsa_kex_list[] = {