From 74d4a07adeb79460caa5a14cb5d3d8e12c1d90ff Mon Sep 17 00:00:00 2001 From: Zhi Guan Date: Fri, 6 Jul 2018 23:07:32 +0800 Subject: [PATCH] optimize zuc about 15% faster on 64-bit cpu --- crypto/zuc/zuc_core.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crypto/zuc/zuc_core.c b/crypto/zuc/zuc_core.c index a4cc8367..244667f6 100644 --- a/crypto/zuc/zuc_core.c +++ b/crypto/zuc/zuc_core.c @@ -124,6 +124,24 @@ static const uint8_t S1[256] = { {int j; for (j=0; j<15;j++) LFSR[j]=LFSR[j+1];} \ LFSR[15] = V +/* FIXME: check if uint64_t is supported */ +#if 1 +#define LFSRWithWorkMode() \ + { \ + int j; \ + uint64_t a = LFSR[0]; \ + a += ((uint64_t)LFSR[0]) << 8; \ + a += ((uint64_t)LFSR[4]) << 20; \ + a += ((uint64_t)LFSR[10]) << 21; \ + a += ((uint64_t)LFSR[13]) << 17; \ + a += ((uint64_t)LFSR[15]) << 15; \ + a = (a & 0x7fffffff) + (a >> 31); \ + a = (a & 0x7fffffff) + (a >> 31); \ + for (j = 0; j < 15; j++) \ + LFSR[j] = LFSR[j+1]; \ + LFSR[15] = a; \ + } +#else #define LFSRWithWorkMode() \ V = LFSR[0]; \ ADD31(V, ROT31(LFSR[0], 8)); \ @@ -133,6 +151,7 @@ static const uint8_t S1[256] = { ADD31(V, ROT31(LFSR[15], 15)); \ {int j; for (j=0; j<15;j++) LFSR[j]=LFSR[j+1];} \ LFSR[15] = V +#endif #define BitReconstruction2(X1,X2) \ X1 = ((LFSR[11] & 0xFFFF) << 16) | (LFSR[9] >> 15); \ @@ -176,6 +195,7 @@ static const uint8_t S1[256] = { (X0 ^ R1) + R2; \ F_(X1, X2) + void ZUC_set_key(ZUC_KEY *key, const unsigned char *user_key, const unsigned char *iv) { ZUC_UINT31 *LFSR = key->LFSR;