Ns Unit 3
Ns Unit 3
Basics of Cryptography
o Symmetric Key: The same key is used for both encryption and
decryption.
o Asymmetric Key: A pair of keys (public and private) is used, where one
key encrypts the data, and the other decrypts it.
This is a concise answer that should help for your 2-mark question on Cryptography
Basics. Let me know if you'd like to expand on any part!
Introduction:
A cryptographic hash function takes an input (or message) and produces a fixed-
length string of characters, which typically represents the "digest" of the input. This
process ensures the integrity of data by generating a unique identifier for the input data.
• Verify Data Integrity: Ensure that data has not been altered in transmission.
1. Deterministic:
The same input will always produce the same output (hash). This ensures
consistency across different uses of the function.
3. Pre-image Resistance:
It should be computationally infeasible to reverse the process, meaning it should
not be possible to find the original input given only the hash value. This property
protects the confidentiality of data.
4. Collision Resistance:
It should be highly unlikely that two different inputs will produce the same hash
value. This ensures that the hash value is unique to the input.
5. Avalanche Effect:
A small change in the input (even a single bit) should result in a completely
different hash value. This ensures that the hash function is highly sensitive to
even the smallest changes in data.
6. Fast Computation:
The hash function should be efficient and fast to compute. This is important in
systems that require real-time processing.
3. Types of Cryptographic Hash Functions:
Several cryptographic hash functions are widely used in different applications. Some of
the most common ones include:
o Example: e99a18c428cb38d5f260853678922e03
o Example: 2ef7bde608ce5404e97d5f042f95f89f1c2325e2
o Widely used for security applications due to its strong collision resistance
and pre-image resistance.
o Example:
9c56a9d6e9a937a1ed063e68f1ab6c99d5995010d6b29c09337eb0ba58c
d0192
4. SHA-3:
1. Data Integrity:
o Cryptographic hash functions are widely used in file integrity checks.
When files are transmitted over a network, the sender and receiver can
both compute the hash of the file to ensure that no alteration has
occurred. If the hash values match, the file is deemed unaltered.
2. Digital Signatures:
3. Password Hashing:
6. File Deduplication:
o A collision occurs when two different inputs produce the same hash
value. This can be exploited to trick systems that rely on hash values for
verification, leading to security breaches.
To mitigate these risks, modern systems use stronger hash functions like SHA-256 and
SHA-3, which offer enhanced security against collision and pre-image attacks.
6. Conclusion:
Here’s a more detailed but still concise 13-mark answer for Symmetric and Public-
Key Encryption:
1. Symmetric Encryption:
Symmetric encryption uses the same key for both encryption and decryption of data.
This means that both the sender and the receiver must have access to the secret key. It
is efficient and fast, making it suitable for encrypting large volumes of data. However,
the major challenge is the secure distribution of the key.
Key Points:
• The key must remain secret and be shared securely between the sender and
receiver.
Examples:
• AES (Advanced Encryption Standard): One of the most widely used symmetric
encryption algorithms, offering high security.
Advantages:
Disadvantages:
Public-key encryption uses a pair of keys: one public key for encryption and a
corresponding private key for decryption. The public key is shared openly, while the
private key is kept secret by the recipient. This system solves the key distribution
problem but is slower and requires more computational resources.
Key Points:
• Involves two keys: a public key for encryption and a private key for decryption.
Examples:
• Solves the key distribution problem since the public key can be shared openly.
Disadvantages:
Same key for encryption and Public key for encryption, private key for
Key Usage
decryption decryption
4. Use in Practice:
This version should provide enough depth while being concise for your exam. Let me
know if you need further adjustments!
Here’s a detailed yet concise 13-mark answer on Public Key Cryptography Principles
& Algorithms:
Key Principles:
• Asymmetric Key Pair: Involves a pair of keys — public and private — with one
used for encryption and the other for decryption.
• Public Key Sharing: The public key can be freely shared with others, while the
private key must remain confidential.
• Key Distribution Problem Solved: The public key can be shared openly without
the risk of compromising security, while the private key remains confidential.
1. RSA (Rivest-Shamir-Adleman):
• RSA is one of the first and most widely used public-key cryptosystems.
• Key Generation: Involves choosing two large prime numbers, calculating their
product, and deriving the public and private keys.
2. ElGamal:
• Key Generation: Involves selecting a prime number and a generator, and then
choosing a private key. The public key is derived from these values.
• ECC is a public-key cryptosystem that uses elliptic curves over finite fields to
provide security.
• It offers higher security per bit compared to RSA, making it suitable for devices
with limited computational resources.
• Key Generation: Involves selecting an elliptic curve and generating private and
public keys based on the curve’s properties.
• Strength: ECC provides the same level of security as RSA but with much smaller
key sizes, making it more efficient.
• The Diffie-Hellman protocol allows two parties to securely share a secret key
over an insecure channel.
• Key Exchange Process: Both parties agree on a large prime number and a base.
Each party selects a private key and computes a public value. The secret key is
derived by combining each party's public value with their private key.
5. Security Considerations:
• Key Size: The security of public key cryptography is dependent on the key size.
Larger keys offer stronger security but require more computational resources.
• Algorithm Vulnerabilities: Older algorithms like RSA with smaller key sizes may
be vulnerable to attacks, emphasizing the importance of using up-to-date
cryptographic standards.
Conclusion:
This answer provides a balanced explanation of both principles and algorithms in public
key cryptography. Let me know if you need further details!
In symmetric encryption, block ciphers operate on fixed-size blocks of data (e.g., 128
bits). However, most messages exceed the block size, requiring the use of modes of
operation. These modes specify how multiple blocks of data are encrypted using the
same block cipher algorithm.
1. Electronic Codebook (ECB) Mode:
• Advantages:
• Disadvantages:
Example: If the same text block repeats, the ciphertext will be identical for each block,
which can reveal information about the structure of the plaintext.
• Operation: Each block of plaintext is XORed with the previous ciphertext block
before being encrypted.
• Initialization Vector (IV): A random IV is used for the first block to ensure
different ciphertexts for identical plaintexts.
• Advantages:
• Disadvantages:
o Slower than ECB because it requires the previous ciphertext block for
each encryption.
o Errors in one block affect all subsequent blocks due to the chaining
mechanism.
Example: A random IV ensures that even identical plaintexts yield different ciphertexts.
• Operation: A shift register is used to generate a keystream that is XORed with the
plaintext to produce ciphertext.
• Advantages:
o Errors do not propagate, meaning a single bit error in the ciphertext only
affects the corresponding bit in the plaintext.
o Can encrypt data of any size.
• Disadvantages:
• Operation: Similar to OFB, but the previous ciphertext block is used as the input
for the next block of plaintext.
• Advantages:
o Errors only affect the corresponding plaintext block and the following
block.
• Disadvantages:
• Advantages:
o The same counter can be reused without breaking security, as long as the
counter values are unique.
• Disadvantages:
• Operation: A variant of CBC designed for disk encryption, using two keys and a
tweak value to protect data integrity while providing confidentiality.
• Advantages:
• Disadvantages:
• Advantages:
• Disadvantages:
Comparison of Modes:
ECB Fast but vulnerable to pattern attacks Small data, quick operations
Conclusion:
Each mode of operation has its strengths and weaknesses, and their selection depends
on the specific requirements, such as speed, security, and error tolerance. For general-
purpose encryption, CBC and GCM are often preferred, while CTR and XTS are used in
performance-critical and disk encryption scenarios.
This answer should be just right for your exam. Let me know if you'd like any further
changes!
A secure hash function is a mathematical algorithm that takes an input (or message)
and produces a fixed-size string of bytes, typically a hash value or digest, that uniquely
represents the data. The key properties of a secure hash function make it useful for data
integrity, authentication, and digital signatures.
The primary purpose of a secure hash function is to ensure the integrity of the data by
generating a unique output (hash) for every distinct input. Even a small change in the
input should result in a completely different hash value.
• Deterministic: The same input always produces the same output hash.
• Fixed Output Length: Regardless of the input size, the output hash is of a fixed
length (e.g., SHA-256 produces a 256-bit hash).
o Output Length: SHA-3 also offers different lengths like SHA3-224, SHA3-
256, SHA3-384, and SHA3-512.
o Usage: SHA-3 is the latest member of the Secure Hash Algorithm family
and is used in cryptographic applications where higher security is
needed.
• Digital Signatures:
Hash functions are crucial in digital signature algorithms. The document is
hashed, and the resulting hash value is signed with a private key. The recipient
can verify the integrity of the message by comparing the hash of the received
message with the signed hash.
• Password Storage:
Hash functions are often used to store passwords securely. Instead of storing
plaintext passwords, systems store the hash of the password. When a user logs
in, the entered password is hashed and compared to the stored hash. This
ensures that even if the password database is compromised, the passwords
remain secure.
• Blockchain:
Cryptocurrencies like Bitcoin use hash functions to ensure the integrity of
transaction data. In a blockchain, each block contains the hash of the previous
block, creating a secure chain of blocks that is resistant to tampering.
• Collision Attacks:
Collision attacks occur when two distinct inputs generate the same hash output.
If a hash function is vulnerable to such attacks, it undermines its ability to
provide data integrity. For example, MD5 and SHA-1 have been found to be
vulnerable to collision attacks, making them insecure for cryptographic
applications.
• Birthday Paradox:
The birthday paradox shows that finding two different inputs that hash to the
same output (a collision) is easier than one might expect. This issue is a major
concern for hash functions with smaller output lengths, which is why longer
hashes like SHA-256 and SHA-512 are recommended for modern cryptography.
6. Conclusion:
Secure hash functions play a critical role in ensuring data integrity, authentication, and
confidentiality in modern cryptographic systems. While older hash functions like MD5
and SHA-1 are no longer considered secure due to vulnerabilities, newer hash functions
like SHA-2 and SHA-3 are widely regarded as secure and are integral to secure
communication, digital signatures, password security, and blockchain technology.
This answer is concise yet detailed, covering all essential aspects of secure hash
functions. Let me know if you'd like more details!
The core idea behind HMAC is to apply a cryptographic hash function to a message in
combination with a secret key. The result is an authentication code that can be used to
verify the integrity and origin of the message, ensuring it has not been tampered with
during transmission.
2. Working of HMAC:
HMAC(K,M)=H((K⊕ipad)∥M)⊕opad∥H((K⊕opad)∥H((K⊕ipad)∥M))HMAC(K, M) = H((K
\oplus \text{ipad}) \parallel M) \oplus \text{opad} \parallel H((K \oplus \text{opad})
\parallel H((K \oplus \text{ipad}) \parallel M))
Where:
• K = Key
• M = Message
HMAC provides several critical features that make it a robust message authentication
tool:
• Data Integrity: It ensures that the message has not been altered during
transmission. Any change to the message or the key will result in a different
HMAC value, indicating tampering.
• Message Authentication: Only parties possessing the secret key can generate
the correct HMAC, ensuring that the message is from a trusted source.
• Collision Resistance: HMAC inherits the collision resistance of the underlying
hash function, making it resistant to attacks where two different messages
produce the same authentication code.
• Efficiency: HMAC can be implemented using various hash functions (e.g., MD5,
SHA-1, SHA-256), allowing flexibility in performance and security requirements.
5. Applications of HMAC:
• OAuth and API Authentication: Many modern APIs use HMAC to authenticate
requests and ensure that the message comes from a legitimate source.
7. Security Considerations:
While HMAC is considered secure when used with a strong cryptographic hash function
(like SHA-256), certain factors should be considered:
• Key Management: The security of HMAC depends on the secrecy of the key. If
the key is compromised, an attacker can generate valid HMACs, defeating the
purpose of authentication.
• Hash Function Vulnerabilities: If the underlying hash function has weaknesses
(e.g., MD5 or SHA-1), it can undermine the security of HMAC. Therefore, it is
recommended to use secure hash functions like SHA-256 or SHA-3.
8. Conclusion:
HMAC is a widely used cryptographic technique for ensuring the integrity and
authenticity of messages. It combines a cryptographic hash function with a secret key
to produce a secure and efficient authentication code. HMAC is employed in numerous
protocols and systems, from securing web communications to blockchain technology,
making it an essential tool in modern cybersecurity.
This answer covers the main aspects of HMAC, its working mechanism, and
applications. Let me know if you'd like further adjustments!