summaryrefslogtreecommitdiffstats
path: root/crypto/cmac
diff options
context:
space:
mode:
authorAndy Polyakov <appro@openssl.org>2012-01-06 13:19:16 +0000
committerAndy Polyakov <appro@openssl.org>2012-01-06 13:19:16 +0000
commit03cf7e784caa4c61febbf249be63cbae3e368ac9 (patch)
tree4be73ae26ca8602bc1db7a63ae850d449bf64220 /crypto/cmac
parentce0727f9bdbca79d8548c46aad638ca0223b3b71 (diff)
cmac.c: optimize make_kn and move zero_iv to const segment.
Diffstat (limited to 'crypto/cmac')
-rw-r--r--crypto/cmac/cmac.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/crypto/cmac/cmac.c b/crypto/cmac/cmac.c
index 5807e30ddd..064b67d073 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)
@@ -143,7 +141,8 @@ int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in)
int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
const EVP_CIPHER *cipher, ENGINE *impl)
{
- static unsigned char zero_iv[EVP_MAX_BLOCK_LENGTH];
+ __fips_constseg
+ static const unsigned char zero_iv[EVP_MAX_BLOCK_LENGTH] = {0};
/* All zeros means restart */
if (!key && !cipher && !impl && keylen == 0)
{