Unit 2-2
Unit 2-2
Unit 2-2
Game theory
game theory, branch of applied mathematics that provides tools for analyzing situations in which
parties, called players, make decisions that are interdependent. This interdependence causes each
player to consider the other player's possible decisions, or strategies, in formulating strategy.
Cryptography
Confidentiality, Data Integrity, Authentication, Non-repudiation
• Symmetric key cryptography, Private-key cryptography
If the same key is used for both encryption and decryption, it is called symmetric key cryptography.
This means that both Alice and Bob have to agree on a key (k) called “shared secret” before they
exchange the ciphertext.
• asymmetric cryptography, Public-key cryptography
is a cryptographic system that uses pairs of keys. Each pair consists of a public key and a private
key. The generation of such key pairs depends on cryptographic algorithms which are based on
mathematical problems termed one-way functions. (RSA, Deffie Hellman key exchange etc)
Stream Ciphers vs. Block Cipher
Stream cipher and block cipher algorithms differ in the way the plaintext is
encoded and decoded.
Stream ciphers convert one symbol of plaintext into one symbol of ciphertext. This
means that the encryption is carried out one bit or byte of plaintext at a time.
Block cipher on the other hand is based on the idea of partitioning the plaintext
into relatively larger blocks of fixed-length groups of bits, and further encoding
each of the blocks separately using the same key.
Parameters Block Cipher Stream Cipher
Definition Block Cipher is the kind of encryption Stream cipher is the kind of
that converts plaintext by taking each encryption that converts plaintext by
block individually. taking one byte of the plaintext at a
time.
Principle It uses both diffusion and confusion Only the confusion principle is used
principles for the conversion (used by Stream Cipher for the conversion.
later in encryption).
Decryption In Block cipher, reverse encryption or In a stream cipher, XOR is used for
decryption is more difficult than encryption that can quickly converted
stream cipher since more bits are back to plain text.
combined to be encrypted in this
scenario.
Implementation Feistel Cipher is the most popular Vernam Cipher is the main
block cipher implementation. implementation of Stream Cipher.
Parameters Block Cipher Stream Cipher
Conversion of Bits Since a block cipher converts However, in stream cipher, only 8
blocks at once, it converts more bits can be transformed
significant bits than a stream simultaneously.
cipher, which can convert 64 bits
or more.
• In symmetric cryptography, a large number of block ciphers use a design scheme known
as a “Feistel cipher” or “Feistel network.” A Feistel cipher consists of multiple rounds to
process the plaintext with the key, and every round consists of a substitution step
followed by a permutation step.
• The more the number of rounds, the more secure it could be but encryption/decryption
gets slower. The DES is based on a Feistel cipher with 16 rounds.
Data Encryption Standard
• As mentioned before, the key is also 64 bits long. Since 8 bits are used as parity
bits only 56 bits are used for encryption and decryption
• After parity removal, the 56-bit key is divided into two blocks, each of 28 bits.
• They are then bit-wise left shifted in every round.
• We know that the DES uses 16 rounds of Feistel network.
• Similarly, in every round, the two 28-bit blocks from the previous round get left
shifted again by one bit and then clubbed and compressed to the 48-bit key.
• This key is then fed to the encryption function of the same round.
Data Encryption Standard
• First, the plaintext input is divided into 64 bit blocks. If the number of bits in the
message is not evenly divisible by 64, then the last block is padded to make it a 64-
bit block.
• Every 64-bit input data block goes through an initial permutation (IP) round. It
simply permutes, i.e., rearranges all the 64-bit inputs in a specific pattern by
transposing the input blocks.
• After the IP round, the 64-bit block gets divided into two 32-bit blocks, a left block
(L) and a right block (R).
Now the Feistel rounds start. The first round takes L and R as input and follows the
following steps:
• The right side 32-bit block (R) comes as is to the left side and the left side 32-bit
block (L) goes through an operation with the key k of that round and the right side
32-bit block (R):
• Permutation Substitution and XOR operation are performed
• The decryption also works a similar way in the reverse order. (explore decryption)
Advanced Encryption Standard
• Like DES, the AES algorithm is also a symmetric block cipher but is not based on a
Feistel network.
• The AES uses a substitution-permutation network in a more general sense. It not
only offers greater security, but also offers greater speed!
• AES allows a choice of three keys: 128 bits, 192 bits, and 256 bits (Depending on the
choice of the key, AES is named as AES-128, AES-192, and AES-256)
• In AES, the number of encryption rounds depend on the key length. For AES-128,
there are ten rounds; for AES-192, there are 12 rounds; and for AES-256, there are
14 rounds
Advanced Encryption Standard
Complete overview diagram:
Block Diagram of AES Algorithm
• The key must be shared by the sender and receiver before any communication.
• It requires a secured key establishment mechanism in place.
• The sender and receiver must trust each other, as they use the same symmetric
key.
• If a receiver is hacked by an attacker or the receiver deliberately shared the key
with someone else, the system gets compromised.
• It is advisable to keep changing the key for each communication session.
• Often a trusted third party is needed for effective key management, which itself is a
big issue.
CRYPTOGRAPHIC HASH FUNCTIONS
• a cryptographic hash function is a one-way function that converts input data of
arbitrary length and produces a fixed-length output. The output is usually termed
“hash value” or “message digest.”
• They are widely used in many cryptographic protocols, information security
applications such as Digital Signatures and message authentication codes (MACs)
For the hash functions to serve their design purpose and be usable, they should have
the following core properties:
• Input can be any string of any size, but the output is of fixed length, say, a 256-bit
output or a 512-bit output as examples.
• The hash value should be efficiently computable for any given message.
• It is deterministic, in the sense that the same input when provided to the same hash
function produces the same hash value every time.
• It is infeasible to invert and generate the message from its hash value
• Any small change in the message should greatly influence the output hash, just so no
one can correlate the new hash value with the old one after a small change
A Heads-up on Different Hash Functions
• One of the oldest hash functions or compression function is the MD4 hash
function. It belongs to the message digest (MD) family
• other variants of MD4 such as MD5, RIPEMD etc
• Another such hash function family is the Secure Hash Algorithm (SHA) family.
There are basically four algorithms in this family, such as SHA-0, SHA-1, SHA-2,
and SHA-3.
Applications and Use cases of Hash Functions
• Hash functions are used in verifying the integrity and authenticity of information
• Hash functions can also be used to index data in hash tables. This can speed up the
process of searching. Instead of the whole data, if we search based on the hashes,
then it should obviously be faster.
• They can be used to securely authenticate the users without storing the passwords
locally. Imagine a situation where you do not want to store passwords on the server,
obviously because if an adversary hacks on to the server, they cannot get the
password from their stored hashes. Every time a user tries to log in, hash of the
punched in password is calculated and matched against the stored hash. Secured,
isn’t it?
• Bitcoin uses hash functions as a proof of work (PoW) algorithm.(later chapter)
• The two most important applications are digital signatures and in MACs such as hash-
based message authentication codes (HMACs).
• The main difference between MAC
and HMAC is that MAC is a tag or a
piece of information that helps to
authenticate a message,
• while HMAC is a special type of MAC
with a cryptographic hash function
and a secret cryptographic key
Important MAC strategies
• MAC-then-Encrypt: This technique requires the computation of MAC on the cleartext, appending it
to the data, and then encrypting all of that together. This scheme does not provide integrity of the
ciphertext. At the receiving end, the message decryption has to happen first to be able to check the
integrity of the message.
• Encrypt-and-MAC: This technique requires the encryption and MAC computation of the message or
the cleartext, and then appending the MAC at the end of the encrypted message or ciphertext.
Notice that MAC is computed on the cleartext, so integrity of the cleartext can be assured but not of
the ciphertext, which leaves scope for some attacks.
• Encrypt-then-MAC: This technique requires that the cleartext needs to be encrypted first, and then
compute the MAC on the ciphertext. This MAC of the ciphertext is then appended to the ciphertext
itself. This scheme ensures integrity of the ciphertext, so it is possible to first check the integrity and
if valid then decrypt it.
Asymmetric key cryptography, also known
as “public key cryptography,”
• Asymmetric key cryptography, also known as “public key cryptography,” is a revolutionary concept
introduced by Diffie and Hellman.
• With this technique, they solved the problem of key distribution in a symmetric cryptography
system by introducing digital signatures. Note that asymmetric key cryptography does not
eliminate the need for symmetric key cryptography. They usually complement each other; the
advantages of one can compensate for the disadvantages of the other.
Public-Key Cryptography Principles
Public-Key Cryptography Principles
• Private keys are generated locally by each participant and therefore need never
be distributed.
Keys used by public key encryption are referred as Public key and Private key.
Symmetric Key Encryption Asymmetric Key Encryption
It only requires a single key for both encryption and decryption. It requires two keys, a public key and a private key, one to encrypt
and the other one to decrypt.
The size of cipher text is the same or smaller than the original plain The size of cipher text is the same or larger than the original plain
text text.
It is used when a large amount of data is required to transfer. It is used to transfer small amounts of data.
The length of key used is 128 or 256 bits The length of key used is 2048 or higher
In symmetric key encryption, resource utilization is low as compared In asymmetric key encryption, resource utilization is high.
to asymmetric key encryption.
It is efficient as it is used for handling large amount of data. It is comparatively less efficient as it can handle a small amount of
data.
Security is less as only one key is used for both encryption and It is more secure as two keys are used here- one for encryption and
decryption purpose. the other for decryption.
Examples: 3DES, AES, DES and RC4 Examples: Diffie-Hellman, ECC, DSA and RSA
Diffie-Hellman key exchange
It is the first published public-key cryptography. Diffie-Hellman is an key agreement protocol use for
Step 1: Requires two large numbers, one prime (P), and (G), g should be primitive root of P
• y = gb mod p
• ka = ya mod p
• kb = xb mod p
RSA
• RSA is the best known, and most widely used general public key encryption algorithm, published by Ron Rivest, Adi
Shamir & Len Adleman of MIT in 1978
• For signature verification and can be used for encryption and decryption of standard data
• When using RSA for encryption and decryption of general data, it reverses the key set usage. Unlike signature
verification, it uses the receiver’s public key to encrypt the data, and it uses the receiver’s private key in decrypting
the data. Thus, there is no need to exchange any keys in this scenario.
There are two broad components when it comes to RSA cryptography, they are:
• Key Generation: Generating the keys to be used for encrypting and decrypting the data to be exchanged.
• Encryption/Decryption Function: The steps that need to be run when scrambling and recovering the data.
• Steps in RSA Algorithm
Keeping the image above in mind, go ahead and see how the entire process works, starting from
creating the key pair, to encrypting and decrypting the information.
Key Generation : You need to generate public and private keys before running the functions to
generate your ciphertext and plaintext. They use certain variables and parameters, all of which are
explained below:
Encryption/Decryption Function: Once you generate the keys, you pass the parameters to the
functions that calculate your ciphertext and plaintext using the respective key.
• If the plaintext is m, ciphertext = me mod n.
RSA Algorithm
2. Calculate n=pxq
(n) ( p 1)( q 1)
3. Calculate
gcd( (n), e) 1; 1 e (n)
4. Choose value of e
1
d e mod (n)
5. Calculate d
• RSA is for both key management and authentication whereas DSA is only for authentication.
• unlike RSA, which is based on large-number factorization, DSA is based on discrete logarithms