OPENSSL-MAC(1SSL)
π openssl-mac β perform Message Authentication Code operations π
okay bestie, welcome to openssl-mac, section 1SSL of the OpenSSL manual. this is the lil command that spits out a MAC (Message Authentication Code) for a file, and ngl it's lowkey iconic once you get the vibe. let's go π«Ά
πΈ NAME πΈ
openssl-mac β perform Message Authentication Code operations β¨
π SYNOPSIS π
openssl mac [-help] [-cipher] [-digest] [-macopt] [-in filename] [-out
filename] [-binary] [-provider name] [-provider-path path] [-provparam
[name:]key=value] [-propquery propq] mac_name
π¦ DESCRIPTION π¦
so the message authentication code functions basically do one thing and do it so well: they output the MAC of a supplied input file. that's the whole vibe. you feed it a file, it hands you a MAC. π
β¨ OPTIONS β¨
-helpβ prints a usage message. the "help me bestie" button π₯Ί-in filenameβ the input filename you wanna calculate a MAC for. if you don't specify one, it reads from standard input by default. and if the filename is exactly-, standard input gets used too. heads up: files and standard input are expected to be in binary format. no funny business.-out filenameβ the filename to output to. if you don't say, it goes to standard output by default.-binaryβ outputs the MAC in binary form. if you don't pass this, it uses hexadecimal text format instead. so like, hex is the default, binary is the spicy option π-cipher nameβ used by CMAC and GMAC to specify the cipher algorithm. for CMAC it should be a CBC mode cipher, e.g.AES-128-CBC. for GMAC it should be a GCM mode cipher, e.g.AES-128-GCM.-digest nameβ used by HMAC as an alphanumeric string (use this if the key contains printable characters only). the string length must conform to any restrictions of the MAC algorithm. to see the list of supported digests, useopenssl list -digest-commands.-macopt nm:vβ passes options to the MAC algorithm. a comprehensive list of controls can be found in theEVP_MACimplementation documentation. the common parameter names used byEVP_MAC_CTX_get_params()are:key:stringβ specifies the MAC key as an alphanumeric string (use this if the key contains printable characters only). the string length must conform to any restrictions of the MAC algorithm. a key must be specified for every MAC algorithm. πhexkey:stringβ specifies the MAC key in hexadecimal form (two hex digits per byte). the key length must conform to any restrictions of the MAC algorithm. a key must be specified for every MAC algorithm.iv:stringβ used by GMAC to specify an IV as an alphanumeric string (use this if the IV contains printable characters only).hexiv:stringβ used by GMAC to specify an IV in hexadecimal form (two hex digits per byte).size:intβ used byKMAC128orKMAC256to specify an output length. the default sizes are 32 or 64 bytes respectively.custom:stringβ used byKMAC128orKMAC256to specify a customization string. the default is the empty string"".digest:stringβ this option is identical to the-digestoption.cipher:stringβ this option is identical to the-cipheroption.
some additional options can be used only as command-line parameters. they are not passed to the MAC algorithm, but translated into key and hexkey parameters instead:
keyenv:varβ read the MAC key as an alphanumeric string from the environment variable (use this if the key contains printable characters only). the the key length must conform to any restrictions of the MAC algorithm. a key must be specified for every MAC algorithm.keyenvhex:varβ read the MAC key in hexadecimal form (two hex digits per byte) from the environment variable. the key length must conform to any restrictions of the MAC algorithm. a key must be specified for every MAC algorithm.keyfile:filenameβ read the MAC key from the specified file. the key is read as binary data. the key length must conform to any restrictions of the MAC algorithm. a key must be specified for every MAC algorithm.keystdinβ read the MAC key from the standard input. only the first line from stdin is read, and the\0character also terminates the key. the key length must conform to any restrictions of the MAC algorithm. a key must be specified for every MAC algorithm.
-provider name-provider-path path-provparam [name:]key=value-propquery propqβ see "Provider Options" inopenssl(1),provider(7), andproperty(7). πmac_nameβ specifies the name of a supported MAC algorithm which will be used. to see the list of supported MAC's use the commandopenssl list -mac-algorithms. this is the main character argument, fr fr π
π₯ EXAMPLES π₯
to create a hex-encoded HMAC-SHA1 MAC of a file and write to stdout:
openssl mac -digest SHA1 \
-macopt hexkey:000102030405060708090A0B0C0D0E0F10111213 \
-in msg.bin HMAC
to create a SipHash MAC from a file with a binary file output:
openssl mac -macopt hexkey:000102030405060708090A0B0C0D0E0F \
-in msg.bin -out out.bin -binary SipHash
to create a hex-encoded CMAC-AES-128-CBC MAC from a file:
openssl mac -cipher AES-128-CBC \
-macopt hexkey:77A77FAF290C1FA30C683DF16BA7A77B \
-in msg.bin CMAC
to create a hex-encoded KMAC128 MAC from a file with a Customisation String 'Tag' and output length of 16:
openssl mac -macopt custom:Tag -macopt hexkey:40414243444546 \
-macopt size:16 -in msg.bin KMAC128
to create a hex-encoded GMAC-AES-128-GCM with a IV from a file:
openssl mac -cipher AES-128-GCM -macopt hexiv:E0E00F19FED7BA0136A797F3 \
-macopt hexkey:77A77FAF290C1FA30C683DF16BA7A77B -in msg.bin GMAC
π NOTES π
the MAC mechanisms that are available will depend on the options used when building OpenSSL. use openssl list -mac-algorithms to list them. no cap, the build config decides what you get π§
π«Ά SEE ALSO π«Ά
openssl(1), EVP_MAC(3), EVP_MAC-CMAC(7), EVP_MAC-GMAC(7), EVP_MAC-HMAC(7), EVP_MAC-KMAC(7), EVP_MAC-Siphash(7), EVP_MAC-Poly1305(7)
π COPYRIGHT π
Copyright 2018-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>.
aaaand that's the whole thing bestie, you ate π
this was version 4.0.3, dated 2026-09-29, brought to you by the OpenSSL girlies β go MAC something and slay β¨ππΈ
π¦ where this page comes from
- ubuntu stonking: openssl 4.0.3-1ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms