Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: x86/camellia-aesni-avx, avx2 - convert to skcipher interface

Convert the AESNI AVX and AESNI AVX2 implementations of Camellia from
the (deprecated) ablkcipher and blkcipher interfaces over to the
skcipher interface. Note that this includes replacing the use of
ablk_helper with crypto_simd.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Eric Biggers and committed by
Herbert Xu
44893bc2 1af6d037

+208 -443
+99 -214
arch/x86/crypto/camellia_aesni_avx2_glue.c
··· 10 10 * 11 11 */ 12 12 13 - #include <linux/module.h> 14 - #include <linux/types.h> 15 - #include <linux/crypto.h> 16 - #include <linux/err.h> 17 - #include <crypto/ablk_helper.h> 18 - #include <crypto/algapi.h> 19 - #include <crypto/ctr.h> 20 - #include <crypto/xts.h> 21 - #include <asm/fpu/api.h> 22 13 #include <asm/crypto/camellia.h> 23 14 #include <asm/crypto/glue_helper.h> 15 + #include <crypto/algapi.h> 16 + #include <crypto/internal/simd.h> 17 + #include <crypto/xts.h> 18 + #include <linux/crypto.h> 19 + #include <linux/err.h> 20 + #include <linux/module.h> 21 + #include <linux/types.h> 24 22 25 23 #define CAMELLIA_AESNI_PARALLEL_BLOCKS 16 26 24 #define CAMELLIA_AESNI_AVX2_PARALLEL_BLOCKS 32 ··· 147 149 } } 148 150 }; 149 151 150 - static int ecb_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 151 - struct scatterlist *src, unsigned int nbytes) 152 + static int camellia_setkey(struct crypto_skcipher *tfm, const u8 *key, 153 + unsigned int keylen) 152 154 { 153 - return glue_ecb_crypt_128bit(&camellia_enc, desc, dst, src, nbytes); 155 + return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen, 156 + &tfm->base.crt_flags); 154 157 } 155 158 156 - static int ecb_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 157 - struct scatterlist *src, unsigned int nbytes) 159 + static int ecb_encrypt(struct skcipher_request *req) 158 160 { 159 - return glue_ecb_crypt_128bit(&camellia_dec, desc, dst, src, nbytes); 161 + return glue_ecb_req_128bit(&camellia_enc, req); 160 162 } 161 163 162 - static int cbc_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 163 - struct scatterlist *src, unsigned int nbytes) 164 + static int ecb_decrypt(struct skcipher_request *req) 164 165 { 165 - return glue_cbc_encrypt_128bit(GLUE_FUNC_CAST(camellia_enc_blk), desc, 166 - dst, src, nbytes); 166 + return glue_ecb_req_128bit(&camellia_dec, req); 167 167 } 168 168 169 - static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 170 - struct scatterlist *src, unsigned int nbytes) 169 + static int cbc_encrypt(struct skcipher_request *req) 171 170 { 172 - return glue_cbc_decrypt_128bit(&camellia_dec_cbc, desc, dst, src, 173 - nbytes); 171 + return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(camellia_enc_blk), 172 + req); 174 173 } 175 174 176 - static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst, 177 - struct scatterlist *src, unsigned int nbytes) 175 + static int cbc_decrypt(struct skcipher_request *req) 178 176 { 179 - return glue_ctr_crypt_128bit(&camellia_ctr, desc, dst, src, nbytes); 177 + return glue_cbc_decrypt_req_128bit(&camellia_dec_cbc, req); 180 178 } 181 179 182 - static int camellia_setkey(struct crypto_tfm *tfm, const u8 *in_key, 183 - unsigned int key_len) 180 + static int ctr_crypt(struct skcipher_request *req) 184 181 { 185 - return __camellia_setkey(crypto_tfm_ctx(tfm), in_key, key_len, 186 - &tfm->crt_flags); 182 + return glue_ctr_req_128bit(&camellia_ctr, req); 187 183 } 188 184 189 - static int xts_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 190 - struct scatterlist *src, unsigned int nbytes) 185 + static int xts_encrypt(struct skcipher_request *req) 191 186 { 192 - struct camellia_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); 187 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 188 + struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm); 193 189 194 - return glue_xts_crypt_128bit(&camellia_enc_xts, desc, dst, src, nbytes, 195 - XTS_TWEAK_CAST(camellia_enc_blk), 196 - &ctx->tweak_ctx, &ctx->crypt_ctx); 190 + return glue_xts_req_128bit(&camellia_enc_xts, req, 191 + XTS_TWEAK_CAST(camellia_enc_blk), 192 + &ctx->tweak_ctx, &ctx->crypt_ctx); 197 193 } 198 194 199 - static int xts_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 200 - struct scatterlist *src, unsigned int nbytes) 195 + static int xts_decrypt(struct skcipher_request *req) 201 196 { 202 - struct camellia_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); 197 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 198 + struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm); 203 199 204 - return glue_xts_crypt_128bit(&camellia_dec_xts, desc, dst, src, nbytes, 205 - XTS_TWEAK_CAST(camellia_enc_blk), 206 - &ctx->tweak_ctx, &ctx->crypt_ctx); 200 + return glue_xts_req_128bit(&camellia_dec_xts, req, 201 + XTS_TWEAK_CAST(camellia_enc_blk), 202 + &ctx->tweak_ctx, &ctx->crypt_ctx); 207 203 } 208 204 209 - static struct crypto_alg cmll_algs[] = { { 210 - .cra_name = "__ecb-camellia-aesni-avx2", 211 - .cra_driver_name = "__driver-ecb-camellia-aesni-avx2", 212 - .cra_priority = 0, 213 - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | 214 - CRYPTO_ALG_INTERNAL, 215 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 216 - .cra_ctxsize = sizeof(struct camellia_ctx), 217 - .cra_alignmask = 0, 218 - .cra_type = &crypto_blkcipher_type, 219 - .cra_module = THIS_MODULE, 220 - .cra_u = { 221 - .blkcipher = { 222 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 223 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 224 - .setkey = camellia_setkey, 225 - .encrypt = ecb_encrypt, 226 - .decrypt = ecb_decrypt, 227 - }, 205 + static struct skcipher_alg camellia_algs[] = { 206 + { 207 + .base.cra_name = "__ecb(camellia)", 208 + .base.cra_driver_name = "__ecb-camellia-aesni-avx2", 209 + .base.cra_priority = 500, 210 + .base.cra_flags = CRYPTO_ALG_INTERNAL, 211 + .base.cra_blocksize = CAMELLIA_BLOCK_SIZE, 212 + .base.cra_ctxsize = sizeof(struct camellia_ctx), 213 + .base.cra_module = THIS_MODULE, 214 + .min_keysize = CAMELLIA_MIN_KEY_SIZE, 215 + .max_keysize = CAMELLIA_MAX_KEY_SIZE, 216 + .setkey = camellia_setkey, 217 + .encrypt = ecb_encrypt, 218 + .decrypt = ecb_decrypt, 219 + }, { 220 + .base.cra_name = "__cbc(camellia)", 221 + .base.cra_driver_name = "__cbc-camellia-aesni-avx2", 222 + .base.cra_priority = 500, 223 + .base.cra_flags = CRYPTO_ALG_INTERNAL, 224 + .base.cra_blocksize = CAMELLIA_BLOCK_SIZE, 225 + .base.cra_ctxsize = sizeof(struct camellia_ctx), 226 + .base.cra_module = THIS_MODULE, 227 + .min_keysize = CAMELLIA_MIN_KEY_SIZE, 228 + .max_keysize = CAMELLIA_MAX_KEY_SIZE, 229 + .ivsize = CAMELLIA_BLOCK_SIZE, 230 + .setkey = camellia_setkey, 231 + .encrypt = cbc_encrypt, 232 + .decrypt = cbc_decrypt, 233 + }, { 234 + .base.cra_name = "__ctr(camellia)", 235 + .base.cra_driver_name = "__ctr-camellia-aesni-avx2", 236 + .base.cra_priority = 500, 237 + .base.cra_flags = CRYPTO_ALG_INTERNAL, 238 + .base.cra_blocksize = 1, 239 + .base.cra_ctxsize = sizeof(struct camellia_ctx), 240 + .base.cra_module = THIS_MODULE, 241 + .min_keysize = CAMELLIA_MIN_KEY_SIZE, 242 + .max_keysize = CAMELLIA_MAX_KEY_SIZE, 243 + .ivsize = CAMELLIA_BLOCK_SIZE, 244 + .chunksize = CAMELLIA_BLOCK_SIZE, 245 + .setkey = camellia_setkey, 246 + .encrypt = ctr_crypt, 247 + .decrypt = ctr_crypt, 248 + }, { 249 + .base.cra_name = "__xts(camellia)", 250 + .base.cra_driver_name = "__xts-camellia-aesni-avx2", 251 + .base.cra_priority = 500, 252 + .base.cra_flags = CRYPTO_ALG_INTERNAL, 253 + .base.cra_blocksize = CAMELLIA_BLOCK_SIZE, 254 + .base.cra_ctxsize = sizeof(struct camellia_xts_ctx), 255 + .base.cra_module = THIS_MODULE, 256 + .min_keysize = 2 * CAMELLIA_MIN_KEY_SIZE, 257 + .max_keysize = 2 * CAMELLIA_MAX_KEY_SIZE, 258 + .ivsize = CAMELLIA_BLOCK_SIZE, 259 + .setkey = xts_camellia_setkey, 260 + .encrypt = xts_encrypt, 261 + .decrypt = xts_decrypt, 228 262 }, 229 - }, { 230 - .cra_name = "__cbc-camellia-aesni-avx2", 231 - .cra_driver_name = "__driver-cbc-camellia-aesni-avx2", 232 - .cra_priority = 0, 233 - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | 234 - CRYPTO_ALG_INTERNAL, 235 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 236 - .cra_ctxsize = sizeof(struct camellia_ctx), 237 - .cra_alignmask = 0, 238 - .cra_type = &crypto_blkcipher_type, 239 - .cra_module = THIS_MODULE, 240 - .cra_u = { 241 - .blkcipher = { 242 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 243 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 244 - .setkey = camellia_setkey, 245 - .encrypt = cbc_encrypt, 246 - .decrypt = cbc_decrypt, 247 - }, 248 - }, 249 - }, { 250 - .cra_name = "__ctr-camellia-aesni-avx2", 251 - .cra_driver_name = "__driver-ctr-camellia-aesni-avx2", 252 - .cra_priority = 0, 253 - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | 254 - CRYPTO_ALG_INTERNAL, 255 - .cra_blocksize = 1, 256 - .cra_ctxsize = sizeof(struct camellia_ctx), 257 - .cra_alignmask = 0, 258 - .cra_type = &crypto_blkcipher_type, 259 - .cra_module = THIS_MODULE, 260 - .cra_u = { 261 - .blkcipher = { 262 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 263 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 264 - .ivsize = CAMELLIA_BLOCK_SIZE, 265 - .setkey = camellia_setkey, 266 - .encrypt = ctr_crypt, 267 - .decrypt = ctr_crypt, 268 - }, 269 - }, 270 - }, { 271 - .cra_name = "__xts-camellia-aesni-avx2", 272 - .cra_driver_name = "__driver-xts-camellia-aesni-avx2", 273 - .cra_priority = 0, 274 - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | 275 - CRYPTO_ALG_INTERNAL, 276 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 277 - .cra_ctxsize = sizeof(struct camellia_xts_ctx), 278 - .cra_alignmask = 0, 279 - .cra_type = &crypto_blkcipher_type, 280 - .cra_module = THIS_MODULE, 281 - .cra_u = { 282 - .blkcipher = { 283 - .min_keysize = CAMELLIA_MIN_KEY_SIZE * 2, 284 - .max_keysize = CAMELLIA_MAX_KEY_SIZE * 2, 285 - .ivsize = CAMELLIA_BLOCK_SIZE, 286 - .setkey = xts_camellia_setkey, 287 - .encrypt = xts_encrypt, 288 - .decrypt = xts_decrypt, 289 - }, 290 - }, 291 - }, { 292 - .cra_name = "ecb(camellia)", 293 - .cra_driver_name = "ecb-camellia-aesni-avx2", 294 - .cra_priority = 500, 295 - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, 296 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 297 - .cra_ctxsize = sizeof(struct async_helper_ctx), 298 - .cra_alignmask = 0, 299 - .cra_type = &crypto_ablkcipher_type, 300 - .cra_module = THIS_MODULE, 301 - .cra_init = ablk_init, 302 - .cra_exit = ablk_exit, 303 - .cra_u = { 304 - .ablkcipher = { 305 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 306 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 307 - .setkey = ablk_set_key, 308 - .encrypt = ablk_encrypt, 309 - .decrypt = ablk_decrypt, 310 - }, 311 - }, 312 - }, { 313 - .cra_name = "cbc(camellia)", 314 - .cra_driver_name = "cbc-camellia-aesni-avx2", 315 - .cra_priority = 500, 316 - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, 317 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 318 - .cra_ctxsize = sizeof(struct async_helper_ctx), 319 - .cra_alignmask = 0, 320 - .cra_type = &crypto_ablkcipher_type, 321 - .cra_module = THIS_MODULE, 322 - .cra_init = ablk_init, 323 - .cra_exit = ablk_exit, 324 - .cra_u = { 325 - .ablkcipher = { 326 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 327 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 328 - .ivsize = CAMELLIA_BLOCK_SIZE, 329 - .setkey = ablk_set_key, 330 - .encrypt = __ablk_encrypt, 331 - .decrypt = ablk_decrypt, 332 - }, 333 - }, 334 - }, { 335 - .cra_name = "ctr(camellia)", 336 - .cra_driver_name = "ctr-camellia-aesni-avx2", 337 - .cra_priority = 500, 338 - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, 339 - .cra_blocksize = 1, 340 - .cra_ctxsize = sizeof(struct async_helper_ctx), 341 - .cra_alignmask = 0, 342 - .cra_type = &crypto_ablkcipher_type, 343 - .cra_module = THIS_MODULE, 344 - .cra_init = ablk_init, 345 - .cra_exit = ablk_exit, 346 - .cra_u = { 347 - .ablkcipher = { 348 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 349 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 350 - .ivsize = CAMELLIA_BLOCK_SIZE, 351 - .setkey = ablk_set_key, 352 - .encrypt = ablk_encrypt, 353 - .decrypt = ablk_encrypt, 354 - .geniv = "chainiv", 355 - }, 356 - }, 357 - }, { 358 - .cra_name = "xts(camellia)", 359 - .cra_driver_name = "xts-camellia-aesni-avx2", 360 - .cra_priority = 500, 361 - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, 362 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 363 - .cra_ctxsize = sizeof(struct async_helper_ctx), 364 - .cra_alignmask = 0, 365 - .cra_type = &crypto_ablkcipher_type, 366 - .cra_module = THIS_MODULE, 367 - .cra_init = ablk_init, 368 - .cra_exit = ablk_exit, 369 - .cra_u = { 370 - .ablkcipher = { 371 - .min_keysize = CAMELLIA_MIN_KEY_SIZE * 2, 372 - .max_keysize = CAMELLIA_MAX_KEY_SIZE * 2, 373 - .ivsize = CAMELLIA_BLOCK_SIZE, 374 - .setkey = ablk_set_key, 375 - .encrypt = ablk_encrypt, 376 - .decrypt = ablk_decrypt, 377 - }, 378 - }, 379 - } }; 263 + }; 264 + 265 + static struct simd_skcipher_alg *camellia_simd_algs[ARRAY_SIZE(camellia_algs)]; 380 266 381 267 static int __init camellia_aesni_init(void) 382 268 { ··· 280 398 return -ENODEV; 281 399 } 282 400 283 - return crypto_register_algs(cmll_algs, ARRAY_SIZE(cmll_algs)); 401 + return simd_register_skciphers_compat(camellia_algs, 402 + ARRAY_SIZE(camellia_algs), 403 + camellia_simd_algs); 284 404 } 285 405 286 406 static void __exit camellia_aesni_fini(void) 287 407 { 288 - crypto_unregister_algs(cmll_algs, ARRAY_SIZE(cmll_algs)); 408 + simd_unregister_skciphers(camellia_algs, ARRAY_SIZE(camellia_algs), 409 + camellia_simd_algs); 289 410 } 290 411 291 412 module_init(camellia_aesni_init);
+103 -218
arch/x86/crypto/camellia_aesni_avx_glue.c
··· 10 10 * 11 11 */ 12 12 13 - #include <linux/module.h> 14 - #include <linux/types.h> 15 - #include <linux/crypto.h> 16 - #include <linux/err.h> 17 - #include <crypto/ablk_helper.h> 18 - #include <crypto/algapi.h> 19 - #include <crypto/ctr.h> 20 - #include <crypto/xts.h> 21 - #include <asm/fpu/api.h> 22 13 #include <asm/crypto/camellia.h> 23 14 #include <asm/crypto/glue_helper.h> 15 + #include <crypto/algapi.h> 16 + #include <crypto/internal/simd.h> 17 + #include <crypto/xts.h> 18 + #include <linux/crypto.h> 19 + #include <linux/err.h> 20 + #include <linux/module.h> 21 + #include <linux/types.h> 24 22 25 23 #define CAMELLIA_AESNI_PARALLEL_BLOCKS 16 26 24 ··· 151 153 } } 152 154 }; 153 155 154 - static int ecb_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 155 - struct scatterlist *src, unsigned int nbytes) 156 + static int camellia_setkey(struct crypto_skcipher *tfm, const u8 *key, 157 + unsigned int keylen) 156 158 { 157 - return glue_ecb_crypt_128bit(&camellia_enc, desc, dst, src, nbytes); 159 + return __camellia_setkey(crypto_skcipher_ctx(tfm), key, keylen, 160 + &tfm->base.crt_flags); 158 161 } 159 162 160 - static int ecb_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 161 - struct scatterlist *src, unsigned int nbytes) 163 + static int ecb_encrypt(struct skcipher_request *req) 162 164 { 163 - return glue_ecb_crypt_128bit(&camellia_dec, desc, dst, src, nbytes); 165 + return glue_ecb_req_128bit(&camellia_enc, req); 164 166 } 165 167 166 - static int cbc_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 167 - struct scatterlist *src, unsigned int nbytes) 168 + static int ecb_decrypt(struct skcipher_request *req) 168 169 { 169 - return glue_cbc_encrypt_128bit(GLUE_FUNC_CAST(camellia_enc_blk), desc, 170 - dst, src, nbytes); 170 + return glue_ecb_req_128bit(&camellia_dec, req); 171 171 } 172 172 173 - static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 174 - struct scatterlist *src, unsigned int nbytes) 173 + static int cbc_encrypt(struct skcipher_request *req) 175 174 { 176 - return glue_cbc_decrypt_128bit(&camellia_dec_cbc, desc, dst, src, 177 - nbytes); 175 + return glue_cbc_encrypt_req_128bit(GLUE_FUNC_CAST(camellia_enc_blk), 176 + req); 178 177 } 179 178 180 - static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst, 181 - struct scatterlist *src, unsigned int nbytes) 179 + static int cbc_decrypt(struct skcipher_request *req) 182 180 { 183 - return glue_ctr_crypt_128bit(&camellia_ctr, desc, dst, src, nbytes); 181 + return glue_cbc_decrypt_req_128bit(&camellia_dec_cbc, req); 184 182 } 185 183 186 - static int camellia_setkey(struct crypto_tfm *tfm, const u8 *in_key, 187 - unsigned int key_len) 184 + static int ctr_crypt(struct skcipher_request *req) 188 185 { 189 - return __camellia_setkey(crypto_tfm_ctx(tfm), in_key, key_len, 190 - &tfm->crt_flags); 186 + return glue_ctr_req_128bit(&camellia_ctr, req); 191 187 } 192 188 193 - int xts_camellia_setkey(struct crypto_tfm *tfm, const u8 *key, 189 + int xts_camellia_setkey(struct crypto_skcipher *tfm, const u8 *key, 194 190 unsigned int keylen) 195 191 { 196 - struct camellia_xts_ctx *ctx = crypto_tfm_ctx(tfm); 197 - u32 *flags = &tfm->crt_flags; 192 + struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm); 193 + u32 *flags = &tfm->base.crt_flags; 198 194 int err; 199 195 200 - err = xts_check_key(tfm, key, keylen); 196 + err = xts_verify_key(tfm, key, keylen); 201 197 if (err) 202 198 return err; 203 199 ··· 206 214 } 207 215 EXPORT_SYMBOL_GPL(xts_camellia_setkey); 208 216 209 - static int xts_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 210 - struct scatterlist *src, unsigned int nbytes) 217 + static int xts_encrypt(struct skcipher_request *req) 211 218 { 212 - struct camellia_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); 219 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 220 + struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm); 213 221 214 - return glue_xts_crypt_128bit(&camellia_enc_xts, desc, dst, src, nbytes, 215 - XTS_TWEAK_CAST(camellia_enc_blk), 216 - &ctx->tweak_ctx, &ctx->crypt_ctx); 222 + return glue_xts_req_128bit(&camellia_enc_xts, req, 223 + XTS_TWEAK_CAST(camellia_enc_blk), 224 + &ctx->tweak_ctx, &ctx->crypt_ctx); 217 225 } 218 226 219 - static int xts_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, 220 - struct scatterlist *src, unsigned int nbytes) 227 + static int xts_decrypt(struct skcipher_request *req) 221 228 { 222 - struct camellia_xts_ctx *ctx = crypto_blkcipher_ctx(desc->tfm); 229 + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); 230 + struct camellia_xts_ctx *ctx = crypto_skcipher_ctx(tfm); 223 231 224 - return glue_xts_crypt_128bit(&camellia_dec_xts, desc, dst, src, nbytes, 225 - XTS_TWEAK_CAST(camellia_enc_blk), 226 - &ctx->tweak_ctx, &ctx->crypt_ctx); 232 + return glue_xts_req_128bit(&camellia_dec_xts, req, 233 + XTS_TWEAK_CAST(camellia_enc_blk), 234 + &ctx->tweak_ctx, &ctx->crypt_ctx); 227 235 } 228 236 229 - static struct crypto_alg cmll_algs[] = { { 230 - .cra_name = "__ecb-camellia-aesni", 231 - .cra_driver_name = "__driver-ecb-camellia-aesni", 232 - .cra_priority = 0, 233 - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | 234 - CRYPTO_ALG_INTERNAL, 235 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 236 - .cra_ctxsize = sizeof(struct camellia_ctx), 237 - .cra_alignmask = 0, 238 - .cra_type = &crypto_blkcipher_type, 239 - .cra_module = THIS_MODULE, 240 - .cra_u = { 241 - .blkcipher = { 242 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 243 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 244 - .setkey = camellia_setkey, 245 - .encrypt = ecb_encrypt, 246 - .decrypt = ecb_decrypt, 247 - }, 237 + static struct skcipher_alg camellia_algs[] = { 238 + { 239 + .base.cra_name = "__ecb(camellia)", 240 + .base.cra_driver_name = "__ecb-camellia-aesni", 241 + .base.cra_priority = 400, 242 + .base.cra_flags = CRYPTO_ALG_INTERNAL, 243 + .base.cra_blocksize = CAMELLIA_BLOCK_SIZE, 244 + .base.cra_ctxsize = sizeof(struct camellia_ctx), 245 + .base.cra_module = THIS_MODULE, 246 + .min_keysize = CAMELLIA_MIN_KEY_SIZE, 247 + .max_keysize = CAMELLIA_MAX_KEY_SIZE, 248 + .setkey = camellia_setkey, 249 + .encrypt = ecb_encrypt, 250 + .decrypt = ecb_decrypt, 251 + }, { 252 + .base.cra_name = "__cbc(camellia)", 253 + .base.cra_driver_name = "__cbc-camellia-aesni", 254 + .base.cra_priority = 400, 255 + .base.cra_flags = CRYPTO_ALG_INTERNAL, 256 + .base.cra_blocksize = CAMELLIA_BLOCK_SIZE, 257 + .base.cra_ctxsize = sizeof(struct camellia_ctx), 258 + .base.cra_module = THIS_MODULE, 259 + .min_keysize = CAMELLIA_MIN_KEY_SIZE, 260 + .max_keysize = CAMELLIA_MAX_KEY_SIZE, 261 + .ivsize = CAMELLIA_BLOCK_SIZE, 262 + .setkey = camellia_setkey, 263 + .encrypt = cbc_encrypt, 264 + .decrypt = cbc_decrypt, 265 + }, { 266 + .base.cra_name = "__ctr(camellia)", 267 + .base.cra_driver_name = "__ctr-camellia-aesni", 268 + .base.cra_priority = 400, 269 + .base.cra_flags = CRYPTO_ALG_INTERNAL, 270 + .base.cra_blocksize = 1, 271 + .base.cra_ctxsize = sizeof(struct camellia_ctx), 272 + .base.cra_module = THIS_MODULE, 273 + .min_keysize = CAMELLIA_MIN_KEY_SIZE, 274 + .max_keysize = CAMELLIA_MAX_KEY_SIZE, 275 + .ivsize = CAMELLIA_BLOCK_SIZE, 276 + .chunksize = CAMELLIA_BLOCK_SIZE, 277 + .setkey = camellia_setkey, 278 + .encrypt = ctr_crypt, 279 + .decrypt = ctr_crypt, 280 + }, { 281 + .base.cra_name = "__xts(camellia)", 282 + .base.cra_driver_name = "__xts-camellia-aesni", 283 + .base.cra_priority = 400, 284 + .base.cra_flags = CRYPTO_ALG_INTERNAL, 285 + .base.cra_blocksize = CAMELLIA_BLOCK_SIZE, 286 + .base.cra_ctxsize = sizeof(struct camellia_xts_ctx), 287 + .base.cra_module = THIS_MODULE, 288 + .min_keysize = 2 * CAMELLIA_MIN_KEY_SIZE, 289 + .max_keysize = 2 * CAMELLIA_MAX_KEY_SIZE, 290 + .ivsize = CAMELLIA_BLOCK_SIZE, 291 + .setkey = xts_camellia_setkey, 292 + .encrypt = xts_encrypt, 293 + .decrypt = xts_decrypt, 248 294 }, 249 - }, { 250 - .cra_name = "__cbc-camellia-aesni", 251 - .cra_driver_name = "__driver-cbc-camellia-aesni", 252 - .cra_priority = 0, 253 - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | 254 - CRYPTO_ALG_INTERNAL, 255 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 256 - .cra_ctxsize = sizeof(struct camellia_ctx), 257 - .cra_alignmask = 0, 258 - .cra_type = &crypto_blkcipher_type, 259 - .cra_module = THIS_MODULE, 260 - .cra_u = { 261 - .blkcipher = { 262 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 263 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 264 - .setkey = camellia_setkey, 265 - .encrypt = cbc_encrypt, 266 - .decrypt = cbc_decrypt, 267 - }, 268 - }, 269 - }, { 270 - .cra_name = "__ctr-camellia-aesni", 271 - .cra_driver_name = "__driver-ctr-camellia-aesni", 272 - .cra_priority = 0, 273 - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | 274 - CRYPTO_ALG_INTERNAL, 275 - .cra_blocksize = 1, 276 - .cra_ctxsize = sizeof(struct camellia_ctx), 277 - .cra_alignmask = 0, 278 - .cra_type = &crypto_blkcipher_type, 279 - .cra_module = THIS_MODULE, 280 - .cra_u = { 281 - .blkcipher = { 282 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 283 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 284 - .ivsize = CAMELLIA_BLOCK_SIZE, 285 - .setkey = camellia_setkey, 286 - .encrypt = ctr_crypt, 287 - .decrypt = ctr_crypt, 288 - }, 289 - }, 290 - }, { 291 - .cra_name = "__xts-camellia-aesni", 292 - .cra_driver_name = "__driver-xts-camellia-aesni", 293 - .cra_priority = 0, 294 - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER | 295 - CRYPTO_ALG_INTERNAL, 296 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 297 - .cra_ctxsize = sizeof(struct camellia_xts_ctx), 298 - .cra_alignmask = 0, 299 - .cra_type = &crypto_blkcipher_type, 300 - .cra_module = THIS_MODULE, 301 - .cra_u = { 302 - .blkcipher = { 303 - .min_keysize = CAMELLIA_MIN_KEY_SIZE * 2, 304 - .max_keysize = CAMELLIA_MAX_KEY_SIZE * 2, 305 - .ivsize = CAMELLIA_BLOCK_SIZE, 306 - .setkey = xts_camellia_setkey, 307 - .encrypt = xts_encrypt, 308 - .decrypt = xts_decrypt, 309 - }, 310 - }, 311 - }, { 312 - .cra_name = "ecb(camellia)", 313 - .cra_driver_name = "ecb-camellia-aesni", 314 - .cra_priority = 400, 315 - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, 316 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 317 - .cra_ctxsize = sizeof(struct async_helper_ctx), 318 - .cra_alignmask = 0, 319 - .cra_type = &crypto_ablkcipher_type, 320 - .cra_module = THIS_MODULE, 321 - .cra_init = ablk_init, 322 - .cra_exit = ablk_exit, 323 - .cra_u = { 324 - .ablkcipher = { 325 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 326 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 327 - .setkey = ablk_set_key, 328 - .encrypt = ablk_encrypt, 329 - .decrypt = ablk_decrypt, 330 - }, 331 - }, 332 - }, { 333 - .cra_name = "cbc(camellia)", 334 - .cra_driver_name = "cbc-camellia-aesni", 335 - .cra_priority = 400, 336 - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, 337 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 338 - .cra_ctxsize = sizeof(struct async_helper_ctx), 339 - .cra_alignmask = 0, 340 - .cra_type = &crypto_ablkcipher_type, 341 - .cra_module = THIS_MODULE, 342 - .cra_init = ablk_init, 343 - .cra_exit = ablk_exit, 344 - .cra_u = { 345 - .ablkcipher = { 346 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 347 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 348 - .ivsize = CAMELLIA_BLOCK_SIZE, 349 - .setkey = ablk_set_key, 350 - .encrypt = __ablk_encrypt, 351 - .decrypt = ablk_decrypt, 352 - }, 353 - }, 354 - }, { 355 - .cra_name = "ctr(camellia)", 356 - .cra_driver_name = "ctr-camellia-aesni", 357 - .cra_priority = 400, 358 - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, 359 - .cra_blocksize = 1, 360 - .cra_ctxsize = sizeof(struct async_helper_ctx), 361 - .cra_alignmask = 0, 362 - .cra_type = &crypto_ablkcipher_type, 363 - .cra_module = THIS_MODULE, 364 - .cra_init = ablk_init, 365 - .cra_exit = ablk_exit, 366 - .cra_u = { 367 - .ablkcipher = { 368 - .min_keysize = CAMELLIA_MIN_KEY_SIZE, 369 - .max_keysize = CAMELLIA_MAX_KEY_SIZE, 370 - .ivsize = CAMELLIA_BLOCK_SIZE, 371 - .setkey = ablk_set_key, 372 - .encrypt = ablk_encrypt, 373 - .decrypt = ablk_encrypt, 374 - .geniv = "chainiv", 375 - }, 376 - }, 377 - }, { 378 - .cra_name = "xts(camellia)", 379 - .cra_driver_name = "xts-camellia-aesni", 380 - .cra_priority = 400, 381 - .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, 382 - .cra_blocksize = CAMELLIA_BLOCK_SIZE, 383 - .cra_ctxsize = sizeof(struct async_helper_ctx), 384 - .cra_alignmask = 0, 385 - .cra_type = &crypto_ablkcipher_type, 386 - .cra_module = THIS_MODULE, 387 - .cra_init = ablk_init, 388 - .cra_exit = ablk_exit, 389 - .cra_u = { 390 - .ablkcipher = { 391 - .min_keysize = CAMELLIA_MIN_KEY_SIZE * 2, 392 - .max_keysize = CAMELLIA_MAX_KEY_SIZE * 2, 393 - .ivsize = CAMELLIA_BLOCK_SIZE, 394 - .setkey = ablk_set_key, 395 - .encrypt = ablk_encrypt, 396 - .decrypt = ablk_decrypt, 397 - }, 398 - }, 399 - } }; 295 + }; 296 + 297 + static struct simd_skcipher_alg *camellia_simd_algs[ARRAY_SIZE(camellia_algs)]; 400 298 401 299 static int __init camellia_aesni_init(void) 402 300 { ··· 305 423 return -ENODEV; 306 424 } 307 425 308 - return crypto_register_algs(cmll_algs, ARRAY_SIZE(cmll_algs)); 426 + return simd_register_skciphers_compat(camellia_algs, 427 + ARRAY_SIZE(camellia_algs), 428 + camellia_simd_algs); 309 429 } 310 430 311 431 static void __exit camellia_aesni_fini(void) 312 432 { 313 - crypto_unregister_algs(cmll_algs, ARRAY_SIZE(cmll_algs)); 433 + simd_unregister_skciphers(camellia_algs, ARRAY_SIZE(camellia_algs), 434 + camellia_simd_algs); 314 435 } 315 436 316 437 module_init(camellia_aesni_init);
+3 -1
arch/x86/include/asm/crypto/camellia.h
··· 12 12 #define CAMELLIA_TABLE_BYTE_LEN 272 13 13 #define CAMELLIA_PARALLEL_BLOCKS 2 14 14 15 + struct crypto_skcipher; 16 + 15 17 struct camellia_ctx { 16 18 u64 key_table[CAMELLIA_TABLE_BYTE_LEN / sizeof(u64)]; 17 19 u32 key_length; ··· 28 26 const unsigned char *key, 29 27 unsigned int key_len, u32 *flags); 30 28 31 - extern int xts_camellia_setkey(struct crypto_tfm *tfm, const u8 *key, 29 + extern int xts_camellia_setkey(struct crypto_skcipher *tfm, const u8 *key, 32 30 unsigned int keylen); 33 31 34 32 /* regular block cipher functions */
+3 -10
crypto/Kconfig
··· 1162 1162 tristate "Camellia cipher algorithm (x86_64/AES-NI/AVX)" 1163 1163 depends on X86 && 64BIT 1164 1164 depends on CRYPTO 1165 - select CRYPTO_ALGAPI 1166 - select CRYPTO_CRYPTD 1167 - select CRYPTO_ABLK_HELPER 1168 - select CRYPTO_GLUE_HELPER_X86 1165 + select CRYPTO_BLKCIPHER 1169 1166 select CRYPTO_CAMELLIA_X86_64 1167 + select CRYPTO_GLUE_HELPER_X86 1168 + select CRYPTO_SIMD 1170 1169 select CRYPTO_XTS 1171 1170 help 1172 1171 Camellia cipher algorithm module (x86_64/AES-NI/AVX). ··· 1182 1183 tristate "Camellia cipher algorithm (x86_64/AES-NI/AVX2)" 1183 1184 depends on X86 && 64BIT 1184 1185 depends on CRYPTO 1185 - select CRYPTO_ALGAPI 1186 - select CRYPTO_CRYPTD 1187 - select CRYPTO_ABLK_HELPER 1188 - select CRYPTO_GLUE_HELPER_X86 1189 - select CRYPTO_CAMELLIA_X86_64 1190 1186 select CRYPTO_CAMELLIA_AESNI_AVX_X86_64 1191 - select CRYPTO_XTS 1192 1187 help 1193 1188 Camellia cipher algorithm module (x86_64/AES-NI/AVX2). 1194 1189