aes-cipher-glue.c 1.7 KB

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