PKCS12_GEN_MAC(3SSL)
π PKCS12_GEN_MAC π
okay bestie, we're doing PKCS12_GEN_MAC(3SSL) today β that's the OpenSSL manual page for the little squad of functions that create and manipulate a PKCS#12 MAC structure. MAC as in Message Authentication Code, not the computer. π
β¨ NAME β¨
PKCS12_gen_mac, PKCS12_setup_mac, PKCS12_set_mac, PKCS12_set_pbmac1_pbkdf2, PKCS12_verify_mac, PKCS12_get0_mac β functions to create and manipulate a PKCS#12 MAC structure. that's the whole girlband right there π
πΈ SYNOPSIS πΈ
#include <openssl/pkcs12.h>
int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
unsigned char *mac, unsigned int *maclen);
int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen);
int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
unsigned char *salt, int saltlen, int iter,
const EVP_MD *md_type);
int PKCS12_set_pbmac1_pbkdf2(PKCS12 *p12, const char *pass, int passlen,
unsigned char *salt, int saltlen, int iter,
const EVP_MD *md_type,
const char *prf_md_name);
int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt,
int saltlen, const EVP_MD *md_type);
void PKCS12_get0_mac(const ASN1_OCTET_STRING **pmac,
const X509_ALGOR **pmacalg,
const ASN1_OCTET_STRING **psalt,
const ASN1_INTEGER **piter,
const PKCS12 *p12);
copy that exactly ok don't be creative with prototypes, that's not the vibe π
π¦ DESCRIPTION π¦
so here's the tea on each one, one by one, no skipping:
PKCS12_gen_mac()β generates an HMAC over the entire PKCS#12 object using the supplied password plus a set of already configured parameters. the default key generation mechanism it uses isPKCS12KDF. that's the default, note it, love it, respect it β¨PKCS12_verify_mac()β checks the PKCS#12 object's HMAC against the supplied password. important caveat: if the PKCS12 macdata contains PBMAC1, you get an error if the related PBKDF2 parameters are missing, or if the associated key length is not in the range1to64. so likeβ¦ bring your PBKDF2 params and stay in your lane length-wise π«ΆPKCS12_setup_mac()β sets the MAC part of the PKCS#12 structure using the parameters you hand it.PKCS12_set_mac()β sets the MAC and the MAC parameters into the PKCS#12 object. andPKCS12_set_pbmac1_pbkdf2()does that exact same putting-them-in thing, but for when PBMAC1 with PBKDF2 is what's being used to protect the PKCS#12 object. two paths, same goal, main character energy either way π
now the parameter lore, because you will be asked:
- pass β the passphrase used in the HMAC.
- salt β the salt value to use.
- iter β the iteration count.
- md_type β the message digest function to use.
- prf_md_name β specifies the digest used for the PBKDF2 in the PBMAC1 KDF.
and lastly, PKCS12_get0_mac() retrieves any included MAC value, X509_ALGOR object, salt, and iter count from the PKCS12 object. it's the little gremlin that reaches in and pulls the receipts out π
π NOTES π
- if salt is
NULLthen a suitable salt will be generated and used. so you don't have to make one yourself, she's got it π - if iter is
1then an iteration count will be omitted from the PKCS#12 structure. yes, literally omitted. not "set to one". omitted. PKCS12_gen_mac(),PKCS12_verify_mac(),PKCS12_set_mac()andPKCS12_set_pbmac1_pbkdf2()all make assumptions regarding the encoding of the given passphrase. bestie, go readpassphrase-encoding(7)for the full story before you come at me π
π RETURN VALUES π
every function that returns an integer returns 1 on success and 0 if an error occurred. that's it, that's the whole system, no in-between, no "maybe", no situationship π
β ENVIRONMENT β
LEGACY_GOST_PKCS12β if this environment variable is set, MAC generation that utilisesGOST R 34.11-94orGOST 34.11-2012hashing algorithms is performed the usual way and not in accordance with the specification provided in the methodical recommendationMP 26.2.002-2012(or in its later versions, standardisation recommendationP 50.1.112-2016orP 1323565.1.041-2022) of Technical Committee 26 β which specifies that the key used for MAC generation should be the last 32 bytes of the 96-byte sequence generated byPKCS5_PBKDF2_HMAC(3), and not the whole sequence.
ok so to be clear: set the env var β you get the "usual way". don't set it β you get the Technical Committee 26 spec behaviour where the key is only the last 32 bytes of that 96-byte sequence. pick your fighter. πΈ
π§ CONFORMING TO π§
- IETF RFC 7292 (
https://tools.ietf.org/html/rfc7292) - IETF RFC 9579 (
https://tools.ietf.org/html/rfc9579)
π SEE ALSO π
π HISTORY π
the PKCS12_set_pbmac1_pbkdf2 function was added in OpenSSL 3.4. baby of the family, arrived late, already slaying π¦
β¨ COPYRIGHT β¨
Copyright 2021-2026 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.
and that's the page!! this one's from OpenSSL 4.0.3, dated 2026-09-29, and it lives in the 3SSL manual section. go forth and MAC responsibly bestie πβ¨π
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms