From: Dr. Stephen Henson Date: Sun, 14 Oct 2012 12:26:02 +0000 (+0000) Subject: optimize make_kn (from HEAD, by Andy) X-Git-Tag: OpenSSL-fips-2_0-pl1~7 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=82607b291f2e1ebf31fde8956b9d6cfbee060d30;p=oweals%2Fopenssl.git optimize make_kn (from HEAD, by Andy) --- diff --git a/crypto/cmac/cmac.c b/crypto/cmac/cmac.c index ccc7e7a3bd..5ff0fa7028 100644 --- a/crypto/cmac/cmac.c +++ b/crypto/cmac/cmac.c @@ -77,19 +77,17 @@ struct CMAC_CTX_st /* Make temporary keys K1 and K2 */ -static void make_kn(unsigned char *k1, unsigned char *l, int bl) +static void make_kn(unsigned char *k1, const unsigned char *l, int bl) { int i; + unsigned char c = l[0], carry = c>>7, cnext; + /* Shift block to left, including carry */ - for (i = 0; i < bl; i++) - { - k1[i] = l[i] << 1; - if (i < bl - 1 && l[i + 1] & 0x80) - k1[i] |= 1; - } + for (i = 0; i < bl-1; i++, c = cnext) + k1[i] = (c << 1) | ((cnext=l[i+1]) >> 7); + /* If MSB set fixup with R */ - if (l[0] & 0x80) - k1[bl - 1] ^= bl == 16 ? 0x87 : 0x1b; + k1[i] = (c << 1) ^ ((0-carry)&(bl==16?0x87:0x1b)); } CMAC_CTX *CMAC_CTX_new(void)