cipher_aes_ccm_hw_rv32i.inc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /*-
  10. * RISC-V 32 ZKND ZKNE support for AES CCM.
  11. * This file is included by cipher_aes_ccm_hw.c
  12. */
  13. static int ccm_rv32i_zknd_zkne_initkey(PROV_CCM_CTX *ctx, const unsigned char *key,
  14. size_t keylen)
  15. {
  16. PROV_AES_CCM_CTX *actx = (PROV_AES_CCM_CTX *)ctx;
  17. AES_HW_CCM_SET_KEY_FN(rv32i_zkne_set_encrypt_key, rv32i_zkne_encrypt,
  18. NULL, NULL);
  19. return 1;
  20. }
  21. static int ccm_rv32i_zbkb_zknd_zkne_initkey(PROV_CCM_CTX *ctx, const unsigned char *key,
  22. size_t keylen)
  23. {
  24. PROV_AES_CCM_CTX *actx = (PROV_AES_CCM_CTX *)ctx;
  25. AES_HW_CCM_SET_KEY_FN(rv32i_zbkb_zkne_set_encrypt_key, rv32i_zkne_encrypt,
  26. NULL, NULL);
  27. return 1;
  28. }
  29. static const PROV_CCM_HW rv32i_zknd_zkne_ccm = {
  30. ccm_rv32i_zknd_zkne_initkey,
  31. ossl_ccm_generic_setiv,
  32. ossl_ccm_generic_setaad,
  33. ossl_ccm_generic_auth_encrypt,
  34. ossl_ccm_generic_auth_decrypt,
  35. ossl_ccm_generic_gettag
  36. };
  37. static const PROV_CCM_HW rv32i_zbkb_zknd_zkne_ccm = {
  38. ccm_rv32i_zbkb_zknd_zkne_initkey,
  39. ossl_ccm_generic_setiv,
  40. ossl_ccm_generic_setaad,
  41. ossl_ccm_generic_auth_encrypt,
  42. ossl_ccm_generic_auth_decrypt,
  43. ossl_ccm_generic_gettag
  44. };
  45. const PROV_CCM_HW *ossl_prov_aes_hw_ccm(size_t keybits)
  46. {
  47. if (RISCV_HAS_ZBKB_AND_ZKND_AND_ZKNE())
  48. return &rv32i_zbkb_zknd_zkne_ccm;
  49. if (RISCV_HAS_ZKND_AND_ZKNE())
  50. return &rv32i_zknd_zkne_ccm;
  51. return &aes_ccm;
  52. }