CMAC_CTX(3SSL)

πŸ’– CMAC_CTX πŸ’–

okay bestie, so in the OpenSSL manual, this page covers CMAC_CTX, CMAC_CTX_new, CMAC_CTX_cleanup, CMAC_CTX_free, CMAC_CTX_get0_cipher_ctx, CMAC_CTX_copy, CMAC_Init, CMAC_Update, CMAC_Final, and CMAC_resume β€” aka the whole girl gang that makes cipher-based message authentication codes ✨


✨ SYNOPSIS ✨

#include <openssl/cmac.h>

heads up queen: the following functions have been deprecated since OpenSSL 3.0, and you can disable them entirely by defining OPENSSL_API_COMPAT with a suitable version value β€” peep openssl_user_macros(7) for the deets.

typedef struct CMAC_CTX_st CMAC_CTX;

CMAC_CTX *CMAC_CTX_new(void);
void CMAC_CTX_cleanup(CMAC_CTX *ctx);
void CMAC_CTX_free(CMAC_CTX *ctx);
EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx);
int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in);
int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
              const EVP_CIPHER *cipher, ENGINE *impl);
int CMAC_Update(CMAC_CTX *ctx, const void *data, size_t dlen);
int CMAC_Final(CMAC_CTX *ctx, unsigned char *out, size_t *poutlen);
int CMAC_resume(CMAC_CTX *ctx);

🌸 DESCRIPTION 🌸

ngl, the low-level MAC functions documented on this page are deprecated. Like, retired. Gone girl era. Applications should use the new EVP_MAC(3) interface instead. Specifically, bestie, use these for MAC operations:

Alternatively, for a single-step MAC computation, use the EVP_Q_mac(3) function. one and done, no drama πŸŽ€

The CMAC_CTX type is a structure used for the provision of CMAC (Cipher-based Message Authentication Code) operations.

  • CMAC_CTX_new() β€” creates a new CMAC_CTX structure and returns a pointer to it. fresh out the box ✨
  • CMAC_CTX_cleanup() β€” resets the CMAC_CTX structure, clearing any internal data but not freeing the structure itself. it's giving "reset, not delete" πŸ’…
  • CMAC_CTX_free() β€” frees the CMAC_CTX structure and any associated resources. If the argument is NULL, no action is taken. no argument, no problem 🫢
  • CMAC_CTX_get0_cipher_ctx() β€” returns a pointer to the internal EVP_CIPHER_CTX structure within the CMAC_CTX.
  • CMAC_CTX_copy() β€” copies the state from one CMAC_CTX structure to another. twin behavior, lowkey πŸ‘―
  • CMAC_Init() β€” initializes the CMAC_CTX structure for a new CMAC calculation with the specified key, key length, and cipher type. And bestie, impl must be NULL. periodt.
  • CMAC_Update() β€” processes data to be included in the CMAC calculation. This function can be called multiple times to update the context with additional data. feed it, feed it, feed it 🌈
  • CMAC_Final() β€” finalizes the CMAC calculation and retrieves the resulting MAC value. The output is stored in the provided buffer, and the length is stored in the variable pointed to by poutlen. To determine the required buffer size, call it with out set to NULL, which stores only the length in poutlen. Then allocate a buffer of this size and call CMAC_Final() again with the allocated buffer to retrieve the MAC. two-step queen πŸ‘‘
  • CMAC_resume() β€” resumes a previously finalized CMAC calculation, allowing additional data to be processed and a new MAC to be generated. she's back πŸ¦‹

πŸ’€ RETURN VALUES πŸ’€

  • CMAC_CTX_new() β€” returns a pointer to a new CMAC_CTX structure, or NULL if an error occurs.
  • CMAC_CTX_get0_cipher_ctx() β€” returns a pointer to the internal EVP_CIPHER_CTX structure, or NULL if an error occurs.
  • CMAC_CTX_copy(), CMAC_Init(), CMAC_Update(), CMAC_Final() and CMAC_resume() β€” return 1 for success or 0 if an error occurs.

πŸ•°οΈ HISTORY πŸ•°οΈ

All functions described here were deprecated in OpenSSL 3.0. For replacements, see EVP_MAC_CTX_new(3), EVP_MAC_CTX_free(3), EVP_MAC_init(3), EVP_MAC_update(3), and EVP_MAC_final(3). glow-up arc, honestly πŸ“ˆ


Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


okay that's the whole page, bestie πŸ’– this was OpenSSL 4.0.3, dated 2026-09-29 β€” go forth and CMAC responsibly, mwah 🫢✨

πŸ“¦ where this page comes from