]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | /********************************************************************** |
2 | Copyright(c) 2021 Arm Corporation All rights reserved. | |
3 | ||
4 | Redistribution and use in source and binary forms, with or without | |
5 | modification, are permitted provided that the following conditions | |
6 | are met: | |
7 | * Redistributions of source code must retain the above copyright | |
8 | notice, this list of conditions and the following disclaimer. | |
9 | * Redistributions in binary form must reproduce the above copyright | |
10 | notice, this list of conditions and the following disclaimer in | |
11 | the documentation and/or other materials provided with the | |
12 | distribution. | |
13 | * Neither the name of Arm Corporation nor the names of its | |
14 | contributors may be used to endorse or promote products derived | |
15 | from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | **********************************************************************/ | |
29 | .arch armv8-a+crypto | |
30 | .text | |
31 | ||
32 | #include "xts_aes_256_common.S" | |
33 | #include "xts_aes_common.S" | |
34 | ||
35 | .macro vswap vec1:req,vec2:req | |
36 | mov vtmp.16b,\vec1\().16b | |
37 | mov \vec1\().16b,\vec2\().16b | |
38 | mov \vec2\().16b,vtmp.16b | |
39 | .endm | |
40 | ||
41 | /* encrypt the tweak by tweak key (k2), and at the same time | |
42 | * to expand encryption key (k1) | |
43 | * even though two sets of keys share the same set of registers | |
44 | * they never overlap at any given time (k2 is used only once and discarded) | |
45 | */ | |
46 | .macro keyexp_and_encrypt_tweak iv:req,k2:req,k1:req | |
47 | aes_key_expand 0,\k2 | |
48 | aes_enc_round \iv,0 | |
49 | aes_enc_round \iv,1 | |
50 | aes_key_expand 2 | |
51 | aes_key_expand 0,\k1,rcon2 | |
52 | aes_enc_round \iv,2 | |
53 | aes_enc_round \iv,3 | |
54 | aes_key_expand 4 | |
55 | aes_key_expand 2,rcon2 | |
56 | aes_enc_round \iv,4 | |
57 | aes_enc_round \iv,5 | |
58 | aes_key_expand 6 | |
59 | aes_key_expand 4,rcon2 | |
60 | aes_enc_round \iv,6 | |
61 | aes_enc_round \iv,7 | |
62 | aes_key_expand 8 | |
63 | aes_key_expand 6,rcon2 | |
64 | aes_enc_round \iv,8 | |
65 | aes_enc_round \iv,9 | |
66 | aes_key_expand 10 | |
67 | aes_key_expand 8,rcon2 | |
68 | aes_enc_round \iv,10 | |
69 | aes_enc_round \iv,11 | |
70 | aes_key_expand 12 | |
71 | aes_key_expand 10,rcon2 | |
72 | aes_enc_round \iv,12 | |
73 | aes_enc_round \iv,13 | |
74 | aes_key_expand 14 | |
75 | aes_key_expand 12,rcon2 | |
76 | aes_enc_round \iv,14 | |
77 | aes_key_expand 14,rcon2 | |
78 | ||
79 | // transform encryption key into decrption key | |
80 | aesimc vKey1.16b,vKey1.16b | |
81 | vswap vKey0,vKey14 | |
82 | aesimc vKey13.16b,vKey13.16b | |
83 | aesimc vKey2.16b,vKey2.16b | |
84 | vswap vKey1,vKey13 | |
85 | aesimc vKey12.16b,vKey12.16b | |
86 | aesimc vKey3.16b,vKey3.16b | |
87 | vswap vKey2,vKey12 | |
88 | aesimc vKey11.16b,vKey11.16b | |
89 | aesimc vKey4.16b,vKey4.16b | |
90 | vswap vKey3,vKey11 | |
91 | aesimc vKey10.16b,vKey10.16b | |
92 | aesimc vKey5.16b,vKey5.16b | |
93 | vswap vKey4,vKey10 | |
94 | aesimc vKey9.16b,vKey9.16b | |
95 | aesimc vKey6.16b,vKey6.16b | |
96 | vswap vKey5,vKey9 | |
97 | aesimc vKey8.16b,vKey8.16b | |
98 | aesimc vKey7.16b,vKey7.16b | |
99 | vswap vKey6,vKey8 | |
100 | .endm | |
101 | ||
102 | /* | |
103 | * void XTS_AES_256_dec_ce( | |
104 | * uint8_t *k2, //!< key used for tweaking, 32 bytes | |
105 | * uint8_t *k1, //!< key used for decryption of tweaked ciphertext, 32 bytes | |
106 | * uint8_t *TW_initial, //!< initial tweak value, 16 bytes | |
107 | * uint64_t N, //!< sector size, in bytes | |
108 | * const uint8_t *ct, //!< ciphertext sector input data | |
109 | * uint8_t *pt //!< plaintext sector output data | |
110 | * ); | |
111 | */ | |
112 | .global XTS_AES_256_dec_ce | |
113 | .type XTS_AES_256_dec_ce, %function | |
114 | XTS_AES_256_dec_ce: | |
115 | xts_aes_crypt 1,keyexp_and_encrypt_tweak vIV0,key2,key1 | |
116 | .size XTS_AES_256_dec_ce, .-XTS_AES_256_dec_ce |