nisClassNotes
nisClassNotes
A Comprehensive Guide
March 2025
Cryptography and Security
2
Contents
1 RSA Algorithm 9
1.1 Introduction to RSA Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.1.1 Key Setup in RSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.1.2 Encryption and Decryption Process . . . . . . . . . . . . . . . . . . . 9
1.1.3 RSA Example - Key Generation and Usage . . . . . . . . . . . . . . . 10
1.1.4 Mathematical Foundation of RSA . . . . . . . . . . . . . . . . . . . . 10
1.2 Introduction to ElGamal Cryptosystem . . . . . . . . . . . . . . . . . . . . . 11
1.2.1 Key Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2.2 Encryption Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2.3 Decryption Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.2.4 Why ElGamal Works . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.2.5 Example of ElGamal Cryptosystem . . . . . . . . . . . . . . . . . . . 12
1.2.6 Security of ElGamal Cryptosystem . . . . . . . . . . . . . . . . . . . 13
1.2.7 Restating the ElGamal Process . . . . . . . . . . . . . . . . . . . . . 13
1.3 Introduction to Key Management and Distribution . . . . . . . . . . . . . . 13
1.3.1 Key Management in Symmetric and Public-Key Cryptography . . . . 13
1.4 Key Distribution in Symmetric Cryptography . . . . . . . . . . . . . . . . . 14
1.4.1 Key Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.5 Key Distribution Scenario Using KDC . . . . . . . . . . . . . . . . . . . . . 14
1.6 Key Distribution Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.7 Distribution of Public Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.7.1 Public Announcement . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.7.2 Publicly Available Directory . . . . . . . . . . . . . . . . . . . . . . . 15
1.7.3 Public-Key Authority . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.7.4 Public-Key Certificates . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.8 Security of Public-Key Certificates . . . . . . . . . . . . . . . . . . . . . . . 16
1.9 Introduction to Diffie-Hellman Key Exchange . . . . . . . . . . . . . . . . . 16
1.9.1 Key Features of Diffie-Hellman . . . . . . . . . . . . . . . . . . . . . 16
1.10 Overview of Diffie-Hellman Key Exchange . . . . . . . . . . . . . . . . . . . 16
1.11 Example of Diffie-Hellman Key Exchange . . . . . . . . . . . . . . . . . . . . 17
1.12 Security of Diffie-Hellman Key Exchange . . . . . . . . . . . . . . . . . . . . 17
1.12.1 Vulnerabilities and Mitigation . . . . . . . . . . . . . . . . . . . . . . 17
1.13 Applications of Diffie-Hellman Key Exchange . . . . . . . . . . . . . . . . . . 18
1.14 Mathematical Explanation of Shared Key Computation . . . . . . . . . . . . 18
3
Cryptography and Security
4
Cryptography and Security
5
Cryptography and Security
6
Index
2. RSA Algorithm
7
Cryptography and Security
8
Chapter 1
RSA Algorithm
3. Choose an encryption key e such that 1 < e < ϕ(n) and gcd(e, ϕ(n)) = 1.0.Computethedecryptionkeyd
Computethedecryptionkeyd, which satisfies:
5.
4. Publish the public key KU = (e, n).
C = Me (mod n).
9
Cryptography and Security
M = Cd (mod n).
10
Cryptography and Security
11
Cryptography and Security
• During decryption, the receiver computes K = g xk (mod q) = C1x (mod q), allowing
them to recover the plaintext using modular inversion.
3. **Decryption**: To decrypt the ciphertext (C1 , C2 ) = (8, 4), the receiver computes:
(a) Compute the shared secret K = C1x (mod q) = 85 (mod 11) = 32768 (mod 11) =
10.
(b) Compute the modular inverse of K(mod q), which is K −1 = 10−1 (mod 11) = 10
(since 10 · 10 = 100 ≡ 1(mod 11)).
(c) Recover the plaintext:
12
Cryptography and Security
Ciphertext: (C1 , C2 ).
2. **Decryption**: Given ciphertext (C1 , C2 ) and private key x < q: Compute:
13
Cryptography and Security
1. One party selects the key and physically delivers it to the other party.
2. A trusted third party selects the key and delivers it securely to both parties.
3. If the parties have previously communicated, they can use an old key to encrypt a new
key.
4. If both parties have secure communication with a trusted third party (e.g., a Key
Distribution Center or KDC), the third party can relay the key between them.
• **Session Key**: A temporary key used for encrypting data during a single session.
It is discarded after the session ends.
• **Master Key**: A long-term key shared between a user and a KDC. It is used to
encrypt session keys for secure distribution.
1. User A requests a session key from the KDC to establish a connection with user B.
The request includes A’s identity, B’s identity, and a unique nonce N1 .
3. User A stores Ks for use during the session and forwards the information for B to user
B.
14
Cryptography and Security
• Hierarchies of KDCs are required for large networks but must trust each other.
• Decentralized key distribution avoids reliance on central authorities but can be chal-
lenging to implement.
15
Cryptography and Security
2. The integrity of certificates through digital signatures signed by the CA’s private key.
• **Applications**: Widely used in protocols such as Secure Sockets Layer (SSL), Trans-
port Layer Security (TLS), Secure Shell (SSH), and Internet Protocol Security (IPSec).
3. Exchange public keys: Each user shares their public key with the other party.
16
Cryptography and Security
4. Compute the shared secret key: Using their private key and the other party’s public
key, each user computes:
xself
K = yother (mod q).
Both users arrive at the same shared secret K = g xA xB (mod q).
2. **Private Keys**: Alice chooses her private key xA = 97, and Bob chooses his private
key xB = 233.
3. **Public Keys**: Alice computes her public key:
y A = g xA (mod q) = 397 (mod 353) = 40.
Bob computes his public key:
yB = g xB (mod q) = 3233 (mod 353) = 248.
4. **Shared Secret Key**: After exchanging public keys, both compute the shared secret
key: Alice computes:
K = yBxA (mod q) = 24897 (mod 353) = 160.
Bob computes:
K = yAxB (mod q) = 40233 (mod 353) = 160.
Thus, both arrive at the same shared secret K = 160.
17
Cryptography and Security
• **Secure Shell (SSH)**: For secure remote login and file transfer.
Thus, both parties independently compute the same shared secret using modular arith-
metic.
1. **Ephemeral Keys**: Generate new private-public key pairs for every session to ensure
forward secrecy.
2. **Static Keys**: Use long-term private-public key pairs published in directories. While
convenient, this method is more vulnerable to attacks unless combined with authenti-
cation mechanisms.
18
Cryptography and Security
19
Cryptography and Security
1. **Padding**: The input message is padded to ensure its length is a multiple of the
block size. Padding involves appending a ’1’ bit followed by ’0’ bits and then appending
the length of the original message.
2. **Initialization**: A predefined initial value (IV) serves as the starting point for hash
computation.
3. **Processing Blocks**: The padded message is divided into fixed-size blocks. Each
block is processed iteratively using a compression function. The output of one iteration
becomes the input for the next iteration.
4. **Finalization**: After all blocks are processed, the final output is the hash value.
3. **Digital Signatures**:
1. **Unkeyed Hash with Symmetric Encryption**: Encrypt both the message and its
concatenated hash code using symmetric encryption. This ensures both authenticity
and confidentiality.
2. **Unkeyed Hash without Message Encryption**: Encrypt only the hash code using
symmetric encryption. This reduces processing overhead when confidentiality is not
required.
20
Cryptography and Security
3. **Keyed Hash with Symmetric Encryption**: Share a secret key between parties and
compute hashes over concatenated messages and keys. Confidentiality can be added
by encrypting both message and hash code.
21
Cryptography and Security
• **SHA-256**: Generates a 256-bit hash and is widely used for secure applications.
22
Cryptography and Security
1. **Padding**: Append a single ’1’ bit followed by ’0’ bits until the message length is
congruent to 896 modulo 1024. Append the length of the original message as a 128-bit
integer.
3. **Processing Blocks**: Divide the padded message into 1024-bit blocks. Each block
undergoes:
4. **Finalization**: After processing all blocks, output the final state value as the result-
ing hash.
23
Cryptography and Security
3. Intermediate values are shuffled using logical operations to ensure avalanche effect and
completeness properties.
2. **SHA-2 Strengths**: Resistant to collision attacks due to longer hash lengths and
improved mathematical structure.
2. **Data Integrity Checks**: Verify that data has not been tampered with during trans-
mission or storage.
24
Cryptography and Security
• **Authentication**: Confirms that the message originated from the stated sender.
• **Symmetry**: Both sender and receiver use the same secret key.
1. **Message Input**: The sender inputs the message M and a shared secret key K into
a MAC algorithm.
3. **Message Transmission**: The message and MAC are sent to the recipient over an
unsecured channel.
4. **MAC Verification**: The recipient computes the MAC using M and K. If it matches
the received MAC, the message is authenticated.
25
Cryptography and Security
26
Cryptography and Security
27
Cryptography and Security
2. If necessary, the final block is padded with zeroes to form a full 64-bit block.
3. Using DES encryption E and a secret key K, a Data Authentication Code (DAC) is
computed as:
DAC = EK (DN ),
where DN is the final block after CBC processing.
2. Two subkeys K1 and K2 are derived from the main key K using encryption of a zero
block and multiplication in GF (2n ).
Ci = EK (Mi ⊕ Ci−1 ),
where C0 = 0n .
28
Cryptography and Security
29
Cryptography and Security
30
Cryptography and Security
Ci = EK (Mi ⊕ Ci−1 ),
where C0 = 0n .
31
Cryptography and Security
• Securely exchange symmetric keys between parties using a shared symmetric key
called the Key Encryption Key (KEK).
• Protect cryptographic keys from unauthorized access in untrusted environments.
• Enable frequent rotation of lower-level keys while keeping higher-level keys secure.
(a) Input consists of: - A 64-bit constant Initialization Vector (IV). - A plaintext key
divided into 64-bit blocks.
(b) Ciphertext output is one block longer than the plaintext to accommodate the IV.
(c) During decryption (unwrapping), both the plaintext key and IV are recovered. If
the recovered IV differs from its original value (e.g., hexadecimal A6A6...A6A6),
an error or alteration is detected.
(a) **Seed Value**: A truly random initial value that determines the sequence.
(b) **Deterministic Algorithm**: Generates pseudorandom bits based on the seed.
The seed acts as a secret key in cryptographic applications.
—
PRNG Using Hash Functions The hash-based PRNG works as follows:
(a) Start with an initial seed value V0 . - Example: SHA-256-based PRNG from
ISO18031/NIST SP800-90. - Add counters repeatedly hashed.
32
Cryptography and Security
V1 = H(V0 + 1),
R = M SBn (V1 ),
—
PRNG Using MACs MAC-based PRNGs generate pseudorandom values using a secret
key and a deterministic algorithm. They are widely used in cryptographic protocols
like IEEE 802.11i, TLS, and NIST SP800-90.
S1 = M AC(K, S0 ),
R = M SBn (S1 ).
Si+1 = M AC(K, Si ).
33
Cryptography and Security
34
Chapter 2
(a) **Signing**: The sender signs the message using their private key or a hash of
the message.
(b) **Verification**: The recipient verifies the signature using the sender’s public key.
(c) **Authentication**: Ensures that only the sender could have produced the sig-
nature.
(d) **Integrity**: Confirms that the message has not been altered during transmis-
sion.
35
Cryptography and Security
36
Cryptography and Security
• Designed by NIST and NSA in the early 1990s; published as FIPS-186 in 1991
with revisions in 1993, 1996, and 2000.
• Uses SHA (Secure Hash Algorithm) as its hash function.
• DSS specifies DSA (Digital Signature Algorithm) as its core algorithm, which is
used exclusively for digital signatures (unlike RSA).
• FIPS 186-2 includes alternative RSA and elliptic curve signature variants for
flexibility in implementation.
(a) Creates a 320-bit signature with security ranging from 512 to 1024 bits.
(b) Smaller and faster than RSA due to its optimized structure.
(c) Security depends on the difficulty of computing discrete logarithms in finite fields.
37
Cryptography and Security
38
Cryptography and Security
39
Cryptography and Security
40
Cryptography and Security
C.
– The signature pair is:
(r, s) = (1, 2).
The sender sends the message M along with the signature (r, s) = (1, 2).
—
g u1 (mod p) :
“‘ − F irstcomputeg u1 mod p:
g u1 = 47 mod 23 = 16384 mod 23 = 9.
- Then compute y u2 mod p:
y u2 = 86 mod 23 = 262144 mod 23 = 12.
- Multiply g u1 and y u2 , then compute modulo p:
(g u1 y u2 ) mod p = (9 · 12) mod 23 = 108 mod 23 = 16.
- Finally, compute modulo q:
v = (16) mod 11 = 5.
E. Verify: If v = r, the signature is valid. In this case:
v = r = 1.
Therefore, the signature is verified successfully.
—
41
Cryptography and Security
42