optimize zuc

about 15% faster on 64-bit cpu
This commit is contained in:
Zhi Guan
2018-07-06 23:07:32 +08:00
parent afb82ebc20
commit 74d4a07ade

View File

@@ -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;