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, use openssl list -digest-commands.
  • -macopt nm:v β€” passes options to the MAC algorithm. a comprehensive list of controls can be found in the EVP_MAC implementation documentation. the common parameter names used by EVP_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 by KMAC128 or KMAC256 to specify an output length. the default sizes are 32 or 64 bytes respectively.
    • custom:string β€” used by KMAC128 or KMAC256 to specify a customization string. the default is the empty string "".
    • digest:string β€” this option is identical to the -digest option.
    • cipher:string β€” this option is identical to the -cipher option.

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 \0 character 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" in openssl(1), provider(7), and property(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 command openssl 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 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