cast6_generic.c (75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37) | cast6_generic.c (9c1e8836edbbaf3656bc07437b59c04be034ac4e) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* Kernel cryptographic api. 3 * cast6.c - Cast6 cipher algorithm [rfc2612]. 4 * 5 * CAST-256 (*cast6*) is a DES like Substitution-Permutation Network (SPN) 6 * cryptosystem built upon the CAST-128 (*cast5*) [rfc2144] encryption 7 * algorithm. 8 * --- 140 unchanged lines hidden (view full) --- 149int cast6_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) 150{ 151 return __cast6_setkey(crypto_tfm_ctx(tfm), key, keylen, 152 &tfm->crt_flags); 153} 154EXPORT_SYMBOL_GPL(cast6_setkey); 155 156/*forward quad round*/ | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* Kernel cryptographic api. 3 * cast6.c - Cast6 cipher algorithm [rfc2612]. 4 * 5 * CAST-256 (*cast6*) is a DES like Substitution-Permutation Network (SPN) 6 * cryptosystem built upon the CAST-128 (*cast5*) [rfc2144] encryption 7 * algorithm. 8 * --- 140 unchanged lines hidden (view full) --- 149int cast6_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) 150{ 151 return __cast6_setkey(crypto_tfm_ctx(tfm), key, keylen, 152 &tfm->crt_flags); 153} 154EXPORT_SYMBOL_GPL(cast6_setkey); 155 156/*forward quad round*/ |
157static inline void Q(u32 *block, u8 *Kr, u32 *Km) | 157static inline void Q(u32 *block, const u8 *Kr, const u32 *Km) |
158{ 159 u32 I; 160 block[2] ^= F1(block[3], Kr[0], Km[0]); 161 block[1] ^= F2(block[2], Kr[1], Km[1]); 162 block[0] ^= F3(block[1], Kr[2], Km[2]); 163 block[3] ^= F1(block[0], Kr[3], Km[3]); 164} 165 166/*reverse quad round*/ | 158{ 159 u32 I; 160 block[2] ^= F1(block[3], Kr[0], Km[0]); 161 block[1] ^= F2(block[2], Kr[1], Km[1]); 162 block[0] ^= F3(block[1], Kr[2], Km[2]); 163 block[3] ^= F1(block[0], Kr[3], Km[3]); 164} 165 166/*reverse quad round*/ |
167static inline void QBAR(u32 *block, u8 *Kr, u32 *Km) | 167static inline void QBAR(u32 *block, const u8 *Kr, const u32 *Km) |
168{ 169 u32 I; 170 block[3] ^= F1(block[0], Kr[3], Km[3]); 171 block[0] ^= F3(block[1], Kr[2], Km[2]); 172 block[1] ^= F2(block[2], Kr[1], Km[1]); 173 block[2] ^= F1(block[3], Kr[0], Km[0]); 174} 175 | 168{ 169 u32 I; 170 block[3] ^= F1(block[0], Kr[3], Km[3]); 171 block[0] ^= F3(block[1], Kr[2], Km[2]); 172 block[1] ^= F2(block[2], Kr[1], Km[1]); 173 block[2] ^= F1(block[3], Kr[0], Km[0]); 174} 175 |
176void __cast6_encrypt(struct cast6_ctx *c, u8 *outbuf, const u8 *inbuf) | 176void __cast6_encrypt(const void *ctx, u8 *outbuf, const u8 *inbuf) |
177{ | 177{ |
178 const struct cast6_ctx *c = ctx; |
|
178 const __be32 *src = (const __be32 *)inbuf; 179 __be32 *dst = (__be32 *)outbuf; 180 u32 block[4]; | 179 const __be32 *src = (const __be32 *)inbuf; 180 __be32 *dst = (__be32 *)outbuf; 181 u32 block[4]; |
181 u32 *Km; 182 u8 *Kr; | 182 const u32 *Km; 183 const u8 *Kr; |
183 184 block[0] = be32_to_cpu(src[0]); 185 block[1] = be32_to_cpu(src[1]); 186 block[2] = be32_to_cpu(src[2]); 187 block[3] = be32_to_cpu(src[3]); 188 189 Km = c->Km[0]; Kr = c->Kr[0]; Q(block, Kr, Km); 190 Km = c->Km[1]; Kr = c->Kr[1]; Q(block, Kr, Km); --- 15 unchanged lines hidden (view full) --- 206} 207EXPORT_SYMBOL_GPL(__cast6_encrypt); 208 209static void cast6_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf) 210{ 211 __cast6_encrypt(crypto_tfm_ctx(tfm), outbuf, inbuf); 212} 213 | 184 185 block[0] = be32_to_cpu(src[0]); 186 block[1] = be32_to_cpu(src[1]); 187 block[2] = be32_to_cpu(src[2]); 188 block[3] = be32_to_cpu(src[3]); 189 190 Km = c->Km[0]; Kr = c->Kr[0]; Q(block, Kr, Km); 191 Km = c->Km[1]; Kr = c->Kr[1]; Q(block, Kr, Km); --- 15 unchanged lines hidden (view full) --- 207} 208EXPORT_SYMBOL_GPL(__cast6_encrypt); 209 210static void cast6_encrypt(struct crypto_tfm *tfm, u8 *outbuf, const u8 *inbuf) 211{ 212 __cast6_encrypt(crypto_tfm_ctx(tfm), outbuf, inbuf); 213} 214 |
214void __cast6_decrypt(struct cast6_ctx *c, u8 *outbuf, const u8 *inbuf) | 215void __cast6_decrypt(const void *ctx, u8 *outbuf, const u8 *inbuf) |
215{ | 216{ |
217 const struct cast6_ctx *c = ctx; |
|
216 const __be32 *src = (const __be32 *)inbuf; 217 __be32 *dst = (__be32 *)outbuf; 218 u32 block[4]; | 218 const __be32 *src = (const __be32 *)inbuf; 219 __be32 *dst = (__be32 *)outbuf; 220 u32 block[4]; |
219 u32 *Km; 220 u8 *Kr; | 221 const u32 *Km; 222 const u8 *Kr; |
221 222 block[0] = be32_to_cpu(src[0]); 223 block[1] = be32_to_cpu(src[1]); 224 block[2] = be32_to_cpu(src[2]); 225 block[3] = be32_to_cpu(src[3]); 226 227 Km = c->Km[11]; Kr = c->Kr[11]; Q(block, Kr, Km); 228 Km = c->Km[10]; Kr = c->Kr[10]; Q(block, Kr, Km); --- 59 unchanged lines hidden --- | 223 224 block[0] = be32_to_cpu(src[0]); 225 block[1] = be32_to_cpu(src[1]); 226 block[2] = be32_to_cpu(src[2]); 227 block[3] = be32_to_cpu(src[3]); 228 229 Km = c->Km[11]; Kr = c->Kr[11]; Q(block, Kr, Km); 230 Km = c->Km[10]; Kr = c->Kr[10]; Q(block, Kr, Km); --- 59 unchanged lines hidden --- |