X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/7bedb13c064e90654b709137a01c6feaee7a3abe..51e9d3c00a3471f284e89ec1f59f38ca25f10c5f:/sshdss.c diff --git a/sshdss.c b/sshdss.c index 7022a6e2..41974c23 100644 --- a/sshdss.c +++ b/sshdss.c @@ -5,18 +5,6 @@ #include "ssh.h" #include "misc.h" -#define GET_32BIT(cp) \ - (((unsigned long)(unsigned char)(cp)[0] << 24) | \ - ((unsigned long)(unsigned char)(cp)[1] << 16) | \ - ((unsigned long)(unsigned char)(cp)[2] << 8) | \ - ((unsigned long)(unsigned char)(cp)[3])) - -#define PUT_32BIT(cp, value) { \ - (cp)[0] = (unsigned char)((value) >> 24); \ - (cp)[1] = (unsigned char)((value) >> 16); \ - (cp)[2] = (unsigned char)((value) >> 8); \ - (cp)[3] = (unsigned char)(value); } - static void sha_mpint(SHA_State * s, Bignum b) { unsigned char lenbuf[4]; @@ -70,7 +58,7 @@ static Bignum getmp(char **data, int *datalen) return NULL; if (p[0] & 0x80) return NULL; /* negative mp */ - b = bignum_from_bytes(p, length); + b = bignum_from_bytes((unsigned char *)p, length); return b; } @@ -78,7 +66,7 @@ static Bignum get160(char **data, int *datalen) { Bignum b; - b = bignum_from_bytes(*data, 20); + b = bignum_from_bytes((unsigned char *)*data, 20); *data += 20; *datalen -= 20; @@ -91,7 +79,7 @@ static void *dss_newkey(char *data, int len) int slen; struct dss_key *dss; - dss = smalloc(sizeof(struct dss_key)); + dss = snew(struct dss_key); if (!dss) return NULL; getstring(&data, &len, &p, &slen); @@ -141,7 +129,7 @@ static char *dss_fmtkey(void *key) len += 4 * (bignum_bitcount(dss->q) + 15) / 16; len += 4 * (bignum_bitcount(dss->g) + 15) / 16; len += 4 * (bignum_bitcount(dss->y) + 15) / 16; - p = smalloc(len); + p = snewn(len, char); if (!p) return NULL; @@ -188,7 +176,7 @@ static char *dss_fingerprint(void *key) int numlen, i; MD5Init(&md5c); - MD5Update(&md5c, "\0\0\0\7ssh-dss", 11); + MD5Update(&md5c, (unsigned char *)"\0\0\0\7ssh-dss", 11); #define ADD_BIGNUM(bignum) \ numlen = (bignum_bitcount(bignum)+8)/8; \ @@ -209,7 +197,7 @@ static char *dss_fingerprint(void *key) for (i = 0; i < 16; i++) sprintf(buffer + strlen(buffer), "%s%02x", i ? ":" : "", digest[i]); - ret = smalloc(strlen(buffer) + 1); + ret = snewn(strlen(buffer) + 1, char); if (ret) strcpy(ret, buffer); return ret; @@ -268,7 +256,7 @@ static int dss_verifysig(void *key, char *sig, int siglen, /* * Step 2. u1 <- SHA(message) * w mod q. */ - SHA_Simple(data, datalen, hash); + SHA_Simple(data, datalen, (unsigned char *)hash); p = hash; slen = 20; sha = get160(&p, &slen); @@ -322,7 +310,7 @@ static unsigned char *dss_public_blob(void *key, int *len) * 27 + sum of lengths. (five length fields, 20+7=27). */ bloblen = 27 + plen + qlen + glen + ylen; - blob = smalloc(bloblen); + blob = snewn(bloblen, unsigned char); p = blob; PUT_32BIT(p, 7); p += 4; @@ -355,8 +343,6 @@ static unsigned char *dss_private_blob(void *key, int *len) int xlen, bloblen; int i; unsigned char *blob, *p; - SHA_State s; - unsigned char digest[20]; xlen = (bignum_bitcount(dss->x) + 8) / 8; @@ -364,7 +350,7 @@ static unsigned char *dss_private_blob(void *key, int *len) * mpint x, string[20] the SHA of p||q||g. Total 4 + xlen. */ bloblen = 4 + xlen; - blob = smalloc(bloblen); + blob = snewn(bloblen, unsigned char); p = blob; PUT_32BIT(p, xlen); p += 4; @@ -424,7 +410,7 @@ static void *dss_openssh_createkey(unsigned char **blob, int *len) char **b = (char **) blob; struct dss_key *dss; - dss = smalloc(sizeof(struct dss_key)); + dss = snew(struct dss_key); if (!dss) return NULL; @@ -475,7 +461,19 @@ static int dss_openssh_fmtkey(void *key, unsigned char *blob, int len) return bloblen; } -unsigned char *dss_sign(void *key, char *data, int datalen, int *siglen) +static int dss_pubkey_bits(void *blob, int len) +{ + struct dss_key *dss; + int ret; + + dss = dss_newkey((char *) blob, len); + ret = bignum_bitcount(dss->p); + dss_freekey(dss); + + return ret; +} + +static unsigned char *dss_sign(void *key, char *data, int datalen, int *siglen) { /* * The basic DSS signing algorithm is: @@ -608,7 +606,7 @@ unsigned char *dss_sign(void *key, char *data, int datalen, int *siglen) * i.e. 4+7 + 4+40 bytes. */ nbytes = 4 + 7 + 4 + 40; - bytes = smalloc(nbytes); + bytes = snewn(nbytes, unsigned char); PUT_32BIT(bytes, 7); memcpy(bytes + 4, "ssh-dss", 7); PUT_32BIT(bytes + 4 + 7, 40); @@ -632,6 +630,7 @@ const struct ssh_signkey ssh_dss = { dss_createkey, dss_openssh_createkey, dss_openssh_fmtkey, + dss_pubkey_bits, dss_fingerprint, dss_verifysig, dss_sign,