Minisign
Minisign is a dead simple tool to sign files and verify signatures.
It is portable, lightweight, and uses SLH-DSA signatures, which are expected to remain secure even if large quantum computers are built. Ed25519 keys, with smaller and faster signatures, are also supported.
Creating a key pair
$ minisign -G
The public key is printed and put into the
minisign2.pub file.
The secret key is encrypted and saved as a file named
~/.minisign/minisign2.key.
Minisign 0.12 and earlier can't verify signatures made with this key pair. To create an Ed25519 key pair, which works with all versions:
$ minisign -G -E
The files are then named minisign.pub and
~/.minisign/minisign.key, so both kinds of key pairs can
live side by side.
Signing a file
$ minisign -Sm myfile.txt
Or to include a comment in the signature, that will be verified and displayed when verifying the file:
$ minisign -Sm myfile.txt -t 'This comment will be signed as well'
The signature is put into myfile.txt.minisig2, or
myfile.txt.minisig with an Ed25519 key.
Multiple files can also be signed at once:
$ minisign -Sm file1.txt file2.txt *.jpg
The secret key is read from ~/.minisign/minisign2.key, or
from ~/.minisign/minisign.key if there is no
minisign2.key file.
If you have both, add -E to sign with the Ed25519 key:
$ minisign -E -Sm myfile.txt
Verifying a file
$ minisign -Vm myfile.txt -P U0ydTozIP3s57PgrY/1q9ZDA1h28+6Yg2Omth5KCXI18cSA/YcLZe3ks
or
$ minisign -Vm myfile.txt -p minisign2.pub
This requires the signature myfile.txt.minisig2 to be
present in the same directory, or myfile.txt.minisig if the
public key is an Ed25519 key.
Another signature file can be given with -x.
The public key can either reside in a file or be directly specified on
the command line.
Without -p or -P,
./minisign2.pub is used, or ./minisign.pub if
there is no minisign2.pub file.
A public key can only verify signatures made with the same kind of key.
To verify an Ed25519 signature when minisign2.pub is also
present, add -p minisign.pub.
Usage
Usage:
minisign -G [-E] [-f] [-p pubkey_file] [-s seckey_file] [-W]
minisign -R [-E | -s seckey_file] [-p pubkey_file]
minisign -C [-E | -s seckey_file] [-W]
minisign -S [-l] [-x sig_file] [-E | -s seckey_file] [-c untrusted_comment]
[-t trusted_comment] -m file [file ...]
minisign -V [-H] [-x sig_file] [-p pubkey_file | -P pubkey] [-o] [-q] [-Q]
-m file
-G generate a new key pair
-R recreate a public key file from a secret key file
-C change/remove the password of the secret key
-S sign files
-E use an Ed25519 key instead of an SLH-DSA key
-V verify that a signature is valid for a given file
-H require input to be prehashed
-l sign using the legacy format
-m <file> file to sign/verify
-o combined with -V, output the file content after verification
-p <pubkey_file> public key file (default: ./minisign2.pub or ./minisign.pub)
-P <pubkey> public key, as a base64 string
-s <seckey_file> secret key file (default: ~/.minisign/minisign2.key or
~/.minisign/minisign.key)
-W do not encrypt/decrypt the secret key with a password
-x <sigfile> signature file (default: <file>.minisig2 or <file>.minisig)
-c <comment> add a one-line untrusted comment
-t <comment> add a one-line trusted comment
-q quiet mode, suppress output
-Q pretty quiet mode, only print the trusted comment
-f force. Combined with -G, overwrite a previous key pair
-v display version number
Trusted comments
Signature files include an untrusted comment line that can be freely modified even after the signature is created.
They also include a second comment line that cannot be modified without the secret key.
Trusted comments can be used to add instructions or application-specific metadata such as the intended file name, timestamps, resource identifiers, or version numbers to prevent downgrade attacks.
Trusted comments are crucial for describing what has been signed, in addition to merely confirming that a signature exists.
Compilation / installation
Using Zig
Dependencies:
Compilation:
-
With libsodium, dynamically linked:
$ zig build --release=small -
With libsodium, statically linked:
$ zig build --release=small -Dstatic -
Without libsodium (no dependencies required, easy to cross-compile):
$ zig build --release=small -Dwithout-libsodium
The resulting binary can be found in zig-out/bin/minisign.
For faster execution at the cost of a larger binary, replace
small with fast in any of these commands.
WASI is not supported any more. If you need it, use minizign instead.
Using CMake
Dependencies
- libsodium
- cmake
- make
- pkg-config
- a C compilation toolchain
Compilation:
$ mkdir build
$ cd build
$ cmake ..
$ make
# make install
Use cmake -D STATIC_LIBSODIUM=1 .. instead of
cmake .. to link libsodium statically, or
cmake -D BUILD_STATIC_EXECUTABLES=1 .. to build a fully
static binary on platforms that support it.
Pre-hashing
By default, files are signed and verified with very low memory requirements, by pre-hashing the content.
Signatures that are not pre-hashed only exist for Ed25519 keys, and can
be rejected with the -H switch.
Support for these legacy signatures will eventually be removed.
Signature format
Ed25519 signatures (.minisig files)
untrusted comment: <arbitrary text>
base64(<signature_algorithm> || <key_id> || <signature>)
trusted comment: <arbitrary text>
base64(<global_signature>)
-
signature_algorithm:Ed(legacy) orED(hashed) key_id: 8 random bytes, matching the public key-
signature(legacy):ed25519(<file data>) -
signature(prehashed):ed25519(Blake2b-512(<file data>)) -
global_signature:ed25519(<signature> || <trusted_comment>)
New implementations must use the hashed signature format; support for the legacy one is optional and should not be done by default.
SLH-DSA signatures (.minisig2 files)
untrusted comment: <arbitrary text>
base64(<signature_algorithm> || <key_id> || <signature>)
trusted comment: <arbitrary text>
signature_algorithm:SLkey_id: 8 random bytes, matching the public key-
signature:slh-dsa-sha2-128s(SHA-256(<file data>) || <trusted_comment>), withminisignas the context string
The trusted comment is covered by the signature itself, so there is no global signature line.
Public key format
untrusted comment: <arbitrary text>
base64(<signature_algorithm> || <key_id> || <public_key>)
-
signature_algorithm:EdorSL key_id: 8 random bytespublic_key: Ed25519 or SLH-DSA public key, 32 bytes
Ed25519 public keys start with RW, and SLH-DSA public keys
start with U0.
Secret key format
untrusted comment: <arbitrary text>
base64(<signature_algorithm> || <kdf_algorithm> || <cksum_algorithm> ||
<kdf_salt> || <kdf_opslimit> || <kdf_memlimit> || <keynum_sk>)
-
signature_algorithm:EdorSL kdf_algorithm:Sccksum_algorithm:B2kdf_salt: 32 random bytes-
kdf_opslimit:crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE -
kdf_memlimit:crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE -
keynum_sk:<kdf_output> ^ (<key_id> || <secret_key> || <public_key> || <checksum>), 104 bytes key_id: 8 random bytessecret_key: Ed25519 or SLH-DSA secret key, 32 bytespublic_key: Ed25519 or SLH-DSA public key, 32 bytes-
checksum:Blake2b-256(<signature_algorithm> || <key_id> || <secret_key> || <public_key>), 32 bytes