cipher_aes_ccm.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 CCM mode */
  16. #include "cipher_aes_ccm.h"
  17. #include "prov/implementations.h"
  18. #include "prov/providercommon.h"
  19. static void *aes_ccm_newctx(void *provctx, size_t keybits)
  20. {
  21. PROV_AES_CCM_CTX *ctx;
  22. if (!ossl_prov_is_running())
  23. return NULL;
  24. ctx = OPENSSL_zalloc(sizeof(*ctx));
  25. if (ctx != NULL)
  26. ossl_ccm_initctx(&ctx->base, keybits, ossl_prov_aes_hw_ccm(keybits));
  27. return ctx;
  28. }
  29. static void *aes_ccm_dupctx(void *provctx)
  30. {
  31. PROV_AES_CCM_CTX *ctx = provctx;
  32. PROV_AES_CCM_CTX *dupctx = NULL;
  33. if (ctx == NULL)
  34. return NULL;
  35. dupctx = OPENSSL_memdup(provctx, sizeof(*ctx));
  36. if (dupctx == NULL)
  37. return NULL;
  38. /*
  39. * ossl_cm_initctx, via the ossl_prov_aes_hw_ccm functions assign a
  40. * provctx->ccm.ks.ks to the ccm context key so we need to point it to
  41. * the memduped copy
  42. */
  43. dupctx->base.ccm_ctx.key = &dupctx->ccm.ks.ks;
  44. return dupctx;
  45. }
  46. static OSSL_FUNC_cipher_freectx_fn aes_ccm_freectx;
  47. static void aes_ccm_freectx(void *vctx)
  48. {
  49. PROV_AES_CCM_CTX *ctx = (PROV_AES_CCM_CTX *)vctx;
  50. OPENSSL_clear_free(ctx, sizeof(*ctx));
  51. }
  52. /* ossl_aes128ccm_functions */
  53. IMPLEMENT_aead_cipher(aes, ccm, CCM, AEAD_FLAGS, 128, 8, 96);
  54. /* ossl_aes192ccm_functions */
  55. IMPLEMENT_aead_cipher(aes, ccm, CCM, AEAD_FLAGS, 192, 8, 96);
  56. /* ossl_aes256ccm_functions */
  57. IMPLEMENT_aead_cipher(aes, ccm, CCM, AEAD_FLAGS, 256, 8, 96);