2
0

cipher_aria_gcm.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /* Dispatch functions for ARIA GCM mode */
  10. #include "cipher_aria_gcm.h"
  11. #include "prov/implementations.h"
  12. #include "prov/providercommon.h"
  13. static void *aria_gcm_newctx(void *provctx, size_t keybits)
  14. {
  15. PROV_ARIA_GCM_CTX *ctx;
  16. if (!ossl_prov_is_running())
  17. return NULL;
  18. ctx = OPENSSL_zalloc(sizeof(*ctx));
  19. if (ctx != NULL)
  20. ossl_gcm_initctx(provctx, &ctx->base, keybits,
  21. ossl_prov_aria_hw_gcm(keybits));
  22. return ctx;
  23. }
  24. static void *aria_gcm_dupctx(void *provctx)
  25. {
  26. PROV_ARIA_GCM_CTX *ctx = provctx;
  27. PROV_ARIA_GCM_CTX *dctx = NULL;
  28. if (ctx == NULL)
  29. return NULL;
  30. dctx = OPENSSL_memdup(ctx, sizeof(*ctx));
  31. if (dctx != NULL && dctx->base.gcm.key != NULL)
  32. dctx->base.gcm.key = &dctx->ks.ks;
  33. return dctx;
  34. }
  35. static OSSL_FUNC_cipher_freectx_fn aria_gcm_freectx;
  36. static void aria_gcm_freectx(void *vctx)
  37. {
  38. PROV_ARIA_GCM_CTX *ctx = (PROV_ARIA_GCM_CTX *)vctx;
  39. OPENSSL_clear_free(ctx, sizeof(*ctx));
  40. }
  41. /* ossl_aria128gcm_functions */
  42. IMPLEMENT_aead_cipher(aria, gcm, GCM, AEAD_FLAGS, 128, 8, 96);
  43. /* ossl_aria192gcm_functions */
  44. IMPLEMENT_aead_cipher(aria, gcm, GCM, AEAD_FLAGS, 192, 8, 96);
  45. /* ossl_aria256gcm_functions */
  46. IMPLEMENT_aead_cipher(aria, gcm, GCM, AEAD_FLAGS, 256, 8, 96);