cipher_sm4_ccm_hw_rv64i.inc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright 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. * RV64I ZVKSED support for SM4 CCM.
  11. * This file is included by cipher_sm4_ccm_hw.c
  12. */
  13. static int rv64i_zvksed_sm4_ccm_initkey(PROV_CCM_CTX *ctx,
  14. const unsigned char *key,
  15. size_t keylen)
  16. {
  17. PROV_SM4_CCM_CTX *actx = (PROV_SM4_CCM_CTX *)ctx;
  18. SM4_HW_CCM_SET_KEY_FN(rv64i_zvksed_sm4_set_encrypt_key,
  19. rv64i_zvksed_sm4_encrypt, NULL, NULL);
  20. return 1;
  21. }
  22. static const PROV_CCM_HW rv64i_zvksed_sm4_ccm = {
  23. rv64i_zvksed_sm4_ccm_initkey,
  24. ossl_ccm_generic_setiv,
  25. ossl_ccm_generic_setaad,
  26. ossl_ccm_generic_auth_encrypt,
  27. ossl_ccm_generic_auth_decrypt,
  28. ossl_ccm_generic_gettag
  29. };
  30. const PROV_CCM_HW *ossl_prov_sm4_hw_ccm(size_t keybits)
  31. {
  32. if (RISCV_HAS_ZVKB_AND_ZVKSED() && riscv_vlen() >= 128)
  33. return &rv64i_zvksed_sm4_ccm;
  34. else
  35. return &ccm_sm4;
  36. }