Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Scalar AES core transform
0004  *
0005  * Copyright (C) 2017 Linaro Ltd.
0006  * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
0007  */
0008 
0009 #include <crypto/aes.h>
0010 #include <linux/crypto.h>
0011 #include <linux/module.h>
0012 
0013 asmlinkage void __aes_arm_encrypt(u32 *rk, int rounds, const u8 *in, u8 *out);
0014 asmlinkage void __aes_arm_decrypt(u32 *rk, int rounds, const u8 *in, u8 *out);
0015 
0016 static void aes_arm_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
0017 {
0018     struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
0019     int rounds = 6 + ctx->key_length / 4;
0020 
0021     __aes_arm_encrypt(ctx->key_enc, rounds, in, out);
0022 }
0023 
0024 static void aes_arm_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
0025 {
0026     struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
0027     int rounds = 6 + ctx->key_length / 4;
0028 
0029     __aes_arm_decrypt(ctx->key_dec, rounds, in, out);
0030 }
0031 
0032 static struct crypto_alg aes_alg = {
0033     .cra_name           = "aes",
0034     .cra_driver_name        = "aes-arm",
0035     .cra_priority           = 200,
0036     .cra_flags          = CRYPTO_ALG_TYPE_CIPHER,
0037     .cra_blocksize          = AES_BLOCK_SIZE,
0038     .cra_ctxsize            = sizeof(struct crypto_aes_ctx),
0039     .cra_module         = THIS_MODULE,
0040 
0041     .cra_cipher.cia_min_keysize = AES_MIN_KEY_SIZE,
0042     .cra_cipher.cia_max_keysize = AES_MAX_KEY_SIZE,
0043     .cra_cipher.cia_setkey      = crypto_aes_set_key,
0044     .cra_cipher.cia_encrypt     = aes_arm_encrypt,
0045     .cra_cipher.cia_decrypt     = aes_arm_decrypt,
0046 
0047 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
0048     .cra_alignmask          = 3,
0049 #endif
0050 };
0051 
0052 static int __init aes_init(void)
0053 {
0054     return crypto_register_alg(&aes_alg);
0055 }
0056 
0057 static void __exit aes_fini(void)
0058 {
0059     crypto_unregister_alg(&aes_alg);
0060 }
0061 
0062 module_init(aes_init);
0063 module_exit(aes_fini);
0064 
0065 MODULE_DESCRIPTION("Scalar AES cipher for ARM");
0066 MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
0067 MODULE_LICENSE("GPL v2");
0068 MODULE_ALIAS_CRYPTO("aes");