Merge tag 'chrome-platform-for-linus-4.19' of git://git.kernel.org/pub/scm/linux...
[sfrench/cifs-2.6.git] / arch / arm64 / crypto / aes-ce-core.S
1 /*
2  * Copyright (C) 2013 - 2017 Linaro Ltd <ard.biesheuvel@linaro.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8
9 #include <linux/linkage.h>
10 #include <asm/assembler.h>
11
12         .arch           armv8-a+crypto
13
14 ENTRY(__aes_ce_encrypt)
15         sub             w3, w3, #2
16         ld1             {v0.16b}, [x2]
17         ld1             {v1.4s}, [x0], #16
18         cmp             w3, #10
19         bmi             0f
20         bne             3f
21         mov             v3.16b, v1.16b
22         b               2f
23 0:      mov             v2.16b, v1.16b
24         ld1             {v3.4s}, [x0], #16
25 1:      aese            v0.16b, v2.16b
26         aesmc           v0.16b, v0.16b
27 2:      ld1             {v1.4s}, [x0], #16
28         aese            v0.16b, v3.16b
29         aesmc           v0.16b, v0.16b
30 3:      ld1             {v2.4s}, [x0], #16
31         subs            w3, w3, #3
32         aese            v0.16b, v1.16b
33         aesmc           v0.16b, v0.16b
34         ld1             {v3.4s}, [x0], #16
35         bpl             1b
36         aese            v0.16b, v2.16b
37         eor             v0.16b, v0.16b, v3.16b
38         st1             {v0.16b}, [x1]
39         ret
40 ENDPROC(__aes_ce_encrypt)
41
42 ENTRY(__aes_ce_decrypt)
43         sub             w3, w3, #2
44         ld1             {v0.16b}, [x2]
45         ld1             {v1.4s}, [x0], #16
46         cmp             w3, #10
47         bmi             0f
48         bne             3f
49         mov             v3.16b, v1.16b
50         b               2f
51 0:      mov             v2.16b, v1.16b
52         ld1             {v3.4s}, [x0], #16
53 1:      aesd            v0.16b, v2.16b
54         aesimc          v0.16b, v0.16b
55 2:      ld1             {v1.4s}, [x0], #16
56         aesd            v0.16b, v3.16b
57         aesimc          v0.16b, v0.16b
58 3:      ld1             {v2.4s}, [x0], #16
59         subs            w3, w3, #3
60         aesd            v0.16b, v1.16b
61         aesimc          v0.16b, v0.16b
62         ld1             {v3.4s}, [x0], #16
63         bpl             1b
64         aesd            v0.16b, v2.16b
65         eor             v0.16b, v0.16b, v3.16b
66         st1             {v0.16b}, [x1]
67         ret
68 ENDPROC(__aes_ce_decrypt)
69
70 /*
71  * __aes_ce_sub() - use the aese instruction to perform the AES sbox
72  *                  substitution on each byte in 'input'
73  */
74 ENTRY(__aes_ce_sub)
75         dup             v1.4s, w0
76         movi            v0.16b, #0
77         aese            v0.16b, v1.16b
78         umov            w0, v0.s[0]
79         ret
80 ENDPROC(__aes_ce_sub)
81
82 ENTRY(__aes_ce_invert)
83         ld1             {v0.4s}, [x1]
84         aesimc          v1.16b, v0.16b
85         st1             {v1.4s}, [x0]
86         ret
87 ENDPROC(__aes_ce_invert)