cipher_aes_gcm_hw_aesni.inc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2001-2022 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. * AES-NI support for AES GCM.
  11. * This file is included by cipher_aes_gcm_hw.c
  12. */
  13. static int aesni_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, aesni_set_encrypt_key, aesni_encrypt,
  19. aesni_ctr32_encrypt_blocks);
  20. return 1;
  21. }
  22. static const PROV_GCM_HW aesni_gcm = {
  23. aesni_gcm_initkey,
  24. ossl_gcm_setiv,
  25. ossl_gcm_aad_update,
  26. generic_aes_gcm_cipher_update,
  27. ossl_gcm_cipher_final,
  28. ossl_gcm_one_shot
  29. };
  30. #include "cipher_aes_gcm_hw_vaes_avx512.inc"
  31. const PROV_GCM_HW *ossl_prov_aes_hw_gcm(size_t keybits)
  32. {
  33. #ifdef VAES_GCM_ENABLED
  34. if (ossl_vaes_vpclmulqdq_capable())
  35. return &vaes_gcm;
  36. else
  37. #endif
  38. if (AESNI_CAPABLE)
  39. return &aesni_gcm;
  40. else
  41. return &aes_gcm;
  42. }