cipher_sm4_ccm.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright 2021 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 SM4 CCM mode */
  10. #include "cipher_sm4_ccm.h"
  11. #include "prov/implementations.h"
  12. #include "prov/providercommon.h"
  13. static OSSL_FUNC_cipher_freectx_fn sm4_ccm_freectx;
  14. static void *sm4_ccm_newctx(void *provctx, size_t keybits)
  15. {
  16. PROV_SM4_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_sm4_hw_ccm(keybits));
  22. return ctx;
  23. }
  24. static void sm4_ccm_freectx(void *vctx)
  25. {
  26. PROV_SM4_CCM_CTX *ctx = (PROV_SM4_CCM_CTX *)vctx;
  27. OPENSSL_clear_free(ctx, sizeof(*ctx));
  28. }
  29. /* sm4128ccm functions */
  30. IMPLEMENT_aead_cipher(sm4, ccm, CCM, AEAD_FLAGS, 128, 8, 96);