zuc: reduce one XOR & rename one function

This commit is contained in:
Sun Yimin 2022-07-05 12:34:49 +08:00 committed by GitHub
parent 83c6a58365
commit 08d5d28bae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 10 deletions

View File

@ -40,8 +40,8 @@ DATA Aes_to_Zuc_mul_high_nibble<>+0x00(SB)/8, $0xA174A97CDD08D500
DATA Aes_to_Zuc_mul_high_nibble<>+0x08(SB)/8, $0x3DE835E04194499C DATA Aes_to_Zuc_mul_high_nibble<>+0x08(SB)/8, $0x3DE835E04194499C
GLOBL Aes_to_Zuc_mul_high_nibble<>(SB), RODATA, $16 GLOBL Aes_to_Zuc_mul_high_nibble<>(SB), RODATA, $16
DATA Comb_matrix_mul_low_nibble<>+0x00(SB)/8, $0x9A8E3024EBFF4155 DATA Comb_matrix_mul_low_nibble<>+0x00(SB)/8, $0xCFDB6571BEAA1400
DATA Comb_matrix_mul_low_nibble<>+0x08(SB)/8, $0x2D3987935C48F6E2 DATA Comb_matrix_mul_low_nibble<>+0x08(SB)/8, $0x786CD2C6091DA3B7
GLOBL Comb_matrix_mul_low_nibble<>(SB), RODATA, $16 GLOBL Comb_matrix_mul_low_nibble<>(SB), RODATA, $16
DATA Comb_matrix_mul_high_nibble<>+0x00(SB)/8, $0x638CFA1523CCBA55 DATA Comb_matrix_mul_high_nibble<>+0x00(SB)/8, $0x638CFA1523CCBA55
@ -148,8 +148,7 @@ GLOBL flip_mask<>(SB), RODATA, $16
\ \
MOVOU Comb_matrix_mul_low_nibble<>(SB), XTMP1 \ MOVOU Comb_matrix_mul_low_nibble<>(SB), XTMP1 \
MOVOU Comb_matrix_mul_high_nibble<>(SB), XIN_OUT \ MOVOU Comb_matrix_mul_high_nibble<>(SB), XIN_OUT \
MUL_PSHUFB_SSE(XTMP2, XTMP1, XIN_OUT, XTMP3) \ MUL_PSHUFB_SSE(XTMP2, XTMP1, XIN_OUT, XTMP3)
PXOR Const_comb_matrix<>(SB), XIN_OUT
#define Rotl_5_AVX(XDATA, XTMP0) \ #define Rotl_5_AVX(XDATA, XTMP0) \
@ -200,9 +199,7 @@ GLOBL flip_mask<>(SB), RODATA, $16
VAESENCLAST Cancel_aes<>(SB), XTMP2, XTMP2 \ VAESENCLAST Cancel_aes<>(SB), XTMP2, XTMP2 \
VMOVDQU Comb_matrix_mul_low_nibble<>(SB), XTMP1 \ VMOVDQU Comb_matrix_mul_low_nibble<>(SB), XTMP1 \
VMOVDQU Comb_matrix_mul_high_nibble<>(SB), XIN_OUT \ VMOVDQU Comb_matrix_mul_high_nibble<>(SB), XIN_OUT \
MUL_PSHUFB_AVX(XTMP2, XTMP1, XIN_OUT, XTMP3) \ MUL_PSHUFB_AVX(XTMP2, XTMP1, XIN_OUT, XTMP3)
VPXOR Const_comb_matrix<>(SB), XIN_OUT, XIN_OUT
// BITS_REORG(idx) // BITS_REORG(idx)
// params // params

View File

@ -25,7 +25,7 @@ func NewEEACipher(key []byte, count, bearer, direction uint32) (cipher.Stream, e
return newZUCState(key, iv) return newZUCState(key, iv)
} }
func genericXorKeyStream(c *zucState32, dst, src []byte) { func xorKeyStreamGeneric(c *zucState32, dst, src []byte) {
words := (len(src) + 3) / 4 words := (len(src) + 3) / 4
rounds := words / RoundWords rounds := words / RoundWords
var keyWords [RoundWords]uint32 var keyWords [RoundWords]uint32

View File

@ -26,6 +26,6 @@ func xorKeyStream(c *zucState32, dst, src []byte) {
xor.XorBytes(dst[words*4:], src[words*4:], singleWord[:]) xor.XorBytes(dst[words*4:], src[words*4:], singleWord[:])
} }
} else { } else {
genericXorKeyStream(c, dst, src) xorKeyStreamGeneric(c, dst, src)
} }
} }

View File

@ -4,5 +4,5 @@
package zuc package zuc
func xorKeyStream(c *zucState32, dst, src []byte) { func xorKeyStream(c *zucState32, dst, src []byte) {
genericXorKeyStream(c, dst, src) xorKeyStreamGeneric(c, dst, src)
} }