2 #include <openssl/arm_arch.h>
4 #if __ARM_MAX_ARCH__>=7
11 .long 0x01,0x01,0x01,0x01
12 .long 0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d,0x0c0f0e0d @ rotate-n-splat
13 .long 0x1b,0x1b,0x1b,0x1b
15 .globl aes_v8_set_encrypt_key
16 .type aes_v8_set_encrypt_key,%function
18 aes_v8_set_encrypt_key:
51 .byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
70 .byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
85 .byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
103 vmov.i8 q10,#8 @ borrow q10
105 vsub.i8 q2,q2,q10 @ adjust the mask
112 .byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
148 .byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
164 .byte 0x00,0x43,0xf0,0xf3 @ aese q10,q0
180 mov r0,r3 @ return value
183 .size aes_v8_set_encrypt_key,.-aes_v8_set_encrypt_key
185 .globl aes_v8_set_decrypt_key
186 .type aes_v8_set_decrypt_key,%function
188 aes_v8_set_decrypt_key:
195 sub r2,r2,#240 @ restore original r2
197 add r0,r2,r12,lsl#4 @ end of key schedule
207 .byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
208 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
215 .byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
218 eor r0,r0,r0 @ return value
221 .size aes_v8_set_decrypt_key,.-aes_v8_set_decrypt_key
222 .globl aes_v8_encrypt
223 .type aes_v8_encrypt,%function
233 .byte 0x00,0x43,0xb0,0xf3 @ aese q2,q0
234 .byte 0x84,0x43,0xb0,0xf3 @ aesmc q2,q2
237 .byte 0x02,0x43,0xb0,0xf3 @ aese q2,q1
238 .byte 0x84,0x43,0xb0,0xf3 @ aesmc q2,q2
242 .byte 0x00,0x43,0xb0,0xf3 @ aese q2,q0
243 .byte 0x84,0x43,0xb0,0xf3 @ aesmc q2,q2
245 .byte 0x02,0x43,0xb0,0xf3 @ aese q2,q1
250 .size aes_v8_encrypt,.-aes_v8_encrypt
251 .globl aes_v8_decrypt
252 .type aes_v8_decrypt,%function
262 .byte 0x40,0x43,0xb0,0xf3 @ aesd q2,q0
263 .byte 0xc4,0x43,0xb0,0xf3 @ aesimc q2,q2
266 .byte 0x42,0x43,0xb0,0xf3 @ aesd q2,q1
267 .byte 0xc4,0x43,0xb0,0xf3 @ aesimc q2,q2
271 .byte 0x40,0x43,0xb0,0xf3 @ aesd q2,q0
272 .byte 0xc4,0x43,0xb0,0xf3 @ aesimc q2,q2
274 .byte 0x42,0x43,0xb0,0xf3 @ aesd q2,q1
279 .size aes_v8_decrypt,.-aes_v8_decrypt
280 .globl aes_v8_cbc_encrypt
281 .type aes_v8_cbc_encrypt,%function
285 stmdb sp!,{r4,r5,r6,r7,r8,lr}
286 vstmdb sp!,{d8,d9,d10,d11,d12,d13,d14,d15} @ ABI specification says so
287 ldmia ip,{r4,r5} @ load remaining args
293 cmp r5,#0 @ en- or decrypting?
299 vld1.32 {q8,q9},[r3] @ load key schedule...
301 add r7,r3,r5,lsl#4 @ pointer to last 7 round keys
303 vld1.32 {q10,q11},[r7]!
304 vld1.32 {q12,q13},[r7]!
305 vld1.32 {q14,q15},[r7]!
321 .byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
322 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
329 .byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
330 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
333 .byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
334 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
335 .byte 0x04,0x03,0xb0,0xf3 @ aese q0,q2
336 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
339 .byte 0x06,0x03,0xb0,0xf3 @ aese q0,q3
340 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
344 .byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
345 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
347 .byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
348 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
353 .byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
354 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
356 .byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
357 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
359 .byte 0x24,0x03,0xb0,0xf3 @ aese q0,q10
360 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
361 .byte 0x26,0x03,0xb0,0xf3 @ aese q0,q11
362 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
364 .byte 0x28,0x03,0xb0,0xf3 @ aese q0,q12
365 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
367 .byte 0x2a,0x03,0xb0,0xf3 @ aese q0,q13
368 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
369 vld1.32 {q9},[r7] @ re-pre-load rndkey[1]
370 .byte 0x2c,0x03,0xb0,0xf3 @ aese q0,q14
371 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
372 .byte 0x2e,0x03,0xb0,0xf3 @ aese q0,q15
382 .byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
383 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
386 .byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
387 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
390 .byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
391 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
393 .byte 0x04,0x03,0xb0,0xf3 @ aese q0,q2
394 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
396 .byte 0x06,0x03,0xb0,0xf3 @ aese q0,q3
397 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
398 .byte 0x24,0x03,0xb0,0xf3 @ aese q0,q10
399 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
400 .byte 0x26,0x03,0xb0,0xf3 @ aese q0,q11
401 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
403 .byte 0x28,0x03,0xb0,0xf3 @ aese q0,q12
404 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
405 .byte 0x2a,0x03,0xb0,0xf3 @ aese q0,q13
406 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
407 .byte 0x2c,0x03,0xb0,0xf3 @ aese q0,q14
408 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
410 .byte 0x2e,0x03,0xb0,0xf3 @ aese q0,q15
419 subs r2,r2,#32 @ bias
433 .byte 0x60,0x03,0xb0,0xf3 @ aesd q0,q8
434 .byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
435 .byte 0x60,0x23,0xb0,0xf3 @ aesd q1,q8
436 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
437 .byte 0x60,0x43,0xf0,0xf3 @ aesd q10,q8
438 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
441 .byte 0x62,0x03,0xb0,0xf3 @ aesd q0,q9
442 .byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
443 .byte 0x62,0x23,0xb0,0xf3 @ aesd q1,q9
444 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
445 .byte 0x62,0x43,0xf0,0xf3 @ aesd q10,q9
446 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
450 .byte 0x60,0x03,0xb0,0xf3 @ aesd q0,q8
451 .byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
452 .byte 0x60,0x23,0xb0,0xf3 @ aesd q1,q8
453 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
454 .byte 0x60,0x43,0xf0,0xf3 @ aesd q10,q8
455 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
459 movlo r6,r2 @ r6, r6, is zero at this point
460 .byte 0x62,0x03,0xb0,0xf3 @ aesd q0,q9
461 .byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
462 .byte 0x62,0x23,0xb0,0xf3 @ aesd q1,q9
463 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
464 .byte 0x62,0x43,0xf0,0xf3 @ aesd q10,q9
465 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
467 add r0,r0,r6 @ r0 is adjusted in such way that
468 @ at exit from the loop q1-q10
469 @ are loaded with last "words"
472 .byte 0x68,0x03,0xb0,0xf3 @ aesd q0,q12
473 .byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
474 .byte 0x68,0x23,0xb0,0xf3 @ aesd q1,q12
475 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
476 .byte 0x68,0x43,0xf0,0xf3 @ aesd q10,q12
477 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
479 .byte 0x6a,0x03,0xb0,0xf3 @ aesd q0,q13
480 .byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
481 .byte 0x6a,0x23,0xb0,0xf3 @ aesd q1,q13
482 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
483 .byte 0x6a,0x43,0xf0,0xf3 @ aesd q10,q13
484 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
486 .byte 0x6c,0x03,0xb0,0xf3 @ aesd q0,q14
487 .byte 0xc0,0x03,0xb0,0xf3 @ aesimc q0,q0
488 .byte 0x6c,0x23,0xb0,0xf3 @ aesd q1,q14
489 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
490 .byte 0x6c,0x43,0xf0,0xf3 @ aesd q10,q14
491 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
493 .byte 0x6e,0x03,0xb0,0xf3 @ aesd q0,q15
494 .byte 0x6e,0x23,0xb0,0xf3 @ aesd q1,q15
495 .byte 0x6e,0x43,0xf0,0xf3 @ aesd q10,q15
496 vld1.32 {q8},[r7]! @ re-pre-load rndkey[0]
501 vld1.32 {q9},[r7]! @ re-pre-load rndkey[1]
515 .byte 0x60,0x23,0xb0,0xf3 @ aesd q1,q8
516 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
517 .byte 0x60,0x43,0xf0,0xf3 @ aesd q10,q8
518 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
521 .byte 0x62,0x23,0xb0,0xf3 @ aesd q1,q9
522 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
523 .byte 0x62,0x43,0xf0,0xf3 @ aesd q10,q9
524 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
528 .byte 0x60,0x23,0xb0,0xf3 @ aesd q1,q8
529 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
530 .byte 0x60,0x43,0xf0,0xf3 @ aesd q10,q8
531 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
532 .byte 0x62,0x23,0xb0,0xf3 @ aesd q1,q9
533 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
534 .byte 0x62,0x43,0xf0,0xf3 @ aesd q10,q9
535 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
536 .byte 0x68,0x23,0xb0,0xf3 @ aesd q1,q12
537 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
538 .byte 0x68,0x43,0xf0,0xf3 @ aesd q10,q12
539 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
541 .byte 0x6a,0x23,0xb0,0xf3 @ aesd q1,q13
542 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
543 .byte 0x6a,0x43,0xf0,0xf3 @ aesd q10,q13
544 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
546 .byte 0x6c,0x23,0xb0,0xf3 @ aesd q1,q14
547 .byte 0xc2,0x23,0xb0,0xf3 @ aesimc q1,q1
548 .byte 0x6c,0x43,0xf0,0xf3 @ aesd q10,q14
549 .byte 0xe4,0x43,0xf0,0xf3 @ aesimc q10,q10
551 .byte 0x6e,0x23,0xb0,0xf3 @ aesd q1,q15
552 .byte 0x6e,0x43,0xf0,0xf3 @ aesd q10,q15
569 vldmia sp!,{d8,d9,d10,d11,d12,d13,d14,d15}
570 ldmia sp!,{r4,r5,r6,r7,r8,pc}
571 .size aes_v8_cbc_encrypt,.-aes_v8_cbc_encrypt
572 .globl aes_v8_ctr32_encrypt_blocks
573 .type aes_v8_ctr32_encrypt_blocks,%function
575 aes_v8_ctr32_encrypt_blocks:
577 stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,lr}
578 vstmdb sp!,{d8,d9,d10,d11,d12,d13,d14,d15} @ ABI specification says so
579 ldr r4, [ip] @ load remaining arg
585 vld1.32 {q8,q9},[r3] @ load key schedule...
589 add r7,r3,r5,lsl#4 @ pointer to last 5 round keys
591 vld1.32 {q12,q13},[r7]!
592 vld1.32 {q14,q15},[r7]!
615 .byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
616 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
617 .byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
618 .byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
619 .byte 0x20,0x43,0xf0,0xf3 @ aese q10,q8
620 .byte 0xa4,0x43,0xf0,0xf3 @ aesmc q10,q10
623 .byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
624 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
625 .byte 0x22,0x23,0xb0,0xf3 @ aese q1,q9
626 .byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
627 .byte 0x22,0x43,0xf0,0xf3 @ aese q10,q9
628 .byte 0xa4,0x43,0xf0,0xf3 @ aesmc q10,q10
632 .byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
633 .byte 0x80,0x83,0xb0,0xf3 @ aesmc q4,q0
634 .byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
635 .byte 0x82,0xa3,0xb0,0xf3 @ aesmc q5,q1
638 .byte 0x20,0x43,0xf0,0xf3 @ aese q10,q8
639 .byte 0xa4,0x43,0xf0,0xf3 @ aesmc q10,q10
642 .byte 0x22,0x83,0xb0,0xf3 @ aese q4,q9
643 .byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
644 .byte 0x22,0xa3,0xb0,0xf3 @ aese q5,q9
645 .byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
648 .byte 0x22,0x43,0xf0,0xf3 @ aese q10,q9
649 .byte 0xa4,0x23,0xf0,0xf3 @ aesmc q9,q10
652 .byte 0x28,0x83,0xb0,0xf3 @ aese q4,q12
653 .byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
654 .byte 0x28,0xa3,0xb0,0xf3 @ aese q5,q12
655 .byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
658 .byte 0x28,0x23,0xf0,0xf3 @ aese q9,q12
659 .byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
662 .byte 0x2a,0x83,0xb0,0xf3 @ aese q4,q13
663 .byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
664 .byte 0x2a,0xa3,0xb0,0xf3 @ aese q5,q13
665 .byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
668 .byte 0x2a,0x23,0xf0,0xf3 @ aese q9,q13
669 .byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
672 .byte 0x2c,0x83,0xb0,0xf3 @ aese q4,q14
673 .byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
674 .byte 0x2c,0xa3,0xb0,0xf3 @ aese q5,q14
675 .byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
678 .byte 0x2c,0x23,0xf0,0xf3 @ aese q9,q14
679 .byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
682 .byte 0x2e,0x83,0xb0,0xf3 @ aese q4,q15
683 .byte 0x2e,0xa3,0xb0,0xf3 @ aese q5,q15
684 .byte 0x2e,0x23,0xf0,0xf3 @ aese q9,q15
687 vld1.32 {q8},[r7]! @ re-pre-load rndkey[0]
693 vld1.32 {q9},[r7]! @ re-pre-load rndkey[1]
704 .byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
705 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
706 .byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
707 .byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
710 .byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
711 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
712 .byte 0x22,0x23,0xb0,0xf3 @ aese q1,q9
713 .byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
717 .byte 0x20,0x03,0xb0,0xf3 @ aese q0,q8
718 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
719 .byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
720 .byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
721 .byte 0x22,0x03,0xb0,0xf3 @ aese q0,q9
722 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
723 .byte 0x22,0x23,0xb0,0xf3 @ aese q1,q9
724 .byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
726 .byte 0x28,0x03,0xb0,0xf3 @ aese q0,q12
727 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
728 .byte 0x28,0x23,0xb0,0xf3 @ aese q1,q12
729 .byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
731 .byte 0x2a,0x03,0xb0,0xf3 @ aese q0,q13
732 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
733 .byte 0x2a,0x23,0xb0,0xf3 @ aese q1,q13
734 .byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
736 .byte 0x2c,0x03,0xb0,0xf3 @ aese q0,q14
737 .byte 0x80,0x03,0xb0,0xf3 @ aesmc q0,q0
738 .byte 0x2c,0x23,0xb0,0xf3 @ aese q1,q14
739 .byte 0x82,0x23,0xb0,0xf3 @ aesmc q1,q1
741 .byte 0x2e,0x03,0xb0,0xf3 @ aese q0,q15
742 .byte 0x2e,0x23,0xb0,0xf3 @ aese q1,q15
752 vldmia sp!,{d8,d9,d10,d11,d12,d13,d14,d15}
753 ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,pc}
754 .size aes_v8_ctr32_encrypt_blocks,.-aes_v8_ctr32_encrypt_blocks