| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | | - * Glue Code for the AVX assembler implemention of the Cast6 Cipher |
|---|
| 3 | + * Glue Code for the AVX assembler implementation of the Cast6 Cipher |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2012 Johannes Goetzfried |
|---|
| 5 | 6 | * <Johannes.Goetzfried@informatik.stud.uni-erlangen.de> |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * Copyright © 2013 Jussi Kivilinna <jussi.kivilinna@iki.fi> |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 10 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 11 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 | | - * (at your option) any later version. |
|---|
| 13 | | - * |
|---|
| 14 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 15 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | | - * GNU General Public License for more details. |
|---|
| 18 | | - * |
|---|
| 19 | | - * You should have received a copy of the GNU General Public License |
|---|
| 20 | | - * along with this program; if not, write to the Free Software |
|---|
| 21 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|---|
| 22 | | - * USA |
|---|
| 23 | | - * |
|---|
| 24 | 9 | */ |
|---|
| 25 | 10 | |
|---|
| 26 | 11 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 35 | 20 | |
|---|
| 36 | 21 | #define CAST6_PARALLEL_BLOCKS 8 |
|---|
| 37 | 22 | |
|---|
| 38 | | -asmlinkage void cast6_ecb_enc_8way(struct cast6_ctx *ctx, u8 *dst, |
|---|
| 39 | | - const u8 *src); |
|---|
| 40 | | -asmlinkage void cast6_ecb_dec_8way(struct cast6_ctx *ctx, u8 *dst, |
|---|
| 41 | | - const u8 *src); |
|---|
| 23 | +asmlinkage void cast6_ecb_enc_8way(const void *ctx, u8 *dst, const u8 *src); |
|---|
| 24 | +asmlinkage void cast6_ecb_dec_8way(const void *ctx, u8 *dst, const u8 *src); |
|---|
| 42 | 25 | |
|---|
| 43 | | -asmlinkage void cast6_cbc_dec_8way(struct cast6_ctx *ctx, u8 *dst, |
|---|
| 44 | | - const u8 *src); |
|---|
| 45 | | -asmlinkage void cast6_ctr_8way(struct cast6_ctx *ctx, u8 *dst, const u8 *src, |
|---|
| 26 | +asmlinkage void cast6_cbc_dec_8way(const void *ctx, u8 *dst, const u8 *src); |
|---|
| 27 | +asmlinkage void cast6_ctr_8way(const void *ctx, u8 *dst, const u8 *src, |
|---|
| 46 | 28 | le128 *iv); |
|---|
| 47 | 29 | |
|---|
| 48 | | -asmlinkage void cast6_xts_enc_8way(struct cast6_ctx *ctx, u8 *dst, |
|---|
| 49 | | - const u8 *src, le128 *iv); |
|---|
| 50 | | -asmlinkage void cast6_xts_dec_8way(struct cast6_ctx *ctx, u8 *dst, |
|---|
| 51 | | - const u8 *src, le128 *iv); |
|---|
| 30 | +asmlinkage void cast6_xts_enc_8way(const void *ctx, u8 *dst, const u8 *src, |
|---|
| 31 | + le128 *iv); |
|---|
| 32 | +asmlinkage void cast6_xts_dec_8way(const void *ctx, u8 *dst, const u8 *src, |
|---|
| 33 | + le128 *iv); |
|---|
| 52 | 34 | |
|---|
| 53 | 35 | static int cast6_setkey_skcipher(struct crypto_skcipher *tfm, |
|---|
| 54 | 36 | const u8 *key, unsigned int keylen) |
|---|
| .. | .. |
|---|
| 56 | 38 | return cast6_setkey(&tfm->base, key, keylen); |
|---|
| 57 | 39 | } |
|---|
| 58 | 40 | |
|---|
| 59 | | -static void cast6_xts_enc(void *ctx, u128 *dst, const u128 *src, le128 *iv) |
|---|
| 41 | +static void cast6_xts_enc(const void *ctx, u8 *dst, const u8 *src, le128 *iv) |
|---|
| 60 | 42 | { |
|---|
| 61 | | - glue_xts_crypt_128bit_one(ctx, dst, src, iv, |
|---|
| 62 | | - GLUE_FUNC_CAST(__cast6_encrypt)); |
|---|
| 43 | + glue_xts_crypt_128bit_one(ctx, dst, src, iv, __cast6_encrypt); |
|---|
| 63 | 44 | } |
|---|
| 64 | 45 | |
|---|
| 65 | | -static void cast6_xts_dec(void *ctx, u128 *dst, const u128 *src, le128 *iv) |
|---|
| 46 | +static void cast6_xts_dec(const void *ctx, u8 *dst, const u8 *src, le128 *iv) |
|---|
| 66 | 47 | { |
|---|
| 67 | | - glue_xts_crypt_128bit_one(ctx, dst, src, iv, |
|---|
| 68 | | - GLUE_FUNC_CAST(__cast6_decrypt)); |
|---|
| 48 | + glue_xts_crypt_128bit_one(ctx, dst, src, iv, __cast6_decrypt); |
|---|
| 69 | 49 | } |
|---|
| 70 | 50 | |
|---|
| 71 | | -static void cast6_crypt_ctr(void *ctx, u128 *dst, const u128 *src, le128 *iv) |
|---|
| 51 | +static void cast6_crypt_ctr(const void *ctx, u8 *d, const u8 *s, le128 *iv) |
|---|
| 72 | 52 | { |
|---|
| 73 | 53 | be128 ctrblk; |
|---|
| 54 | + u128 *dst = (u128 *)d; |
|---|
| 55 | + const u128 *src = (const u128 *)s; |
|---|
| 74 | 56 | |
|---|
| 75 | 57 | le128_to_be128(&ctrblk, iv); |
|---|
| 76 | 58 | le128_inc(iv); |
|---|
| .. | .. |
|---|
| 85 | 67 | |
|---|
| 86 | 68 | .funcs = { { |
|---|
| 87 | 69 | .num_blocks = CAST6_PARALLEL_BLOCKS, |
|---|
| 88 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(cast6_ecb_enc_8way) } |
|---|
| 70 | + .fn_u = { .ecb = cast6_ecb_enc_8way } |
|---|
| 89 | 71 | }, { |
|---|
| 90 | 72 | .num_blocks = 1, |
|---|
| 91 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(__cast6_encrypt) } |
|---|
| 73 | + .fn_u = { .ecb = __cast6_encrypt } |
|---|
| 92 | 74 | } } |
|---|
| 93 | 75 | }; |
|---|
| 94 | 76 | |
|---|
| .. | .. |
|---|
| 98 | 80 | |
|---|
| 99 | 81 | .funcs = { { |
|---|
| 100 | 82 | .num_blocks = CAST6_PARALLEL_BLOCKS, |
|---|
| 101 | | - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(cast6_ctr_8way) } |
|---|
| 83 | + .fn_u = { .ctr = cast6_ctr_8way } |
|---|
| 102 | 84 | }, { |
|---|
| 103 | 85 | .num_blocks = 1, |
|---|
| 104 | | - .fn_u = { .ctr = GLUE_CTR_FUNC_CAST(cast6_crypt_ctr) } |
|---|
| 86 | + .fn_u = { .ctr = cast6_crypt_ctr } |
|---|
| 105 | 87 | } } |
|---|
| 106 | 88 | }; |
|---|
| 107 | 89 | |
|---|
| .. | .. |
|---|
| 111 | 93 | |
|---|
| 112 | 94 | .funcs = { { |
|---|
| 113 | 95 | .num_blocks = CAST6_PARALLEL_BLOCKS, |
|---|
| 114 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(cast6_xts_enc_8way) } |
|---|
| 96 | + .fn_u = { .xts = cast6_xts_enc_8way } |
|---|
| 115 | 97 | }, { |
|---|
| 116 | 98 | .num_blocks = 1, |
|---|
| 117 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(cast6_xts_enc) } |
|---|
| 99 | + .fn_u = { .xts = cast6_xts_enc } |
|---|
| 118 | 100 | } } |
|---|
| 119 | 101 | }; |
|---|
| 120 | 102 | |
|---|
| .. | .. |
|---|
| 124 | 106 | |
|---|
| 125 | 107 | .funcs = { { |
|---|
| 126 | 108 | .num_blocks = CAST6_PARALLEL_BLOCKS, |
|---|
| 127 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(cast6_ecb_dec_8way) } |
|---|
| 109 | + .fn_u = { .ecb = cast6_ecb_dec_8way } |
|---|
| 128 | 110 | }, { |
|---|
| 129 | 111 | .num_blocks = 1, |
|---|
| 130 | | - .fn_u = { .ecb = GLUE_FUNC_CAST(__cast6_decrypt) } |
|---|
| 112 | + .fn_u = { .ecb = __cast6_decrypt } |
|---|
| 131 | 113 | } } |
|---|
| 132 | 114 | }; |
|---|
| 133 | 115 | |
|---|
| .. | .. |
|---|
| 137 | 119 | |
|---|
| 138 | 120 | .funcs = { { |
|---|
| 139 | 121 | .num_blocks = CAST6_PARALLEL_BLOCKS, |
|---|
| 140 | | - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(cast6_cbc_dec_8way) } |
|---|
| 122 | + .fn_u = { .cbc = cast6_cbc_dec_8way } |
|---|
| 141 | 123 | }, { |
|---|
| 142 | 124 | .num_blocks = 1, |
|---|
| 143 | | - .fn_u = { .cbc = GLUE_CBC_FUNC_CAST(__cast6_decrypt) } |
|---|
| 125 | + .fn_u = { .cbc = __cast6_decrypt } |
|---|
| 144 | 126 | } } |
|---|
| 145 | 127 | }; |
|---|
| 146 | 128 | |
|---|
| .. | .. |
|---|
| 150 | 132 | |
|---|
| 151 | 133 | .funcs = { { |
|---|
| 152 | 134 | .num_blocks = CAST6_PARALLEL_BLOCKS, |
|---|
| 153 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(cast6_xts_dec_8way) } |
|---|
| 135 | + .fn_u = { .xts = cast6_xts_dec_8way } |
|---|
| 154 | 136 | }, { |
|---|
| 155 | 137 | .num_blocks = 1, |
|---|
| 156 | | - .fn_u = { .xts = GLUE_XTS_FUNC_CAST(cast6_xts_dec) } |
|---|
| 138 | + .fn_u = { .xts = cast6_xts_dec } |
|---|
| 157 | 139 | } } |
|---|
| 158 | 140 | }; |
|---|
| 159 | 141 | |
|---|
| .. | .. |
|---|
| 169 | 151 | |
|---|
| 170 | 152 | static int cbc_encrypt(struct skcipher_request *req) |
|---|
| 171 | 153 | { |
|---|
| 172 | | - return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(__cast6_encrypt), |
|---|
| 173 | | - req); |
|---|
| 154 | + return glue_cbc_encrypt_req_128bit(__cast6_encrypt, req); |
|---|
| 174 | 155 | } |
|---|
| 175 | 156 | |
|---|
| 176 | 157 | static int cbc_decrypt(struct skcipher_request *req) |
|---|
| .. | .. |
|---|
| 192 | 173 | unsigned int keylen) |
|---|
| 193 | 174 | { |
|---|
| 194 | 175 | struct cast6_xts_ctx *ctx = crypto_skcipher_ctx(tfm); |
|---|
| 195 | | - u32 *flags = &tfm->base.crt_flags; |
|---|
| 196 | 176 | int err; |
|---|
| 197 | 177 | |
|---|
| 198 | 178 | err = xts_verify_key(tfm, key, keylen); |
|---|
| .. | .. |
|---|
| 200 | 180 | return err; |
|---|
| 201 | 181 | |
|---|
| 202 | 182 | /* first half of xts-key is for crypt */ |
|---|
| 203 | | - err = __cast6_setkey(&ctx->crypt_ctx, key, keylen / 2, flags); |
|---|
| 183 | + err = __cast6_setkey(&ctx->crypt_ctx, key, keylen / 2); |
|---|
| 204 | 184 | if (err) |
|---|
| 205 | 185 | return err; |
|---|
| 206 | 186 | |
|---|
| 207 | 187 | /* second half of xts-key is for tweak */ |
|---|
| 208 | | - return __cast6_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2, |
|---|
| 209 | | - flags); |
|---|
| 188 | + return __cast6_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2); |
|---|
| 210 | 189 | } |
|---|
| 211 | 190 | |
|---|
| 212 | 191 | static int xts_encrypt(struct skcipher_request *req) |
|---|
| .. | .. |
|---|
| 214 | 193 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
|---|
| 215 | 194 | struct cast6_xts_ctx *ctx = crypto_skcipher_ctx(tfm); |
|---|
| 216 | 195 | |
|---|
| 217 | | - return glue_xts_req_128bit(&cast6_enc_xts, req, |
|---|
| 218 | | - XTS_TWEAK_CAST(__cast6_encrypt), |
|---|
| 219 | | - &ctx->tweak_ctx, &ctx->crypt_ctx); |
|---|
| 196 | + return glue_xts_req_128bit(&cast6_enc_xts, req, __cast6_encrypt, |
|---|
| 197 | + &ctx->tweak_ctx, &ctx->crypt_ctx, false); |
|---|
| 220 | 198 | } |
|---|
| 221 | 199 | |
|---|
| 222 | 200 | static int xts_decrypt(struct skcipher_request *req) |
|---|
| .. | .. |
|---|
| 224 | 202 | struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
|---|
| 225 | 203 | struct cast6_xts_ctx *ctx = crypto_skcipher_ctx(tfm); |
|---|
| 226 | 204 | |
|---|
| 227 | | - return glue_xts_req_128bit(&cast6_dec_xts, req, |
|---|
| 228 | | - XTS_TWEAK_CAST(__cast6_encrypt), |
|---|
| 229 | | - &ctx->tweak_ctx, &ctx->crypt_ctx); |
|---|
| 205 | + return glue_xts_req_128bit(&cast6_dec_xts, req, __cast6_encrypt, |
|---|
| 206 | + &ctx->tweak_ctx, &ctx->crypt_ctx, true); |
|---|
| 230 | 207 | } |
|---|
| 231 | 208 | |
|---|
| 232 | 209 | static struct skcipher_alg cast6_algs[] = { |
|---|