cipher_aes_ccm_hw_rv64i.inc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2022-2023 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 64 ZKND ZKNE support for AES CCM.
  11. * This file is included by cipher_aes_ccm_hw.c
  12. */
  13. static int ccm_rv64i_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(rv64i_zkne_set_encrypt_key, rv64i_zkne_encrypt,
  18. NULL, NULL);
  19. return 1;
  20. }
  21. static const PROV_CCM_HW rv64i_zknd_zkne_ccm = {
  22. ccm_rv64i_zknd_zkne_initkey,
  23. ossl_ccm_generic_setiv,
  24. ossl_ccm_generic_setaad,
  25. ossl_ccm_generic_auth_encrypt,
  26. ossl_ccm_generic_auth_decrypt,
  27. ossl_ccm_generic_gettag
  28. };
  29. /*-
  30. * RISC-V RV64 ZVKNED support for AES CCM.
  31. * This file is included by cipher_aes_ccm_hw.c
  32. */
  33. static int ccm_rv64i_zvkned_initkey(PROV_CCM_CTX *ctx, const unsigned char *key,
  34. size_t keylen)
  35. {
  36. PROV_AES_CCM_CTX *actx = (PROV_AES_CCM_CTX *)ctx;
  37. /* Zvkned only supports 128 and 256 bit keys for key schedule generation. */
  38. if (keylen * 8 == 128 || keylen * 8 == 256) {
  39. AES_HW_CCM_SET_KEY_FN(rv64i_zvkned_set_encrypt_key, rv64i_zvkned_encrypt,
  40. NULL, NULL);
  41. } else {
  42. AES_HW_CCM_SET_KEY_FN(AES_set_encrypt_key, rv64i_zvkned_encrypt, NULL, NULL)
  43. }
  44. return 1;
  45. }
  46. static const PROV_CCM_HW rv64i_zvkned_ccm = {
  47. ccm_rv64i_zvkned_initkey,
  48. ossl_ccm_generic_setiv,
  49. ossl_ccm_generic_setaad,
  50. ossl_ccm_generic_auth_encrypt,
  51. ossl_ccm_generic_auth_decrypt,
  52. ossl_ccm_generic_gettag
  53. };
  54. const PROV_CCM_HW *ossl_prov_aes_hw_ccm(size_t keybits)
  55. {
  56. if (RISCV_HAS_ZVKNED() && riscv_vlen() >= 128)
  57. return &rv64i_zvkned_ccm;
  58. else if (RISCV_HAS_ZKND_AND_ZKNE())
  59. return &rv64i_zknd_zkne_ccm;
  60. else
  61. return &aes_ccm;
  62. }