]> git.proxmox.com Git - ceph.git/blob - ceph/src/crypto/isa-l/isa-l_crypto/aes/aarch64/xts_aes_128_dec.S
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / crypto / isa-l / isa-l_crypto / aes / aarch64 / xts_aes_128_dec.S
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_128_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_key_expand 1
50 aes_enc_round \iv,1
51 aes_key_expand 0,\k1,rcon2
52 aes_key_expand 2
53 aes_enc_round \iv,2
54 aes_key_expand 1,rcon2
55 aes_key_expand 3
56 aes_enc_round \iv,3
57 aes_key_expand 2,rcon2
58 aes_key_expand 4
59 aes_enc_round \iv,4
60 aes_key_expand 3,rcon2
61 aes_key_expand 5
62 aes_enc_round \iv,5
63 aes_key_expand 4,rcon2
64 aes_key_expand 6
65 aes_enc_round \iv,6
66 aes_key_expand 5,rcon2
67 aes_key_expand 7
68 aes_enc_round \iv,7
69 aes_key_expand 6,rcon2
70 aes_key_expand 8
71 aes_enc_round \iv,8
72 aes_key_expand 7,rcon2
73 aes_key_expand 9
74 aes_enc_round \iv,9
75 aes_key_expand 8,rcon2
76 aes_key_expand 10
77 aes_enc_round \iv,10
78 aes_key_expand 9,rcon2
79 aes_key_expand 10,rcon2
80
81 // transform encryption key into decrption key
82 aesimc vKey1.16b,vKey1.16b
83 vswap vKey0,vKey10
84 aesimc vKey9.16b,vKey9.16b
85
86 aesimc vKey2.16b,vKey2.16b
87 aesimc vKey8.16b,vKey8.16b
88 vswap vKey1,vKey9
89
90 aesimc vKey3.16b,vKey3.16b
91 aesimc vKey7.16b,vKey7.16b
92 vswap vKey2,vKey8
93
94 aesimc vKey4.16b,vKey4.16b
95 aesimc vKey6.16b,vKey6.16b
96 vswap vKey3,vKey7
97
98 aesimc vKey5.16b,vKey5.16b
99 vswap vKey4,vKey6
100 .endm
101
102 /*
103 * void XTS_AES_128_dec_ce(
104 * uint8_t *k2, //!< key used for tweaking, 16 bytes
105 * uint8_t *k1, //!< key used for decryption of tweaked ciphertext, 16 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_128_dec_ce
113 .type XTS_AES_128_dec_ce, %function
114 XTS_AES_128_dec_ce:
115 xts_aes_crypt 1,keyexp_and_encrypt_tweak vIV0,key2,key1
116 .size XTS_AES_128_dec_ce, .-XTS_AES_128_dec_ce