.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Glue Code for x86_64/AVX2/AES-NI assembler optimized version of Camellia |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright © 2013 Jussi Kivilinna <jussi.kivilinna@mbnet.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> |
---|
.. | .. |
---|
24 | 19 | #define CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS 32 |
---|
25 | 20 | |
---|
26 | 21 | /* 32-way AVX2/AES-NI parallel cipher functions */ |
---|
27 | | -asmlinkage void camellia_ecb_enc_32way(struct camellia_ctx *ctx, u8 *dst, |
---|
28 | | - const u8 *src); |
---|
29 | | -asmlinkage void camellia_ecb_dec_32way(struct camellia_ctx *ctx, u8 *dst, |
---|
30 | | - const u8 *src); |
---|
| 22 | +asmlinkage void camellia_ecb_enc_32way(const void *ctx, u8 *dst, const u8 *src); |
---|
| 23 | +asmlinkage void camellia_ecb_dec_32way(const void *ctx, u8 *dst, const u8 *src); |
---|
31 | 24 | |
---|
32 | | -asmlinkage void camellia_cbc_dec_32way(struct camellia_ctx *ctx, u8 *dst, |
---|
33 | | - const u8 *src); |
---|
34 | | -asmlinkage void camellia_ctr_32way(struct camellia_ctx *ctx, u8 *dst, |
---|
35 | | - const u8 *src, le128 *iv); |
---|
| 25 | +asmlinkage void camellia_cbc_dec_32way(const void *ctx, u8 *dst, const u8 *src); |
---|
| 26 | +asmlinkage void camellia_ctr_32way(const void *ctx, u8 *dst, const u8 *src, |
---|
| 27 | + le128 *iv); |
---|
36 | 28 | |
---|
37 | | -asmlinkage void camellia_xts_enc_32way(struct camellia_ctx *ctx, u8 *dst, |
---|
38 | | - const u8 *src, le128 *iv); |
---|
39 | | -asmlinkage void camellia_xts_dec_32way(struct camellia_ctx *ctx, u8 *dst, |
---|
40 | | - const u8 *src, le128 *iv); |
---|
| 29 | +asmlinkage void camellia_xts_enc_32way(const void *ctx, u8 *dst, const u8 *src, |
---|
| 30 | + le128 *iv); |
---|
| 31 | +asmlinkage void camellia_xts_dec_32way(const void *ctx, u8 *dst, const u8 *src, |
---|
| 32 | + le128 *iv); |
---|
41 | 33 | |
---|
42 | 34 | static const struct common_glue_ctx camellia_enc = { |
---|
43 | 35 | .num_funcs = 4, |
---|
.. | .. |
---|
45 | 37 | |
---|
46 | 38 | .funcs = { { |
---|
47 | 39 | .num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS, |
---|
48 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_enc_32way) } |
---|
| 40 | + .fn_u = { .ecb = camellia_ecb_enc_32way } |
---|
49 | 41 | }, { |
---|
50 | 42 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
51 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_enc_16way) } |
---|
| 43 | + .fn_u = { .ecb = camellia_ecb_enc_16way } |
---|
52 | 44 | }, { |
---|
53 | 45 | .num_blocks = 2, |
---|
54 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_enc_blk_2way) } |
---|
| 46 | + .fn_u = { .ecb = camellia_enc_blk_2way } |
---|
55 | 47 | }, { |
---|
56 | 48 | .num_blocks = 1, |
---|
57 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_enc_blk) } |
---|
| 49 | + .fn_u = { .ecb = camellia_enc_blk } |
---|
58 | 50 | } } |
---|
59 | 51 | }; |
---|
60 | 52 | |
---|
.. | .. |
---|
64 | 56 | |
---|
65 | 57 | .funcs = { { |
---|
66 | 58 | .num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS, |
---|
67 | | - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_ctr_32way) } |
---|
| 59 | + .fn_u = { .ctr = camellia_ctr_32way } |
---|
68 | 60 | }, { |
---|
69 | 61 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
70 | | - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_ctr_16way) } |
---|
| 62 | + .fn_u = { .ctr = camellia_ctr_16way } |
---|
71 | 63 | }, { |
---|
72 | 64 | .num_blocks = 2, |
---|
73 | | - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_crypt_ctr_2way) } |
---|
| 65 | + .fn_u = { .ctr = camellia_crypt_ctr_2way } |
---|
74 | 66 | }, { |
---|
75 | 67 | .num_blocks = 1, |
---|
76 | | - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(camellia_crypt_ctr) } |
---|
| 68 | + .fn_u = { .ctr = camellia_crypt_ctr } |
---|
77 | 69 | } } |
---|
78 | 70 | }; |
---|
79 | 71 | |
---|
.. | .. |
---|
83 | 75 | |
---|
84 | 76 | .funcs = { { |
---|
85 | 77 | .num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS, |
---|
86 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_enc_32way) } |
---|
| 78 | + .fn_u = { .xts = camellia_xts_enc_32way } |
---|
87 | 79 | }, { |
---|
88 | 80 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
89 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_enc_16way) } |
---|
| 81 | + .fn_u = { .xts = camellia_xts_enc_16way } |
---|
90 | 82 | }, { |
---|
91 | 83 | .num_blocks = 1, |
---|
92 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_enc) } |
---|
| 84 | + .fn_u = { .xts = camellia_xts_enc } |
---|
93 | 85 | } } |
---|
94 | 86 | }; |
---|
95 | 87 | |
---|
.. | .. |
---|
99 | 91 | |
---|
100 | 92 | .funcs = { { |
---|
101 | 93 | .num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS, |
---|
102 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_dec_32way) } |
---|
| 94 | + .fn_u = { .ecb = camellia_ecb_dec_32way } |
---|
103 | 95 | }, { |
---|
104 | 96 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
105 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_ecb_dec_16way) } |
---|
| 97 | + .fn_u = { .ecb = camellia_ecb_dec_16way } |
---|
106 | 98 | }, { |
---|
107 | 99 | .num_blocks = 2, |
---|
108 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_dec_blk_2way) } |
---|
| 100 | + .fn_u = { .ecb = camellia_dec_blk_2way } |
---|
109 | 101 | }, { |
---|
110 | 102 | .num_blocks = 1, |
---|
111 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(camellia_dec_blk) } |
---|
| 103 | + .fn_u = { .ecb = camellia_dec_blk } |
---|
112 | 104 | } } |
---|
113 | 105 | }; |
---|
114 | 106 | |
---|
.. | .. |
---|
118 | 110 | |
---|
119 | 111 | .funcs = { { |
---|
120 | 112 | .num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS, |
---|
121 | | - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_cbc_dec_32way) } |
---|
| 113 | + .fn_u = { .cbc = camellia_cbc_dec_32way } |
---|
122 | 114 | }, { |
---|
123 | 115 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
124 | | - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_cbc_dec_16way) } |
---|
| 116 | + .fn_u = { .cbc = camellia_cbc_dec_16way } |
---|
125 | 117 | }, { |
---|
126 | 118 | .num_blocks = 2, |
---|
127 | | - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_decrypt_cbc_2way) } |
---|
| 119 | + .fn_u = { .cbc = camellia_decrypt_cbc_2way } |
---|
128 | 120 | }, { |
---|
129 | 121 | .num_blocks = 1, |
---|
130 | | - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(camellia_dec_blk) } |
---|
| 122 | + .fn_u = { .cbc = camellia_dec_blk } |
---|
131 | 123 | } } |
---|
132 | 124 | }; |
---|
133 | 125 | |
---|
.. | .. |
---|
137 | 129 | |
---|
138 | 130 | .funcs = { { |
---|
139 | 131 | .num_blocks = CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS, |
---|
140 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_dec_32way) } |
---|
| 132 | + .fn_u = { .xts = camellia_xts_dec_32way } |
---|
141 | 133 | }, { |
---|
142 | 134 | .num_blocks = CAMELLIA_AESNI_PARALLEL_BLOCKS, |
---|
143 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_dec_16way) } |
---|
| 135 | + .fn_u = { .xts = camellia_xts_dec_16way } |
---|
144 | 136 | }, { |
---|
145 | 137 | .num_blocks = 1, |
---|
146 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(camellia_xts_dec) } |
---|
| 138 | + .fn_u = { .xts = camellia_xts_dec } |
---|
147 | 139 | } } |
---|
148 | 140 | }; |
---|
149 | 141 | |
---|
150 | 142 | static int camellia_setkey(struct crypto_skcipher *tfm, const u8 *key, |
---|
151 | 143 | unsigned int keylen) |
---|
152 | 144 | { |
---|
153 | | - return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen, |
---|
154 | | - &tfm->base.crt_flags); |
---|
| 145 | + return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen); |
---|
155 | 146 | } |
---|
156 | 147 | |
---|
157 | 148 | static int ecb_encrypt(struct skcipher_request *req) |
---|
.. | .. |
---|
166 | 157 | |
---|
167 | 158 | static int cbc_encrypt(struct skcipher_request *req) |
---|
168 | 159 | { |
---|
169 | | - return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(camellia_enc_blk), |
---|
170 | | - req); |
---|
| 160 | + return glue_cbc_encrypt_req_128bit(camellia_enc_blk, req); |
---|
171 | 161 | } |
---|
172 | 162 | |
---|
173 | 163 | static int cbc_decrypt(struct skcipher_request *req) |
---|
.. | .. |
---|
185 | 175 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
---|
186 | 176 | struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm); |
---|
187 | 177 | |
---|
188 | | - return glue_xts_req_128bit(&camellia_enc_xts, req, |
---|
189 | | - XTS_TWEAK_CAST(camellia_enc_blk), |
---|
190 | | - &ctx->tweak_ctx, &ctx->crypt_ctx); |
---|
| 178 | + return glue_xts_req_128bit(&camellia_enc_xts, req, camellia_enc_blk, |
---|
| 179 | + &ctx->tweak_ctx, &ctx->crypt_ctx, false); |
---|
191 | 180 | } |
---|
192 | 181 | |
---|
193 | 182 | static int xts_decrypt(struct skcipher_request *req) |
---|
.. | .. |
---|
195 | 184 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
---|
196 | 185 | struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm); |
---|
197 | 186 | |
---|
198 | | - return glue_xts_req_128bit(&camellia_dec_xts, req, |
---|
199 | | - XTS_TWEAK_CAST(camellia_enc_blk), |
---|
200 | | - &ctx->tweak_ctx, &ctx->crypt_ctx); |
---|
| 187 | + return glue_xts_req_128bit(&camellia_dec_xts, req, camellia_enc_blk, |
---|
| 188 | + &ctx->tweak_ctx, &ctx->crypt_ctx, true); |
---|
201 | 189 | } |
---|
202 | 190 | |
---|
203 | 191 | static struct skcipher_alg camellia_algs[] = { |
---|