cipher_aria_ccm.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 CCM mode */
  10. #include "cipher_aria_ccm.h"
  11. #include "prov/implementations.h"
  12. #include "prov/providercommon.h"
  13. static OSSL_FUNC_cipher_freectx_fn aria_ccm_freectx;
  14. static void *aria_ccm_newctx(void *provctx, size_t keybits)
  15. {
  16. PROV_ARIA_CCM_CTX *ctx;
  17. if (!ossl_prov_is_running())
  18. return NULL;
  19. ctx = OPENSSL_zalloc(sizeof(*ctx));
  20. if (ctx != NULL)
  21. ossl_ccm_initctx(&ctx->base, keybits, ossl_prov_aria_hw_ccm(keybits));
  22. return ctx;
  23. }
  24. static void *aria_ccm_dupctx(void *provctx)
  25. {
  26. PROV_ARIA_CCM_CTX *ctx = provctx;
  27. PROV_ARIA_CCM_CTX *dctx = NULL;
  28. if (ctx == NULL)
  29. return NULL;
  30. dctx = OPENSSL_memdup(ctx, sizeof(*ctx));
  31. if (dctx != NULL && dctx->base.ccm_ctx.key != NULL)
  32. dctx->base.ccm_ctx.key = &dctx->ks.ks;
  33. return dctx;
  34. }
  35. static void aria_ccm_freectx(void *vctx)
  36. {
  37. PROV_ARIA_CCM_CTX *ctx = (PROV_ARIA_CCM_CTX *)vctx;
  38. OPENSSL_clear_free(ctx, sizeof(*ctx));
  39. }
  40. /* aria128ccm functions */
  41. IMPLEMENT_aead_cipher(aria, ccm, CCM, AEAD_FLAGS, 128, 8, 96);
  42. /* aria192ccm functions */
  43. IMPLEMENT_aead_cipher(aria, ccm, CCM, AEAD_FLAGS, 192, 8, 96);
  44. /* aria256ccm functions */
  45. IMPLEMENT_aead_cipher(aria, ccm, CCM, AEAD_FLAGS, 256, 8, 96);