aes-cipher-glue.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Scalar AES core transform
  3. *
  4. * Copyright (C) 2017 Linaro Ltd.
  5. * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <crypto/aes.h>
  12. #include <linux/crypto.h>
  13. #include <linux/module.h>
  14. asmlinkage void __aes_arm_encrypt(u32 *rk, int rounds, const u8 *in, u8 *out);
  15. EXPORT_SYMBOL(__aes_arm_encrypt);
  16. asmlinkage void __aes_arm_decrypt(u32 *rk, int rounds, const u8 *in, u8 *out);
  17. EXPORT_SYMBOL(__aes_arm_decrypt);
  18. static void aes_encrypt(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_arm_encrypt(ctx->key_enc, rounds, in, out);
  23. }
  24. static void aes_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
  25. {
  26. struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
  27. int rounds = 6 + ctx->key_length / 4;
  28. __aes_arm_decrypt(ctx->key_dec, rounds, in, out);
  29. }
  30. static struct crypto_alg aes_alg = {
  31. .cra_name = "aes",
  32. .cra_driver_name = "aes-arm",
  33. .cra_priority = 200,
  34. .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
  35. .cra_blocksize = AES_BLOCK_SIZE,
  36. .cra_ctxsize = sizeof(struct crypto_aes_ctx),
  37. .cra_module = THIS_MODULE,
  38. .cra_cipher.cia_min_keysize = AES_MIN_KEY_SIZE,
  39. .cra_cipher.cia_max_keysize = AES_MAX_KEY_SIZE,
  40. .cra_cipher.cia_setkey = crypto_aes_set_key,
  41. .cra_cipher.cia_encrypt = aes_encrypt,
  42. .cra_cipher.cia_decrypt = aes_decrypt,
  43. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  44. .cra_alignmask = 3,
  45. #endif
  46. };
  47. static int __init aes_init(void)
  48. {
  49. return crypto_register_alg(&aes_alg);
  50. }
  51. static void __exit aes_fini(void)
  52. {
  53. crypto_unregister_alg(&aes_alg);
  54. }
  55. module_init(aes_init);
  56. module_exit(aes_fini);
  57. MODULE_DESCRIPTION("Scalar AES cipher for ARM");
  58. MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
  59. MODULE_LICENSE("GPL v2");
  60. MODULE_ALIAS_CRYPTO("aes");