aes-cipher-glue.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Scalar AES core transform
  4. *
  5. * Copyright (C) 2017 Linaro Ltd <[email protected]>
  6. */
  7. #include <crypto/aes.h>
  8. #include <linux/crypto.h>
  9. #include <linux/module.h>
  10. asmlinkage void __aes_arm64_encrypt(u32 *rk, u8 *out, const u8 *in, int rounds);
  11. asmlinkage void __aes_arm64_decrypt(u32 *rk, u8 *out, const u8 *in, int rounds);
  12. static void aes_arm64_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
  13. {
  14. struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
  15. int rounds = 6 + ctx->key_length / 4;
  16. __aes_arm64_encrypt(ctx->key_enc, out, in, rounds);
  17. }
  18. static void aes_arm64_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
  19. {
  20. struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
  21. int rounds = 6 + ctx->key_length / 4;
  22. __aes_arm64_decrypt(ctx->key_dec, out, in, rounds);
  23. }
  24. static struct crypto_alg aes_alg = {
  25. .cra_name = "aes",
  26. .cra_driver_name = "aes-arm64",
  27. .cra_priority = 200,
  28. .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
  29. .cra_blocksize = AES_BLOCK_SIZE,
  30. .cra_ctxsize = sizeof(struct crypto_aes_ctx),
  31. .cra_module = THIS_MODULE,
  32. .cra_cipher.cia_min_keysize = AES_MIN_KEY_SIZE,
  33. .cra_cipher.cia_max_keysize = AES_MAX_KEY_SIZE,
  34. .cra_cipher.cia_setkey = crypto_aes_set_key,
  35. .cra_cipher.cia_encrypt = aes_arm64_encrypt,
  36. .cra_cipher.cia_decrypt = aes_arm64_decrypt
  37. };
  38. static int __init aes_init(void)
  39. {
  40. return crypto_register_alg(&aes_alg);
  41. }
  42. static void __exit aes_fini(void)
  43. {
  44. crypto_unregister_alg(&aes_alg);
  45. }
  46. module_init(aes_init);
  47. module_exit(aes_fini);
  48. MODULE_DESCRIPTION("Scalar AES cipher for arm64");
  49. MODULE_AUTHOR("Ard Biesheuvel <[email protected]>");
  50. MODULE_LICENSE("GPL v2");
  51. MODULE_ALIAS_CRYPTO("aes");