cipher_aes_gcm.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2019-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. * AES low level APIs are deprecated for public use, but still ok for internal
  11. * use where we're using them to implement the higher level EVP interface, as is
  12. * the case here.
  13. */
  14. #include "internal/deprecated.h"
  15. /* Dispatch functions for AES GCM mode */
  16. #include "cipher_aes_gcm.h"
  17. #include "prov/implementations.h"
  18. #include "prov/providercommon.h"
  19. static void *aes_gcm_newctx(void *provctx, size_t keybits)
  20. {
  21. PROV_AES_GCM_CTX *ctx;
  22. if (!ossl_prov_is_running())
  23. return NULL;
  24. ctx = OPENSSL_zalloc(sizeof(*ctx));
  25. if (ctx != NULL)
  26. ossl_gcm_initctx(provctx, &ctx->base, keybits,
  27. ossl_prov_aes_hw_gcm(keybits));
  28. return ctx;
  29. }
  30. static void *aes_gcm_dupctx(void *provctx)
  31. {
  32. PROV_AES_GCM_CTX *ctx = provctx;
  33. PROV_AES_GCM_CTX *dctx = NULL;
  34. if (ctx == NULL)
  35. return NULL;
  36. dctx = OPENSSL_memdup(ctx, sizeof(*ctx));
  37. if (dctx != NULL && dctx->base.gcm.key != NULL)
  38. dctx->base.gcm.key = &dctx->ks.ks;
  39. return dctx;
  40. }
  41. static OSSL_FUNC_cipher_freectx_fn aes_gcm_freectx;
  42. static void aes_gcm_freectx(void *vctx)
  43. {
  44. PROV_AES_GCM_CTX *ctx = (PROV_AES_GCM_CTX *)vctx;
  45. OPENSSL_clear_free(ctx, sizeof(*ctx));
  46. }
  47. /* ossl_aes128gcm_functions */
  48. IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 128, 8, 96);
  49. /* ossl_aes192gcm_functions */
  50. IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 192, 8, 96);
  51. /* ossl_aes256gcm_functions */
  52. IMPLEMENT_aead_cipher(aes, gcm, GCM, AEAD_FLAGS, 256, 8, 96);