From 674299c346e4028068db22defb47ba631f0af51a Mon Sep 17 00:00:00 2001 From: Thomas Date: Mon, 13 Feb 2017 10:02:25 +0100 Subject: [PATCH] misc: use time constant implementation for AES CTR increment --- src/misc.c | 18 +++++++++++------- src/wincng.h | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/misc.c b/src/misc.c index 94904ab5..1bb938d1 100644 --- a/src/misc.c +++ b/src/misc.c @@ -662,12 +662,16 @@ void _libssh2_xor_data(unsigned char *output, void _libssh2_aes_ctr_increment(unsigned char *ctr, size_t length) { - if (length == 0) - return; - size_t i = (length - 1); - while (ctr[i]++ == 0xFF) { - if (i == 0) - break; - i--; + unsigned char *pc; + unsigned int val, carry; + + pc = ctr + length - 1; + carry = 1; + + while(pc >= ctr) + { + val = (unsigned int)*pc + carry; + *pc-- = val & 0xFF; + carry = val >> 8; } } diff --git a/src/wincng.h b/src/wincng.h index 4bb1067e..2d9c0614 100755 --- a/src/wincng.h +++ b/src/wincng.h @@ -302,7 +302,7 @@ struct _libssh2_wincng_cipher_ctx { struct _libssh2_wincng_cipher_type { BCRYPT_ALG_HANDLE *phAlg; unsigned long dwKeyLength; - int useIV; + int useIV; /* TODO: Convert to bool when a C89 compatible bool type is defined */ int ctrMode; };