1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Simplify hashing operations in sshrsa.c and sshdss.c.

We can now simply call the centralised functions to put uint32s and
mpints into hash states, so there's no need to have duplicate local
copies doing the same things less type-generically.
This commit is contained in:
Simon Tatham 2018-05-24 09:42:02 +01:00
parent 0e3082ee89
commit f1b1b1d260
2 changed files with 7 additions and 51 deletions

View File

@ -9,34 +9,6 @@
#include "ssh.h"
#include "misc.h"
static void sha_mpint(SHA_State * s, Bignum b)
{
unsigned char lenbuf[4];
int len;
len = (bignum_bitcount(b) + 8) / 8;
PUT_32BIT(lenbuf, len);
SHA_Bytes(s, lenbuf, 4);
while (len-- > 0) {
lenbuf[0] = bignum_byte(b, len);
SHA_Bytes(s, lenbuf, 1);
}
smemclr(lenbuf, sizeof(lenbuf));
}
static void sha512_mpint(SHA512_State * s, Bignum b)
{
unsigned char lenbuf[4];
int len;
len = (bignum_bitcount(b) + 8) / 8;
PUT_32BIT(lenbuf, len);
SHA512_Bytes(s, lenbuf, 4);
while (len-- > 0) {
lenbuf[0] = bignum_byte(b, len);
SHA512_Bytes(s, lenbuf, 1);
}
smemclr(lenbuf, sizeof(lenbuf));
}
static void getstring(const char **data, int *datalen,
const char **p, int *length)
{
@ -395,9 +367,9 @@ static void *dss_createkey(const struct ssh_signkey *self,
getstring(&pb, &priv_len, &hash, &hashlen);
if (hashlen == 20) {
SHA_Init(&s);
sha_mpint(&s, dss->p);
sha_mpint(&s, dss->q);
sha_mpint(&s, dss->g);
put_mp_ssh2(&s, dss->p);
put_mp_ssh2(&s, dss->q);
put_mp_ssh2(&s, dss->g);
SHA_Final(&s, digest);
if (0 != memcmp(hash, digest, 20)) {
dss_freekey(dss);
@ -569,7 +541,7 @@ Bignum *dss_gen_k(const char *id_string, Bignum modulus, Bignum private_key,
*/
SHA512_Init(&ss);
SHA512_Bytes(&ss, id_string, strlen(id_string) + 1);
sha512_mpint(&ss, private_key);
put_mp_ssh2(&ss, private_key);
SHA512_Final(&ss, digest512);
/*

View File

@ -94,20 +94,6 @@ int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key)
return 1;
}
static void sha512_mpint(SHA512_State * s, Bignum b)
{
unsigned char lenbuf[4];
int len;
len = (bignum_bitcount(b) + 8) / 8;
PUT_32BIT(lenbuf, len);
SHA512_Bytes(s, lenbuf, 4);
while (len-- > 0) {
lenbuf[0] = bignum_byte(b, len);
SHA512_Bytes(s, lenbuf, 1);
}
smemclr(lenbuf, sizeof(lenbuf));
}
/*
* Compute (base ^ exp) % mod, provided mod == p * q, with p,q
* distinct primes, and iqmp is the multiplicative inverse of q mod p.
@ -232,12 +218,10 @@ static Bignum rsa_privkey_op(Bignum input, struct RSAKey *key)
* byte = random_byte();
*/
if (digestused >= lenof(digest512)) {
unsigned char seqbuf[4];
PUT_32BIT(seqbuf, hashseq);
SHA512_Init(&ss);
SHA512_Bytes(&ss, "RSA deterministic blinding", 26);
SHA512_Bytes(&ss, seqbuf, sizeof(seqbuf));
sha512_mpint(&ss, key->private_exponent);
put_uint32(&ss, hashseq);
put_mp_ssh2(&ss, key->private_exponent);
SHA512_Final(&ss, digest512);
hashseq++;
@ -247,7 +231,7 @@ static Bignum rsa_privkey_op(Bignum input, struct RSAKey *key)
*/
SHA512_Init(&ss);
SHA512_Bytes(&ss, digest512, sizeof(digest512));
sha512_mpint(&ss, input);
put_mp_ssh2(&ss, input);
SHA512_Final(&ss, digest512);
digestused = 0;