OPENSSL-MAC(1ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… openssl-mac β€” the OpenSSL manual, but make it make sense

okay so bestie, this is openssl-mac from the OpenSSL manual set (1ossl section, iykyk) β€” the page that teaches you how to do Message Authentication Code stuff from the command line. grab a strawberry πŸ“, we're gonna get into it.


✨ NAME ✨

openssl-mac β€” perform Message Authentication Code operations

like, literally, it makes MACs. no cap. πŸ’…


πŸ¦‹ 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

okay the way this is just the whole vibe in one line 😭 every flag gets its own little moment below, don't worry.


🌸 DESCRIPTION 🌸

The message authentication code functions output the MAC of a supplied input file.

that's it. that's the whole thing. you give it input, it gives you a MAC. iconic behaviour honestly. πŸŽ€


πŸ”₯ OPTIONS πŸ”₯

  • -help β€” Print a usage message. your little "wait how does this work again" safety net 🫢
  • -in filename β€” Input filename to calculate a MAC for, or standard input by default. Standard input is used if the filename is -. Files and standard input are expected to be in binary format. so like, binary in, bestie β€” no fancy text parsing here, fr fr.
  • -out filename β€” Filename to output to, or standard output by default. yes, -out means output. groundbreaking, i know. πŸ‘‘
  • -binary β€” Output the MAC in binary form. Uses hexadecimal text format if not specified. so if you don't pass this, you get cute lil hex text. if you do, it's raw bytes. choose wisely πŸ’€
  • -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. match the mode to the MAC, don't do it wrong πŸ™ˆ
  • -digest name β€” Used by HMAC as an alphanumeric string (use 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. lowkey this one's for when your key is all nice printable characters ✨
  • -macopt nm:v β€” Passes options to the MAC algorithm. A comprehensive list of controls can be found in the EVP_MAC implementation documentation. Common parameter names used by EVP_MAC_CTX_get_params() are:
    • key:string β€” Specifies the MAC key as an alphanumeric string (use 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. yes, every one. mandatory. no key, no MAC, periodt. πŸ‘‘
    • 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. same rule, hex edition 🧚
    • iv:string β€” Used by GMAC to specify an IV as an alphanumeric string (use 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. so yeah, those are the defaults, don't @ me πŸ’œ
    • 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. literally the same thing, just living over here πŸ¦‹
    • cipher:string β€” This option is identical to the -cipher option. also the same thing. twins fr fr.
  • -provider name β€” provider time! 🌈
  • -provider-path path β€” path for that provider πŸŽ€
  • -provparam [name:]key=value β€” provider params, key=value style πŸ’–
  • -propquery propq β€” property query, as one does ✨

all four of these: See "Provider Options" in openssl(1), provider(7), and property(7). that's where the lore lives, go read it πŸ“š

  • 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 argument at the end, the main character of the whole command honestly 🌟

πŸ’– EXAMPLES πŸ’–

bestie these are the good part, let's go πŸŽ€

one: 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

two: 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

see the -binary there? that's the raw-bytes vibe check πŸ’€

three: 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

four: 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

look at that custom:Tag β€” personalized MAC, we love to see it πŸŽ€

five: 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.

so like, your build might not have everything. it's giving "depends on how she was compiled" 😭 go check with that command before you get confused.


πŸ‘‘ 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)

the whole friend group, all tagged πŸ’œ


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>.

like yeah, legal stuff, but read it β€” it's the rules, bestie πŸ“œ


and that's the page!! this version is 3.5.0, dated 2026-09-25 β€” from the OPENSSL-MAC(1ossl) crew, OpenSSL edition. slay, go MAC something, ily πŸ’…βœ¨

πŸ“¦ where this page comes from