internal-keccakp-400-armv7m.S 7.59 KB
Newer Older
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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
#if defined(__ARM_ARCH_ISA_THUMB) && __ARM_ARCH == 7
/*
 * Copyright (C) 2021 Southern Storm Software, Pty Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

	.syntax unified
	.thumb
	.text

	.align	2
	.type	rconst, %object
rconst:
	.byte	0x01
	.byte	0x00
	.byte	0x82
	.byte	0x80
	.byte	0x8a
	.byte	0x80
	.byte	0x00
	.byte	0x80
	.byte	0x8b
	.byte	0x80
	.byte	0x01
	.byte	0x00
	.byte	0x81
	.byte	0x80
	.byte	0x09
	.byte	0x80
	.byte	0x8a
	.byte	0x00
	.byte	0x88
	.byte	0x00
	.byte	0x09
	.byte	0x80
	.byte	0x0a
	.byte	0x00
	.byte	0x8b
	.byte	0x80
	.byte	0x8b
	.byte	0x00
	.byte	0x89
	.byte	0x80
	.byte	0x03
	.byte	0x80
	.byte	0x02
	.byte	0x80
	.byte	0x80
	.byte	0x00
	.byte	0x0a
	.byte	0x80
	.byte	0x0a
	.byte	0x00
	.size	rconst, .-rconst

	.align	2
	.global	keccakp_400_permute
	.thumb
	.thumb_func
	.type	keccakp_400_permute, %function
keccakp_400_permute:
	push	{r4, r5, r6, r7, r8, r9, r10, fp, lr}
	ldrh	r7, [r0, #0]
	ldrh	r8, [r0, #2]
	ldrh	r9, [r0, #4]
	ldrh	r10, [r0, #6]
	ldrh	fp, [r0, #8]
	mov	lr, #40
	sub	lr, lr, r1, lsl #1
.L1:
	ldrh	r1, [r0, #10]
	eors	r1, r7
	ldrh	r6, [r0, #20]
	eors	r1, r6
	ldrh	r6, [r0, #30]
	eors	r1, r6
	ldrh	r6, [r0, #40]
	eors	r1, r6
	ldrh	r2, [r0, #12]
	eor	r2, r8
	ldrh	r6, [r0, #22]
	eors	r2, r6
	ldrh	r6, [r0, #32]
	eors	r2, r6
	ldrh	r6, [r0, #42]
	eors	r2, r6
	ldrh	r3, [r0, #14]
	eor	r3, r9
	ldrh	r6, [r0, #24]
	eors	r3, r6
	ldrh	r6, [r0, #34]
	eors	r3, r6
	ldrh	r6, [r0, #44]
	eors	r3, r6
	ldrh	r4, [r0, #16]
	eor	r4, r10
	ldrh	r6, [r0, #26]
	eors	r4, r6
	ldrh	r6, [r0, #36]
	eors	r4, r6
	ldrh	r6, [r0, #46]
	eors	r4, r6
	ldrh	ip, [r0, #18]
	eor	ip, fp
	ldrh	r6, [r0, #28]
	eor	ip, r6
	ldrh	r6, [r0, #38]
	eor	ip, r6
	ldrh	r6, [r0, #48]
	eor	ip, r6
	lsl	r5, r1, #1
	orr	r5, r5, r1, lsr #15
	eors	r5, r4
	uxth	r5, r5
	eor	fp, r5
	eors	r6, r5
	strh	r6, [r0, #48]
	ldrh	r6, [r0, #38]
	eors	r6, r5
	strh	r6, [r0, #38]
	ldrh	r6, [r0, #28]
	eors	r6, r5
	strh	r6, [r0, #28]
	ldrh	r6, [r0, #18]
	eors	r6, r5
	strh	r6, [r0, #18]
	lsl	r5, ip, #1
	orr	r5, r5, ip, lsr #15
	eors	r5, r3
	uxth	r5, r5
	eor	r10, r5
	ldrh	r6, [r0, #46]
	eors	r6, r5
	strh	r6, [r0, #46]
	ldrh	r6, [r0, #36]
	eors	r6, r5
	strh	r6, [r0, #36]
	ldrh	r6, [r0, #26]
	eors	r6, r5
	strh	r6, [r0, #26]
	ldrh	r6, [r0, #16]
	eors	r6, r5
	strh	r6, [r0, #16]
	lsl	r5, r4, #1
	orr	r5, r5, r4, lsr #15
	eors	r5, r2
	uxth	r5, r5
	eor	r9, r5
	ldrh	r6, [r0, #44]
	eors	r6, r5
	strh	r6, [r0, #44]
	ldrh	r6, [r0, #34]
	eors	r6, r5
	strh	r6, [r0, #34]
	ldrh	r6, [r0, #24]
	eors	r6, r5
	strh	r6, [r0, #24]
	ldrh	r6, [r0, #14]
	eors	r6, r5
	strh	r6, [r0, #14]
	lsl	r5, r3, #1
	orr	r5, r5, r3, lsr #15
	eors	r5, r1
	uxth	r5, r5
	eor	r8, r5
	ldrh	r6, [r0, #42]
	eors	r6, r5
	strh	r6, [r0, #42]
	ldrh	r6, [r0, #32]
	eors	r6, r5
	strh	r6, [r0, #32]
	ldrh	r6, [r0, #22]
	eors	r6, r5
	strh	r6, [r0, #22]
	ldrh	r6, [r0, #12]
	eors	r6, r5
	strh	r6, [r0, #12]
	lsl	r5, r2, #1
	orr	r5, r5, r2, lsr #15
	eor	r5, ip
	uxth	r5, r5
	eors	r7, r5
	ldrh	r6, [r0, #40]
	eors	r6, r5
	strh	r6, [r0, #40]
	ldrh	r6, [r0, #30]
	eors	r6, r5
	strh	r6, [r0, #30]
	ldrh	r6, [r0, #20]
	eors	r6, r5
	strh	r6, [r0, #20]
	ldrh	r6, [r0, #10]
	eors	r6, r5
	strh	r6, [r0, #10]
	lsl	r1, r8, #1
	orr	r1, r1, r8, lsr #15
	ldrh	r2, [r0, #12]
	lsl	r2, r2, #12
	orr	r8, r2, r2, lsr #16
	ldrh	r2, [r0, #18]
	lsl	r2, r2, #4
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #12]
	ldrh	r2, [r0, #44]
	lsl	r2, r2, #13
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #18]
	ldrh	r2, [r0, #28]
	lsl	r2, r2, #7
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #44]
	ldrh	r2, [r0, #40]
	lsl	r2, r2, #2
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #28]
	lsl	r9, r9, #14
	orr	r3, r9, r9, lsr #16
	strh	r3, [r0, #40]
	ldrh	r2, [r0, #24]
	lsl	r2, r2, #11
	orr	r9, r2, r2, lsr #16
	ldrh	r2, [r0, #26]
	lsl	r2, r2, #9
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #24]
	ldrh	r2, [r0, #38]
	rev16	r3, r2
	strh	r3, [r0, #26]
	ldrh	r2, [r0, #46]
	rev16	r3, r2
	strh	r3, [r0, #38]
	ldrh	r2, [r0, #30]
	lsl	r2, r2, #9
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #46]
	lsl	fp, fp, #11
	orr	r3, fp, fp, lsr #16
	strh	r3, [r0, #30]
	ldrh	r2, [r0, #48]
	lsl	r2, r2, #14
	orr	fp, r2, r2, lsr #16
	ldrh	r2, [r0, #42]
	lsl	r2, r2, #2
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #48]
	ldrh	r2, [r0, #16]
	lsl	r2, r2, #7
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #42]
	ldrh	r2, [r0, #32]
	lsl	r2, r2, #13
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #16]
	ldrh	r2, [r0, #10]
	lsl	r2, r2, #4
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #32]
	lsl	r10, r10, #12
	orr	r3, r10, r10, lsr #16
	strh	r3, [r0, #10]
	ldrh	r2, [r0, #36]
	lsl	r2, r2, #5
	orr	r10, r2, r2, lsr #16
	ldrh	r2, [r0, #34]
	lsl	r2, r2, #15
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #36]
	ldrh	r2, [r0, #22]
	lsl	r2, r2, #10
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #34]
	ldrh	r2, [r0, #14]
	lsl	r2, r2, #6
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #22]
	ldrh	r2, [r0, #20]
	lsl	r2, r2, #3
	orr	r3, r2, r2, lsr #16
	strh	r3, [r0, #14]
	strh	r1, [r0, #20]
	ldrh	r1, [r0, #40]
	ldrh	r2, [r0, #42]
	ldrh	r3, [r0, #44]
	ldrh	r4, [r0, #46]
	ldrh	ip, [r0, #48]
	bic	r6, r3, r2
	eors	r6, r1
	strh	r6, [r0, #40]
	bic	r6, r4, r3
	eors	r6, r2
	strh	r6, [r0, #42]
	bic	r6, ip, r4
	eors	r6, r3
	strh	r6, [r0, #44]
	bic	r6, r1, ip
	eors	r6, r4
	strh	r6, [r0, #46]
	bic	r6, r2, r1
	eor	r6, ip
	strh	r6, [r0, #48]
	ldrh	r1, [r0, #30]
	ldrh	r2, [r0, #32]
	ldrh	r3, [r0, #34]
	ldrh	r4, [r0, #36]
	ldrh	ip, [r0, #38]
	bic	r6, r3, r2
	eors	r6, r1
	strh	r6, [r0, #30]
	bic	r6, r4, r3
	eors	r6, r2
	strh	r6, [r0, #32]
	bic	r6, ip, r4
	eors	r6, r3
	strh	r6, [r0, #34]
	bic	r6, r1, ip
	eors	r6, r4
	strh	r6, [r0, #36]
	bic	r6, r2, r1
	eor	r6, ip
	strh	r6, [r0, #38]
	ldrh	r1, [r0, #20]
	ldrh	r2, [r0, #22]
	ldrh	r3, [r0, #24]
	ldrh	r4, [r0, #26]
	ldrh	ip, [r0, #28]
	bic	r6, r3, r2
	eors	r6, r1
	strh	r6, [r0, #20]
	bic	r6, r4, r3
	eors	r6, r2
	strh	r6, [r0, #22]
	bic	r6, ip, r4
	eors	r6, r3
	strh	r6, [r0, #24]
	bic	r6, r1, ip
	eors	r6, r4
	strh	r6, [r0, #26]
	bic	r6, r2, r1
	eor	r6, ip
	strh	r6, [r0, #28]
	ldrh	r1, [r0, #10]
	ldrh	r2, [r0, #12]
	ldrh	r3, [r0, #14]
	ldrh	r4, [r0, #16]
	ldrh	ip, [r0, #18]
	bic	r6, r3, r2
	eors	r6, r1
	strh	r6, [r0, #10]
	bic	r6, r4, r3
	eors	r6, r2
	strh	r6, [r0, #12]
	bic	r6, ip, r4
	eors	r6, r3
	strh	r6, [r0, #14]
	bic	r6, r1, ip
	eors	r6, r4
	strh	r6, [r0, #16]
	bic	r6, r2, r1
	eor	r6, ip
	strh	r6, [r0, #18]
	bic	r1, r9, r8
	bic	r2, r10, r9
	bic	r3, fp, r10
	bic	r4, r7, fp
	bic	ip, r8, r7
	eors	r1, r7
	eor	r2, r8
	eor	r3, r9
	eor	r4, r10
	eor	ip, fp
	adr	r5, rconst
	uxth	r8, r2
	ldrh	r6, [r5, lr]
	uxth	r9, r3
	eor	r7, r1, r6
	uxth	r10, r4
	uxth	r7, r7
	uxth	fp, ip
	add	lr, #2
	cmp	lr, #40
	bne	.L1
	strh	r7, [r0, #0]
	strh	r8, [r0, #2]
	strh	r9, [r0, #4]
	strh	r10, [r0, #6]
	strh	fp, [r0, #8]
	pop	{r4, r5, r6, r7, r8, r9, r10, fp, pc}
	.size	keccakp_400_permute, .-keccakp_400_permute

#endif