1. Home
  2. Explore
  3. Computer Science
  4. Cryptography Fundamentals

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Cryptography Fundamentals

Fundamentals of Cryptography

What Is Cryptography?

Cryptography is the use of mathematical algorithms and keys to protect information from unauthorized access or alteration. It transforms readable data, called plaintext, into an unreadable form called ciphertext.

  • Encryption converts plaintext into ciphertext.

  • Decryption converts ciphertext back into plaintext.

  • A cryptographic key controls how encryption and decryption occur.

  • Without the correct key, encrypted data should remain inaccessible or extremely difficult to interpret.

Cryptography protects information during storage and transmission. It is used in activities such as online transactions, email, messaging, file storage, wireless communication, and device security.

Cryptography protects digital information by ensuring that only authorized parties can access, understand, verify, or modify it.


Steganography

Steganography hides the existence of a message rather than merely hiding the message’s contents.

A hidden message can be embedded within:

  • Image files

  • Audio files

  • Video files

  • File headers

  • Metadata fields

  • Unused portions or spaces within a file

The data is placed where it does not noticeably change the appearance or operation of the host file. For example, a small message might be hidden in the unused data areas of an image.

Steganography and Cryptography

  • Cryptography makes information unreadable to unauthorized users.

  • Steganography attempts to make the information difficult to detect in the first place.

  • The two techniques can be combined: a message can first be encrypted and then hidden inside an image or audio file.

Steganography does not necessarily provide strong protection if the hidden data is discovered. Encryption can provide an additional layer of security.


Security Benefits of Cryptography

Cryptography supports several major security objectives.

Confidentiality

Confidentiality ensures that information can be viewed only by authorized individuals or systems.

Encryption provides confidentiality by transforming readable information into ciphertext. Only a person or system with the proper decryption key can recover the original content.

Example: Encrypting a document ensures that only users who possess the correct key can open and read it.

Integrity

Integrity ensures that data remains accurate, complete, and unaltered.

Cryptographic hashes and digital signatures can detect whether information changed during storage or transmission. If even a small part of a file is modified, its cryptographic value will usually change.

Example: A downloaded software file can be hashed and compared with the publisher’s original hash to determine whether the file was altered.

Authentication

Authentication verifies the identity of a user, device, sender, or system.

Cryptographic techniques can demonstrate that a message came from a particular source. Digital certificates, digital signatures, and cryptographic protocols are commonly used for authentication.

Example: A website certificate helps a browser verify that it is communicating with the intended website.

Non-repudiation

Non-repudiation provides evidence that a particular party performed an action or sent a message. It makes it difficult for that party to later deny the action.

Digital signatures can support non-repudiation by linking a message to the private key of its signer. The strength of non-repudiation also depends on proper key protection and trustworthy procedures.

Obfuscation

Obfuscation makes information, code, or system behavior difficult to understand.

Unlike encryption, obfuscation is not necessarily intended to provide strong secrecy. It is often used to make data or software harder to analyze.

Example: Software developers may obfuscate application code to make reverse engineering more difficult.

Security Through Obscurity

Security through obscurity relies on keeping the design or operation of a system secret. This may provide an additional obstacle, but it should not replace sound cryptographic protection.

A secure system should remain secure even when its algorithms are publicly known. Security should depend primarily on protecting the key, not on hiding the algorithm.


Cryptographic Algorithm Categories

The main categories discussed are hash algorithms, symmetric cryptography, and asymmetric cryptography.

Hash Algorithms

A hash algorithm converts input data of arbitrary size into a fixed-length value called a hash, hash value, or digest.

The digest acts like a digital fingerprint of the original data.

Properties of Cryptographic Hashes

A secure cryptographic hash generally has the following properties:

  • The same input consistently produces the same digest.

  • A small change in the input produces a substantially different digest.

  • It is computationally difficult to recover the original input from the digest.

  • It is difficult to find two different inputs that produce the same digest.

  • The output has a fixed length for a given algorithm.

Hashing is generally a one-way process. A hash is not intended to be decrypted back into the original data.

Uses of Hashing

Hashing is used to:

  • Verify file integrity

  • Detect unauthorized changes

  • Store password verifiers

  • Support digital signatures

  • Identify data or software

  • Assist in blockchain systems

Passwords should not normally be stored as plaintext. Instead, a system can store a salted and appropriately processed password hash. During login, the entered password is processed and compared with the stored value.

Common Hash Algorithms

Examples include:

  • SHA family: Secure Hash Algorithms, such as SHA-256 and SHA-3

  • RIPEMD: A family of cryptographic hash functions

  • MD5: An older hash algorithm that is no longer suitable for collision-resistant security

  • Whirlpool: A cryptographic hash function

Older algorithms such as MD5 and some forms of SHA-1 are considered weak for many security applications because attackers can generate collisions more easily than acceptable.


Symmetric Cryptography

Symmetric cryptography uses the same secret key for both encryption and decryption.

If one party encrypts a message with a key, the receiving party must possess the same key to decrypt it.

How Symmetric Cryptography Works

  1. The sender and receiver obtain the same secret key.

  2. The sender uses the key to encrypt plaintext.

  3. The encrypted ciphertext is transmitted or stored.

  4. The receiver uses the same key to decrypt the ciphertext.

Advantages

  • Fast execution

  • Efficient for large amounts of data

  • Relatively low computational overhead

  • Suitable for full-disk, file, database, and network encryption

Limitation: Key Distribution

The primary challenge is securely distributing the shared key. If an attacker obtains the key, the attacker may be able to decrypt all data protected by that key.

The difficulty increases as the number of communicating parties grows because each relationship may require a securely shared secret.

Private-Key Cryptography

Symmetric cryptography is also called private-key cryptography or secret-key cryptography because the encryption key must remain secret.

Common Symmetric Algorithms

  • AES: Advanced Encryption Standard; a widely used modern block cipher

  • DES: Data Encryption Standard; obsolete because its key size is too small

  • Blowfish: An older symmetric block cipher

  • Twofish: A successor-style design related to Blowfish and a strong block cipher

AES is commonly preferred for modern applications because it provides strong security and efficient performance when implemented correctly.


Asymmetric Cryptography

Asymmetric cryptography, also called public-key cryptography, uses a mathematically related key pair:

  • Public key: Shared openly

  • Private key: Kept secret by its owner

Data encrypted with one key is associated with the other key in the pair, depending on the operation being performed.

Encryption with a Public and Private Key

For confidentiality:

  1. The recipient publishes a public key.

  2. A sender encrypts a message using the recipient’s public key.

  3. Only the recipient’s corresponding private key can decrypt the message.

This allows people to send encrypted information without first sharing a secret key through a secure channel.

Digital Signatures

For authentication, integrity, and non-repudiation:

  1. The sender creates a digest of the message.

  2. The sender uses their private key to create a digital signature.

  3. The recipient uses the sender’s public key to verify the signature.

  4. The recipient also checks that the message’s digest has not changed.

A digital signature does not primarily provide confidentiality. Its main purposes are to verify the signer and detect modification.

Advantages

  • Simplifies secure key exchange

  • Supports authentication

  • Enables digital signatures

  • Supports secure communication between parties that have not previously shared a secret

Limitations

  • Usually slower than symmetric encryption

  • Requires more computational resources

  • Often used to exchange or establish symmetric session keys rather than encrypting large amounts of data directly


RSA and ECC

RSA

RSA is an asymmetric algorithm based on the mathematical difficulty of factoring very large numbers, particularly the product of large prime numbers.

  • Supports encryption, key exchange, and digital signatures

  • Requires relatively large keys for strong security

  • Can be computationally expensive compared with newer approaches

Elliptic Curve Cryptography

Elliptic Curve Cryptography (ECC) uses mathematical operations involving points on elliptic curves.

  • Provides strong security with smaller keys than RSA

  • Often requires less storage and bandwidth

  • Can be faster and more efficient for mobile devices and other resource-constrained systems

  • Is widely used in modern applications

ECC is especially useful when processing power, memory, bandwidth, or battery life is limited.


Cryptographic Algorithm Variations

One-Time Pad

A one-time pad (OTP) combines plaintext with a truly random key that:

  • Is at least as long as the message

  • Is used only once

  • Is kept completely secret

  • Is never reused

When these conditions are met, a one-time pad can provide theoretically perfect secrecy.

The major practical problems are generating, distributing, protecting, and securely destroying keys that are as long as the messages they protect. Reusing a one-time-pad key can reveal relationships between messages and seriously weaken security.

Stream Ciphers

A stream cipher encrypts data continuously, often one bit or byte at a time, by combining the plaintext with a generated keystream.

Important considerations include:

  • The keystream must be unpredictable.

  • The key and initialization values must not be reused improperly.

  • Reusing the same keystream with multiple messages can expose information.

Stream ciphers are useful when data arrives continuously or when low latency is important.

Block Ciphers

A block cipher processes data in fixed-size blocks. The algorithm transforms each block using a key.

Block ciphers require appropriate modes of operation to securely process messages longer than one block. Poor mode selection or incorrect initialization-vector handling can expose patterns or permit attacks.

AES is a common example of a block cipher.

Sponge Functions

A sponge function absorbs input data into an internal state and then squeezes out an output of the desired length.

This structure supports variable-length outputs and is used in algorithms such as SHA-3 and related constructions. Sponge functions can be used to create hashes, message authentication values, and other cryptographic outputs.


Key Exchange and Digital Signatures

Diffie–Hellman

Diffie–Hellman (DH) is a key-agreement method that allows two parties to establish a shared secret over an untrusted network.

The parties exchange public information and independently compute the same shared secret. The secret itself does not need to be transmitted directly.

DH is primarily a method for establishing a shared key, not a complete authentication system. Without authentication, it may be vulnerable to a man-in-the-middle attack.

Ephemeral Diffie–Hellman

Ephemeral Diffie–Hellman (DHE) uses temporary key pairs for individual sessions.

Because the keys are temporary, they can provide perfect forward secrecy when implemented correctly.

Elliptic Curve Diffie–Hellman

Elliptic Curve Diffie–Hellman (ECDH) performs key agreement using elliptic-curve mathematics.

It provides the benefits of Diffie–Hellman while using smaller keys and often requiring fewer computational resources.

Perfect Forward Secrecy

Perfect forward secrecy (PFS) ensures that the compromise of a long-term private key does not expose the session keys or previously recorded communications.

A protocol achieves PFS by generating separate, temporary session keys. Even if an attacker later obtains a server’s long-term private key, previously captured encrypted traffic should remain protected.

Digital Signature Algorithm

The Digital Signature Algorithm (DSA) creates and verifies digital signatures.

Digital signatures help provide:

  • Authentication: Evidence of who signed the data

  • Integrity: Evidence that the data was not changed

  • Non-repudiation: Difficulty for the signer to deny signing the data

The private key creates the signature, while the corresponding public key verifies it.


Applications of Cryptography

File and File-System Encryption

File encryption protects individual files or groups of files.

File-Level Encryption

File-level encryption encrypts selected files. Users or applications may choose which files require protection.

Advantages include:

  • Selective protection

  • Flexibility

  • Ability to share encrypted files individually

File-System Encryption

File-system encryption integrates encryption into the operating system’s file-system functions. The system can encrypt and decrypt files automatically and transparently as authorized users access them.

Encrypting File System (EFS) in Microsoft Windows is an example of file-system encryption.

Common Encryption Tools

Examples of file-encryption tools include:

  • GNU Privacy Guard (GnuPG)

  • AxCrypt

  • Folder Lock

  • VeraCrypt

The security of any tool depends on correct configuration, strong keys, secure authentication, and protection against key loss.


Disk and Volume Encryption

Full-Disk Encryption

Full-disk encryption (FDE) encrypts the entire storage device, including:

  • User files

  • Folders

  • Operating-system files

  • Boot-related data

  • System configuration data

  • The Windows registry, where applicable

BitLocker is a full-disk encryption technology included with Microsoft Windows.

If a laptop protected by FDE is stolen, an attacker who removes the drive and connects it to another device should still find the data unreadable without the required key or authentication mechanism.

Full-disk encryption primarily protects data at rest when a device is lost or stolen. It does not automatically protect data after an authorized user has logged in.

Volume-Level Encryption

Volume-level encryption protects a specific logical section, or volume, of a storage device. A volume has its own file system and is accessible to users or applications.

Volume encryption can protect selected areas without encrypting the entire physical disk.


Database Encryption

Database encryption can be implemented in multiple ways.

Plug-In Encryption

The plug-in method adds an encryption module or package to the database management system. The module performs encryption and decryption functions alongside the database system.

This approach may provide flexibility but can require additional software, configuration, and maintenance.

Transparent Data Encryption

Transparent Data Encryption (TDE) performs encryption and decryption within the database engine.

Benefits include:

  • Minimal application changes

  • No need for applications to manage encryption directly

  • No need to modify the database management system’s source code

  • Simpler administration

  • Protection of database files and storage media if the files are copied or stolen

TDE generally operates transparently to authorized users and applications. It does not necessarily protect data from an already authorized user or compromised application.


Hardware-Based Cryptography

Cryptographic functions can be built directly into hardware devices such as:

  • USB drives

  • Hard drives

  • Storage controllers

  • Security appliances

  • Embedded devices

When hardware-based encryption is enabled, data written to the device may be encrypted automatically, reducing the need for user intervention.

Advanced encrypted USB devices may allow administrators to:

  • Control access remotely

  • Disable a user’s access

  • Revoke device access

  • Erase stored data

  • Trigger a self-destruct or cryptographic-erasure function

Hardware-based cryptography can improve performance and protect keys from ordinary software-based attacks, but the hardware and its management system must still be trusted and properly secured.


Self-Encrypting Drives

A self-encrypting drive (SED) automatically encrypts data written to the drive.

During startup or power-up:

  1. The drive and host device perform an authentication process.

  2. If authentication succeeds, the drive releases or uses the encryption key.

  3. If authentication fails, the drive can deny access.

  4. In some designs, repeated or administrative authentication failure can cause the drive to destroy its encryption keys.

If the encryption keys are securely deleted, the encrypted data becomes permanently unreadable. This is known as cryptographic erasure.


Hardware Security Modules

A hardware security module (HSM) is a specialized device that performs and protects cryptographic operations.

An HSM typically provides:

  • Secure key generation

  • Protected key storage

  • Symmetric encryption

  • Asymmetric encryption

  • Digital-signature operations

  • Hardware-assisted cryptographic processing

HSMs help prevent private keys from being exposed to ordinary operating-system processes. They are commonly used by organizations that need strong protection for certificate keys, payment systems, identity systems, and other sensitive cryptographic material.


Trusted Execution Environments

A trusted execution environment (TEE) is an isolated and protected area within a computing device. It is designed to protect the confidentiality and integrity of code and data even if the ordinary operating system is compromised.

A TEE can be used to:

  • Process sensitive information

  • Protect authentication credentials

  • Store cryptographic keys

  • Verify software or device state

  • Isolate security-critical operations

Trusted Platform Module

A Trusted Platform Module (TPM) is a standardized hardware security component that provides cryptographic services.

A TPM can include:

  • Secure key generation and storage

  • A hardware random-number generator

  • Support for asymmetric cryptography

  • Platform-integrity measurements

  • Device authentication

  • Support for secure boot and disk encryption

Secure Enclave

On Apple devices and many Android devices, similar protected hardware areas are commonly referred to as a Secure Enclave or secure area.

These components can generate and protect public-private key pairs while limiting direct access to private keys.


Blockchain and Cryptography

A blockchain is a distributed, shared record used to record transactions and track assets.

It maintains a ledger across multiple computers. Participants use a consensus process to agree on the valid state of the ledger.

Cryptography contributes to blockchain security through:

  • Hashes that link blocks together

  • Digital signatures that authenticate transactions

  • Consensus mechanisms that help participants agree on valid records

  • Tamper-evident records

  • Public or controlled verification of transactions

Changing an earlier block would generally alter its hash and disrupt the links to later blocks, making unauthorized modification detectable.

Types of Blockchains

Public Blockchain

A public blockchain is open to anyone who meets the participation requirements.

Characteristics include:

  • Broad participation

  • Publicly observable records, depending on the design

  • Decentralized validation

  • No single organization necessarily controls membership

Private Blockchain

A private blockchain restricts participation to approved users or organizations.

Characteristics include:

  • Controlled membership

  • Greater administrative control

  • Use within a company or limited business network

  • Potentially faster and more efficient validation

Federated Blockchain

A federated blockchain, also called a consortium blockchain, is governed by a group of selected organizations.

It combines elements of public and private systems:

  • Participation is restricted

  • Multiple organizations share control

  • It is useful when several trusted entities need a common ledger


Cryptography on Low-Power Devices

Cryptography is important for Internet of Things devices, sensors, embedded systems, and other systems that require rapid responses.

However, these devices often have limited:

  • Processing power

  • Memory

  • Battery capacity

  • Storage

  • Network bandwidth

Cryptographic operations consume time and energy. Stronger algorithms may require more processing, while lightweight algorithms may reduce resource usage but must still provide adequate security.

Designers must balance:

  • Security strength

  • Performance

  • Power consumption

  • Response time

  • Key-storage capabilities

  • Hardware limitations

The objective is to protect the device without consuming so many resources that the device becomes unreliable or unusable.


Cryptographic Limitations and Attacks

Cryptography is powerful, but it is not automatically secure. Weak algorithms, poor key management, implementation errors, and protocol weaknesses can expose protected information.

Algorithm Attacks

An algorithm attack targets weaknesses in the algorithm or the way it is implemented.

Attackers may use mathematical analysis, statistical analysis, repeated observations, or known information to infer plaintext or cryptographic keys.

Known-Ciphertext Analysis

In a known-ciphertext attack, the attacker studies encrypted data and searches for patterns or weaknesses.

Statistical analysis may reveal information when:

  • The encryption algorithm is weak

  • Keys are reused improperly

  • Random values are predictable

  • Message formats are known

  • The same plaintext produces recognizable ciphertext patterns

Modern secure encryption is designed to resist practical ciphertext-only analysis, but incorrect implementation can still create vulnerabilities.

Downgrade Attacks

A downgrade attack forces a system to use an older or weaker security mode instead of the strongest available option.

An attacker may attempt to:

  • Disable modern encryption

  • Force use of an obsolete protocol version

  • Select a weaker cipher suite

  • Cause a system to fall back to an insecure compatibility mode

Systems should disable obsolete algorithms and enforce secure protocol configurations.

Brute-Force Attacks

A brute-force attack tries possible keys until the correct key is found.

The difficulty of brute force depends on:

  • Key length

  • Key randomness

  • The number of possible keys

  • Available computing power

  • Rate-limiting and account protections

Long, randomly generated keys make exhaustive guessing more difficult.


Collision Attacks

A collision occurs when two different inputs produce the same hash value.

A collision attack attempts to create two distinct messages, M1M_1M1​ and M2M_2M2​, such that:

H(M1)=H(M2)H(M_1) = H(M_2)H(M1​)=H(M2​)

where HHH is the hash function.

Collisions are a serious concern when hashes are used to verify identity, authenticate files, or sign documents. A malicious party might create a harmless document and a harmful document with the same digest, then substitute the harmful version.

A secure hash function should make finding such pairs computationally impractical.


Birthday Attacks

A birthday attack exploits the mathematics behind the birthday paradox.

The birthday paradox demonstrates that in a group of only 23 people, there is approximately a 50% probability that at least two people share a birthday. The probability becomes even higher as the group grows.

Cryptographic birthday attacks apply the same principle to hash values. Finding any two messages with the same hash is easier than finding a message that matches one particular preselected hash.

For a hash with an ideal output size of nnn bits, a generic collision attack may require approximately:

2n/22^{n/2}2n/2

attempts rather than 2n2^n2n attempts. Therefore, hash functions need sufficiently large output sizes and strong collision resistance.


Quantum Computing and Cryptography

Traditional computers use bits that represent either 000 or $1. Quantum computers use quantum bits, or qubits.

A qubit can exist in a combination of states through superposition, allowing quantum systems to process certain types of calculations in ways that differ from traditional computers.

Quantum computers could threaten current cryptography because some quantum algorithms can solve certain mathematical problems much more efficiently.

Potential Threats

A sufficiently powerful quantum computer could undermine:

  • RSA

  • Diffie–Hellman

  • Elliptic-curve cryptography

  • Other systems based on integer factoring or discrete logarithms

These algorithms are widely used for encryption, key exchange, and digital signatures.

Quantum attacks could allow an attacker to:

  • Recover private keys from public keys

  • Decrypt protected communications

  • Forge digital signatures

  • Break previously trusted key-exchange systems

Post-Quantum Cryptography

Post-quantum cryptography (PQC) develops cryptographic algorithms intended to resist attacks from both classical and quantum computers.

Organizations must consider the possibility of “harvest now, decrypt later” attacks, in which adversaries collect encrypted data today and attempt to decrypt it once sufficiently powerful quantum computers become available.

Post-quantum algorithms are designed to replace vulnerable public-key systems while preserving important functions such as:

  • Key exchange

  • Encryption

  • Authentication

  • Digital signatures

Symmetric algorithms and hash functions are generally less affected by quantum computing, although larger key or digest sizes may be needed to maintain equivalent security.


Key Concepts to Remember

  • Cryptography: Protects information using mathematical algorithms and keys.

  • Encryption: Converts plaintext into ciphertext.

  • Decryption: Converts ciphertext back into plaintext.

  • Confidentiality: Prevents unauthorized disclosure.

  • Integrity: Detects unauthorized modification.

  • Authentication: Verifies identity or origin.

  • Non-repudiation: Provides evidence that an action or message came from a particular party.

  • Obfuscation: Makes information or code difficult to understand.

  • Hashing: Creates a one-way digital fingerprint of data.

  • Symmetric cryptography: Uses one shared secret key for encryption and decryption.

  • Asymmetric cryptography: Uses a public key and a private key.

  • Digital signatures: Support authentication, integrity, and non-repudiation.

  • Full-disk encryption: Protects all data on a storage device, including the operating system.

  • HSMs, TPMs, TEEs, and Secure Enclaves: Protect cryptographic operations and keys using specialized hardware or isolated environments.

  • Blockchain: Uses cryptography and distributed agreement to maintain a tamper-evident ledger.

  • Collision attacks: Seek different inputs that generate the same hash.

  • Birthday attacks: Use probability to find hash collisions more efficiently.

  • Post-quantum cryptography: Develops algorithms designed to remain secure against quantum computers.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent