Skip to content

Commit fce7116

Browse files
ElenaTyulenevaipl_ci
authored andcommitted
[SB][Library][Feature] Improve the performance of SHA3-224 hash function (#841)
1 parent e9f4150 commit fce7116

4 files changed

Lines changed: 95 additions & 1 deletion

File tree

sources/ippcp/asm_intel64/pcpsha3_avx512vl.asm

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,89 @@ default rel
3434

3535
section .text align=IPP_ALIGN_FACTOR
3636

37+
;;
38+
;; void
39+
;; cp_SHA3_224_Absorb(void *state, const Ipp8u *input, Ipp64u inlen);
40+
;; Input:
41+
;; - state/arg1: pointer to the state
42+
;; - input/arg2: pointer to the input message
43+
;; - inlen/arg3: length of the input message in bytes
44+
align IPP_ALIGN_FACTOR
45+
IPPASM cp_SHA3_224_Absorb, PUBLIC
46+
USES_GPR NONVOLATILE_REGS_LIN64_GPR NONVOLATILE_REGS_WIN64_GPR
47+
USES_XMM_AVX NONVOLATILE_REGS_WIN64_YMM
48+
COMP_ABI 3
49+
50+
mov arg1, [arg1] ; state.ctx into arg1
51+
52+
; check for partially processed block
53+
mov r14, [arg1 + 8*25]
54+
or r14, r14 ; s[25] == 0?
55+
je .absorb_main_loop_start
56+
57+
; process remaining bytes if message long enough
58+
mov r12, SHA3_224_RATE ; c = rate - s[25]
59+
sub r12, r14 ; r12 = capacity
60+
61+
cmp arg3, r12 ; if mlen < capacity then cannot permute yet
62+
jb .absorb_skip_permute
63+
64+
mov r10, arg3
65+
lea r13, [arg1 + r14] ; r13 = state + s[25]
66+
mov arg3, arg2
67+
CALL_IPPASM keccak_1600_partial_add
68+
mov arg3, r10
69+
70+
CALL_IPPASM keccak_1600_load_state
71+
CALL_IPPASM keccak1600_block_64bit
72+
73+
mov qword [arg1 + 8*25], 0 ; clear s[25]
74+
jmp .absorb_partial_block_done
75+
76+
.absorb_skip_permute:
77+
mov r11, arg3 ; copy message length to r11
78+
xor r12, r12 ; zero message offset
79+
add [arg1 + 8*25], r11 ; store partially processed length in s[25]
80+
add arg1, r14 ; state += s[25]
81+
jmp .absorb_final_partial_add
82+
83+
.absorb_main_loop_start:
84+
CALL_IPPASM keccak_1600_load_state
85+
86+
.absorb_partial_block_done:
87+
mov r11, arg3 ; copy message length to r11
88+
xor r12, r12 ; zero message offset
89+
90+
; Process the input message in blocks
91+
align IPP_ALIGN_FACTOR
92+
.absorb_while_loop:
93+
cmp r11, SHA3_224_RATE ; compare mlen to rate
94+
jb .absorb_while_loop_done
95+
96+
ABSORB_BYTES arg2, r12, SHA3_224_RATE ; input, offset, rate
97+
98+
sub r11, SHA3_224_RATE ; Subtract the rate from the remaining length
99+
add r12, SHA3_224_RATE ; Adjust the pointer to the next block of the input message
100+
CALL_IPPASM keccak1600_block_64bit ; Perform the Keccak permutation
101+
jmp .absorb_while_loop
102+
103+
align IPP_ALIGN_FACTOR
104+
.absorb_while_loop_done:
105+
106+
CALL_IPPASM keccak_1600_save_state
107+
add [arg1 + 8*25], r11 ; store partially processed length in s[25]
108+
109+
.absorb_final_partial_add:
110+
add arg2, r12
111+
mov r13, arg1
112+
mov r12, r11
113+
CALL_IPPASM keccak_1600_partial_add
114+
115+
REST_XMM_AVX
116+
REST_GPR
117+
ret
118+
ENDFUNC cp_SHA3_224_Absorb
119+
37120
;;
38121
;; void
39122
;; cp_SHA3_256_Absorb(void *state, const Ipp8u *input, Ipp64u inlen);

sources/ippcp/asm_intel64/pcpsha3_common.inc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
%define arg10 [rsp + ARG_10]
3737

3838
;; SHA3 rates
39+
%define SHA3_224_RATE 144
3940
%define SHA3_256_RATE 136
4041
%define SHA3_384_RATE 104
4142
%define SHA3_512_RATE 72
@@ -102,9 +103,12 @@
102103
vpxorq ymm16, ymm16, ymm31
103104
%endif
104105
%if %%RATE > SHA3_256_RATE
105-
;; SHAKE128 RATE
106+
;; SHA3_224 RATE
106107
vmovq xmm31, [%%INPUT + %%OFFSET + 8*17]
107108
vpxorq ymm17, ymm17, ymm31
109+
%endif
110+
%if %%RATE > SHA3_224_RATE
111+
;; SHAKE128 RATE
108112
vmovq xmm31, [%%INPUT + %%OFFSET + 8*18]
109113
vpxorq ymm18, ymm18, ymm31
110114
vmovq xmm31, [%%INPUT + %%OFFSET + 8*19]

sources/ippcp/hash/sha3/sha3-224/pcpsha3_224_stuff.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626
IPP_OWN_DEFN(static void, cp_sha3_224_hashUpdate, (void* pHash, const Ipp8u* pMsg, int msgLen))
2727
{
2828
int block_size = MBS_SHA3_224;
29+
#if (_IPP32E >= _IPP32E_K0)
30+
IPP_UNREFERENCED_PARAMETER(block_size);
31+
cp_SHA3_224_Absorb(&pHash, pMsg, (Ipp64u)msgLen);
32+
#else
2933
cpUpdateSHA3(pHash, pMsg, msgLen, &block_size);
34+
#endif
3035
}
3136

3237
#endif /* _PCP_SHA3_224_STUFF_H */

sources/ippcp/hash/sha3/sha3_stuff.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ IPP_OWN_DECL(void,
5454
(Ipp8u * output, Ipp64u outlen, const Ipp8u* input, Ipp64u inplen))
5555

5656
// Absorb (Update)
57+
#define cp_SHA3_224_Absorb OWNAPI(cp_SHA3_224_Absorb)
58+
IPP_OWN_DECL(void, cp_SHA3_224_Absorb, (void* state, const Ipp8u* input, Ipp64u inlen))
5759
#define cp_SHA3_256_Absorb OWNAPI(cp_SHA3_256_Absorb)
5860
IPP_OWN_DECL(void, cp_SHA3_256_Absorb, (void* state, const Ipp8u* input, Ipp64u inlen))
5961
#define cp_SHA3_384_Absorb OWNAPI(cp_SHA3_384_Absorb)

0 commit comments

Comments
 (0)