cipher_sm4_gcm_hw_rv64i.inc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_gcm_initkey(PROV_GCM_CTX *ctx,
  14. const unsigned char *key,
  15. size_t keylen)
  16. {
  17. PROV_SM4_GCM_CTX *actx = (PROV_SM4_GCM_CTX *)ctx;
  18. SM4_KEY *ks = &actx->ks.ks;
  19. SM4_GCM_HW_SET_KEY_CTR_FN(ks, rv64i_zvksed_sm4_set_encrypt_key,
  20. rv64i_zvksed_sm4_encrypt, NULL);
  21. return 1;
  22. }
  23. static const PROV_GCM_HW rv64i_zvksed_sm4_gcm = {
  24. rv64i_zvksed_sm4_gcm_initkey,
  25. ossl_gcm_setiv,
  26. ossl_gcm_aad_update,
  27. hw_gcm_cipher_update,
  28. ossl_gcm_cipher_final,
  29. ossl_gcm_one_shot
  30. };
  31. const PROV_GCM_HW *ossl_prov_sm4_hw_gcm(size_t keybits)
  32. {
  33. if (RISCV_HAS_ZVKB_AND_ZVKSED() && riscv_vlen() >= 128)
  34. return &rv64i_zvksed_sm4_gcm;
  35. else
  36. return &sm4_gcm;
  37. }