Definition
Symmetric cryptography is cryptography in which one secret key serves an operation and its reverse: the same key encrypts and decrypts, or creates and checks an authentication §1.6 code. Whoever holds the key can do both. Asymmetric cryptography, or public-key cryptography, uses a key pair: a private key kept by its owner and a public key that anyone may have, related so that the private key cannot in practice be computed from the public one. The public key lets others check or encrypt, but not sign or decrypt.
The idea
Two devices that share a secret key can protect their messages with symmetric cryptography alone, compactly and fast. More parties cause trouble. If 100 devices must each talk privately with every other, every pair needs its own key: 4950 keys. If one key is shared by the whole group instead, every member can read every message and can create messages that all other members accept as authentic.
Asymmetric cryptography separates the abilities. A device publishes its public key and keeps its private key. Anyone can use the public key to check the device’s signatures or to agree on a secret with it, but nothing done with the public key lets anyone sign as the device. The price is larger keys, larger signatures and more computation.
Protocols therefore combine the two: public-key methods set up and authenticate a shared secret once, and symmetric methods protect the bulk of the data. TLS (Transport Layer Security) version 1.3, a protocol for secure connections between client and server programs over the Internet, can work this way: Diffie–Hellman key agreement §19.1.4 produces a shared secret, the server proves its identity with a signature, a key derivation function §5.20 turns the shared secret into symmetric keys, and authenticated encryption §5.16 protects the data.
How it works
Symmetric primitives each use one shared secret key .
Encryption with a block cipher §15.3, an algorithm §14.1 that encrypts fixed-size blocks under a key, such as AES (Advanced Encryption Standard): encrypts and the same decrypts.
Message authentication code (MAC) §5.7, such as HMAC §5.8 (hash-based message authentication code): computes a tag, and the verifier recomputes the tag with the same and compares.
Authenticated encryption: one encrypts and also protects the message against undetected change.
Key derivation function: turns one secret key into several keys.
Asymmetric primitives each use a key pair.
Digital signature §5.14: the private key signs and the public key verifies.
Public-key encryption: the public key encrypts and the private key decrypts. NIST’s key-management recommendation SP 800-57 (Special Publication 800-57) lists its use for encrypting keys, called key transport.
Key agreement, such as Diffie–Hellman key agreement: each party combines its own private key with the other party’s public key, and both arrive at the same shared secret, which then feeds symmetric cryptography.
The two families rest on different foundations. A symmetric key is safe only while it is random, secret and long enough that trying every value is infeasible, meaning far beyond any realistic amount of computation, and only while no attack on the algorithm is much faster than trying every key. A key pair is safe only while a particular mathematical problem stays infeasible. For RSA, the algorithm that Rivest, Shamir and Adleman published in 1978 [317], the problem is factoring: splitting a large public number, the modulus, into the secret primes whose product it is. ECC (elliptic-curve §19.1.5 cryptography) computes with the points of an elliptic curve, a set of number pairs with a rule for adding two of them. For ECC the problem is the elliptic-curve discrete logarithm §19.1.3: given a public point equal to a fixed base point added to itself a secret number of times, find that number.
Worked example
Counting keys. Let be the number of parties, each of which must talk privately with every other. With symmetric keys each pair needs its own key, so there are keys. For parties A, B and C the pairs are A with B, A with C and B with C: keys, stored as secret copies. For : keys, 99 on each party and secret copies in all. With key pairs, each party keeps one private key and the 99 public keys of the others, which must be authentic but need not be secret.
A verifier that forges. RFC 4231 publishes test values for HMAC-SHA-256 §5.9, HMAC used with the hash function SHA-256 §5.2 (Secure Hash Algorithm with a 256-bit output). In its test case 2 the key is the 4 characters Jefe, far too short for real use, the message is what do ya want for nothing? and the tag is
5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
A receiver that holds the key checks this tag by recomputing it. With the same key it can also compute the tag of a message it wrote itself, what do ya want for everything?:
2b7562ba9a2bf92b75acb1463d8a6b2d866eca6640ed10c125b17aef7d20ff00
Its own check accepts this pair, and so does the check of every other holder of the key. Nothing in the pair shows that the receiver, not the sender, made it.
Key sizes for equal strength. SP 800-57 Part 1 Revision 5 defines security strength as a number, in bits, associated with the number of operations needed to break an algorithm. For a strength of 128 bits it lists AES with a 128-bit key (16 bytes), RSA with a 3072-bit modulus ( bytes), and ECC with a key of 256 to 383 bits ( bytes at the low end).
Stated precisely
Symmetric. Let be a secret key. An encryption scheme has and , with for every plaintext , where is a ciphertext. A MAC has and for a message and a tag . Both operations of each pair take the same . For a MAC that verifies by recomputing, such as HMAC, accepts exactly when , so any party that can run with can compute for any . Symmetric security is promised only against parties that do not hold .
Asymmetric. Key generation outputs a pair , the public and the private key. A signature scheme has and for a signature ; public-key encryption has and . Asymmetric security is promised against parties that hold . SP 800-57 defines a public-key algorithm by this property: determining the private key from the public key is computationally infeasible. Signing a new message, or decrypting, without must be infeasible too. For a concrete algorithm both rest on the assumption that its mathematical problem cannot be solved with feasible computation at the chosen key size.
Limits and common mistakes
The family of an algorithm is not a permission rule. A signature verifier that can also call a signing service can sign. Conversely, some key-storage interfaces let a program verify MACs with a key without letting it compute them; that program cannot obtain tags, but whoever extracts the key can forge.
A public key is not secret, but it must be authentic: an attacker who substitutes its own public key gets its own signatures accepted. Key agreement alone authenticates nobody, because an attacker in the middle can run one key agreement with each side. TLS, for example, authenticates the server with a signature or a pre-shared key.
A public identifier, such as a serial number or a key identifier, is not a public key and lets nobody check anything.
Neither family stops a replay attack §1.26, the sending again of a genuine recorded message, and neither decides what an authentic message may do.
A signature of Ed25519, a signature scheme defined in RFC 8032, is 64 bytes against 32 bytes for an HMAC-SHA-256 tag, and checking it takes much more computation than recomputing the tag.
SP 800-57 warns that large-scale quantum computers, when they become available, will threaten the approved public-key algorithms, so that signature and key-agreement schemes may need quantum-resistant replacements. RFC 8032 states that quantum computers would break its signature schemes, Ed25519 included.
Questions answered
Can a symmetric verifier forge a message that passes its own check?
Yes, a symmetric verifier can forge a message that passes its own check. A verifier that checks a MAC (message authentication code), a tag computed from a message with a secret key, holds the same key that creates tags, so it can compute a valid tag for any message it writes. Checking a MAC such as HMAC (hash-based message authentication code) means recomputing the tag of the received message with the key and comparing. The same computation on a message of the verifier’s choosing gives a tag that its own check accepts, and so does the check of every other holder of the key.
This is not a flaw in the MAC; it follows from using one key for both operations. Consequently a valid tag cannot prove to a third party which key holder made the message, and an attacker who extracts a shared key from any one verifier can forge messages for all of them.
A verifier of a digital signature holds only the public key, from which the private signing key cannot in practice be computed, so it cannot create a signature that its own check accepts. Two refinements apply. A symmetric verifier whose key sits in protected hardware that allows only verification cannot get tags from that hardware, although the key inside could compute them. And a signature verifier that can call a signing service can sign through it.
Related entries: Digital signature (§5.14), Message authentication code (MAC) (§5.7), Authenticated encryption (AEAD) (§5.16), Key derivation function (KDF) (§5.20), Diffie–Hellman key agreement (§19.1.4), Secure element (§5.38), Per-device key derivation (§5.24). Further reading: [147, 167, 168, 317].