1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56#include <linux/linkage.h>
57
58#define DIGEST_PTR %rdi
59#define DATA_PTR %rsi
60#define NUM_BLKS %rdx
61
62
63#define FRAME_SIZE 32
64
65#define ABCD %xmm0
66#define E0 %xmm1
67#define E1 %xmm2
68#define MSG0 %xmm3
69#define MSG1 %xmm4
70#define MSG2 %xmm5
71#define MSG3 %xmm6
72#define SHUF_MASK %xmm7
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94.text
95.align 32
96SYM_FUNC_START(sha1_ni_transform)
97 push %rbp
98 mov %rsp, %rbp
99 sub $FRAME_SIZE, %rsp
100 and $~0xF, %rsp
101
102 shl $6, NUM_BLKS
103 jz .Ldone_hash
104 add DATA_PTR, NUM_BLKS
105
106
107 pinsrd $3, 1*16(DIGEST_PTR), E0
108 movdqu 0*16(DIGEST_PTR), ABCD
109 pand UPPER_WORD_MASK(%rip), E0
110 pshufd $0x1B, ABCD, ABCD
111
112 movdqa PSHUFFLE_BYTE_FLIP_MASK(%rip), SHUF_MASK
113
114.Lloop0:
115
116 movdqa E0, (0*16)(%rsp)
117 movdqa ABCD, (1*16)(%rsp)
118
119
120 movdqu 0*16(DATA_PTR), MSG0
121 pshufb SHUF_MASK, MSG0
122 paddd MSG0, E0
123 movdqa ABCD, E1
124 sha1rnds4 $0, E0, ABCD
125
126
127 movdqu 1*16(DATA_PTR), MSG1
128 pshufb SHUF_MASK, MSG1
129 sha1nexte MSG1, E1
130 movdqa ABCD, E0
131 sha1rnds4 $0, E1, ABCD
132 sha1msg1 MSG1, MSG0
133
134
135 movdqu 2*16(DATA_PTR), MSG2
136 pshufb SHUF_MASK, MSG2
137 sha1nexte MSG2, E0
138 movdqa ABCD, E1
139 sha1rnds4 $0, E0, ABCD
140 sha1msg1 MSG2, MSG1
141 pxor MSG2, MSG0
142
143
144 movdqu 3*16(DATA_PTR), MSG3
145 pshufb SHUF_MASK, MSG3
146 sha1nexte MSG3, E1
147 movdqa ABCD, E0
148 sha1msg2 MSG3, MSG0
149 sha1rnds4 $0, E1, ABCD
150 sha1msg1 MSG3, MSG2
151 pxor MSG3, MSG1
152
153
154 sha1nexte MSG0, E0
155 movdqa ABCD, E1
156 sha1msg2 MSG0, MSG1
157 sha1rnds4 $0, E0, ABCD
158 sha1msg1 MSG0, MSG3
159 pxor MSG0, MSG2
160
161
162 sha1nexte MSG1, E1
163 movdqa ABCD, E0
164 sha1msg2 MSG1, MSG2
165 sha1rnds4 $1, E1, ABCD
166 sha1msg1 MSG1, MSG0
167 pxor MSG1, MSG3
168
169
170 sha1nexte MSG2, E0
171 movdqa ABCD, E1
172 sha1msg2 MSG2, MSG3
173 sha1rnds4 $1, E0, ABCD
174 sha1msg1 MSG2, MSG1
175 pxor MSG2, MSG0
176
177
178 sha1nexte MSG3, E1
179 movdqa ABCD, E0
180 sha1msg2 MSG3, MSG0
181 sha1rnds4 $1, E1, ABCD
182 sha1msg1 MSG3, MSG2
183 pxor MSG3, MSG1
184
185
186 sha1nexte MSG0, E0
187 movdqa ABCD, E1
188 sha1msg2 MSG0, MSG1
189 sha1rnds4 $1, E0, ABCD
190 sha1msg1 MSG0, MSG3
191 pxor MSG0, MSG2
192
193
194 sha1nexte MSG1, E1
195 movdqa ABCD, E0
196 sha1msg2 MSG1, MSG2
197 sha1rnds4 $1, E1, ABCD
198 sha1msg1 MSG1, MSG0
199 pxor MSG1, MSG3
200
201
202 sha1nexte MSG2, E0
203 movdqa ABCD, E1
204 sha1msg2 MSG2, MSG3
205 sha1rnds4 $2, E0, ABCD
206 sha1msg1 MSG2, MSG1
207 pxor MSG2, MSG0
208
209
210 sha1nexte MSG3, E1
211 movdqa ABCD, E0
212 sha1msg2 MSG3, MSG0
213 sha1rnds4 $2, E1, ABCD
214 sha1msg1 MSG3, MSG2
215 pxor MSG3, MSG1
216
217
218 sha1nexte MSG0, E0
219 movdqa ABCD, E1
220 sha1msg2 MSG0, MSG1
221 sha1rnds4 $2, E0, ABCD
222 sha1msg1 MSG0, MSG3
223 pxor MSG0, MSG2
224
225
226 sha1nexte MSG1, E1
227 movdqa ABCD, E0
228 sha1msg2 MSG1, MSG2
229 sha1rnds4 $2, E1, ABCD
230 sha1msg1 MSG1, MSG0
231 pxor MSG1, MSG3
232
233
234 sha1nexte MSG2, E0
235 movdqa ABCD, E1
236 sha1msg2 MSG2, MSG3
237 sha1rnds4 $2, E0, ABCD
238 sha1msg1 MSG2, MSG1
239 pxor MSG2, MSG0
240
241
242 sha1nexte MSG3, E1
243 movdqa ABCD, E0
244 sha1msg2 MSG3, MSG0
245 sha1rnds4 $3, E1, ABCD
246 sha1msg1 MSG3, MSG2
247 pxor MSG3, MSG1
248
249
250 sha1nexte MSG0, E0
251 movdqa ABCD, E1
252 sha1msg2 MSG0, MSG1
253 sha1rnds4 $3, E0, ABCD
254 sha1msg1 MSG0, MSG3
255 pxor MSG0, MSG2
256
257
258 sha1nexte MSG1, E1
259 movdqa ABCD, E0
260 sha1msg2 MSG1, MSG2
261 sha1rnds4 $3, E1, ABCD
262 pxor MSG1, MSG3
263
264
265 sha1nexte MSG2, E0
266 movdqa ABCD, E1
267 sha1msg2 MSG2, MSG3
268 sha1rnds4 $3, E0, ABCD
269
270
271 sha1nexte MSG3, E1
272 movdqa ABCD, E0
273 sha1rnds4 $3, E1, ABCD
274
275
276 sha1nexte (0*16)(%rsp), E0
277 paddd (1*16)(%rsp), ABCD
278
279
280 add $64, DATA_PTR
281 cmp NUM_BLKS, DATA_PTR
282 jne .Lloop0
283
284
285 pshufd $0x1B, ABCD, ABCD
286 movdqu ABCD, 0*16(DIGEST_PTR)
287 pextrd $3, E0, 1*16(DIGEST_PTR)
288
289.Ldone_hash:
290 mov %rbp, %rsp
291 pop %rbp
292
293 ret
294SYM_FUNC_END(sha1_ni_transform)
295
296.section .rodata.cst16.PSHUFFLE_BYTE_FLIP_MASK, "aM", @progbits, 16
297.align 16
298PSHUFFLE_BYTE_FLIP_MASK:
299 .octa 0x000102030405060708090a0b0c0d0e0f
300
301.section .rodata.cst16.UPPER_WORD_MASK, "aM", @progbits, 16
302.align 16
303UPPER_WORD_MASK:
304 .octa 0xFFFFFFFF000000000000000000000000
305