• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * This file is part of the openHiTLS project.
3 *
4 * openHiTLS is licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 *
8 *     http://license.coscl.org.cn/MulanPSL2
9 *
10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13 * See the Mulan PSL v2 for more details.
14 */
15
16#include "hitls_build.h"
17#ifdef HITLS_CRYPTO_CHACHA20
18
19.text
20
21// Input ctx、in、out、len.
22REGCTX .req x0
23REGINC .req x1
24REGOUT .req x2
25REGLEN .req x3
26
27// 64-byte input, temporarily loaded register(0 ~ 15).
28WINPUT0 .req w5
29XINPUT0 .req x5
30WINPUT1 .req w6
31XINPUT1 .req x6
32WINPUT2 .req w7
33XINPUT2 .req x7
34WINPUT3 .req w8
35XINPUT3 .req x8
36WINPUT4 .req w9
37XINPUT4 .req x9
38WINPUT5 .req w10
39XINPUT5 .req x10
40WINPUT6 .req w11
41XINPUT6 .req x11
42WINPUT7 .req w12
43XINPUT7 .req x12
44WINPUT8 .req w13
45XINPUT8 .req x13
46WINPUT9 .req w14
47XINPUT9 .req x14
48WINPUT10 .req w15
49XINPUT10 .req x15
50WINPUT11 .req w16
51XINPUT11 .req x16
52WINPUT12 .req w17
53XINPUT12 .req x17
54WINPUT13 .req w19
55XINPUT13 .req x19
56WINPUT14 .req w20
57XINPUT14 .req x20
58WINPUT15 .req w21
59XINPUT15 .req x21
60
61// 8 blocks in parallel, 6 blocks of 64-byte data in 8 blocks of 512 bytes.
62VREG01 .req v0
63VREG02 .req v1
64VREG03 .req v2
65VREG04 .req v3
66VREG11 .req v4
67VREG12 .req v5
68VREG13 .req v6
69VREG14 .req v7
70VREG21 .req v8
71VREG22 .req v9
72VREG23 .req v10
73VREG24 .req v11
74VREG31 .req v12
75VREG32 .req v13
76VREG33 .req v14
77VREG34 .req v15
78VREG41 .req v16
79VREG42 .req v17
80VREG43 .req v18
81VREG44 .req v19
82VREG51 .req v20
83VREG52 .req v21
84VREG53 .req v22
85VREG54 .req v23
86
87// Public register, used for temporary calculation.
88VCUR01 .req v24
89QCUR01 .req q24
90VCUR02 .req v25
91QCUR02 .req q25
92VCUR03 .req v26
93QCUR03 .req q26
94VCUR04 .req v27
95QCUR04 .req q27
96VCUR05 .req v28
97QCUR05 .req q28
98VCUR06 .req v29
99QCUR06 .req q29
100
101// Counter、sigma、key、adder register.
102VCOUN0 .req v27
103VSIGMA .req v28
104VKEY01 .req v29
105VKEY02 .req v30
106VADDER .req v31
107
108// Counter、sigma、key、adder register.
109WSIG01 .req w22
110XSIG01 .req x22
111WSIG02 .req w23
112XSIG02 .req x23
113WKEY01 .req w24
114XKEY01 .req x24
115WKEY02 .req w25
116XKEY02 .req x25
117WKEY03 .req w26
118XKEY03 .req x26
119WKEY04 .req w27
120XKEY04 .req x27
121WCOUN1 .req w28
122XCOUN1 .req x28
123WCOUN2 .req w30
124XCOUN2 .req x30
125
126.macro VADD2 src, dest, src2, dest2
127    add \dest, \dest, \src
128    add \dest2, \dest2, \src2
129.endm
130
131.macro VEOR2 src, dest, src2, dest2
132    eor \dest, \dest, \src
133    eor \dest2, \dest2, \src2
134.endm
135
136.macro VEORX srca, srcb, dest, srca2, srcb2, dest2
137    eor \dest, \srcb, \srca
138    eor \dest2, \srcb2, \srca2
139.endm
140
141.macro VREV322 dest, dest2
142    rev32 \dest, \dest
143    rev32 \dest2, \dest2
144.endm
145
146.macro VUSHR2 src, dest, src2, dest2, count
147    ushr \dest, \src, \count
148    ushr \dest2, \src2, \count
149.endm
150
151.macro VSLI2 src, dest, src2, dest2, count
152    sli \dest, \src, \count
153    sli \dest2, \src2, \count
154.endm
155
156.macro VEXT2 src, src2, count
157    ext \src, \src, \src, \count
158    ext \src2, \src2, \src2, \count
159.endm
160
161.macro WCHA_ADD_A_B
162    add WINPUT0, WINPUT0, WINPUT4
163    add WINPUT1, WINPUT1, WINPUT5
164    add WINPUT2, WINPUT2, WINPUT6
165    add WINPUT3, WINPUT3, WINPUT7
166.endm
167
168.macro WCHA_EOR_D_A
169    eor WINPUT12, WINPUT12, WINPUT0
170    eor WINPUT13, WINPUT13, WINPUT1
171    eor WINPUT14, WINPUT14, WINPUT2
172    eor WINPUT15, WINPUT15, WINPUT3
173.endm
174
175.macro WCHA_ROR_D  count
176    ror WINPUT12, WINPUT12, \count
177    ror WINPUT13, WINPUT13, \count
178    ror WINPUT14, WINPUT14, \count
179    ror WINPUT15, WINPUT15, \count
180.endm
181
182.macro WCHA_ADD_C_D
183    add WINPUT8, WINPUT8, WINPUT12
184    add WINPUT9, WINPUT9, WINPUT13
185    add WINPUT10, WINPUT10, WINPUT14
186    add WINPUT11, WINPUT11, WINPUT15
187.endm
188
189.macro WCHA_EOR_B_C
190    eor WINPUT4, WINPUT4, WINPUT8
191    eor WINPUT5, WINPUT5, WINPUT9
192    eor WINPUT6, WINPUT6, WINPUT10
193    eor WINPUT7, WINPUT7, WINPUT11
194.endm
195
196.macro WCHA_ROR_B  count
197    ror WINPUT4, WINPUT4, \count
198    ror WINPUT5, WINPUT5, \count
199    ror WINPUT6, WINPUT6, \count
200    ror WINPUT7, WINPUT7, \count
201.endm
202
203.macro WCHA_ADD2_A_B
204    add WINPUT0, WINPUT0, WINPUT5
205    add WINPUT1, WINPUT1, WINPUT6
206    add WINPUT2, WINPUT2, WINPUT7
207    add WINPUT3, WINPUT3, WINPUT4
208.endm
209
210.macro WCHA_EOR2_D_A
211    eor WINPUT15, WINPUT15, WINPUT0
212    eor WINPUT12, WINPUT12, WINPUT1
213    eor WINPUT13, WINPUT13, WINPUT2
214    eor WINPUT14, WINPUT14, WINPUT3
215.endm
216
217.macro WCHA_ADD2_C_D
218    add WINPUT10, WINPUT10, WINPUT15
219    add WINPUT11, WINPUT11, WINPUT12
220    add WINPUT8, WINPUT8, WINPUT13
221    add WINPUT9, WINPUT9, WINPUT14
222.endm
223
224.macro WCHA_EOR2_B_C
225    eor WINPUT5, WINPUT5, WINPUT10
226    eor WINPUT6, WINPUT6, WINPUT11
227    eor WINPUT7, WINPUT7, WINPUT8
228    eor WINPUT4, WINPUT4, WINPUT9
229.endm
230
231#endif
232