.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* Kernel cryptographic api. |
---|
2 | 3 | * cast6.c - Cast6 cipher algorithm [rfc2612]. |
---|
3 | 4 | * |
---|
.. | .. |
---|
6 | 7 | * algorithm. |
---|
7 | 8 | * |
---|
8 | 9 | * Copyright (C) 2003 Kartikey Mahendra Bhatt <kartik_me@hotmail.com>. |
---|
9 | | - * |
---|
10 | | - * This program is free software; you can redistribute it and/or modify it |
---|
11 | | - * under the terms of GNU General Public License as published by the Free |
---|
12 | | - * Software Foundation; either version 2 of the License, or (at your option) |
---|
13 | | - * any later version. |
---|
14 | | - * |
---|
15 | | - * You should have received a copy of the GNU General Public License |
---|
16 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | 10 | */ |
---|
18 | 11 | |
---|
19 | 12 | |
---|
.. | .. |
---|
110 | 103 | key[7] ^= F2(key[0], Tr[i % 4][7], Tm[i][7]); |
---|
111 | 104 | } |
---|
112 | 105 | |
---|
113 | | -int __cast6_setkey(struct cast6_ctx *c, const u8 *in_key, |
---|
114 | | - unsigned key_len, u32 *flags) |
---|
| 106 | +int __cast6_setkey(struct cast6_ctx *c, const u8 *in_key, unsigned int key_len) |
---|
115 | 107 | { |
---|
116 | 108 | int i; |
---|
117 | 109 | u32 key[8]; |
---|
118 | 110 | __be32 p_key[8]; /* padded key */ |
---|
119 | 111 | |
---|
120 | | - if (key_len % 4 != 0) { |
---|
121 | | - *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; |
---|
| 112 | + if (key_len % 4 != 0) |
---|
122 | 113 | return -EINVAL; |
---|
123 | | - } |
---|
124 | 114 | |
---|
125 | 115 | memset(p_key, 0, 32); |
---|
126 | 116 | memcpy(p_key, in_key, key_len); |
---|
.. | .. |
---|
155 | 145 | |
---|
156 | 146 | int cast6_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) |
---|
157 | 147 | { |
---|
158 | | - return __cast6_setkey(crypto_tfm_ctx(tfm), key, keylen, |
---|
159 | | - &tfm->crt_flags); |
---|
| 148 | + return __cast6_setkey(crypto_tfm_ctx(tfm), key, keylen); |
---|
160 | 149 | } |
---|
161 | 150 | EXPORT_SYMBOL_GPL(cast6_setkey); |
---|
162 | 151 | |
---|
163 | 152 | /*forward quad round*/ |
---|
164 | | -static inline void Q(u32 *block, u8 *Kr, u32 *Km) |
---|
| 153 | +static inline void Q(u32 *block, const u8 *Kr, const u32 *Km) |
---|
165 | 154 | { |
---|
166 | 155 | u32 I; |
---|
167 | 156 | block[2] ^= F1(block[3], Kr[0], Km[0]); |
---|
.. | .. |
---|
171 | 160 | } |
---|
172 | 161 | |
---|
173 | 162 | /*reverse quad round*/ |
---|
174 | | -static inline void QBAR(u32 *block, u8 *Kr, u32 *Km) |
---|
| 163 | +static inline void QBAR(u32 *block, const u8 *Kr, const u32 *Km) |
---|
175 | 164 | { |
---|
176 | 165 | u32 I; |
---|
177 | 166 | block[3] ^= F1(block[0], Kr[3], Km[3]); |
---|
.. | .. |
---|
180 | 169 | block[2] ^= F1(block[3], Kr[0], Km[0]); |
---|
181 | 170 | } |
---|
182 | 171 | |
---|
183 | | -void __cast6_encrypt(struct cast6_ctx *c, u8 *outbuf, const u8 *inbuf) |
---|
| 172 | +void __cast6_encrypt(const void *ctx, u8 *outbuf, const u8 *inbuf) |
---|
184 | 173 | { |
---|
| 174 | + const struct cast6_ctx *c = ctx; |
---|
185 | 175 | const __be32 *src = (const __be32 *)inbuf; |
---|
186 | 176 | __be32 *dst = (__be32 *)outbuf; |
---|
187 | 177 | u32 block[4]; |
---|
188 | | - u32 *Km; |
---|
189 | | - u8 *Kr; |
---|
| 178 | + const u32 *Km; |
---|
| 179 | + const u8 *Kr; |
---|
190 | 180 | |
---|
191 | 181 | block[0] = be32_to_cpu(src[0]); |
---|
192 | 182 | block[1] = be32_to_cpu(src[1]); |
---|
.. | .. |
---|
218 | 208 | __cast6_encrypt(crypto_tfm_ctx(tfm), outbuf, inbuf); |
---|
219 | 209 | } |
---|
220 | 210 | |
---|
221 | | -void __cast6_decrypt(struct cast6_ctx *c, u8 *outbuf, const u8 *inbuf) |
---|
| 211 | +void __cast6_decrypt(const void *ctx, u8 *outbuf, const u8 *inbuf) |
---|
222 | 212 | { |
---|
| 213 | + const struct cast6_ctx *c = ctx; |
---|
223 | 214 | const __be32 *src = (const __be32 *)inbuf; |
---|
224 | 215 | __be32 *dst = (__be32 *)outbuf; |
---|
225 | 216 | u32 block[4]; |
---|
226 | | - u32 *Km; |
---|
227 | | - u8 *Kr; |
---|
| 217 | + const u32 *Km; |
---|
| 218 | + const u8 *Kr; |
---|
228 | 219 | |
---|
229 | 220 | block[0] = be32_to_cpu(src[0]); |
---|
230 | 221 | block[1] = be32_to_cpu(src[1]); |
---|
.. | .. |
---|
285 | 276 | crypto_unregister_alg(&alg); |
---|
286 | 277 | } |
---|
287 | 278 | |
---|
288 | | -module_init(cast6_mod_init); |
---|
| 279 | +subsys_initcall(cast6_mod_init); |
---|
289 | 280 | module_exit(cast6_mod_fini); |
---|
290 | 281 | |
---|
291 | 282 | MODULE_LICENSE("GPL"); |
---|