Unit 2: Symmetric and Public Key Cryptography

CSE436 — Blockchain 10 min read

I. Foundations of Modern Cryptography

Cryptography is the mathematical discipline of protecting information and verifying digital actions. Modern cryptography follows Kerckhoffs’s principle (1883): a system should remain secure even when its design is public, provided the secret key remains unknown.

  • Security objectives:
    • Confidentiality: Preventing unauthorized disclosure, usually through encryption.
    • Integrity: Detecting unauthorized modification through hashes or message authentication codes.
    • Authentication: Establishing the identity or origin of a participant or message.
    • Non-repudiation: Providing evidence that links a signer to a digital signature.
  • Core terminology:
    • Plaintext (P): Original readable data.
    • Ciphertext (C): Encrypted data.
    • Key (K): A value controlling a cryptographic operation.
    • Encryption (E) and decryption (D):
TEXT
C = E_K(P)
P = D_K(C)
  • Security assumptions:
    • Algorithms are public; keys supply secrecy.
    • Keys must come from a cryptographically secure random number generator.
    • Security is computational rather than absolute: attacks should require infeasible time or resources.
    • Correct implementation, key storage and protocol design are as important as algorithm strength.
  • Principal models:
    1. Symmetric cryptography: The same secret key is used for encryption and decryption.
    2. Asymmetric cryptography: A mathematically related public-key/private-key pair is used.
  • Blockchain context: Blockchains primarily use hashes, digital signatures, Merkle structures and consensus rules; encryption is not what makes a blockchain immutable.

II. OpenSSL — Command-Line Cryptographic Operations

OpenSSL is an open-source toolkit that implements cryptographic algorithms, certificate operations and the Transport Layer Security protocol. Its command-line interface is useful for generating keys, hashing files, encrypting data and creating signatures.

A. Working with the OpenSSL command line

The OpenSSL command line exposes cryptographic primitives through commands whose options must be selected carefully.

  • Version and help: Installation details and supported commands can be inspected directly.
BASH
openssl version
openssl help
openssl list -digest-algorithms
openssl list -cipher-algorithms
  • Secure random generation: rand obtains bytes from OpenSSL’s cryptographically secure random generator.
BASH
openssl rand -hex 32
  • 32 means 32 random bytes, equivalent to 256 bits.
  • Hexadecimal encoding produces 64 printable hexadecimal characters.
  • Message digest: SHA-256 maps a file of any length to a 256-bit digest.
BASH
openssl dgst -sha256 document.txt
  • Changing even one input bit should unpredictably alter the digest.
  • A digest detects changes but does not authenticate the sender by itself.
  • Password-based AES encryption:
BASH
openssl enc -aes-256-cbc -salt -pbkdf2 -iter 200000 \
  -in message.txt -out message.enc
  • AES decryption:
BASH
openssl enc -d -aes-256-cbc -pbkdf2 -iter 200000 \
  -in message.enc -out message.txt
  • -salt prevents identical passwords from producing identical derived keys.
  • -pbkdf2 derives a key from the password through repeated computation.
  • The same cipher and derivation parameters are required during decryption.
  • RSA key-pair generation:
BASH
openssl genpkey -algorithm RSA \
  -pkeyopt rsa_keygen_bits:3072 -out private.pem

openssl pkey -in private.pem -pubout -out public.pem
  • Signing and verification:
BASH
openssl dgst -sha256 -sign private.pem \
  -out signature.bin document.txt

openssl dgst -sha256 -verify public.pem \
  -signature signature.bin document.txt
  • Signing uses the private key.
  • Successful verification proves that the signature matches the document and public key.

B. Operational safeguards and limitations

OpenSSL demonstrates cryptographic operations but does not automatically guarantee a secure system.

  • Private-key protection: Private keys should be encrypted at rest, access-controlled and never placed in public repositories.
  • Password handling: Passwords typed as command arguments may appear in shell history or process listings; interactive input or protected configuration is safer.
  • Authentication limitation: AES-CBC encryption does not itself detect ciphertext modification; an authenticated mode such as AES-GCM is generally preferred in application protocols.
  • File replacement risk: Decrypting directly over the original file can destroy data if the password or parameters are wrong.
  • Version dependence: Available algorithms and defaults vary between OpenSSL releases, particularly OpenSSL 1.1.1 and 3.x.
  • Legacy avoidance: DES, 3DES, RC4, MD5 and SHA-1 should not be selected for new security designs.

III. Cryptographic Primitives — Basic Security Building Blocks

A cryptographic primitive is a low-level algorithm designed to provide a specific security property. Secure protocols combine primitives without assuming that one primitive supplies every property.

A. Cryptographic primitives

Cryptographic primitives include encryption, hashes, MACs, key derivation functions, random generators and digital signatures.

  • Symmetric encryption: A shared key transforms plaintext into ciphertext and restores it.
TEXT
C = E_K(P),    P = D_K(C)
  • AES is a block cipher; ChaCha20 is a stream cipher.
  • Confidentiality alone does not necessarily provide integrity.
  • Cryptographic hash function:
TEXT
h = H(m)
  • (m) is the message and (h) is its fixed-length digest.
  • Preimage resistance: Given (h), finding (m) should be infeasible.
  • Second-preimage resistance: Given (m_1), finding (m_2 \ne m_1) with the same digest should be infeasible.
  • Collision resistance: Finding any pair with (H(m_1)=H(m_2)) should be infeasible.
  • For an ideal (n)-bit hash, collision search takes approximately (2^{n/2}) operations.
  • Message authentication code:
TEXT
t = MAC_K(m)
  • The tag (t) provides integrity and source authentication between parties sharing (K).
  • HMAC-SHA-256 securely combines a secret key with SHA-256.
  • Key derivation function: PBKDF2, scrypt and Argon2 derive keys from passwords; HKDF derives independent subkeys from strong key material.
  • Cryptographically secure randomness: CSPRNG output must be unpredictable; timestamps and ordinary programming-language random functions are unsuitable for private keys.
  • Digital signature: A private key signs a message, while the corresponding public key verifies it.

B. Composition and security limitations

Primitives must be composed according to a defined protocol because individually secure algorithms can form an insecure construction.

  • Authenticated encryption: AES-GCM and ChaCha20-Poly1305 provide confidentiality and integrity together.
  • Nonce requirement: A nonce is a value used once; repeating a nonce with the same GCM key can reveal information and undermine authentication.
  • Encoding requirement: Signed or hashed data needs deterministic serialization; different byte encodings of equivalent data produce different hashes.
  • Domain separation: Distinct labels or keys prevent a hash or derived key used for one purpose from being confused with another.
  • Side channels: Timing, power use, memory access and error messages may leak secrets despite mathematically secure primitives.

IV. Advanced Encryption Standard — Symmetric Block Encryption

AES is a standardized symmetric block cipher selected by the US National Institute of Standards and Technology in 2001. It encrypts 128-bit blocks using keys of 128, 192 or 256 bits.

A. Advanced Encryption Standard (AES)

AES transforms a 128-bit block through repeated substitution, permutation, mixing and key addition operations.

  • State representation: The 16-byte input is arranged as a (4 \times 4) byte matrix called the state.
  • Key and round counts:
    • AES-128 uses 10 rounds.
    • AES-192 uses 12 rounds.
    • AES-256 uses 14 rounds.
  • Round transformations:
    • SubBytes: Replaces every byte through a nonlinear substitution box.
    • ShiftRows: Cyclically shifts state rows by different offsets.
    • MixColumns: Mixes each column using arithmetic in (GF(2^8)).
    • AddRoundKey: XORs the state with a round key derived from the original key.
  • Round structure: An initial AddRoundKey is followed by full rounds; the final round omits MixColumns.
  • Avalanche effect: A one-bit change in plaintext or key should alter many ciphertext bits after the rounds.
  • Performance: AES is efficient in software and hardware, with processor instructions such as AES-NI accelerating operations.

B. Modes, applications and limitations

AES requires a mode of operation to securely process data longer than one 128-bit block.

  1. Non-authenticated modes:
    • ECB: Encrypts equal blocks identically and reveals patterns; it should not be used for structured data.
    • CBC: Chains blocks and requires an unpredictable initialization vector, padding and separate authentication.
    • CTR: Converts AES into a stream-like cipher; reusing a nonce-counter sequence exposes plaintext relationships.
  2. Authenticated mode:
    • GCM: Combines counter-mode encryption with an authentication tag.
    • A common nonce length is 96 bits, and the nonce must be unique for each key.
  • Applications: AES protects stored files, databases, network traffic, backups and wallet data.
  • Limitation: Symmetric parties must securely establish and protect the shared key; AES does not solve key distribution.

V. Asymmetric Cryptography — Public and Private Keys

Asymmetric cryptography uses a public key that may be distributed and a private key that must remain secret. Its security relies on computationally difficult mathematical problems.

A. Asymmetric cryptography

Asymmetric systems support key establishment, encryption and digital signatures without requiring every participant to share the same secret beforehand.

  • RSA foundation: RSA relies on the practical difficulty of factoring a large composite integer (n=pq), where (p) and (q) are secret primes.
  • Elliptic-curve foundation: ECC relies on the elliptic-curve discrete logarithm problem and provides strong security with comparatively small keys.
  • Diffie–Hellman agreement: Two parties derive a common secret over a public channel.
TEXT
A = g^a mod p
B = g^b mod p
Shared secret = B^a mod p = A^b mod p
  • (p) is a public prime modulus, (g) is a generator, and (a,b) are private values.
  • Authentication is still required to prevent man-in-the-middle attacks.
  • Digital signatures:
TEXT
σ = Sign_sk(H(m))
Verify_pk(H(m), σ) → valid or invalid
  • (sk) is the private signing key, (pk) the public key, (m) the message and (\sigma) the signature.
  • RSA-PSS, ECDSA and EdDSA are established signature schemes.

B. Applications and limitations

Asymmetric cryptography complements rather than replaces symmetric cryptography.

  • Hybrid encryption: Public-key methods establish or encrypt a session key; AES then encrypts bulk data efficiently.
  • Authentication: Certificates bind public keys to identities through signatures from certificate authorities.
  • Performance: Public-key operations are slower and require larger computations than symmetric encryption.
  • Private-key failure: Theft permits unauthorized signatures; loss may permanently remove access to protected assets.
  • Algorithm constraints: RSA requires secure padding, while ECDSA requires a unique unpredictable nonce for every signature.

VI. Cryptographic Constructs and Blockchain Technology — Building Verifiable Ledgers

Blockchain systems combine primitives into higher-level constructs that allow participants to verify transactions and ledger history without trusting a single record keeper.

A. Cryptographic constructs and blockchain technology

Blockchain security emerges from hashes, signatures, authenticated data structures and consensus mechanisms working together.

  • Transaction identifiers: A serialized transaction is hashed to obtain an identifier; changing its bytes changes the identifier.
  • Hash-linked blocks: A block header contains a reference to the previous block’s hash, making historical alteration detectable.
  • Merkle tree: Transaction hashes are repeatedly paired and hashed until one Merkle root remains.
TEXT
Parent = H(Left || Right)
  • || means byte concatenation.
  • A Merkle proof verifies inclusion using only a logarithmic number of sibling hashes.
  • Digital ownership: A private key authorizes a transaction signature; network nodes verify it with the corresponding public key.
  • Addresses: Blockchain addresses are commonly derived from public keys using hashing and encoding, but formats differ between platforms.
  • Consensus integration: Proof of Work, Proof of Stake and related protocols determine which valid block history participants accept.
  • Smart contracts: Deterministic programs apply ledger rules; cryptographic verification does not guarantee that contract logic is error-free.

B. Security significance and limitations

Blockchain cryptography provides verifiability and tamper evidence, but its guarantees depend on the complete protocol and operational environment.

  • Immutability qualification: Hash links reveal modification, while consensus and economic cost make accepted history difficult—not mathematically impossible—to rewrite.
  • Privacy limitation: Public ledgers may expose transaction values and address relationships; pseudonymity is not anonymity.
  • Key-management risk: A valid signature cannot distinguish the rightful owner from an attacker using a stolen private key.
  • Hash-security risk: Collision or preimage breakthroughs could weaken identifiers and hash-linked structures.
  • Quantum risk: Large quantum computers would threaten RSA and elliptic-curve signatures through Shor’s algorithm, while symmetric key sizes can be increased against Grover-style search.
  • Overall construction: Hashing protects structural integrity, signatures authorize state changes, and consensus establishes the accepted ordering of those changes.