From 8d6d7a3615282248415696e281a17ac28096720e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 2 Jan 2019 22:01:38 +0000 Subject: [PATCH] Use a strbuf in ssh_ecdhkex_m_setup. This removes the one remaining failure at -Wvla. (Of course, that array isn't for a _hash_ function, so it wouldn't have been quite appropriate to make it a static array of size MAX_HASH_LEN.) --- sshecc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sshecc.c b/sshecc.c index 1e1fcc6f..5d898104 100644 --- a/sshecc.c +++ b/sshecc.c @@ -1269,15 +1269,15 @@ static void ssh_ecdhkex_w_setup(ecdh_key *dh) static void ssh_ecdhkex_m_setup(ecdh_key *dh) { - unsigned char bytes[dh->curve->fieldBytes]; - for (size_t i = 0; i < sizeof(bytes); ++i) - bytes[i] = random_byte(); + strbuf *bytes; + for (size_t i = 0; i < dh->curve->fieldBytes; ++i) + put_byte(bytes, random_byte()); - bytes[0] &= 0xF8; - bytes[dh->curve->fieldBytes-1] &= 0x7F; - bytes[dh->curve->fieldBytes-1] |= 0x40; - dh->private = mp_from_bytes_le(make_ptrlen(bytes, dh->curve->fieldBytes)); - smemclr(bytes, sizeof(bytes)); + bytes->u[0] &= 0xF8; + bytes->u[bytes->len-1] &= 0x7F; + bytes->u[bytes->len-1] |= 0x40; + dh->private = mp_from_bytes_le(ptrlen_from_strbuf(bytes)); + strbuf_free(bytes); dh->m_public = ecc_montgomery_multiply(dh->curve->m.G, dh->private); }