Cryptography Notes

The Basics of Cryptography

Cryptography

  • Cryptography is the science of using mathematics to encrypt and decrypt data.

  • It enables secure storage and transmission of sensitive information across insecure networks like the Internet.

  • Cryptanalysis is the science of analyzing and breaking secure communication.

  • Classical cryptanalysis involves analytical reasoning, mathematical tools, pattern finding, patience, determination, and luck.

  • Cryptanalysts are also called attackers.

  • Cryptology encompasses both cryptography and cryptanalysis.

How Cryptography Works

  • A cryptographic algorithm, or cipher, is a mathematical function used in the encryption and decryption process.

  • A cipher works with a key (word, number, or phrase) to encrypt plaintext.

  • Different keys encrypt the same plaintext into different ciphertext.

  • The security of encrypted data depends on the strength of the cryptographic algorithm and the secrecy of the key.

  • A cryptosystem comprises a cryptographic algorithm, all possible keys, and the protocols that make it work.

Terminologies

  • Plaintext/Cleartext: Data that can be read and understood without special measures.

  • Encryption: The method of disguising plaintext to hide its substance.

  • Ciphertext: Unreadable gibberish resulting from encrypting plaintext.

  • Encryption ensures information is hidden from unintended recipients, even those who can see the encrypted data.

  • Decryption: The process of reverting ciphertext to its original plaintext.

Short History of Cryptography

  • Cryptography's roots are found in Roman and Egyptian civilizations.

  • As civilizations evolved, the need to communicate secretly led to the continuous evolution of cryptography.

Hieroglyph

  • The first known evidence of cryptography is traced to the use of hieroglyphs.

  • Around 4000 years ago, Egyptians used hieroglyphs to communicate messages.

Caesar Shift Cipher

  • Julius Caesar used this cipher to protect messages of military significance by shifting letters.

  • Every letter is replaced by a letter a fixed number of positions down the alphabet.

  • Example: Shift each letter forward by 3 places in the alphabet: H → K, E → H, L → O, L → O, O → R so HELLO becomes KHOOR

  • To decrypt, shift each letter backward by 3 places: KHOOR → HELLO

Kamasutra Cipher

  • One of the earliest known substitution methods, described in the Kamasutra around 400 BC.

  • Purpose was to teach women how to hide secret messages.

  • A simple substitution cipher where the 26 letters are organized into 13 pairs.

  • To encrypt or decrypt, each letter is replaced with its paired counterpart.

  • Example: if the mapping: A <-> X, B <-> Y, C <-> Z, D <-> W, E <-> V, F <-> U, G <-> T, H <-> S, I <-> R, J <-> Q, K <-> P, L <-> O, M <-> N

  • Plaintext: HELLO maps to Ciphertext: SVOOL

Cryptography with Alice and Bob

Untrusted Communication Channels
  • Alice wants to send a private message to Bob via postal mail, but suspects the postman is reading the mail.

Symmetric-Key Encryption
  • Alice and Bob meet to exchange identical keys to open a lockbox.

  • Alice locks the message inside the lockbox using her key and sends it to Bob.

  • The mailman cannot read the message without the key.

  • Bob uses his identical key to unlock the lockbox and read the message.

  • Inconvenient as Alice and Bob has to meet to exchange keys.

Public-Key Encryption
  • Bob sends an unlocked padlock to Alice, keeping the key safe.

  • Alice puts her message in a lockbox and locks it with Bob's padlock, mailing it to Bob.

  • Only Bob can open it with his key.

  • Alice could buy a blue padlock and key and mail the padlock to Bob so that he can reply.

  • Bob generates a key pair consisting of his public key (padlock) and private key (key).

  • Bob publishes his public key, and Alice fetches it.

  • Alice generates a temporary symmetric key and uses Bob's public key to securely send it to Bob.

  • Bob uses his private key to unlock his copy of the symmetric key.

  • Bob and Alice can then use those symmetric keys to securely send messages back and forth.

Features of Cryptography

  • Modern cryptography concerns itself with:

    • Confidentiality: Information is understood only by the intended recipient.

    • Integrity: Information cannot be altered during storage or transit without detection.

    • Non-repudiation: The sender cannot deny their intentions in creating or transmitting information.

    • Authentication: Sender and recipient can confirm each other's identity, origin, and destination of information.

Major Types of Cryptography

  • Hash Functions

  • Symmetric Key Cryptography

  • Asymmetric Key Cryptography

One-Way Hash Algorithms
  • Produces a fixed-length output (digest) from a variable-length input string.

  • Collision resistant: Any modification generates a different hash.

  • One-way: Irreversible, ensuring data security.

  • Cryptographic providers support these hash algorithms: MD4, MD5, SHA and SHA256.

  • MD4 & MD5

    • Invented by Ron Rivest. MD stands for Message Digest. Produce 128-bit hash values.

    • MD5 is no longer considered secure for digital signing due to lack of collision resistance but still widely used for key generation.

  • SHA

    • Stands for Secure Hash Algorithm. Designed by NIST and NSA. Produces 160-bit hash values.

    • Generally considered more secure than MD4 and MD5 and is the recommended hash algorithm.

  • SHA256

    • A 256-bit modern version of SHA and is only supported by the Microsoft Enhanced RSA and AES Cryptographic Provider.

Symmetric Key Cryptography
  • Also known as private key, secret key, or single-key encryption.

  • Uses one key for both encryption and decryption.

    • Block cipher: Encrypts data in fixed-size blocks.

    • Stream cipher: Converts one bit (or one byte) of data at a time, generating a keystream that XORed with the plaintext data.

  • Examples:

    • Data Encryption Standard (DES): Developed by IBM in the early 1970s.

    • Triple DES: Adds extra levels of security to DES, not broken by modern machines.

    • Blowfish: A fast, free, publicly available block cipher designed by Bruce Schneer in 1993.

    • Advanced Encryption Standard (AES): Approved by the US National Security Agency for top secret information.

Asymmetric Key Cryptography
  • Uses a pair of keys: one secret key and one public key.

  • Considered more secure because an encrypted message can only be decrypted with the recipient’s private key.

  • Examples:

    • RSA: Named for Rivest, Shamier, and Adleman in 1977, used for secure data transmission.

    • ECC: Elliptic curve cryptography uses algebraic structures of elliptic curves to create strong cryptographic keys.

Applications of Cryptography

  • Computer passwords: Hashed and encrypted before being stored.

  • Digital Currencies: Cryptography protect transactions and prevent fraud.

  • Secure web browsing: Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols encrypt data sent between the web server and the client.

  • Electronic Signatures: Validated using public key cryptography.

  • Authentication: Cryptographic methods are used to confirm the user’s identity.

  • Cryptocurrencies: Protect transactions, thwart fraud, and maintain the network’s integrity.

  • End-to-end Internet Encryption: Protect two-way communications like video conversations, instant messages, and email.

Cryptographic Attacks

  • Brute force attacks: Trying various private keys to decipher an encrypted message or data. For an 8-bit key possible keys will be 28=2562^8 = 256.

  • Ciphertext-only attacks: Attacker gains access to a collection of ciphertext.

  • Chosen plaintext attacks: Attacker can choose arbitrary plaintext data to obtain the ciphertext.

  • Chosen ciphertext attack: Attacker analyses a chosen ciphertext corresponding to its plaintext.

  • Known plaintext attacks: Attacker knows the plaintext of some portions of the ciphertext.

  • Key and algorithm attacks: Attacker tries to recover the key used to encrypt or decrypt the data by analyzing the cryptographic algorithm.

Preventing Cryptography Attacks

  • Regularly update the cryptographic algorithms and protocols.

  • Ensure that the data is appropriately encrypted.

  • Use strong and unique keys for encryption.

  • Store the keys in a secure location.

  • Ensure that the cryptographic system is implemented correctly.

  • Regularly test the system for vulnerabilities.

  • Educate employees about cryptography attacks and how to prevent them.