aes-cipher-glue.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Scalar AES core transform
  3. *
  4. * Copyright (C) 2017 Linaro Ltd <ard.biesheuvel@linaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <crypto/aes.h>
  11. #include <linux/crypto.h>
  12. #include <linux/module.h>
  13. asmlinkage void __aes_arm64_encrypt(u32 *rk, u8 *out, const u8 *in, int rounds);
  14. EXPORT_SYMBOL(__aes_arm64_encrypt);
  15. asmlinkage void __aes_arm64_decrypt(u32 *rk, u8 *out, const u8 *in, int rounds);
  16. EXPORT_SYMBOL(__aes_arm64_decrypt);
  17. static void aes_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
  18. {
  19. struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
  20. int rounds = 6 + ctx->key_length / 4;
  21. __aes_arm64_encrypt(ctx->key_enc, out, in, rounds);
  22. }
  23. static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
  24. {
  25. struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
  26. int rounds = 6 + ctx->key_length / 4;
  27. __aes_arm64_decrypt(ctx->key_dec, out, in, rounds);
  28. }
  29. static struct crypto_alg aes_alg = {
  30. .cra_name = "aes",
  31. .cra_driver_name = "aes-arm64",
  32. .cra_priority = 200,
  33. .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
  34. .cra_blocksize = AES_BLOCK_SIZE,
  35. .cra_ctxsize = sizeof(struct crypto_aes_ctx),
  36. .cra_module = THIS_MODULE,
  37. .cra_cipher.cia_min_keysize = AES_MIN_KEY_SIZE,
  38. .cra_cipher.cia_max_keysize = AES_MAX_KEY_SIZE,
  39. .cra_cipher.cia_setkey = crypto_aes_set_key,
  40. .cra_cipher.cia_encrypt = aes_encrypt,
  41. .cra_cipher.cia_decrypt = aes_decrypt
  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 arm64");
  54. MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
  55. MODULE_LICENSE("GPL v2");
  56. MODULE_ALIAS_CRYPTO("aes");