Definition
A digital signature is a value that a signer computes from a message with a private key and that anyone holding the matching public key can check. The two keys are generated together; the owner keeps the private key secret and may give out the public key. A valid signature shows that the message was signed with the private key and has not changed since. The public key cannot in practice be used to sign, so only a holder of the private key can sign.
The idea
A company sends software updates to 10,000 door locks, and each lock must reject updates that the company did not issue. If the company protected its updates with a message authentication code §5.7, a short value computed from the update with a secret key, and gave every lock the same key, every lock would hold a key that also creates valid codes. An attacker who reads that key out of one lock can make updates that all 10,000 locks accept.
A digital signature separates the two abilities. Signing needs the private key, which stays with the company. Checking needs only the public key, which can be copied into every lock and read by anyone without harm, because computing the private key from it, or a valid signature on a new message without the private key, is infeasible: far beyond any realistic amount of computation.
A bank’s specimen of a customer’s handwritten signature is a fair picture: a clerk compares a bank check against it, and it does not let the clerk sign. The picture stops at two points: a digital signature depends on every bit of the message and fails on any other message, and verification is an exact computation, not a judgment by eye.
How it works
A signature scheme consists of three algorithms §14.1.
Key generation makes a key pair from random input: a private key, also called the signing key, and a public key, also called the verification key.
Signing takes the private key and a message and outputs a signature.
Verification takes the public key, a message and a signature, and answers accept or reject.
In use the steps are these.
The signer generates the key pair once and keeps the private key where nobody else can read it.
Each verifier obtains the public key by a route it already trusts: a copy installed at manufacture, or a certificate, which is a record that binds a public key to its owner’s name and is signed by a party the verifier already trusts.
The signer computes the signature over the exact bytes of the message and sends both.
The verifier checks the signature with the public key it trusts, over the exact bytes it received. Only after acceptance does it apply its other checks, such as whether the message is recent and permitted.
Ed25519 is one signature scheme, defined in RFC 8032 as an instance of EdDSA (Edwards-curve Digital Signature Algorithm), which computes with points of an elliptic curve §19.1.5: a set of number pairs with a rule for adding two of them. Its private key is 32 random bytes, its public key is 32 bytes computed from the private key, and its signature is 64 bytes, in two 32-byte halves called and . Signing uses the hash function SHA-512 (Secure Hash Algorithm with a 512-bit output), which turns any input into a 64-byte value. Signing hashes the private key, then hashes half of that result followed by the message, and takes the per-signature secret number from this second hash. Signing therefore needs no fresh random number, and the same key and message always give the same signature.
Worked example
RFC 8032 publishes test values for Ed25519. In its second Ed25519 test case (section 7.1) the private key is
4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb
the public key computed from it is
3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c
and the message is the single byte 0x72, the letter r in ASCII.
Signing gives the 64-byte signature, shown here as its two halves:
=
92a009a9f0d4cab8720e820b5f642540a2b27b5416503f8fb3762223ebdb69da
=085ac1e43e15996e458f3613d0f11d8c387b2eaeb4302aeeb00d291612bb0c00
Signing the same message again with the same key gives the same 64 bytes.
A verifier that holds only the public key accepts this signature for the message 0x72. For the message 0x73, the letter s, which differs in one bit, it rejects the same signature. It also rejects the message 0x72 when the lowest bit of the signature’s first byte is flipped, turning 92 into 93. The verifier used only the public key, and nothing it holds lets it sign 0x73.
HMAC §5.8 (hash-based message authentication code) is a message authentication code built from a hash function; HMAC-SHA-256 §5.9 uses the hash function SHA-256 §5.2 (Secure Hash Algorithm with a 256-bit output) and gives a 32-byte tag. A 20-byte message with an Ed25519 signature occupies bytes. With an HMAC-SHA-256 tag it would occupy bytes. The signature costs bytes more per message, and checking it takes much more computation than recomputing an HMAC tag.
Stated precisely
A signature scheme is three algorithms: outputs a key pair , the public and the private key; outputs a signature of a message ; and answers accept or reject. Correctness: for every key pair that outputs and every , answers accept.
Security is defined by a contest.
A key pair is generated, and the attacker receives .
The attacker obtains the signatures of messages of its choice, as many as it likes, each chosen after seeing the earlier answers.
The attacker outputs a pair and wins if answers accept and it never obtained a signature of .
The scheme is existentially unforgeable under chosen-message attack (EUF-CMA) if every attacker with a feasible amount of computation wins only with negligible probability, a probability too small to matter. Existentially means that a signature on any new message counts as a win, even a meaningless message. Unlike in the contest for a message authentication code, the attacker holds and runs verification itself, so no receiver can count its failed attempts. RFC 8032 adds that Ed25519 signatures are not malleable: verification rejects any not below a fixed number a little above , so nobody can turn a valid signature into a different valid signature of the same message.
The guarantee rests on four assumptions.
The private key was generated from unpredictable random data and has stayed secret.
The verifier’s copy of the public key belongs to the intended signer.
The scheme is EUF-CMA secure. For a concrete scheme this property is not proved outright; it rests on assumptions, among them that a named mathematical problem cannot be solved with feasible computation. RFC 8032 gives Ed25519 a nominal strength of 128 bits, a measure of the number of operations an attack is estimated to need.
The signer and every verifier read the signed bytes in the same way.
Limits and common mistakes
A valid signature shows only that a holder of the private key signed exactly these bytes, not that the content is true, safe, current or permitted. An old signed message sent again, a replay attack §1.26, verifies as before. A device that must refuse older software compares a version number inside the signed bytes with the newest version it has accepted.
A signature that verifies under a public key chosen by the attacker proves nothing. The verifier’s key must come from a root of trust §1.33, a component that the device trusts without further checks, such as a key in read-only memory, or from a chain of certificates that ends at one.
Whoever steals the private key can sign anything until verifiers stop trusting the public key. That withdrawal, key revocation §5.32, must be designed in advance. The private key belongs in protected hardware behind a controlled signing service.
Non-repudiation means that a receiver can prove to a third party, who also holds the authentic public key, that the private key signed the message. It does not show that the key’s owner intended to sign, or that the key had not been stolen.
A signature does not hide the message. Confidentiality §1.8 needs encryption.
Some signature schemes need a fresh secret random number for every signature, and RFC 8032 warns that signing with bad randomness can, depending on the algorithm, reveal the whole private key. Ed25519 derives that number from the private key and the message instead.
Questions answered
Why might a signature be preferable to a shared MAC across many independent verifiers?
A signature is preferable because everyone who holds a key shared for a message authentication code (MAC) can also create valid tags, while a signature verifier holds only a public key that cannot sign. A MAC tag is computed from a message with a secret key and checked by recomputing it with the same key. With one key shared by many independent verifiers, such as thousands of devices with different owners:
an attacker who extracts the key from any one verifier can make messages that every other verifier accepts;
any verifier can pose as the sender, so a tag cannot show which key holder made a message;
every new verifier needs a secret copy of the key, delivered over a protected channel.
With a digital signature the sender keeps the only private key, and the verifiers hold a public key that anyone may read. Breaking into a verifier yields nothing that signs, one signature serves every verifier, and a new verifier needs only an authentic copy of the public key.
A separate MAC key per verifier also stops cross-device forgery, but then the sender must hold every key, or a master secret that derives them, and send a different tag to each verifier. The signature costs more bytes (64 bytes for a signature of the scheme Ed25519, against 32 bytes for a tag of the MAC HMAC-SHA-256) and more computation, and its public key must reach every verifier unaltered. For one verifier, or a closed group whose members may all create messages, a shared MAC key is simpler.
Related entries: Message authentication code (MAC) (§5.7), Authenticity versus authorship (§1.38), Root of trust (§1.33), Authentication coverage (§5.41), Symmetric versus asymmetric cryptography (§5.15), Forgery probability (§5.13), Key revocation (§5.32), Replay attack (§1.26). Further reading: [66, 147, 168].