Cryptography Essentials: Keys, Hashes, and Authentication
X.509 Certificate Format
An X.509 certificate is a digital certificate used to establish the identity of an entity, such as a person or a website, and ensure secure communication.
Key Components
- Version: Specifies the X.509 version (usually v3).
- Serial Number: A unique identifier for the certificate issued by the Certificate Authority (CA).
- Signature Algorithm: The algorithm used by the CA to sign the certificate (e.g., RSA or ECDSA).
- Issuer: The CA that issued the certificate (e.g., “CN=Example CA”).
- Validity Period: The start and end date of the certificate’s validity.
- Subject: The entity the certificate is issued to (e.g., “CN=www.example.com“).
- Subject Public Key: The public key of the subject.
- Extensions: Extra fields that provide additional information, such as:
- Key Usage: What the key can be used for (e.g., encryption, signing).
- Subject Alternative Name (SAN): Additional identifiers (e.g., IP addresses or DNS names).
- Signature: The CA’s digital signature that ensures the certificate’s authenticity and integrity.
Message Authentication Code (MAC)
A Message Authentication Code (MAC) is a cryptographic value used to verify the authenticity and integrity of a message. It ensures that the message comes from a legitimate sender and that the message has not been tampered with during transmission. The MAC is generated using a secret key and a hash function.
Malicious Code Forms
- Virus: Attaches to a legitimate program or file, spreading when executed and often causing damage.
- Trojan Horse: Disguises itself as a legitimate application, allowing unauthorized access and potential damage.
- Worm: Self-replicating code that spreads over networks, causing congestion or system crashes.
Digital Signatures
A digital signature is a mathematical scheme used to verify the authenticity and integrity of a message, document, or transaction. It ensures that the data has not been altered and that it truly comes from the sender.
Types of Digital Signatures
- Basic Digital Signature: The sender signs the message with their private key (e.g., signing an email). Provides authentication and integrity.
- Advanced Digital Signature: Uses a secure signature creation device (SSCD) for enhanced security (e.g., signing sensitive documents). Provides strong authentication, integrity, and non-repudiation.
- Qualified Digital Signature: Issued by a Qualified Trust Service Provider (QTSP), meeting legal standards for transactions (e.g., legal contracts).
Benefits of Digital Signatures
- Authentication: Ensures the sender’s legitimacy.
- Integrity: Guarantees the content’s unchanged state.
- Non-repudiation: Prevents the sender from denying they sent the message.
Message Authentication
Message Authentication verifies that a message hasn’t been altered and confirms the sender’s identity.
Approaches to Achieve Message Authentication
- Plaintext Message Authentication: Directly verifying the message content (not commonly used due to low security).
- Hash Functions: Generating a fixed-size hash of the message for verification.
- Message Authentication Code (MAC): Using a secret key and a cryptographic algorithm to create a MAC.
- Digital Signatures: Encrypting the message hash with the sender’s private key.
- Public Key Infrastructure (PKI): Using digital certificates to authenticate messages.
SHA Algorithm (Secure Hash Algorithm)
The SHA (Secure Hash Algorithm) produces a fixed-size hash value from an input message.
Key Features of SHA
- Fixed Size Output: Produces a hash of a consistent size (e.g., SHA-256 outputs a 256-bit hash).
- One-way Function: Easy to generate a hash, but hard to reverse.
- Collision-Resistant: Unlikely that two different inputs produce the same hash.
Types of SHA Algorithms
- SHA-0: Original, now insecure.
- SHA-1: 160-bit hash, considered weak.
- SHA-2: Includes SHA-224, SHA-256, SHA-384, SHA-512.
- SHA-3: Latest version with enhanced security.
Usage of SHA
- Data Integrity
- Digital Signatures
- Password Hashing
Diffie-Hellman Key Exchange
The Diffie-Hellman Key Exchange securely shares a secret key between two parties over a public channel.
How It Works
- Agree on public parameters (prime number p and base g).
- Each party picks a private key.
- Compute public values (g raised to the private key, modulo p).
- Exchange public values and compute the shared secret key.
Key Points
- Secure as eavesdroppers only see public values.
- Helps agree on a shared secret key for encryption.
Hash Function Uses
A hash function produces a fixed-size hash value from an input.
Main Uses of Hash Functions
- Data Integrity: Detects data alterations.
- Password Storage: Stores password hashes instead of plain text.
- Digital Signatures: Creates a message digest for signing.
- Checksums: Verifies file integrity (e.g., MD5, SHA).
- Efficient Data Retrieval: Used in databases and hash tables.
Characteristics of Hash Functions
- Deterministic: Same input produces the same output.
- Fixed Output Length: Output is always a fixed size.
- Efficient: Quick processing for applications like data integrity checks.
- Pre-image Resistance: Hard to find the original input from the hash.
- Collision Resistance: Difficult to find two inputs with the same hash.
- Avalanche Effect: Small input changes result in significantly different hashes.
Kerberos Working
Kerberos is a network authentication protocol using symmetric key cryptography and a Key Distribution Center (KDC).
How Kerberos Works
- User logs in with credentials.
- Authentication Server (AS) issues a Ticket Granting Ticket (TGT).
- User requests service access using the TGT.
- Ticket Granting Server (TGS) issues a service ticket.
- User accesses the service with the service ticket.
Key Points
- Relies on encrypted tickets.
- Tickets are time-sensitive.
- Centralized authentication through KDC.
Public Key Distribution
Securely distributing public keys is crucial in public key cryptography.
Approaches to Public Key Distribution
- Public Announcement: Insecure, keys are publicly shared.
- Public Key Directories: Central authority maintains a directory of keys.
- Public Key Certificates: Trusted Certificate Authorities (CAs) issue certificates.
- Web of Trust: Decentralized authentication based on mutual trust.
- Key Exchange Protocols: Secure exchange over networks (e.g., Diffie-Hellman, SSL/TLS).
HMAC Algorithm
HMAC (Hash-Based Message Authentication Code) verifies data integrity and authenticity using a secret key and a hash function.
Steps in HMAC Algorithm
- Key Padding: Pad the key to match the hash function’s block size.
- Inner Hashing: XOR the padded key with inner padding and hash with the message.
- Outer Hashing: XOR the key with outer padding and hash with the inner hash result.
- Output: The final HMAC is a fixed-length code.
Key Points
HMAC provides strong security by using both a secret key and a hash function, making it difficult to tamper with data.