{
    "mode": "man",
    "parameter": "EVP_MAC-KMAC",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/EVP_MAC-KMAC/7/json",
    "generated": "2026-08-15T17:56:55Z",
    "sections": {
        "NAME": {
            "content": "EVPMAC-KMAC, EVPMAC-KMAC128, EVPMAC-KMAC256 - The KMAC EVPMAC implementations\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Support for computing KMAC MACs through the EVPMAC API.\n",
            "subsections": [
                {
                    "name": "Identity",
                    "content": "These implementations are identified with one of these names and properties, to be used with\nEVPMACfetch():\n\n\"KMAC-128\", \"provider=default\" or \"provider=fips\"\n\"KMAC-256\", \"provider=default\" or \"provider=fips\"\n"
                },
                {
                    "name": "Supported parameters",
                    "content": "The general description of these parameters can be found in \"PARAMETERS\" in EVPMAC(3).\n\nAll  these  parameters  (except  for  \"block-size\") can be set with EVPMACCTXsetparams().\nFurthermore, the \"size\" parameter can be retrieved  with  EVPMACCTXgetparams(),  or  with\nEVPMACCTXgetmacsize().   The  length of the \"size\" parameter should not exceed that of a\nsizet.  Likewise, the \"block-size\" parameter can be retrieved with EVPMACCTXgetparams(),\nor with EVPMACCTXgetblocksize().\n\n\"key\" (OSSLMACPARAMKEY) <octet string>\nSets  the  MAC  key.   Setting  this  parameter  is  identical  to  passing  a   key   to\nEVPMACinit(3).  The length of the key (in bytes) must be in the range 4...512.\n\n\"custom\" (OSSLMACPARAMCUSTOM) <octet string>\nSets  the  customization  string.   It  is an optional value with a length of at most 512\nbytes, and is empty by default.\n\n\"size\" (OSSLMACPARAMSIZE) <unsigned integer>\nSets the MAC size.  By default, it is 32 for \"KMAC-128\" and 64 for \"KMAC-256\".\n\n\"block-size\" (OSSLMACPARAMBLOCKSIZE) <unsigned integer>\nGets the MAC block size.  It is 168 for \"KMAC-128\" and 136 for \"KMAC-256\".\n\n\"xof\" (OSSLMACPARAMXOF) <integer>\nThe \"xof\" parameter value is expected to be 1 or 0.  Use  1  to  enable  XOF  mode.   The\ndefault value is 0.\n\nThe  \"custom\"  parameter must be set as part of or before the EVPMACinit() call.  The \"xof\"\nand \"size\" parameters can be set at any time before EVPMACfinal().  The \"key\" parameter  is\nset as part of the EVPMACinit() call, but can be set before it instead.\n"
                }
            ]
        },
        "EXAMPLES": {
            "content": "#include <openssl/evp.h>\n#include <openssl/params.h>\n\nstatic int dokmac(const unsigned char *in, sizet inlen,\nconst unsigned char *key, sizet keylen,\nconst unsigned char *custom, sizet customlen,\nint xofenabled, unsigned char *out, int outlen)\n{\nEVPMACCTX *ctx = NULL;\nEVPMAC *mac = NULL;\nOSSLPARAM params[4], *p;\nint ret = 0;\nsizet l = 0;\n\nmac = EVPMACfetch(NULL, \"KMAC-128\", NULL);\nif (mac == NULL)\ngoto err;\nctx = EVPMACCTXnew(mac);\n/* The mac can be freed after it is used by EVPMACCTXnew */\nEVPMACfree(mac);\nif (ctx == NULL)\ngoto err;\n\n/*\n* Setup parameters required before calling EVPMACinit()\n* The parameters OSSLMACPARAMXOF and OSSLMACPARAMSIZE may also be\n* used at this point.\n*/\np = params;\n*p++ = OSSLPARAMconstructoctetstring(OSSLMACPARAMKEY,\n(void *)key, keylen);\nif (custom != NULL && customlen != 0)\n*p++ = OSSLPARAMconstructoctetstring(OSSLMACPARAMCUSTOM,\n(void *)custom, customlen);\n*p = OSSLPARAMconstructend();\nif (!EVPMACCTXsetparams(ctx, params))\ngoto err;\n\nif (!EVPMACinit(ctx))\ngoto err;\n\n/*\n* Note: the following optional parameters can be set any time\n* before EVPMACfinal().\n*/\np = params;\n*p++ = OSSLPARAMconstructint(OSSLMACPARAMXOF, &xofenabled);\n*p++ = OSSLPARAMconstructint(OSSLMACPARAMSIZE, &outlen);\n*p = OSSLPARAMconstructend();\nif (!EVPMACCTXsetparams(ctx, params))\ngoto err;\n\n/* The update may be called multiple times here for streamed input */\nif (!EVPMACupdate(ctx, in, inlen))\ngoto err;\nif (!EVPMACfinal(ctx, out, &l, outlen))\ngoto err;\nret = 1;\nerr:\nEVPMACCTXfree(ctx);\nreturn ret;\n}\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "EVPMACCTXgetparams(3),    EVPMACCTXsetparams(3),    \"PARAMETERS\"    in    EVPMAC(3),\nOSSLPARAM(3)\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.\n\nLicensed under the Apache License 2.0 (the \"License\").  You may not use this file  except  in\ncompliance  with  the  License.   You  can  obtain  a  copy in the file LICENSE in the source\ndistribution or at <https://www.openssl.org/source/license.html>.\n\n3.0.13                                       2026-07-29                           EVPMAC-KMAC(7SSL)",
            "subsections": []
        }
    },
    "summary": "EVPMAC-KMAC, EVPMAC-KMAC128, EVPMAC-KMAC256 - The KMAC EVPMAC implementations",
    "flags": [],
    "examples": [
        "#include <openssl/evp.h>",
        "#include <openssl/params.h>",
        "static int dokmac(const unsigned char *in, sizet inlen,",
        "const unsigned char *key, sizet keylen,",
        "const unsigned char *custom, sizet customlen,",
        "int xofenabled, unsigned char *out, int outlen)",
        "EVPMACCTX *ctx = NULL;",
        "EVPMAC *mac = NULL;",
        "OSSLPARAM params[4], *p;",
        "int ret = 0;",
        "sizet l = 0;",
        "mac = EVPMACfetch(NULL, \"KMAC-128\", NULL);",
        "if (mac == NULL)",
        "goto err;",
        "ctx = EVPMACCTXnew(mac);",
        "/* The mac can be freed after it is used by EVPMACCTXnew */",
        "EVPMACfree(mac);",
        "if (ctx == NULL)",
        "goto err;",
        "/*",
        "* Setup parameters required before calling EVPMACinit()",
        "* The parameters OSSLMACPARAMXOF and OSSLMACPARAMSIZE may also be",
        "* used at this point.",
        "*/",
        "p = params;",
        "*p++ = OSSLPARAMconstructoctetstring(OSSLMACPARAMKEY,",
        "(void *)key, keylen);",
        "if (custom != NULL && customlen != 0)",
        "*p++ = OSSLPARAMconstructoctetstring(OSSLMACPARAMCUSTOM,",
        "(void *)custom, customlen);",
        "*p = OSSLPARAMconstructend();",
        "if (!EVPMACCTXsetparams(ctx, params))",
        "goto err;",
        "if (!EVPMACinit(ctx))",
        "goto err;",
        "/*",
        "* Note: the following optional parameters can be set any time",
        "* before EVPMACfinal().",
        "*/",
        "p = params;",
        "*p++ = OSSLPARAMconstructint(OSSLMACPARAMXOF, &xofenabled);",
        "*p++ = OSSLPARAMconstructint(OSSLMACPARAMSIZE, &outlen);",
        "*p = OSSLPARAMconstructend();",
        "if (!EVPMACCTXsetparams(ctx, params))",
        "goto err;",
        "/* The update may be called multiple times here for streamed input */",
        "if (!EVPMACupdate(ctx, in, inlen))",
        "goto err;",
        "if (!EVPMACfinal(ctx, out, &l, outlen))",
        "goto err;",
        "ret = 1;",
        "err:",
        "EVPMACCTXfree(ctx);",
        "return ret;"
    ],
    "see_also": [
        {
            "name": "EVPMACCTXgetparams",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/EVPMACCTXgetparams/3/json"
        },
        {
            "name": "EVPMACCTXsetparams",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/EVPMACCTXsetparams/3/json"
        },
        {
            "name": "EVPMAC",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/EVPMAC/3/json"
        },
        {
            "name": "OSSLPARAM",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/OSSLPARAM/3/json"
        }
    ]
}