Text file
src/crypto/sha1/sha1block_arm64.s
1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build !purego
6
7 #include "textflag.h"
8
9 #define HASHUPDATECHOOSE \
10 SHA1C V16.S4, V1, V2 \
11 SHA1H V3, V1 \
12 VMOV V2.B16, V3.B16
13
14 #define HASHUPDATEPARITY \
15 SHA1P V16.S4, V1, V2 \
16 SHA1H V3, V1 \
17 VMOV V2.B16, V3.B16
18
19 #define HASHUPDATEMAJ \
20 SHA1M V16.S4, V1, V2 \
21 SHA1H V3, V1 \
22 VMOV V2.B16, V3.B16
23
24 // func sha1block(h []uint32, p []byte, k []uint32)
25 TEXT ·sha1block(SB),NOSPLIT,$0
26 MOVD h_base+0(FP), R0 // hash value first address
27 MOVD p_base+24(FP), R1 // message first address
28 MOVD k_base+48(FP), R2 // k constants first address
29 MOVD p_len+32(FP), R3 // message length
30 VLD1.P 16(R0), [V0.S4]
31 FMOVS (R0), F20
32 SUB $16, R0, R0
33
34 blockloop:
35
36 VLD1.P 16(R1), [V4.B16] // load message
37 VLD1.P 16(R1), [V5.B16]
38 VLD1.P 16(R1), [V6.B16]
39 VLD1.P 16(R1), [V7.B16]
40 VLD1 (R2), [V19.S4] // load constant k0-k79
41 VMOV V0.B16, V2.B16
42 VMOV V20.S[0], V1
43 VMOV V2.B16, V3.B16
44 VDUP V19.S[0], V17.S4
45 VREV32 V4.B16, V4.B16 // prepare for using message in Byte format
46 VREV32 V5.B16, V5.B16
47 VREV32 V6.B16, V6.B16
48 VREV32 V7.B16, V7.B16
49
50
51 VDUP V19.S[1], V18.S4
52 VADD V17.S4, V4.S4, V16.S4
53 SHA1SU0 V6.S4, V5.S4, V4.S4
54 HASHUPDATECHOOSE
55 SHA1SU1 V7.S4, V4.S4
56
57 VADD V17.S4, V5.S4, V16.S4
58 SHA1SU0 V7.S4, V6.S4, V5.S4
59 HASHUPDATECHOOSE
60 SHA1SU1 V4.S4, V5.S4
61 VADD V17.S4, V6.S4, V16.S4
62 SHA1SU0 V4.S4, V7.S4, V6.S4
63 HASHUPDATECHOOSE
64 SHA1SU1 V5.S4, V6.S4
65
66 VADD V17.S4, V7.S4, V16.S4
67 SHA1SU0 V5.S4, V4.S4, V7.S4
68 HASHUPDATECHOOSE
69 SHA1SU1 V6.S4, V7.S4
70
71 VADD V17.S4, V4.S4, V16.S4
72 SHA1SU0 V6.S4, V5.S4, V4.S4
73 HASHUPDATECHOOSE
74 SHA1SU1 V7.S4, V4.S4
75
76 VDUP V19.S[2], V17.S4
77 VADD V18.S4, V5.S4, V16.S4
78 SHA1SU0 V7.S4, V6.S4, V5.S4
79 HASHUPDATEPARITY
80 SHA1SU1 V4.S4, V5.S4
81
82 VADD V18.S4, V6.S4, V16.S4
83 SHA1SU0 V4.S4, V7.S4, V6.S4
84 HASHUPDATEPARITY
85 SHA1SU1 V5.S4, V6.S4
86
87 VADD V18.S4, V7.S4, V16.S4
88 SHA1SU0 V5.S4, V4.S4, V7.S4
89 HASHUPDATEPARITY
90 SHA1SU1 V6.S4, V7.S4
91
92 VADD V18.S4, V4.S4, V16.S4
93 SHA1SU0 V6.S4, V5.S4, V4.S4
94 HASHUPDATEPARITY
95 SHA1SU1 V7.S4, V4.S4
96
97 VADD V18.S4, V5.S4, V16.S4
98 SHA1SU0 V7.S4, V6.S4, V5.S4
99 HASHUPDATEPARITY
100 SHA1SU1 V4.S4, V5.S4
101
102 VDUP V19.S[3], V18.S4
103 VADD V17.S4, V6.S4, V16.S4
104 SHA1SU0 V4.S4, V7.S4, V6.S4
105 HASHUPDATEMAJ
106 SHA1SU1 V5.S4, V6.S4
107
108 VADD V17.S4, V7.S4, V16.S4
109 SHA1SU0 V5.S4, V4.S4, V7.S4
110 HASHUPDATEMAJ
111 SHA1SU1 V6.S4, V7.S4
112
113 VADD V17.S4, V4.S4, V16.S4
114 SHA1SU0 V6.S4, V5.S4, V4.S4
115 HASHUPDATEMAJ
116 SHA1SU1 V7.S4, V4.S4
117
118 VADD V17.S4, V5.S4, V16.S4
119 SHA1SU0 V7.S4, V6.S4, V5.S4
120 HASHUPDATEMAJ
121 SHA1SU1 V4.S4, V5.S4
122
123 VADD V17.S4, V6.S4, V16.S4
124 SHA1SU0 V4.S4, V7.S4, V6.S4
125 HASHUPDATEMAJ
126 SHA1SU1 V5.S4, V6.S4
127
128 VADD V18.S4, V7.S4, V16.S4
129 SHA1SU0 V5.S4, V4.S4, V7.S4
130 HASHUPDATEPARITY
131 SHA1SU1 V6.S4, V7.S4
132
133 VADD V18.S4, V4.S4, V16.S4
134 HASHUPDATEPARITY
135
136 VADD V18.S4, V5.S4, V16.S4
137 HASHUPDATEPARITY
138
139 VADD V18.S4, V6.S4, V16.S4
140 HASHUPDATEPARITY
141
142 VADD V18.S4, V7.S4, V16.S4
143 HASHUPDATEPARITY
144
145 SUB $64, R3, R3 // message length - 64bytes, then compare with 64bytes
146 VADD V2.S4, V0.S4, V0.S4
147 VADD V1.S4, V20.S4, V20.S4
148 CBNZ R3, blockloop
149
150 sha1ret:
151
152 VST1.P [V0.S4], 16(R0) // store hash value H(dcba)
153 FMOVS F20, (R0) // store hash value H(e)
154 RET
155
View as plain text