Simeon Simeonov - TDE
Cryptographic primitives are the most basic building blocks in cryptographic systems and protocols.
Creating cryptographic routines is very hard, and testing them to be reliable takes a long time, it is essentially never sensible (nor secure) to design a new cryptographic primitive to suit the needs of a new cryptographic system.
Since algorithms in this field are not only required to be designed well but also need to be tested well by the cryptologist community, even if a cryptographic routine looks good from a design point of view it might still contain errors. Successfully withstanding such scrutiny gives some confidence (in fact, so far, the only confidence) that the algorithm is indeed secure enough to use. Security proofs for cryptographic primitives are generally not available.
When choosing primitive for a cryptographic system, one should always consider if the primitive:
A hash function is any function that can be used to map data of arbitrary size to fixed-size values (or a set of fixed-size values)
Cryptographic hash functions or cryptographically secure hash functions are hash functions with special properties (making them desirable for cryptographic systems)
(Over)simplified list of desired properties:
| Designers | Ronald Rivest |
| Published | 1992 |
| Digest size | 128 bits (16 bytes) |
| Block size | 512 bits |
| Broken? | Yes (broken collision resistance in 2^18 time) |
Still in use in lagacy applications and in applications where collision resistance is not needed
| Designers | NSA |
| Published | 1995 |
| Digest size | 160 bits (20 bytes) |
| Block size | 512 bits |
| Broken? | Yes |
Still in use. Revision control systems such as Git, Mercurial, and Monotone use SHA-1, not for security, but to identify revisions and to ensure that the data has not changed due to accidental corruption.
| Designers | NSA |
| Published | 2001 |
| Digest sizes | 224, 256, 384 or 512 bits |
| Block sizes | 256 bits (SHA-224 and SHA-256) or 512 bits |
| Broken? | No |
| Designers | Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles van Assche |
| Published | 2016 |
| Digest size | arbitrary |
| Block size | variable |
| Broken? | No |
Based on Keccak - winner of the NIST hash function competition after some controversial adjustments. Very fast and flexible.
| Designers | Jean-Philippe Aumasson, Samuel Neves, Zooko Wilcox-O'Hearn and Christian Winnerlein |
| Published | 2008 (BLAKE) |
| Digest size | up to 64 bytes (BLAKE2b), up to 32 bytes (BLAKE2s) |
| Block size | variable (stream) |
| Broken? | No |
BLAKE2 is based on Daniel J. Bernstein's ChaCha stream cipher and is extremely fast. BLAKE2b and BLAKE2s are specified in RFC 7693.
Cryptographic hash functions are used for many different things in cryptographic systems and protocols. Few examples:
HMAC (hash-based message authentication code) is a specific type of message authentication code (MAC) involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and authenticity of a message. An HMAC is a type of keyed hash function that can also be used in a key derivation scheme or a key stretching scheme.
HMAC can provide authentication using a shared secret instead of using digital signatures with asymmetric cryptography. It trades off the need for a complex public key infrastructure by delegating the key exchange to the communicating parties, who are responsible for establishing and using a trusted channel to agree on the key prior to communication.
XOR (eXclusive OR) - is a logical operator
With two inputs, XOR is true if and only if the inputs differ (one is true, one is false)
PBKDF2 (Password-Based Key Derivation Function 2) is a key derivation function with a sliding computational cost, used to reduce vulnerability to brute-force attacks.
PBKDF2 applies a pseudorandom function, such as HMAC, to the input password or passphrase along with a salt value and repeats the process many times to produce a derived key, which can then be used as a cryptographic key in subsequent operations. The added computational work makes password cracking much more difficult, and is known as key stretching.
Most cryptographic applications require random numbers for: generating keys, initialization vectors, nonces (arbitrary numbers that can be used just once), salts, tokens etc, etc.
The "quality" of the randomness required for these applications varies. For example, creating a nonce in some protocols needs only uniqueness. On the other hand, the generation of a master key requires a higher quality, such as more entropy.
Entropy is obtained from a high-quality source, generally the operating system's randomness API.
In practical situations, numbers are needed with more randomness than the available entropy can provide. Also, the processes to extract randomness from a running system are slow in actual practice. In such instances, a cryptographically secure pseudorandom number generator (CSPRNG) can sometimes be used. A CSPRNG can "stretch" the available entropy over more bits.
CSPRNG must
"Practical" CSPRNG schemes not only include an CSPRNG algorithm, but also a way to initialize ("seed") it while keeping the seed secret.
Symmetric ciphers use the same cryptographic keys for both the encryption of plaintext and the decryption of ciphertext.
“Anyone, from the most clueless amateur to the best cryptographer, can create an algorithm that he himself can’t break. It’s not even hard. What is hard is creating an algorithm that no one else can break, even after years of analysis. And the only way to prove that is to subject the algorithm to years of analysis by the best cryptographers around.” - Bruce Schneier
A "perfect" cipher - the one-time pad has been known since 1882, but is not practically applicable in modern systems:
There two types of modern ciphers:
| Designer | IBM |
| Published | 1975 |
| Key size | 56 bits |
| Block size | 64 bits |
Not used anymore. 3DES was published in 1981 (with keysize of 112 bits or 168 bits).
| Designer | Bruce Schneier |
| Published | 1993 |
| Key size | 32-448 bits |
| Block size | 64 bits |
Schneier has stated that "Blowfish is unpatented, and will remain so in all countries. The algorithm is hereby placed in the public domain, and can be freely used by anyone.". Still in use in legacy applications and notably in the bcrypt password hashing function.
| Designer | Joan Daemen, Vincent Rijmen |
| Published | 1998 |
| Key size | 128 bits, 192 bits or 256 bits |
| Block size | 128 bits |
Rijndael was thew winner of the NIST AES selection process. Currently the most widely adopted block cipher (both in hardware and software).
A block cipher by itself is only suitable for the secure cryptographic transformation (encryption or decryption) of one fixed-length group of bits called a block. A mode of operation describes how to repeatedly apply a cipher's single-block operation to securely transform amounts of data larger than a block.
The GCM algorithm provides both data authenticity (integrity) and confidentiality and belongs to the class of authenticated encryption with associated data (AEAD) methods. This means that as input it takes a key K, some plaintext P, and some associated data AD; it then encrypts the plaintext using the key to produce ciphertext C, and computes an authentication tag T from the ciphertext and the associated data (which remains unencrypted). A recipient with knowledge of K, upon reception of AD, C and T, can decrypt the ciphertext to recover the plaintext P and can check the tag T to ensure that neither ciphertext nor associated data were tampered with.
Stream ciphers typically execute at a higher speed than block ciphers and have lower hardware complexity. However, stream ciphers can be susceptible to security breaches, for example, when the same starting state (seed) is used twice.
Essentially they behave as pseudorandom functions where they key is / is part of the "seed".
| Designer | Daniel J. Bernstein (djb) |
| Published | 2008 |
| Key size | 128 bits or 256 bits |
ChaCha20-Poly1305 is an AEAD algorithm, that combines the ChaCha20 stream cipher with the Poly1305 message authentication code. It has fast software performance, and without hardware acceleration, is usually faster than AES-GCM.
Asymmetric cryptography makes use pairs of related keys. Each key pair consists of a public key and a corresponding private key. Key pairs are generated with cryptographic algorithms based on mathematical problems termed one-way functions. Security of public-key cryptography depends on keeping the private key secret, while the public key can be openly distributed without compromising security.
Usually we use public key cryptography for:
| Designers | Ron Rivest, Adi Shamir and Leonard Adleman |
| Published | 1977, patented until 2000 :( |
The security of RSA relies on the practical difficulty of factoring the product of two large prime numbers, the "factoring problem". Still the most widely used public key system. A key size of 2048 or 4096 bits should be used. A very good CSPRNG is needed.
In modern cryptographic systems and protocols (like TLS >= 1.2) RSA is only used for verifying that the client is initiating session with the "right" server. Encryption / decryption is performed using common negotiated key and symmetric ciphers.
Forward secrecy is a desired feature of specific key-agreement protocols that gives assurances that session keys will not be compromised even if long-term secrets used in the session key exchange are compromised, limiting damage. For HTTPS, the long-term secret is typically the private key of the server.
Post-quantum cryptography (PQC), sometimes referred to as quantum-proof, quantum-safe, or quantum-resistant, is the development of cryptographic algorithms (usually public-key algorithms) that are thought to be secure against a cryptanalytic attack by a quantum computer. Most widely-used public-key algorithms rely on the difficulty of one of three mathematical problems: the integer factorization problem, the discrete logarithm problem or the elliptic-curve discrete logarithm problem. All of these problems could be easily solved on a sufficiently powerful quantum computer running Shor's algorithm or even faster and less demanding (in terms of the number of qubits required) alternatives.