vmx.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /**
  3. * Routines supporting VMX instructions on the Power 8
  4. *
  5. * Copyright (C) 2015 International Business Machines Inc.
  6. *
  7. * Author: Marcelo Henrique Cerri <mhcerri@br.ibm.com>
  8. */
  9. #include <linux/module.h>
  10. #include <linux/moduleparam.h>
  11. #include <linux/types.h>
  12. #include <linux/err.h>
  13. #include <linux/cpufeature.h>
  14. #include <linux/crypto.h>
  15. #include <asm/cputable.h>
  16. #include <crypto/internal/hash.h>
  17. #include <crypto/internal/skcipher.h>
  18. extern struct shash_alg p8_ghash_alg;
  19. extern struct crypto_alg p8_aes_alg;
  20. extern struct skcipher_alg p8_aes_cbc_alg;
  21. extern struct skcipher_alg p8_aes_ctr_alg;
  22. extern struct skcipher_alg p8_aes_xts_alg;
  23. static int __init p8_init(void)
  24. {
  25. int ret;
  26. ret = crypto_register_shash(&p8_ghash_alg);
  27. if (ret)
  28. goto err;
  29. ret = crypto_register_alg(&p8_aes_alg);
  30. if (ret)
  31. goto err_unregister_ghash;
  32. ret = crypto_register_skcipher(&p8_aes_cbc_alg);
  33. if (ret)
  34. goto err_unregister_aes;
  35. ret = crypto_register_skcipher(&p8_aes_ctr_alg);
  36. if (ret)
  37. goto err_unregister_aes_cbc;
  38. ret = crypto_register_skcipher(&p8_aes_xts_alg);
  39. if (ret)
  40. goto err_unregister_aes_ctr;
  41. return 0;
  42. err_unregister_aes_ctr:
  43. crypto_unregister_skcipher(&p8_aes_ctr_alg);
  44. err_unregister_aes_cbc:
  45. crypto_unregister_skcipher(&p8_aes_cbc_alg);
  46. err_unregister_aes:
  47. crypto_unregister_alg(&p8_aes_alg);
  48. err_unregister_ghash:
  49. crypto_unregister_shash(&p8_ghash_alg);
  50. err:
  51. return ret;
  52. }
  53. static void __exit p8_exit(void)
  54. {
  55. crypto_unregister_skcipher(&p8_aes_xts_alg);
  56. crypto_unregister_skcipher(&p8_aes_ctr_alg);
  57. crypto_unregister_skcipher(&p8_aes_cbc_alg);
  58. crypto_unregister_alg(&p8_aes_alg);
  59. crypto_unregister_shash(&p8_ghash_alg);
  60. }
  61. module_cpu_feature_match(PPC_MODULE_FEATURE_VEC_CRYPTO, p8_init);
  62. module_exit(p8_exit);
  63. MODULE_AUTHOR("Marcelo Cerri<mhcerri@br.ibm.com>");
  64. MODULE_DESCRIPTION("IBM VMX cryptographic acceleration instructions "
  65. "support on Power 8");
  66. MODULE_LICENSE("GPL");
  67. MODULE_VERSION("1.0.0");