cipher_sm4_xts_hw_rv64i.inc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. * RISC-V 64 ZVKSED support for SM4 GCM.
  11. * This file is included by cipher_sm4_gcm_hw.c
  12. */
  13. static int rv64i_zvksed_sm4_xts_initkey(PROV_CIPHER_CTX *ctx,
  14. const unsigned char *key,
  15. size_t keylen)
  16. {
  17. PROV_SM4_XTS_CTX *xctx = (PROV_SM4_XTS_CTX *)ctx;
  18. OSSL_xts_stream_fn stream_fn = NULL;
  19. OSSL_xts_stream_fn stream_gb_fn = NULL;
  20. XTS_SET_KEY_FN(rv64i_zvksed_sm4_set_encrypt_key,
  21. rv64i_zvksed_sm4_set_decrypt_key,
  22. rv64i_zvksed_sm4_encrypt,
  23. rv64i_zvksed_sm4_decrypt,
  24. stream_fn, stream_gb_fn);
  25. return 1;
  26. }
  27. static const PROV_CIPHER_HW rv64i_zvksed_sm4_xts = {
  28. rv64i_zvksed_sm4_xts_initkey,
  29. NULL,
  30. cipher_hw_sm4_xts_copyctx
  31. };
  32. const PROV_CIPHER_HW *ossl_prov_cipher_hw_sm4_xts(size_t keybits)
  33. {
  34. if (RISCV_HAS_ZVKB_AND_ZVKSED() && riscv_vlen() >= 128)
  35. return &rv64i_zvksed_sm4_xts;
  36. else
  37. return &sm4_generic_xts;
  38. }