sse: [ZUC] suport 16-byte tags in Remainder function
@@ -1897,12 +1897,11 @@ exit_cipher:
%endif
bswap %%TAG
mov [%%T], %%TAG
-%else ;; %%TAG_SZ == 8
+%else ; %%TAG_SZ == 8 or 16
%define %%TAG %%TMP1
- ;; - update T
- mov %%TAG, [%%T]
- movq %%TMP2, %%XTMP6
- xor %%TAG, %%TMP2
+ ;; Update lower 64 bits of T
+ movq %%TAG, %%XTMP6
+ xor %%TAG, [%%T]
;; XOR with keyStr[n_bits] (Z_length, from spec)
@@ -1931,7 +1930,40 @@ exit_cipher:
bswap %%TAG
ror %%TAG, 32
mov [%%T], %%TAG
-%endif
+%if %%TAG_SZ == 16
+ ;; Update higher 64 bits of T
+ pextrq %%TAG, %%XTMP6, 1
+ xor %%TAG, [%%T + 8]
+
+ ;; XOR with keyStr[n_bits] (Z_length, from spec)
+
+ ; Read keyStr[N_BITS / 32]
+ mov %%TMP2, %%N_BITS
+ shr %%TMP2, 5
+ mov %%TMP3, [%%KS + %%TMP2*4 + 4*2]
+ mov %%TMP4, [%%KS + %%TMP2*4 + 4*3]
+
+ ; Rotate left by N_BITS % 32
+ mov %%TMP2, rcx ; Save RCX
+ mov rcx, %%N_BITS
+ and rcx, 0x1F
+ rol %%TMP3, cl
+ rol %%TMP4, cl
+ mov rcx, %%TMP2 ; Restore RCX
+
+ shl %%TMP4, 32
+ mov DWORD(%%TMP3), DWORD(%%TMP3) ; Clear top 32 bits
+ or %%TMP4, %%TMP3
+
+ ; XOR with previous digest calculation
+ xor %%TAG, %%TMP4
+
+ ; Byte swap both dwords of the digest before writing out
+ bswap %%TAG
+ ror %%TAG, 32
+ mov [%%T + 8], %%TAG
+%endif ; %%TAG_SZ == 16
+%endif ; %%TAG_SZ == 4
FUNC_RESTORE
@@ -1967,10 +1999,10 @@ ZUC_EIA3REMAINDER:
cmp TAG_SZ, 8
je remainder_tag_sz_8
- jb remainder_tag_sz_4
+ ja remainder_tag_sz_16
; Key size = 256
- ;; TODO: Handle tag sizes of 16 bytes
+ ; Fall-through for tag size = 4 bytes
remainder_tag_sz_4:
REMAINDER T, KS, DATA, N_BITS, r11, r12, r13, r14, r15, \
xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, \
@@ -1983,6 +2015,12 @@ remainder_tag_sz_8:
xmm8, xmm9, xmm10, xmm11, 256, 8
ret
+remainder_tag_sz_16:
+ REMAINDER T, KS, DATA, N_BITS, r11, r12, r13, r14, r15, \
+ xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, \
+ xmm8, xmm9, xmm10, xmm11, 256, 16
+ ret
+
remainder_key_sz_128:
REMAINDER T, KS, DATA, N_BITS, r11, r12, r13, r14, r15, \
xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7, \
