Introduction to Cryptography and Security

Unlock the basics of cryptography and security! This student-friendly guide covers ciphers, algorithms like AES, attacker models, and randomness. Dive into crypto essentials today!

Podcast

Úvod do kryptografie0:00 / 14:25
0:001:00 remaining

Welcome to an essential guide on the Introduction to Cryptography and Security! In today's digital world, understanding how data is protected is more crucial than ever. This article will break down the fundamental concepts, algorithms, and security principles that safeguard our information.

What is Cryptography and Information Security?

Cryptography is both the art and science of securing data against adversaries. It's not just about encryption; it encompasses a broader range of techniques to protect information. Information security, on the other hand, deals with the overall protection of information systems from unauthorized access, use, disclosure, disruption, modification, or destruction.

Core Terminology in Cryptography

  • Cryptography: The art and science of securing data against adversaries.
  • Steganography: The art of concealing data within other data, like watermarking.
  • Cryptanalysis: The art and science of revealing weaknesses in cryptography.
  • Cryptology: The combined field of Cryptography and Cryptanalysis.

Encryption transforms data (plaintext) into an unintelligible form (ciphertext) using a critical parameter called a key. Decryption reverses this process, recovering plaintext using a decryption key. This process primarily provides data confidentiality, ensuring that only authorized parties can understand the data's semantics.

Understanding Encryption: Data Transformation

Encryption involves transforming data using a secret key. This differs from simple encoding, which uses a known, fixed mapping.

Encryption vs. Encoding

  • Encoding: Applies a fixed, known mapping. For example, text encoded to integers, or ASCII values. This is not suitable for hiding content because the mapping is public.
  • Encryption: Applies a secret mapping defined by a secret key (K). This key can be fixed or changing. It transforms data such that only someone with the correct key can reverse the transformation. Encryption mappings are one-to-one and operate within the same data domain, making them a permutation of the data blocks.

The Role of Keys in Encryption

Keys are critical for the security of encrypted data. The length and usage of a key significantly impact security:

  • Small Key (e.g., 1 bit): A specific key bit for each data bit. Used in Vernam cipher and stream ciphers. If a (plaintext, ciphertext) pair is known, the key can be simply determined, making it essential for the key to be unique.
  • Large Key (≥ 128 bits): A fixed key for each data block. Used in block ciphers and asymmetric ciphers. These keys are long enough to make brute-force attacks infeasible and are mixed with data using complex algorithms to produce random-looking ciphertext.

Kerckhoffs' Principle: A Cornerstone of Crypto Design

This fundamental principle states that a system's security should not rely upon the secrecy of its design details. In other words, the security should only depend on the secrecy of the key, not the algorithm itself. Claude Shannon articulated this as: "the enemy knows the system." Hardcoding secrets into hardware, for example, is risky because if the adversary learns the secret, all installations must be replaced.

Cryptographic algorithms can be categorized:

  • With keys: Ciphers (asymmetric, symmetric), MAC (Message Authentication Code).
  • Without keys (unkeyed): Hash functions, RNG (Random Number Generators).

Attacker Models and Types of Attacks

Understanding potential adversaries and their capabilities is crucial for designing secure systems. An attacker model clearly specifies what an attacker can and cannot do.

Types of Adversaries

  • Passive Adversary: Observes and records information but does not alter it. Examples include ciphertext-only and known-plaintext attacks.
  • Active Adversary: Interacts with ongoing transmissions by injecting or altering data, or initiates new interactions with legitimate parties. Examples include chosen-plaintext and chosen-ciphertext attacks.

Common Attacks Targeting Encryption

  • Exhaustive Search (Brute Force): Trying all possible options, typically all possible keys, until the correct one is found.
  • Ciphertext-Only Attack: The adversary has access only to the ciphertext and attempts to recover the plaintext or key.
  • Known-Plaintext Attack: The adversary has access to some plaintext and its corresponding ciphertext and tries to recover the unknown plaintext or key from further ciphertext.
  • Chosen-Plaintext Attack: The adversary can choose a certain amount of plaintext and observe the resulting ciphertext, allowing for advanced analysis.
  • Chosen-Ciphertext Attack: For a fixed key, the adversary can provide ciphertext of their choice and receive the corresponding plaintext. The goal is to deduce the secret key or other information to decrypt new ciphertext.

Countermeasures against these attacks include using large keys (over 100 bits) to make brute-force infeasible and designing ciphers that produce random-looking ciphertext.

Symmetric Encryption: Block vs. Stream Ciphers

Symmetric encryption uses the same key for both encryption and decryption. It's a fundamental concept in modern cryptography.

Stream Ciphers: One Bit/Byte at a Time

Stream ciphers encrypt or decrypt data one bit or byte at a time. They are designed as deterministic RNGs that generate a large random sequence called a keystream, initialized by a unique pair of a key (K) and an initialization vector (IV).

  • Vernam Cipher (One-Time Pad - OTP): A symmetric stream cipher that encrypts plaintext by one bit at a time. It's a perfect (secure) cipher if the key is as long as the plaintext and used only once. However, this makes it impractical and expensive for most applications. Reusing the keystream can lead to severe vulnerabilities, as the XOR properties allow for the cancellation or extraction of the keystream.
  • Characteristics: Extremely fast bitwise operations (XOR, AND, OR, shift). Widely used for hardware implementation and efficient for unknown file sizes or continuous streams (e.g., audio, video).
  • Examples: ChaCha20 (recommended), RC4 (weak and dropped in TLS 1.3).

Block Ciphers: Processing in Fixed-Size Blocks

Block ciphers operate on blocks of fixed size, typically 64, 128, or 256 bits. They perform permutations on these blocks. If the last block is incomplete, it must be completed with padding (e.g., zero padding). Distinguishing padding from actual data is crucial during decryption, often done by indicating the padding length in the last byte.

  • Characteristics: Suitable for software implementation and efficient for known file sizes due to possible parallel processing. Padding may be needed, which can sometimes lead to attacks.
  • Modes of Operation: Block ciphers have many versions (modes), some of which use an IV that must be unique.

Data Encryption Standard (DES)

DES, based on IBM's LUCIPHER, was a US standard from 1977. It encrypts 64-bit blocks with a 56-bit key (though initially designed for 128 bits, reduced due to classified reasons). DES has known weaknesses:

  • Weak Keys: Four specific keys where E_K(x) = x.
  • Semi-Weak Keys: Six pairs where E_K1(E_K2(x)) = x.
  • Breaking DES: While a 56-bit key space seems large (2^56), brute-force attacks became feasible with specialized hardware. By 1998, the EFF DES-breaking machine could crack keys in hours.

Triple DES (3DES)

To counter DES's vulnerabilities, Triple DES was introduced. It applies DES encryption three times with two or three different keys (K1, K2, K3):

  1. Encrypt with K1.
  2. Decrypt with K2.
  3. Encrypt with K3.

If K3 = K1, the effective key length is 112 bits, offering improved security over single DES.

Advanced Encryption Standard (AES)

AES is the current symmetric encryption standard, chosen in 2000 and standardized in 2001 (FIPS standard). It was selected for its high security, ease of implementation, and speed in both software and hardware.

Key Features of AES

  • Key Lengths & Rounds: AES supports 128-bit (10 rounds), 192-bit (12 rounds), or 256-bit (14 rounds) key lengths.
  • Fixed Block Size: Always 128 bits.
  • Rijndael vs. AES: Rijndael, the algorithm AES is based on, allowed variable block and key sizes, which determined the number of rounds. AES restricted these values to the fixed sizes mentioned above.

How AES Works (Building Blocks)

  1. Key Scheduling: The MasterKey is expanded into a set of RoundKeys (10, 12, or 14 depending on the key length).
  2. Algorithm Steps (per round):
  • AddRoundKey: XORs the state with a RoundKey.
  • SubBytes: A non-linear byte-for-byte substitution using an S-box (8-bit to 8-bit permutation). This is the only non-linear operation.
  • ShiftRows: Cyclically shifts rows of the state array.
  • MixColumn: Mixes the columns of the state array (except for the last round). These mixing operations (MixColumn, ShiftRows) ensure the avalanche effect, where a small change in plaintext or key results in a significant change in the ciphertext.
  1. Encryption vs. Decryption: Decryption uses the reversed order of RoundKeys and inverse operations for each step.

Flashcards

1 / 41

What is the purpose of an Initialization Vector (IV) in symmetric encryption?

To randomize the ciphertext for the same key and plaintext so identical plaintexts encrypt to different ciphertexts (with same key).

Tap to flip · Swipe to navigate

The Critical Role of Randomness in Cryptography

Cryptography heavily relies on values that are hard to guess, unpredictable, and unique. These include keys, Initialization Vectors (IVs), nonces, and challenges.

Types of Random Number Generators (RNGs)

  • Truly Random Number Generators (TRNGs): Non-deterministic, based on physical processes (e.g., radio decay, thermal noise). They are aperiodic and slow but highly unpredictable.
  • Pseudorandom Number Generators (PRNGs): Deterministic, software functions. They are fast and periodic. They are initialized by a seed, which fully determines the subsequent "random" data. If the seed or internal state is compromised, future values become predictable.

Combining TRNGs and PRNGs

System RNGs (like /dev/urandom in Linux) often combine both: a PRNG seeded by a TRNG. This provides the speed of a PRNG with the non-determinism of a TRNG.

  • Recommended (CSPRNGs - Cryptographically Secure PRNGs):
  • Based on crypto-primitives: ChaCha20, AES CTR mode, iterative hashing.
  • Number theoretic: Blum Blum Shub.
  • Special designs: Yarrow, Fortuna (/dev/random, /dev/urandom).
  • Not Recommended (Predictable/Weak):
  • Standard random functions: rand, java.util.Random.
  • Mersenne twister, Dual_EC_DRBG, RC4 (for generating keys or sensitive values).

Initialization Vector (IV)

An IV is an additional parameter used in many cipher modes. It does not need to be random, but it must be unique for each encryption with the same key. The IV helps randomize the ciphertext for the same key and plaintext pair. If the same IV and key are used, the same keystream is generated, which can lead to vulnerabilities.

Key Takeaways for Cryptography and Security

  • Do not implement your own crypto! Use well-vetted, standardized cryptographic libraries.
  • An Initialization Vector (IV) randomizes ciphertext for the same key/plaintext pair; it must be unique.
  • Modes of operation for block ciphers are very important (and will be covered in more detail in advanced topics).
  • A PRNG is deterministic; its output is determined by its seed or internal state.
  • Never use simple rand() functions or similar for generating cryptographic random values.
  • Always use system RNGs or CSPRNGs for cryptographic purposes.

Frequently Asked Questions about Cryptography and Security

What is the difference between encryption and encoding?

Encoding transforms data using a publicly known, fixed mapping (e.g., ASCII to binary). Encryption, however, uses a secret key to transform data, making it unintelligible without that specific key, thus providing confidentiality.

Why is Kerckhoffs' Principle important in cryptography?

Kerckhoffs' Principle states that the security of a cryptographic system should depend only on the secrecy of the key, not on the secrecy of the algorithm itself. This principle ensures that systems remain secure even if the attacker knows all the details of the encryption method, making them robust and publicly reviewable.

What are the main differences between stream ciphers and block ciphers?

Stream ciphers process data bit by bit or byte by byte, are generally faster, and are suitable for hardware implementations and continuous data streams. Block ciphers process data in fixed-size blocks, are better for software implementations and known file sizes, and often require padding for incomplete blocks.

Why should I not use standard random functions for cryptography?

Standard random functions (like rand() or java.util.Random) are typically pseudorandom and not cryptographically secure. Their outputs can often be predicted or reverse-engineered if their internal state or seed is known, making them unsuitable for generating cryptographic keys, IVs, or other security-sensitive values.

What is AES and why is it preferred over DES?

AES (Advanced Encryption Standard) is the current symmetric encryption standard, offering stronger security with key lengths of 128, 192, or 256 bits, and a fixed block size of 128 bits. It replaced DES (Data Encryption Standard) because DES's 56-bit key length became vulnerable to brute-force attacks due to increasing computational power.

Sign up to access full content

Create a free account to unlock all study materials, take interactive tests, listen to podcasts and more.

Create free account

Related topics