.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Glue Code for x86_64/AVX/AES-NI assembler optimized version of Camellia |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright © 2012-2013 Jussi Kivilinna <jussi.kivilinna@iki.fi> |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License as published by |
---|
8 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
9 | | - * (at your option) any later version. |
---|
10 | | - * |
---|
11 | 6 | */ |
---|
12 | 7 | |
---|
13 | 8 | #include <asm/crypto/camellia.h> |
---|
.. | .. |
---|
23 | 18 | #define CAMELLIA_AESNI_PARALLEL_BLOCKS 16 |
---|
24 | 19 | |
---|
25 | 20 | /* 16-way parallel cipher functions (avx/aes-ni) */ |
---|
26 | | -asmlinkage void camellia_ecb_enc_16way(struct camellia_ctx *ctx, u8 *dst, |
---|
27 | | - const u8 *src); |
---|
| 21 | +asmlinkage void camellia_ecb_enc_16way(const void *ctx, u8 *dst, const u8 *src); |
---|
28 | 22 | EXPORT_SYMBOL_GPL(camellia_ecb_enc_16way); |
---|
29 | 23 | |
---|
30 | | -asmlinkage void camellia_ecb_dec_16way(struct camellia_ctx *ctx, u8 *dst, |
---|
31 | | - const u8 *src); |
---|
| 24 | +asmlinkage void camellia_ecb_dec_16way(const void *ctx, u8 *dst, const u8 *src); |
---|
32 | 25 | EXPORT_SYMBOL_GPL(camellia_ecb_dec_16way); |
---|
33 | 26 | |
---|
34 | | -asmlinkage void camellia_cbc_dec_16way(struct camellia_ctx *ctx, u8 *dst, |
---|
35 | | - const u8 *src); |
---|
| 27 | +asmlinkage void camellia_cbc_dec_16way(const void *ctx, u8 *dst, const u8 *src); |
---|
36 | 28 | EXPORT_SYMBOL_GPL(camellia_cbc_dec_16way); |
---|
37 | 29 | |
---|
38 | | -asmlinkage void camellia_ctr_16way(struct camellia_ctx *ctx, u8 *dst, |
---|
39 | | - const u8 *src, le128 *iv); |
---|
| 30 | +asmlinkage void camellia_ctr_16way(const void *ctx, u8 *dst, const u8 *src, |
---|
| 31 | + le128 *iv); |
---|
40 | 32 | EXPORT_SYMBOL_GPL(camellia_ctr_16way); |
---|
41 | 33 | |
---|
42 | | -asmlinkage void camellia_xts_enc_16way(struct camellia_ctx *ctx, u8 *dst, |
---|
43 | | - const u8 *src, le128 *iv); |
---|
| 34 | +asmlinkage void camellia_xts_enc_16way(const void *ctx, u8 *dst, const u8 *src, |
---|
| 35 | + le128 *iv); |
---|
44 | 36 | EXPORT_SYMBOL_GPL(camellia_xts_enc_16way); |
---|
45 | 37 | |
---|
46 | | -asmlinkage void camellia_xts_dec_16way(struct camellia_ctx *ctx, u8 *dst, |
---|
47 | | - const u8 *src, le128 *iv); |
---|
| 38 | +asmlinkage void camellia_xts_dec_16way(const void *ctx, u8 *dst, const u8 *src, |
---|
| 39 | + le128 *iv); |
---|
48 | 40 | EXPORT_SYMBOL_GPL(camellia_xts_dec_16way); |
---|
49 | 41 | |
---|
50 | | -void camellia_xts_enc(void *ctx, u128 *dst, const u128 *src, le128 *iv) |
---|
| 42 | +void camellia_xts_enc(const void *ctx, u8 *dst, const u8 *src, le128 *iv) |
---|
51 | 43 | { |
---|
52 | | - glue_xts_crypt_128bit_one(ctx, dst, src, iv, |
---|
53 | | - GLUE_FUNC_CAST(camellia_enc_blk)); |
---|
| 44 | + glue_xts_crypt_128bit_one(ctx, dst, src, iv, camellia_enc_blk); |
---|
54 | 45 | } |
---|
55 | 46 | EXPORT_SYMBOL_GPL(camellia_xts_enc); |
---|
56 | 47 | |
---|
57 | | -void camellia_xts_dec(void *ctx, u128 *dst, const u128 *src, le128 *iv) |
---|
| 48 | +void camellia_xts_dec(const void *ctx, u8 *dst, const u8 *src, le128 *iv) |
---|
58 | 49 | { |
---|
59 | | - glue_xts_crypt_128bit_one(ctx, dst, src, iv, |
---|
60 | | - GLUE_FUNC_CAST(camellia_dec_blk)); |
---|
| 50 | + glue_xts_crypt_128bit_one(ctx, dst, src, iv, camellia_dec_blk); |
---|
61 | 51 | } |
---|
62 | 52 | EXPORT_SYMBOL_GPL(camellia_xts_dec); |
---|
63 | 53 | |
---|
.. | .. |
---|
67 | 57 | |
---|
68 | 58 | .funcs = { { |
---|
69 | 59 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
70 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_enc_16way) } |
---|
| 60 | + .fn_u = { .ecb = camellia_ecb_enc_16way } |
---|
71 | 61 | }, { |
---|
72 | 62 | .num_blocks = 2, |
---|
73 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_enc_blk_2way) } |
---|
| 63 | + .fn_u = { .ecb = camellia_enc_blk_2way } |
---|
74 | 64 | }, { |
---|
75 | 65 | .num_blocks = 1, |
---|
76 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_enc_blk) } |
---|
| 66 | + .fn_u = { .ecb = camellia_enc_blk } |
---|
77 | 67 | } } |
---|
78 | 68 | }; |
---|
79 | 69 | |
---|
.. | .. |
---|
83 | 73 | |
---|
84 | 74 | .funcs = { { |
---|
85 | 75 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
86 | | - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_ctr_16way) } |
---|
| 76 | + .fn_u = { .ctr = camellia_ctr_16way } |
---|
87 | 77 | }, { |
---|
88 | 78 | .num_blocks = 2, |
---|
89 | | - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_crypt_ctr_2way) } |
---|
| 79 | + .fn_u = { .ctr = camellia_crypt_ctr_2way } |
---|
90 | 80 | }, { |
---|
91 | 81 | .num_blocks = 1, |
---|
92 | | - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_crypt_ctr) } |
---|
| 82 | + .fn_u = { .ctr = camellia_crypt_ctr } |
---|
93 | 83 | } } |
---|
94 | 84 | }; |
---|
95 | 85 | |
---|
.. | .. |
---|
99 | 89 | |
---|
100 | 90 | .funcs = { { |
---|
101 | 91 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
102 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_enc_16way) } |
---|
| 92 | + .fn_u = { .xts = camellia_xts_enc_16way } |
---|
103 | 93 | }, { |
---|
104 | 94 | .num_blocks = 1, |
---|
105 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_enc) } |
---|
| 95 | + .fn_u = { .xts = camellia_xts_enc } |
---|
106 | 96 | } } |
---|
107 | 97 | }; |
---|
108 | 98 | |
---|
.. | .. |
---|
112 | 102 | |
---|
113 | 103 | .funcs = { { |
---|
114 | 104 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
115 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_dec_16way) } |
---|
| 105 | + .fn_u = { .ecb = camellia_ecb_dec_16way } |
---|
116 | 106 | }, { |
---|
117 | 107 | .num_blocks = 2, |
---|
118 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_dec_blk_2way) } |
---|
| 108 | + .fn_u = { .ecb = camellia_dec_blk_2way } |
---|
119 | 109 | }, { |
---|
120 | 110 | .num_blocks = 1, |
---|
121 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_dec_blk) } |
---|
| 111 | + .fn_u = { .ecb = camellia_dec_blk } |
---|
122 | 112 | } } |
---|
123 | 113 | }; |
---|
124 | 114 | |
---|
.. | .. |
---|
128 | 118 | |
---|
129 | 119 | .funcs = { { |
---|
130 | 120 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
131 | | - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_cbc_dec_16way) } |
---|
| 121 | + .fn_u = { .cbc = camellia_cbc_dec_16way } |
---|
132 | 122 | }, { |
---|
133 | 123 | .num_blocks = 2, |
---|
134 | | - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_decrypt_cbc_2way) } |
---|
| 124 | + .fn_u = { .cbc = camellia_decrypt_cbc_2way } |
---|
135 | 125 | }, { |
---|
136 | 126 | .num_blocks = 1, |
---|
137 | | - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_dec_blk) } |
---|
| 127 | + .fn_u = { .cbc = camellia_dec_blk } |
---|
138 | 128 | } } |
---|
139 | 129 | }; |
---|
140 | 130 | |
---|
.. | .. |
---|
144 | 134 | |
---|
145 | 135 | .funcs = { { |
---|
146 | 136 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
147 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_dec_16way) } |
---|
| 137 | + .fn_u = { .xts = camellia_xts_dec_16way } |
---|
148 | 138 | }, { |
---|
149 | 139 | .num_blocks = 1, |
---|
150 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_dec) } |
---|
| 140 | + .fn_u = { .xts = camellia_xts_dec } |
---|
151 | 141 | } } |
---|
152 | 142 | }; |
---|
153 | 143 | |
---|
154 | 144 | static int camellia_setkey(struct crypto_skcipher *tfm, const u8 *key, |
---|
155 | 145 | unsigned int keylen) |
---|
156 | 146 | { |
---|
157 | | - return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen, |
---|
158 | | - &tfm->base.crt_flags); |
---|
| 147 | + return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen); |
---|
159 | 148 | } |
---|
160 | 149 | |
---|
161 | 150 | static int ecb_encrypt(struct skcipher_request *req) |
---|
.. | .. |
---|
170 | 159 | |
---|
171 | 160 | static int cbc_encrypt(struct skcipher_request *req) |
---|
172 | 161 | { |
---|
173 | | - return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(camellia_enc_blk), |
---|
174 | | - req); |
---|
| 162 | + return glue_cbc_encrypt_req_128bit(camellia_enc_blk, req); |
---|
175 | 163 | } |
---|
176 | 164 | |
---|
177 | 165 | static int cbc_decrypt(struct skcipher_request *req) |
---|
.. | .. |
---|
188 | 176 | unsigned int keylen) |
---|
189 | 177 | { |
---|
190 | 178 | struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm); |
---|
191 | | - u32 *flags = &tfm->base.crt_flags; |
---|
192 | 179 | int err; |
---|
193 | 180 | |
---|
194 | 181 | err = xts_verify_key(tfm, key, keylen); |
---|
.. | .. |
---|
196 | 183 | return err; |
---|
197 | 184 | |
---|
198 | 185 | /* first half of xts-key is for crypt */ |
---|
199 | | - err = __camellia_setkey(&ctx->crypt_ctx, key, keylen / 2, flags); |
---|
| 186 | + err = __camellia_setkey(&ctx->crypt_ctx, key, keylen / 2); |
---|
200 | 187 | if (err) |
---|
201 | 188 | return err; |
---|
202 | 189 | |
---|
203 | 190 | /* second half of xts-key is for tweak */ |
---|
204 | | - return __camellia_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2, |
---|
205 | | - flags); |
---|
| 191 | + return __camellia_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2); |
---|
206 | 192 | } |
---|
207 | 193 | EXPORT_SYMBOL_GPL(xts_camellia_setkey); |
---|
208 | 194 | |
---|
.. | .. |
---|
211 | 197 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
---|
212 | 198 | struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm); |
---|
213 | 199 | |
---|
214 | | - return glue_xts_req_128bit(&camellia_enc_xts, req, |
---|
215 | | - XTS_TWEAK_CAST(camellia_enc_blk), |
---|
216 | | - &ctx->tweak_ctx, &ctx->crypt_ctx); |
---|
| 200 | + return glue_xts_req_128bit(&camellia_enc_xts, req, camellia_enc_blk, |
---|
| 201 | + &ctx->tweak_ctx, &ctx->crypt_ctx, false); |
---|
217 | 202 | } |
---|
218 | 203 | |
---|
219 | 204 | static int xts_decrypt(struct skcipher_request *req) |
---|
.. | .. |
---|
221 | 206 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
---|
222 | 207 | struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm); |
---|
223 | 208 | |
---|
224 | | - return glue_xts_req_128bit(&camellia_dec_xts, req, |
---|
225 | | - XTS_TWEAK_CAST(camellia_enc_blk), |
---|
226 | | - &ctx->tweak_ctx, &ctx->crypt_ctx); |
---|
| 209 | + return glue_xts_req_128bit(&camellia_dec_xts, req, camellia_enc_blk, |
---|
| 210 | + &ctx->tweak_ctx, &ctx->crypt_ctx, true); |
---|
227 | 211 | } |
---|
228 | 212 | |
---|
229 | 213 | static struct skcipher_alg camellia_algs[] = { |
---|