summaryrefslogtreecommitdiffstats
path: root/src/crypto/isa-l/isa-l_crypto/sha1_mb/aarch64/sha1_mb_x2_ce.S
blob: 93f653ad2860799b54ac1849c5d6b093077beb2d (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/**********************************************************************
  Copyright(c) 2019 Arm Corporation All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:
    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the
      distribution.
    * Neither the name of Arm Corporation nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**********************************************************************/
	.arch armv8-a+crypto
	.text
	.align	2
	.p2align 3,,7

/*
Macros
*/

.macro	declare_var_vector_reg name:req,reg:req
	\name\()_q	.req	q\reg
	\name\()_v	.req	v\reg
	\name\()_s	.req	s\reg
.endm

/**
maros for round 4-67
*/
.macro sha1_4_rounds inst:req,msg0:req,msg1:req,msg2:req,msg3:req,abcd:req,e0:req,tmp0:req,e1:req,tmp1:req,k:req
	sha1h	l0_\e0\()_s, l0_\abcd\()_s
	sha1h	l1_\e0\()_s, l1_\abcd\()_s

	\inst	l0_\abcd\()_q,l0_\e1\()_s,l0_\tmp1\()_v.4s
	\inst	l1_\abcd\()_q,l1_\e1\()_s,l1_\tmp1\()_v.4s

	add 	l0_\tmp1\()_v.4s,l0_\msg3\()_v.4s,\k\()_v.4s
	add 	l1_\tmp1\()_v.4s,l1_\msg3\()_v.4s,\k\()_v.4s

	sha1su1	l0_\msg0\()_v.4s,l0_\msg3\()_v.4s
	sha1su1	l1_\msg0\()_v.4s,l1_\msg3\()_v.4s

	sha1su0	l0_\msg1\()_v.4s,l0_\msg2\()_v.4s,l0_\msg3\()_v.4s
	sha1su0	l1_\msg1\()_v.4s,l1_\msg2\()_v.4s,l1_\msg3\()_v.4s
.endm


/*
Variable list
*/

	declare_var_vector_reg	key_0,28
	declare_var_vector_reg	key_1,29
	declare_var_vector_reg	key_2,30
	declare_var_vector_reg	key_3,31


/*
lane variables
*/
	declare_var_vector_reg	l0_abcd,0
	declare_var_vector_reg	l0_e0,1
	declare_var_vector_reg	l0_e1,2
	declare_var_vector_reg	l0_abcd_saved,3
	declare_var_vector_reg	l0_e0_saved,4
	declare_var_vector_reg	l0_tmp_0,5
	declare_var_vector_reg	l0_tmp_1,6
	declare_var_vector_reg	l0_msg_0,16
	declare_var_vector_reg	l0_msg_1,17
	declare_var_vector_reg	l0_msg_2,18
	declare_var_vector_reg	l0_msg_3,19

	declare_var_vector_reg	l1_abcd,7
	declare_var_vector_reg	l1_e0,8
	declare_var_vector_reg	l1_e1,9
	declare_var_vector_reg	l1_abcd_saved,24
	declare_var_vector_reg	l1_e0_saved,25
	declare_var_vector_reg	l1_tmp_0,26
	declare_var_vector_reg	l1_tmp_1,27
	declare_var_vector_reg	l1_msg_0,20
	declare_var_vector_reg	l1_msg_1,21
	declare_var_vector_reg	l1_msg_2,22
	declare_var_vector_reg	l1_msg_3,23

/*
	void sha1_mb_ce_x2(SHA1_JOB * job_0, SHA1_JOB * job_1,int len);
*/
	l0_job .req x0
	l1_job .req x1
	len .req w2

	l0_data		.req	x3
	l1_data		.req	x4
	tmp		.req	x5
	.global	sha1_mb_ce_x2
	.type	sha1_mb_ce_x2, %function
sha1_mb_ce_x2:
	//push 	d8,d9 to stack
	stp	d8, d9, [sp, -256]!

	adr	tmp, KEY
	ld1	{key_0_v.4s-key_3_v.4s},[tmp]
	ldr	l0_data,	[l0_job]
	ldr	l1_data,	[l1_job]
	ldr	l0_abcd_q,	[l0_job, 64]
	ldr	l0_e0_s,	[l0_job, 80]
	ldr	l1_abcd_q,	[l1_job, 64]
	ldr	l1_e0_s,	[l1_job, 80]

start_loop:

	//load msgs
	ld1	{l0_msg_0_v.4s-l0_msg_3_v.4s},[l0_data]
	ld1	{l1_msg_0_v.4s-l1_msg_3_v.4s},[l1_data]

	//adjust loop parameter
	add	l0_data,l0_data,64
	add	l1_data,l1_data,64
	sub	len, len, #1
	cmp	len, 0
	//backup digest
	mov	l0_abcd_saved_v.16b,	l0_abcd_v.16b
	mov	l0_e0_saved_v.16b,	l0_e0_v.16b
	mov	l1_abcd_saved_v.16b,	l1_abcd_v.16b
	mov	l1_e0_saved_v.16b,	l1_e0_v.16b

	rev32	l0_msg_0_v.16b,	l0_msg_0_v.16b
	rev32	l0_msg_1_v.16b,	l0_msg_1_v.16b
	add	l0_tmp_0_v.4s,	l0_msg_0_v.4s,	key_0_v.4s
	rev32	l0_msg_2_v.16b,	l0_msg_2_v.16b
	add	l0_tmp_1_v.4s,	l0_msg_1_v.4s,	key_0_v.4s
	rev32	l0_msg_3_v.16b,	l0_msg_3_v.16b

	rev32	l1_msg_0_v.16b,	l1_msg_0_v.16b
	rev32	l1_msg_1_v.16b,	l1_msg_1_v.16b
	add	l1_tmp_0_v.4s,	l1_msg_0_v.4s,	key_0_v.4s
	rev32	l1_msg_2_v.16b,	l1_msg_2_v.16b
	add	l1_tmp_1_v.4s,	l1_msg_1_v.4s,	key_0_v.4s
	rev32	l1_msg_3_v.16b,	l1_msg_3_v.16b

	/* rounds 0-3 */
	sha1h	l0_e1_s,	l0_abcd_s
	sha1c	l0_abcd_q,	l0_e0_s,	l0_tmp_0_v.4s
	add	l0_tmp_0_v.4s,	l0_msg_2_v.4s,	key_0_v.4s
	sha1su0	l0_msg_0_v.4s,	l0_msg_1_v.4s,	l0_msg_2_v.4s

	sha1h	l1_e1_s,	l1_abcd_s
	sha1c	l1_abcd_q,	l1_e0_s,	l1_tmp_0_v.4s
	add	l1_tmp_0_v.4s,	l1_msg_2_v.4s,	key_0_v.4s
	sha1su0	l1_msg_0_v.4s,	l1_msg_1_v.4s,	l1_msg_2_v.4s

	sha1_4_rounds	sha1c,msg_0,msg_1,msg_2,msg_3,abcd,e0,tmp_0,e1,tmp_1,key_0     /* rounds 4-7 */
	sha1_4_rounds	sha1c,msg_1,msg_2,msg_3,msg_0,abcd,e1,tmp_1,e0,tmp_0,key_0
	sha1_4_rounds	sha1c,msg_2,msg_3,msg_0,msg_1,abcd,e0,tmp_0,e1,tmp_1,key_1     /* rounds 12-15 */
	sha1_4_rounds	sha1c,msg_3,msg_0,msg_1,msg_2,abcd,e1,tmp_1,e0,tmp_0,key_1
	sha1_4_rounds	sha1p,msg_0,msg_1,msg_2,msg_3,abcd,e0,tmp_0,e1,tmp_1,key_1     /* rounds 20-23 */
	sha1_4_rounds	sha1p,msg_1,msg_2,msg_3,msg_0,abcd,e1,tmp_1,e0,tmp_0,key_1
	sha1_4_rounds	sha1p,msg_2,msg_3,msg_0,msg_1,abcd,e0,tmp_0,e1,tmp_1,key_1
	sha1_4_rounds	sha1p,msg_3,msg_0,msg_1,msg_2,abcd,e1,tmp_1,e0,tmp_0,key_2
	sha1_4_rounds	sha1p,msg_0,msg_1,msg_2,msg_3,abcd,e0,tmp_0,e1,tmp_1,key_2     /* rounds 36-39 */
	sha1_4_rounds	sha1m,msg_1,msg_2,msg_3,msg_0,abcd,e1,tmp_1,e0,tmp_0,key_2
	sha1_4_rounds	sha1m,msg_2,msg_3,msg_0,msg_1,abcd,e0,tmp_0,e1,tmp_1,key_2
	sha1_4_rounds	sha1m,msg_3,msg_0,msg_1,msg_2,abcd,e1,tmp_1,e0,tmp_0,key_2
	sha1_4_rounds	sha1m,msg_0,msg_1,msg_2,msg_3,abcd,e0,tmp_0,e1,tmp_1,key_3     /* rounds 52-55 */
	sha1_4_rounds	sha1m,msg_1,msg_2,msg_3,msg_0,abcd,e1,tmp_1,e0,tmp_0,key_3
	sha1_4_rounds	sha1p,msg_2,msg_3,msg_0,msg_1,abcd,e0,tmp_0,e1,tmp_1,key_3
	sha1_4_rounds	sha1p,msg_3,msg_0,msg_1,msg_2,abcd,e1,tmp_1,e0,tmp_0,key_3

	/* rounds 68-71 */
	sha1h	l0_e0_s,	l0_abcd_s
	sha1p	l0_abcd_q,	l0_e1_s,	l0_tmp_1_v.4s
	add	l0_tmp_1_v.4s,	l0_msg_3_v.4s,	key_3_v.4s
	sha1su1	l0_msg_0_v.4s,	l0_msg_3_v.4s

	sha1h	l1_e0_s,	l1_abcd_s
	sha1p	l1_abcd_q,	l1_e1_s,	l1_tmp_1_v.4s
	add	l1_tmp_1_v.4s,	l1_msg_3_v.4s,	key_3_v.4s
	sha1su1	l1_msg_0_v.4s,	l1_msg_3_v.4s

	/* rounds 72-75 */
	sha1h   l0_e1_s,	l0_abcd_s
	sha1p   l0_abcd_q,	l0_e0_s,	l0_tmp_0_v.4s

	sha1h   l1_e1_s,	l1_abcd_s
	sha1p   l1_abcd_q,	l1_e0_s,	l1_tmp_0_v.4s

	/* rounds 76-79 */
	sha1h   l0_e0_s,	l0_abcd_s
	sha1p   l0_abcd_q,	l0_e1_s,	l0_tmp_1_v.4s

	sha1h   l1_e0_s,	l1_abcd_s
	sha1p   l1_abcd_q,	l1_e1_s,	l1_tmp_1_v.4s



	add     l0_abcd_v.4s,	l0_abcd_v.4s,	l0_abcd_saved_v.4s
	add     l0_e0_v.2s,	l0_e0_v.2s,	l0_e0_saved_v.2s
	add     l1_abcd_v.4s,	l1_abcd_v.4s,	l1_abcd_saved_v.4s
	add     l1_e0_v.2s,	l1_e0_v.2s,	l1_e0_saved_v.2s




	bgt	start_loop

	str	l0_abcd_q,	[l0_job, 64]
	str	l0_e0_s, 	[l0_job, 80]


	str	l1_abcd_q,	[l1_job, 64]
	str	l1_e0_s, 	[l1_job, 80]

	//pop d8,d9 from stack
	ldp	d8, d9, [sp], 256
	ret

	.size	sha1_mb_ce_x2, .-sha1_mb_ce_x2
	.section	.rodata.cst16,"aM",@progbits,16
	.align	4
KEY:
	.word	0x5a827999
	.word	0x5a827999
	.word	0x5a827999
	.word	0x5a827999
	.word	0x6ed9eba1
	.word	0x6ed9eba1
	.word	0x6ed9eba1
	.word	0x6ed9eba1
	.word	0x8f1bbcdc
	.word	0x8f1bbcdc
	.word	0x8f1bbcdc
	.word	0x8f1bbcdc
	.word	0xca62c1d6
	.word	0xca62c1d6
	.word	0xca62c1d6
	.word	0xca62c1d6