aes-cipher-glue.c 1.8 KB

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