cipher_aes_gcm_hw_rv32i.inc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 32 ZKND ZKNE support for AES GCM.
  11. * This file is included by cipher_aes_gcm_hw.c
  12. */
  13. static int rv32i_zknd_zkne_gcm_initkey(PROV_GCM_CTX *ctx, const unsigned char *key,
  14. size_t keylen)
  15. {
  16. PROV_AES_GCM_CTX *actx = (PROV_AES_GCM_CTX *)ctx;
  17. AES_KEY *ks = &actx->ks.ks;
  18. GCM_HW_SET_KEY_CTR_FN(ks, rv32i_zkne_set_encrypt_key, rv32i_zkne_encrypt,
  19. NULL);
  20. return 1;
  21. }
  22. static int rv32i_zbkb_zknd_zkne_gcm_initkey(PROV_GCM_CTX *ctx,
  23. const unsigned char *key,
  24. size_t keylen)
  25. {
  26. PROV_AES_GCM_CTX *actx = (PROV_AES_GCM_CTX *)ctx;
  27. AES_KEY *ks = &actx->ks.ks;
  28. GCM_HW_SET_KEY_CTR_FN(ks, rv32i_zbkb_zkne_set_encrypt_key, rv32i_zkne_encrypt,
  29. NULL);
  30. return 1;
  31. }
  32. static const PROV_GCM_HW rv32i_zknd_zkne_gcm = {
  33. rv32i_zknd_zkne_gcm_initkey,
  34. ossl_gcm_setiv,
  35. ossl_gcm_aad_update,
  36. generic_aes_gcm_cipher_update,
  37. ossl_gcm_cipher_final,
  38. ossl_gcm_one_shot
  39. };
  40. static const PROV_GCM_HW rv32i_zbkb_zknd_zkne_gcm = {
  41. rv32i_zbkb_zknd_zkne_gcm_initkey,
  42. ossl_gcm_setiv,
  43. ossl_gcm_aad_update,
  44. generic_aes_gcm_cipher_update,
  45. ossl_gcm_cipher_final,
  46. ossl_gcm_one_shot
  47. };
  48. const PROV_GCM_HW *ossl_prov_aes_hw_gcm(size_t keybits)
  49. {
  50. if (RISCV_HAS_ZBKB_AND_ZKND_AND_ZKNE())
  51. return &rv32i_zbkb_zknd_zkne_gcm;
  52. if (RISCV_HAS_ZKND_AND_ZKNE())
  53. return &rv32i_zknd_zkne_gcm;
  54. return &aes_gcm;
  55. }