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

Remove obsolete functions.

There are several old functions that the previous commits have removed
all, or nearly all, of the references to. match_ssh_id is superseded
by ptrlen_eq_string; get_ssh_{string,uint32} is yet another replicated
set of decode functions (this time _partly_ centralised into misc.c);
the old APIs for the SSH-1 RSA decode functions are gone (together
with their last couple of holdout clients), as are
ssh{1,2}_{read,write}_bignum and ssh{1,2}_bignum_length.

Particularly odd was the use of ssh1_{read,write}_bignum in the SSH-2
Diffie-Hellman implementation. I'd completely forgotten I did that!
Now replaced with a raw bignum_from_bytes, which is simpler anyway.
This commit is contained in:
Simon Tatham 2018-05-29 20:36:21 +01:00
parent 4d8c033596
commit 6dc6392596
8 changed files with 12 additions and 180 deletions

View File

@ -807,30 +807,13 @@ int main(int argc, char **argv)
ssh1key = snew(struct RSAKey);
if (!load_encrypted) {
strbuf *blob;
int n, l;
BinarySource src[1];
blob = strbuf_new();
ret = rsa_ssh1_loadpub(infilename, BinarySink_UPCAST(blob),
&origcomment, &error);
n = 4; /* skip modulus bits */
l = ssh1_read_bignum(blob->u + n,
blob->len - n,
&ssh1key->exponent);
if (l < 0) {
error = "SSH-1 public key blob was too short";
} else {
n += l;
l = ssh1_read_bignum(
blob->u + n,
blob->len - n, &ssh1key->modulus);
if (l < 0) {
error = "SSH-1 public key blob was too short";
} else
n += l;
}
BinarySource_BARE_INIT(src, blob->u, blob->len);
get_rsa_ssh1_pub(src, ssh1key, NULL, RSA_SSH1_EXPONENT_FIRST);
strbuf_free(blob);
ssh1key->comment = dupstr(origcomment);

33
misc.c
View File

@ -1181,12 +1181,6 @@ int smemeq(const void *av, const void *bv, size_t len)
return (0x100 - val) >> 8;
}
int match_ssh_id(int stringlen, const void *string, const char *id)
{
int idlen = strlen(id);
return (idlen == stringlen && !memcmp(string, id, idlen));
}
ptrlen make_ptrlen(const void *ptr, size_t len)
{
ptrlen pl;
@ -1209,33 +1203,6 @@ char *mkstr(ptrlen pl)
return p;
}
void *get_ssh_string(int *datalen, const void **data, int *stringlen)
{
void *ret;
unsigned int len;
if (*datalen < 4)
return NULL;
len = GET_32BIT_MSB_FIRST((const unsigned char *)*data);
if (*datalen - 4 < len)
return NULL;
ret = (void *)((const char *)*data + 4);
*datalen -= len + 4;
*data = (const char *)*data + len + 4;
*stringlen = len;
return ret;
}
int get_ssh_uint32(int *datalen, const void **data, unsigned *ret)
{
if (*datalen < 4)
return FALSE;
*ret = GET_32BIT_MSB_FIRST((const unsigned char *)*data);
*datalen -= 4;
*data = (const char *)*data + 4;
return TRUE;
}
int strstartswith(const char *s, const char *t)
{
return !memcmp(s, t, strlen(t));

17
misc.h
View File

@ -109,23 +109,6 @@ void smemclr(void *b, size_t len);
* by the 'eq' in the name. */
int smemeq(const void *av, const void *bv, size_t len);
/* Extracts an SSH-marshalled string from the start of *data. If
* successful (*datalen is not too small), advances data/datalen past
* the string and returns a pointer to the string itself and its
* length in *stringlen. Otherwise does nothing and returns NULL.
*
* Like strchr, this function can discard const from its parameter.
* Treat it as if it was a family of two functions, one returning a
* non-const string given a non-const pointer, and one taking and
* returning const. */
void *get_ssh_string(int *datalen, const void **data, int *stringlen);
/* Extracts an SSH uint32, similarly. Returns TRUE on success, and
* leaves the extracted value in *ret. */
int get_ssh_uint32(int *datalen, const void **data, unsigned *ret);
/* Given a not-necessarily-zero-terminated string in (length,data)
* form, check if it equals an ordinary C zero-terminated string. */
int match_ssh_id(int stringlen, const void *string, const char *id);
char *buildinfo(const char *newline);
/*

8
ssh.h
View File

@ -180,13 +180,9 @@ struct ec_point *ec_public(const Bignum privateKey, const struct ec_curve *curve
*/
typedef enum { RSA_SSH1_EXPONENT_FIRST, RSA_SSH1_MODULUS_FIRST } RsaSsh1Order;
int rsa_ssh1_readpub(const unsigned char *data, int len, struct RSAKey *result,
const unsigned char **keystr, RsaSsh1Order order);
void BinarySource_get_rsa_ssh1_pub(
BinarySource *src, struct RSAKey *result,
ptrlen *keystr, RsaSsh1Order order);
int rsa_ssh1_readpriv(const unsigned char *data, int len,
struct RSAKey *result);
void BinarySource_get_rsa_ssh1_priv(
BinarySource *src, struct RSAKey *rsa);
int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key);
@ -667,14 +663,10 @@ extern Bignum Zero, One;
Bignum bignum_from_bytes(const void *data, int nbytes);
Bignum bignum_from_bytes_le(const void *data, int nbytes);
Bignum bignum_random_in_range(const Bignum lower, const Bignum upper);
int ssh1_read_bignum(const unsigned char *data, int len, Bignum * result);
int bignum_bitcount(Bignum bn);
int ssh1_bignum_length(Bignum bn);
int ssh2_bignum_length(Bignum bn);
int bignum_byte(Bignum bn, int i);
int bignum_bit(Bignum bn, int i);
void bignum_set_bit(Bignum bn, int i, int value);
int ssh1_write_bignum(void *data, Bignum bn);
Bignum biggcd(Bignum a, Bignum b);
unsigned short bignum_mod_short(Bignum number, unsigned short modulus);
Bignum bignum_add_long(Bignum number, unsigned long addend);

65
sshbn.c
View File

@ -1509,36 +1509,7 @@ Bignum bignum_random_in_range(const Bignum lower, const Bignum upper)
}
/*
* Read an SSH-1-format bignum from a data buffer. Return the number
* of bytes consumed, or -1 if there wasn't enough data.
*/
int ssh1_read_bignum(const unsigned char *data, int len, Bignum * result)
{
const unsigned char *p = data;
int i;
int w, b;
if (len < 2)
return -1;
w = 0;
for (i = 0; i < 2; i++)
w = (w << 8) + *p++;
b = (w + 7) / 8; /* bits -> bytes */
if (len < b+2)
return -1;
if (!result) /* just return length */
return b + 2;
*result = bignum_from_bytes(p, b);
return p + b - data;
}
/*
* Return the bit count of a bignum, for SSH-1 encoding.
* Return the bit count of a bignum.
*/
int bignum_bitcount(Bignum bn)
{
@ -1548,22 +1519,6 @@ int bignum_bitcount(Bignum bn)
return bitcount + 1;
}
/*
* Return the byte length of a bignum when SSH-1 encoded.
*/
int ssh1_bignum_length(Bignum bn)
{
return 2 + (bignum_bitcount(bn) + 7) / 8;
}
/*
* Return the byte length of a bignum when SSH-2 encoded.
*/
int ssh2_bignum_length(Bignum bn)
{
return 4 + (bignum_bitcount(bn) + 8) / 8;
}
/*
* Return a byte from a bignum; 0 is least significant, etc.
*/
@ -1604,24 +1559,6 @@ void bignum_set_bit(Bignum bn, int bitnum, int value)
}
}
/*
* Write a SSH-1-format bignum into a buffer. It is assumed the
* buffer is big enough. Returns the number of bytes used.
*/
int ssh1_write_bignum(void *data, Bignum bn)
{
unsigned char *p = data;
int len = ssh1_bignum_length(bn);
int i;
int bitc = bignum_bitcount(bn);
*p++ = (bitc >> 8) & 0xFF;
*p++ = (bitc) & 0xFF;
for (i = len - 2; i--;)
*p++ = bignum_byte(bn, i);
return len;
}
void BinarySink_put_mp_ssh1(BinarySink *bs, Bignum bn)
{
int bits = bignum_bitcount(bn);

View File

@ -247,7 +247,7 @@ Bignum dh_create_e(void *handle, int nbits)
int nbytes;
unsigned char *buf;
nbytes = ssh1_bignum_length(ctx->qmask);
nbytes = (bignum_bitcount(ctx->qmask) + 7) / 8;
buf = snewn(nbytes, unsigned char);
do {
@ -258,10 +258,9 @@ Bignum dh_create_e(void *handle, int nbits)
if (ctx->x)
freebn(ctx->x);
if (nbits == 0 || nbits > bignum_bitcount(ctx->qmask)) {
ssh1_write_bignum(buf, ctx->qmask);
for (i = 2; i < nbytes; i++)
buf[i] &= random_byte();
ssh1_read_bignum(buf, nbytes, &ctx->x); /* can't fail */
for (i = 0; i < nbytes; i++)
buf[i] = bignum_byte(ctx->qmask, i) & random_byte();
ctx->x = bignum_from_bytes(buf, nbytes);
} else {
int b, nb;
ctx->x = bn_power_2(nbits);

View File

@ -47,44 +47,12 @@ void BinarySource_get_rsa_ssh1_pub(
}
}
int rsa_ssh1_readpub(const unsigned char *data, int len, struct RSAKey *result,
const unsigned char **keystr, RsaSsh1Order order)
{
BinarySource src;
ptrlen key_pl;
BinarySource_BARE_INIT(&src, data, len);
get_rsa_ssh1_pub(&src, result, &key_pl, order);
if (keystr)
*keystr = key_pl.ptr;
if (get_err(&src))
return -1;
else
return key_pl.len;
}
void BinarySource_get_rsa_ssh1_priv(
BinarySource *src, struct RSAKey *rsa)
{
rsa->private_exponent = get_mp_ssh1(src);
}
int rsa_ssh1_readpriv(const unsigned char *data, int len,
struct RSAKey *result)
{
BinarySource src;
BinarySource_BARE_INIT(&src, data, len);
get_rsa_ssh1_priv(&src, result);
if (get_err(&src))
return -1;
else
return src.pos;
}
int rsa_ssh1_encrypt(unsigned char *data, int length, struct RSAKey *key)
{
Bignum b1, b2;

View File

@ -701,10 +701,13 @@ void run_client(void)
FILE *fp = stdout; /* FIXME: add a -o option? */
if (key->ssh_version == 1) {
BinarySource src[1];
struct RSAKey rkey;
BinarySource_BARE_INIT(src, key->blob->u, key->blob->len);
memset(&rkey, 0, sizeof(rkey));
rkey.comment = dupstr(key->comment);
rsa_ssh1_readpub(key->blob->u, key->blob->len, &rkey, NULL,
get_rsa_ssh1_pub(src, &rkey, NULL,
RSA_SSH1_EXPONENT_FIRST);
ssh1_write_pubkey(fp, &rkey);
freersakey(&rkey);