1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32:48 -05:00

sshhmac.c: stop freeing/remaking persistent ssh_hash objects.

The h_outer, h_inner and h_live hash objects in the HMAC
implementation are now no longer freed and reallocated all the time.
Instead, they're reinitialised in place using the new ssh_hash_reset
and ssh_hash_copyfrom API functions.

This is partly a performance optimisation (malloc and free take time),
but also, it should fix an intermittent failure in the side-channel
test system 'testsc', which seems to be happening because of those
free/malloc pairs not happening the same way in successive runs. (In
other words, this didn't reflect a genuine side-channel leakage in the
actual crypto, only a failure of experimental control in the test.)
This commit is contained in:
Simon Tatham
2019-12-15 11:58:33 +00:00
parent 156762fc02
commit 3fd334b5ca
2 changed files with 3 additions and 31 deletions

View File

@ -1320,12 +1320,6 @@ static void test_mac(const ssh2_macalg *malg)
size_t maclen = malg->len;
uint8_t *data = snewn(datalen + maclen, uint8_t);
/* Preliminarily key the MAC, to avoid the divergence of control
* flow in which hmac_key() avoids some free()s the first time
* through */
random_read(mkey, malg->keylen);
ssh2_mac_setkey(m, make_ptrlen(mkey, malg->keylen));
for (size_t i = 0; i < looplimit(16); i++) {
random_read(mkey, malg->keylen);
random_read(data, datalen);