CMSC456 - Cryptography
May 17, 2022

Published with the permission of Professor Jonathan Katz
Randomness
Pseudorandom Functions (PRFs)
all functions that map from to
How large is this set of functions? For any bit in the input string, we can apply an Identity function, a NOT function (), a ONE function (), or a ZERO function (). Therefore a function in this space is just a sequence of these smaller function components such that we accumulate of them, one for each bit. This unique ordering and arrangement of the sub functions is what comprises the function table.
| Input | Output |
|---|---|
| possibilities | |
| possibilities | |
| possibilities | |
| possibilities | |
| possibilities |
Because there are ways to configure an bit string, and each of these can be transformed into any other bit string, the size of the function space is as follows:
is a pseudorandom function if for uniform key is indistinguishable from a uniform function .
In this mode of thinking, an attacker can probe however much they like, but they should not be able to distinguish whether they are given a box with a uniformly chosen key or an actual function ; both of which are chosen uniformly and at random.
Pseudorandom Permutations (PRPs)
Let . is a PRP if it is a bijection, meaning that the inverse () exists.
Let be the set of permutations. What is ?
For something to be a ‘permutation’, we disallow duplicate values in out output function. Therefore the number of possibilities for each entry in the list of all possible bit strings actually dwindles over time, leading to possibilities rather than the much larger set of possibilities in the set of all functions.
Pseudorandom Generators (PRGs)
Access to a PRF immediately implies the access to a PRG , simply because the only requirement for a PRG is that it is indistinguishable from a PRF. In practice though, we don’t have usually use PRFs, only PRGs that are indistinguishable from them. The ontology of true PRGs is still a contested topic. If PRGs do actually exist, this would imply that . In practice we either simply assume that PRGs exist, or construct valid PRGs on the backs of weaker assumptions.
Probabilities
Events
An Event is a particular occurrence in some experiment. e.g., the event that random variable X takes values x.
: probability of event E
Conditional Probability
Probability that one event occurs, given that some other event occurred.
Bayes Theorem
Relatedly, Bayes Theorem shows us how to rearrange such probabilities:
Independence
Two random variables are independent iff
for all
In other words, the probability of having value is the same, regardless of ’s value
Law of Total Probability
Say that are a partition of all possibilities. Then for any :
Negligible Probabilities (s)
is negligible for every polynomial there is an such that for all it holds that . Typically, we denote arbitrary negligible functions as ‘’s.
Let and be negligible functions. It follows that
- Defining implies a third negligible function.
- Similarly, also implies a negligible function for any Polynomial
Group Theory and Related Math
Abelian Groups
An Abelian Group is a set and a binary operation defined on such that the following properties hold.
- Closure: Given a pair of elements ; is also in
- Identity: There is an element such that for all other , .
- Inverse: Every element has an inverse such that , meaning they produce the Identity.
- Associativity for all ;
- Communativity for all ;
Cyclic Groups
Let be a finite group of order and let be some element of . We can now define a cyclic group by using as a “generator” and checking if it is able to populate .
We write the generated group as . We expect that will simply produce since we are generating . Values may begin to loop before each power is represented. It’s only when each power produces a distinct value that produces a set of the expected order, which then tells us that is a generator and produces a cyclic group. Cyclic groups can have more than one group.
This operation can be performed both in groups under addition modulo and groups under multiplication modulo .
When an expression regarding a given group is written , we define as the generator and as the index within the group.
-
Example 1: Given , find :
-
Example: Given , find :
Relevant Theorems:
- Any group of prime order is cyclic, and every non-identity element is a generator
- If is prime, then is cyclic, noting that the order of said group is
Diffie-Hellman Problems
Based on our understanding of cyclic groups and associated notation, we describe two interesting problems. It can be demonstrated that a proof of one version’s ease or difficulty extends to the other’s.
Given a cyclic group and a generator , define:
Computational Diffie-Hellman Problem (CDH):
Given , find the result
Decisional Diffie-Hellman Problem (DDH):
Given the result , find originating values
When selecting a group to compute on, we generally search for groups that are hard to solve for in cryptographic contexts. For example, is easy for any and any selected generator . Therefore for our purposes we select prime-order groups. These have the added benefit that every element except for the identity is a generator!
Example:
Select a prime-order subgroup of where is prime
- E.g. let for prime
- So has order
-
Take the subgroup of powers ie
- is a group
- Can show that it has order
- Since is prime, must be cyclic
Group Order
The order of an Abelian Group is the number of elements contained within it. Note that this means each element tallied must conform to the properties of Abelian Groups.
- For groups where , their order is simply .
-
For groups where , it is less clear. For these, we denote their order as .
- If is prime, then we know all elements of are Invertible , therefore .
- If for distinct primes, then the invertible elements are the integers from to that are not multiples of or . Therefore .
- Note that assuming we have an efficient algorithm for Invertibility and access to all potential members of the group, we can simply traverse each element in the generated group and ask if it is Invertible, which is a required property of a true Abelian Group. Tallying the invertible elements reveals the true Order.
Group Isomorphisms
Let be groups with respect to the operations , respectively. A function is an isomorphism from to if:
- is a bijection / permutation and
- For all we have
If there exists an isomorphism that satisfies these conditions we state that the two groups are isomorphic and write .
In essence, all we are doing is renaming elements.
Chinese Remainder Theorem
The Chinese Remainder Theorem states that for some where are relatively prime, we can conclude that
Moreover, let be the function that maps elements to pairs where and defined by
By this definition, serves as an isomorphism in both the cases of and .
Greatest Common Divisor (GCD)
Given two numbers where , we determine the largest value that evenly divides both and and denote it . In the process of solving for , we can also find the factors of and that produce such that . These values will always exist.
Euclidean Algorithm:
If is , we know that we are done. Otherwise, we recurse, using in place of and in place of . When reaches , will by definition be the GCD.
let EuclideanGCD (a: int) (b: int) =
(* This is the base case *)
if a == 0 then
(b, 0, 1)
(* Otherwise *)
else
(* Use the remainder to compute recursively *)
let (d, X, Y) = EuclideanGCD (b % a) a in
(* Rewrite X and Y *)
(d, Y - floor(b / a) * X, X)
Modular Invertibility
An integer is Invertible modulo if there exists an integer such that . Therefore to determine if integer is Invertible, we simply need to find a value which satisfies this condition. The resulting value is written .
We can test for Invertibility succinctly by asserting that is valid , meaning that and share no common factors.
Division Mod N
If an expression is written , it is only valid so long as we know is Invertible . To evaluate, first solve then plug into .
Modular Exponentiation
If an expression is written for some base and an integer exponent , we must solve it in a clever way, as we expect to be a large value. By solving it recursively and applying a modulo at each step of the function, we can keep the values we are working with comparatively small.
By Hand Algorithm:
Note that if we can solve for the modulo , the exponent can be rewritten as , meaning we can rewrite our full expression as . If this produces an exponent that is easier to work with it can make the process way easier!
Naïve Algorithm:
let rec modExp_naive (a: int) (b: int) (n: int) =
(* This is the base case *)
if b == 0 then
(* a^0 = 1 in all cases *)
1
else
(* a * [a^(b-1) mod N] mod N *)
(a * (modExp_naive a (b-1) n)) mod n
This code is based on the following recurrence:
Intelligent Algorithm:
let rec modExp_smart (a: int) (b: int) (n: int) =
(* This is the base case *)
if b == 0 then
(* a^0 = 1 in all cases *)
1
else
(* If b is even *)
if b mod 2 == 0 then
(* (a^{b/2})^2 mod N *)
let sub = modExp_smart a (b / 2) n in
(sub * sub) mod n
else
(* a * (a^{(b-1)/2})^2 mod N *)
let sub = modExp_smart a ((b - 1) / 2) n in
(a * sub * sub) mod n
This code is based on the following recurrence:
Security Metrics
A Note on Evaluating Attackers
When running an attacker, the exact output for a given set of messages is not entirely relevant. Instead, we care about the probability that running the attacker produces a (successful attack) rather than a (failed attack). For an attacker to be viable, we must showcase that this probability is greater than (random) for selecting the bit of the encoded message , plus a negl. Formally, an attacker is successful iff .
Perfect Secrecy
For an encryption scheme to be ‘perfectly secret’, observing a given ciphertext should reveal no information at all about the plaintext. Formally, this means that the likelihood of guessing the correct plaintext is unchanged by observing the ciphertext.
One major limitation of this definition is that it requires the key
Malleability
Malleability refers to a scheme’s ability to be resistant to ciphertext modifications and the ability of adversaries to produce expected results in a decrypted plaintext. An example of this is the One-Time Pad, which is extremely malleable, allowing for attackers to make deterministic alterations to what will eventually become the plaintext, even if perfect secrecy is maintained.
Integrity
Integrity refers to a scheme’s ability to verify that a given ciphertext was actually sent by who we believe it was. Violating this principle only requires that an adversary gets a recipient to accept a message that was never actually sent by an honest party.
EAV-Security
Highly related to Perfect Secrecy, EAV-Security specifies a standard of security for protecting against Eavesdroppers who are able to listen in on the communication channel and observe transmitted ciphertexts. To showcase that a scheme is not EAV-Secure, one needs only demonstrate that it is not perfectly secret across an arbitrary quantity of messages. For example, a single use One-Time Pad is perfectly EAV-Secure, but this security is broken if the key is ever reused.
CPA-Security
By definition stronger in definition than EAV-Security, CPA-Security allows for the attacker to choose their own plaintexts, sending these plaintexts through the encryption algorithm and witnessing the ciphertexts they produce. We evaluate the security of the scheme by asking if this extra information gives the attacker an upper hand in decrypting the messages.
Attacker:
𝑘 ← Gen ( 1 𝑛 ) interacts with an encryption oracle𝐴 ( 1 𝑛 ) , outputtingEnc 𝑘 ( ) where𝑚 0 , 𝑚 1 .| 𝑚 0 | = | 𝑚 1 | . give𝑏 ← { 0 , 1 } , 𝑐 ← Enc 𝑘 ( 𝑚 𝑏 ) to𝑐 𝐴 can continue to interact with𝐴 Enc 𝑘 ( ) outputs𝐴 ;𝑏 ′ succeeds if𝐴 and experiment evaluates to𝑏 = 𝑏 ′ in this case1
CCA-Security
By definition stronger in definition than both EAV-Security and CPA-Security, CCA-Security allows the attack to choose their own plaintexts, witness the resulting ciphertexts, and decrypt ciphertexts of their chosing, witnessing the resulting decodings. The one exception occurs with the challenge ciphertext being presented to the attacker
Attacker:
𝑘 ← Gen ( 1 𝑛 ) interacts with an encryption oracle𝐴 ( 1 𝑛 ) and decryption oracleEnc 𝑘 ( ) , outputtingDec 𝑘 ( ) where𝑚 0 , 𝑚 1 .| 𝑚 0 | = | 𝑚 1 | . give𝑏 ← { 0 , 1 } , 𝑐 ← Enc 𝑘 ( 𝑚 𝑏 ) to𝑐 .𝐴 can continue to interact with𝐴 andEnc 𝑘 ( ) Dec 𝑘 ( ) outputs𝐴 ;𝑏 ′ succeeds if𝐴 and experiment evaluates to𝑏 = 𝑏 ′ in this case1
Unforgeability
We define unforgeability only in a formal context, one that is decided by the evaluation of this experiment. Essentially, we are checking if the attacker
𝑘 ← Gen ( 1 𝑛 ) interacts with an encryption oracle𝐴 ( 1 𝑛 ) , eventually outputting ciphertextEnc 𝑘 ( ) .𝑐 and let𝑚 ≔ Dec ( 𝑐 ) denote the set of all queries that𝑄 submitted to the encryption oracle.𝐴 - iff
and𝑚 ≠ ⊥ output𝑚 ∉ 𝑄 , otherwise output1 .0
A private-key encryption scheme
Authenticated Encryption
A scheme is said to possess Authenticated Encryption (AE) if it posessses both CCA-Security and Unforgeability.
Probabilistic Polynomial Time (PPT)
A scheme is secure in the context of PPT if an attacker succeeds in breaking the scheme with at most negligible probability. By manipulating the security parameter
function 𝑓 : ℕ → ℝ ⟺ ∃ 𝑐 where 𝑓 ( 𝑛 ) < 𝑛 𝑐 for all 𝑛 Runs in polynomial timealgorithm 𝐴 : there exists a polynomial⟺ such that for all input𝑝 the computation of𝑥 ∈ { 0 , 1 } ∗ terminates within at most𝐴 ( 𝑥 ) steps.𝑝 ( | 𝑥 | )
Cryptographic Utilities
Stream Ciphers
Linear Feedback Shift Registers (LFSRs)
Historically used for random number generation, LFSRs are comprised of an array of
Note that the superscript
To denote the outputs of an LFSR as
One way to conceptualize this is to realize the first
LFSRs can be used to construct stream ciphers of the form
Note that a degree-
An LFSR is said to have maximum length if it cycles through all
Key-recovery attacks:
The output of a maximum-length LFSR has good properties, and typically far too many possible states to traverse. Despite this, LFSRs are not secure stream ciphers. If we assume the feedback coefficients are known to the attacker, then the first
Even if the feedback coefficients are hidden to an attacker, the initial state can still be deduced in only
Feedback Shift Registers (FSRs)
FSRs are the product of introducing Nonlinearity to LFSRs. This makes the systems less predictable, and more secure. There are multiple approaches for introducing this nonlinearity:
-
Nonlinear feedback: The most apparent way to implement nonlinearity is to make the feedback loop nonlinear. Everything is identical to an LFSR, except that the new value of the leftmost register
is now determined nonlinearly.𝑠 𝑛 − 1 Given some arbitrary nonlinear function
that operates on the collection of registers, the FSR is able to generate a new state for𝑔 . For security, we posit that for𝑠 𝑛 − 1 to be “balanced”,𝑔 where the probability is computed over uniformly selected states. In practice, we often see the use of ANDs and ORs.Pr [ 𝑔 ( 𝑠 𝑛 − 1 , … , 𝑠 0 ) = 1 ] ≈ 1 / 2 Formally:
{ 𝑠 𝑖 ( 𝑡 + 1 ) ≔ 𝑠 𝑖 + 1 ( 𝑡 ) 𝑖 = 0 , … , 𝑛 − 2 𝑠 𝑛 − 1 ( 𝑡 + 1 ) ≔ 𝑔 ( 𝑠 𝑛 − 1 ( 𝑡 ) , … , 𝑠 0 ( 𝑡 ) ) - Nonlinear output: Rather than updating our new state nonlinearly, we can simply determine our output nonlinearly. Here, we denote the function that computes the output bit to be
and refer to it as the filter. As before, we expect it to be balanced to avoid obvious bias.𝑔 - Combination generators: By using more than one LFSR, we can generate the final output stream by combining the outputs of the individual LFSRs in some nonlinear way. The individual LFSRs do not have to be of the same degree, and their having this property is actually advantageous in achieving maximization. Care must be taken to ensure the combined output is balanced, as before.
Trivium is the best example of an FSR used in practice as a stream cipher, and is an implementation of a combination generator. Within, we can see three couples, nonlinear FSRs that have decrees 93, 84, and 111 respectively. The state is the concatenation of the states of these sub-FSRs. In the

Block Ciphers
Block Ciphers Formal Definition
When a block scheme is in CTR Mode (Counter), XORing takes place after encryption via the PRF. The outputs of each block are independent from one another. Thus, modifiying the

By contrast when in CBC Mode (Cipher Block Chaining), XORing takes place prior to encryption via the PRF. The outputs of each block are XORed with the input of the subsequent block, meaning that modification to

Both of these are CPA-Secure.
Neither of these are CCA-Secure because they are malleable. By changing bits in the ciphertext, certain blocks of the decrypted message will become random through the inverse function
Cipher Block Chaining Message Authentication Code (CBC-MAC)
A message,
This methodology does not require an IV, unlike CBC-Mode encryption. It is deterministic for this reason. CBC-MACs do not need to be probabilistic to be secure! Verification can simply be done by re-computing the result.
Note that we explicitly avoid using an

The methodology of
To ensure the utility of CBC-MAC for arbitrary length messages, we must also encode the length of the message (in blocks) as the first block of our CBC. This is done at the start of the blocks rather than at the end to ensure unforgeability.

Confusion-Diffusion Paradigm
The CDP is, simply, a paradigm for constructing concise and random-looking permutations. The goal is to construct a PRP
Through the use of numerous PRPs
On its own, this definition is not enough. Assuming the input on
Therefore we require an additional step to perform diffusion. In this diffusion step, the bits of the output are permuted using a mixing permutation. This spreads local change (e.g. change in a single byte) throughout the entirety of the output.
In practice, it is the application of the confusion and diffusion steps in sequence that is referred to as a ‘round’. As the rounds are applied, the output of one becomes the input to the next. Through the application of sufficient rounds,
Substitution-Permutation Networks (SPNs)
SPNs are used to directly implement the Confusion-Diffusion Paradigm.
For each round:
- Key mixing (Confusion): Set
, where𝑥 ≔ 𝑥 ⊕ 𝑘 is the current round’s sub-key.𝑘 - Substitution (
/𝑓 𝑖 -box): Set𝑆 where𝑥 ≔ 𝑆 1 ( 𝑥 1 ) ‖ … ‖ 𝑆 𝑛 ( 𝑥 𝑛 ) is the𝑥 𝑖 th byte of𝑖 .𝑥 - Permutation (Diffusion): Permute the bits of
to obtain the output of the round.𝑥
Finally, perform another Key mixing step such that the final Substitution and Permutation processes are not wasted.
There are certain requirements placed on the SPN that are required to achieve the desired effect:
- Changing a single input bit for any given
-box changes at least two of the resulting output bits.𝑆 - Mixing permutations are designed such that the bits output by any given
-box affect the input of multiple𝑆 -boxes in the next round.𝑆
The presence of these requirements causes an Avalanche Effect: a single permuted bit in the input can be expected to alter half of the output bits.
An example of a properly constructed 3-round SPN.

Feistel Networks
Unlike the S-Boxes used in SPNs, the sub-functions of Feistel Networks do not need to be invertible. By consequence, even Hash functions can be used in each of the blocks. The goal here, then, is to compose an invertible function from non-invertible components.
For a balanced Feistel Network with
-
via𝑓 𝑖 : { 0 , 1 } ℓ / 2 → { 0 , 1 } ℓ / 2 𝑓 𝑖 ( 𝑅 ) ≝ 𝑓 𝑖 ̂ ( 𝑘 𝑖 , 𝑅 ) - Note that the functions
are public and known- it is only the keys used for them that are kept a secret.𝑓 𝑖 ̂
- Note that the functions
-
At each stage of the network, we solve each half of the network
and𝐿 𝑖 .𝑅 𝑖 𝐿 𝑖 ≔ 𝑅 𝑖 − 1 𝑅 𝑖 ≔ 𝐿 𝑖 − 1 ⊕ 𝑓 𝑖 ( 𝑅 𝑖 − 1 )
- To invert / decrypt, we simply run the output of the network back through- but reverse the order of each sub-function
.𝑓 𝑖
This is an example of a 3-round Feistel Network

Attacking Feistel Networks:
-
In the one round case:
where𝐹 𝑘 ( 𝐿 0 , 𝑅 0 ) = ( 𝑅 0 , 𝑓 1 ( 𝑅 0 ) ⊕ 𝐿 0 ) is in some way dependent on𝑓 1 .𝑘 - The left half of the output is always the right half of the input, and is being XORed with the left half of the input. Simply using the all zero string can allow the attacker to make inferences about
.𝑓 1
-
In the two-round case:
where𝐹 𝑘 ( 𝐿 0 , 𝑅 0 ) = ( 𝑓 1 ( 𝑅 0 ) ⊕ 𝐿 0 , 𝑅 0 ⊕ 𝑓 2 ( 𝑓 1 ( 𝑅 0 ) ⊕ 𝐿 0 ) ) are in some way dependent on𝑓 1 , 𝑓 2 .𝑘 - There are still correlations between the outputs of
on related inputs that can be used to distinguish𝐹 𝑘 from a random permutation. In this way, even a two round Feistel Network does not uphold Perfect Secrecy.𝐹 𝑘
- With more than two rounds and certain conditions being satisfied, Feistel Networks become indistinguishable from PRPs.
Data Encryption Standard (DES)
The DES block cipher is a 16-round Feistel Network with a block length of 64 bits and a key length of 56 bits. The same round function
By the DES definition, each of the sub-keys
The DES round function
- Each
-box is a 4-to-1 function (4 inputs are mapped to each possible output)𝑆 - Each row in the table contains each of the 16 possible 4-bit strings exactly once
- Changing one bit of any input to an
-box always changes at least two bits of the output𝑆
This produces the same avalanche effect as described in SPNs.
Attacks on DES can only practically carried out if the number of rounds is greatly reduced from 16 to a number ≤ 3. It’s in these cases we can showcase the avalanche effect is not complete, allowing us to make inferences about the scheme and plaintext we should not be able to.
Davies-Meyer Construction
The purpose of this construction is to construct a collision-resistant compression function from any given block cipher that satisfies strong security properties.
The Davies-Meyer Construction defines the compression function
Proving collision resistance based on the assumption that
Hash Functions
Hash Functions Formal Definition
Put simply, hash functions transform arbitrary length inputs (
Collision Resistance:
Formally, we look at keyed hash functions.
Attacker:
𝑠 ← Gen ( 1 𝑛 ) - The adversary
is given key𝐴 and outputs two messages𝑠 𝑥 , 𝑥 ′ - Both hash messages are run through the hash function producing hashes in the form
{ 0 , 1 } ℓ ′ 𝑛 - iff
the attacker𝐻 𝑠 ( 𝑥 ) = 𝐻 𝑠 ( 𝑥 ′ ) outputs𝐴 , otherwise outputs1 .0
To insist that a hash function is collision resistant is to show that the probability of this attacker outputting
Weaker Notions: Strict Collision Resistance is not always necessary.
Second-preimage resistance: A hash function is collision-resistant if it is infeasible for any PPT adversary to find a collision in
Preimage resistance: For an attacker given
Hash-and-MAC
By applying a hash function
ChooseGen ′ : uniformly from𝑘 ;{ 0 , 1 } 𝑛 𝑠 ← Gen 𝐻 ( 1 𝑛 ) GivenMac ′ : , for some message𝑘 , 𝑠 , output𝑚 ∈ { 0 , 1 } ∗ 𝑡 ← Mac 𝑘 ( 𝐻 𝑠 ( 𝑚 ) ) GivenVrfy ′ : , for some message𝑘 , 𝑠 , and some tag𝑚 ∈ { 0 , 1 } ∗ , output𝑡 iff1 .Vrfy 𝑘 ( 𝐻 𝑠 ( 𝑚 ) , 𝑡 ) = 1
HMAC
In practice, the Hash-and-MAC methodology is rarely used because it requires instantiating two cryptographic primitives, the Hash function and a block cipher. Utilizing the Merkle-Damgård Transform to hash our arbitrarily sized message, we can perform our MAC and Hash in synchrony.

ChooseGen ( 1 𝑛 ) : uniformly from𝑘 ;{ 0 , 1 } 𝑛 ′ 𝑠 ← Gen 𝐻 ( 1 𝑛 ) -
GivenMac ′ : , for some message𝑘 , 𝑠 , output𝑚 ∈ { 0 , 1 } ∗ 𝑡 ≔ 𝐻 𝑠 ( ( 𝑘 ⊕ opad ) ‖ 𝐻 𝑠 ( ( 𝑘 ⊕ ipad ) ‖ 𝑚 ) ) -
GivenVrfy ′ : , for some message𝑘 , 𝑠 , and some tag𝑚 ∈ { 0 , 1 } ∗ , output𝑡 iff1 .𝑡 = 𝐻 𝑠 ( ( 𝑘 ⊕ opad ) ‖ 𝐻 𝑠 ( ( 𝑘 ⊕ ipad ) ‖ 𝑚 ) )
Merkle-Damgård Transform
The purpose of this scheme is to transform fixed length hash functions into arbitrary length hash functions.
Let
remains unchangedGen : -
receiving input of key𝐻 : and string𝑠 of length𝑥 ∈ { 0 , 1 } ∗ , do:𝐿 < 2 ℓ - Append a
to1 , followed by enough zeros that the length of the resulting string is𝑥 less than a multiple ofℓ . Then append𝑛 ′ , encoded as an𝐿 -bit string. Parse the resulting string as the sequence ofℓ -bit blocks𝑛 ′ .𝑥 1 , … , 𝑥 𝐵 - Set
.𝑧 0 ≔ 𝐼 𝑉 - For
, compute𝑖 = 1 , … , 𝐵 .𝑧 𝑖 ≔ ℎ 𝑠 ( 𝑧 𝑖 − 1 ‖ 𝑥 𝑖 ) - Output
.𝑧 𝐵
- Append a
If

Likelihood of Collision
Given a positive integer
PKCS #7 Encoding
The purpose of this encoding is to ensure that messages encoded using a block cipher encryption scheme are less succeptible to tampering or forgery, boosting the integrity and decreasing the malleability of the scheme.
Sender:
- Assume message is an integral # of bytes
- Let
be the block length in bytes of the cipher𝐿 -
Let
be the number of bytes that need to be appended to the message to get length as multiple of L𝑏 > 0 ; note1 ≤ 𝑏 ≤ 𝐿 𝑏 ≠ 0
-
Append
(encoded in 1 byte),𝑏 times𝑏 - I.e. if 3 bytes of padding are needed, append
0x030303 - I.e. if 4 bytes of padding are needed, append
0x04040404
- I.e. if 3 bytes of padding are needed, append
Receiver:
- Extract the final number from the the Encoded Data. This number will be interpreted as
. This is why𝑏 must always be𝑏 , even if our message already evenly fits into the block length. The receiver must be able to unambiguously read the amount of padding. If it expects to read the padding amount and we instead see the unpadded ciphertext, things would go wrong.≥ 1 - Use CBC-Mode decryption to obtain the encoded data
-
Say the final byte of encoded data has value
𝑏 - If
or𝑏 = 0 return ‘error’𝑏 > 𝐿 - If final
bytes of the encoded data are not all equal to𝑏 , return ‘error’𝑏 - Otherwise, strop off final
bytes of the encoded data, and output what remains as the message𝑏
- If
Padding Oracles
By understanding the definition of PKCS #7 Encoding, we can systematically approach the violation of a scheme through what at first appears to be a trivial leakage of information. So long as the ‘Padding Oracle’ tells us whether a given ciphertext
Formal Assumptions
The Factoring Assumption
Let
Here we define an experiment in which an attacker
( 𝑁 , 𝑝 , 𝑞 ) ← GenModulus ( 1 𝑛 ) is given𝒜︀ and outputs𝑁 𝑝 ′ , 𝑞 ′ > 1 - The output of the experiment is defined to be
, returning1 ⟺ 𝑝 ′ ∗ 𝑞 ′ = 𝑁 otherwise.0
Note that if the experiment evaluates to
The Factoring Assumption states that for all PPTs
RSA Assumption
Given a modulus
Informally, our task is to compute
Let
Here we define an experiment in which the attacker
( 𝑁 , 𝑒 , 𝑑 ) ← GenRSA ( 1 𝑛 ) - Choose a uniform
𝑦 ∈ ℤ 𝑁 ∗ is given𝒜︀ and outputs( 𝑁 , 𝑒 , 𝑦 ) 𝑥 ∈ ℤ 𝑛 ∗ - The output of the experiment is defined to be
, returning1 ⟺ 𝑥 𝑒 = [ 𝑦 mod 𝑁 ] otherwise.0
The RSA Assumption states that for all PPTs
Discrete-Logarithm / Diffie-Hellman Assumptions
Let
Here we define an experiment in which the attacker
( 𝔾 , 𝑞 , 𝑔 ) ← 𝒢︀ ( 1 𝑛 ) - Choose a uniform
ℎ ∈ 𝔾 is given𝒜︀ and outputs some( 𝔾 , 𝑞 , 𝑔 , ℎ ) 𝑥 ∈ ℤ 𝑞 - The output of the experiment is defined to be
, returning1 ⟺ 𝑔 𝑥 = ℎ otherwise.0
The DLog Assumption states that for all PPTs
Encryption Schemes
Private-Key Encryption
Formal Definition for Private Key Encryption
A private-key encryption scheme contains three probabilistic functions,
we assume that this key satisfies𝑘 ← Gen ( 1 𝑛 ) .| 𝑘 | ≥ 𝑛 where𝑐 ← Enc 𝑘 ( 𝑚 ) 𝑚 ∈ { 0 , 1 } ∗ where𝑚 ← Dec 𝑘 ( 𝑐 ) or an error, denoted𝑚 ∈ { 0 , 1 } ∗ ⊥
We require, simply, that
If, for some reason, we specify the Message Space (
We also make a few assumptions moving forwards:
is actually deterministicDec - Calls to
are probabilistically independent from one anotherEnc - We assume all encryption schemes are stateless, like the one above, unless specified otherwise
One-Time Pad
Only to be used with a given key one time, the One-Time Pad specifies a means to achieve perfect secrecy in communication at the cost of the requirement that
- Let
ℳ︀ = { 0 , 1 } 𝑛 : choose a uniform keyGen 𝑘 ∈ { 0 , 1 } 𝑛 Enc 𝑘 ( 𝑚 ) = 𝑘 ⊕ 𝑚 Dec 𝑘 ( 𝑐 ) = 𝑘 ⊕ 𝑐
Public-Key Encryption
Plain Rivest-Shamir-Adleman (RSA) Scheme
Before fortifying it, we first consider an insecure “plain” RSA encryption scheme.
Here, we define
( 𝑁 , 𝑝 , 𝑞 ) ← GenModulus ( 1 𝑛 ) 𝜑 ( 𝑛 ) ≔ ( 𝑝 − 1 ) ∗ ( 𝑞 − 1 ) - Choose some
such that𝑒 > 1 GCD ( 𝑒 , 𝜑 ( 𝑁 ) ) = 1 - Compute
𝑑 ≔ [ 𝑒 − 1 mod 𝜑 ( 𝑁 ) ] - Return
( 𝑁 , 𝑒 , 𝑑 )
Now, with
on inputGen : run1 𝑛 .( 𝑁 , 𝑒 , 𝑑 ) ← GenRSA ( 1 𝑛 ) is the public key.⟨ 𝑁 , 𝑒 ⟩ is the private key.⟨ 𝑁 , 𝑑 ⟩ on input a public keyEnc : and a message𝑝 𝑘 = ⟨ 𝑁 , 𝑒 ⟩ , compute the ciphertext𝑚 ∈ ℤ 𝑁 ∗ .𝑐 ≔ [ 𝑚 𝑒 mod 𝑁 ] on input a private keyDec : and a ciphertext𝑠 𝑘 = ⟨ 𝑁 , 𝑑 ⟩ , compute the message𝑐 ∈ ℤ 𝑁 ∗ .𝑚 ≔ [ 𝑐 𝑑 mod 𝑁 ]
If the message is not chosen uniformly from
Diffie-Hellman key-exchange protocol
The Diffie-Hellman key-exchange protocol is radical in that it allows for the exchange of secret keys over an insecure channel, such as the public internet.
We assume we are given
The protocol is defined formally as follows:
- Alice performs
( 𝔾 , 𝑞 , 𝑔 ) ← 𝒢︀ ( 1 𝑛 ) - Alice chooses a uniform
and computes𝑥 ∈ ℤ 𝑞 .ℎ 𝐴 ≔ 𝑔 𝑥 - Alice sends
to Bob.( 𝔾 , 𝑞 , 𝑔 , ℎ 𝐴 ) - Receiving
, Bob chooses a uniform( 𝔾 , 𝑞 , 𝑔 , ℎ 𝐴 ) and computes𝑦 ∈ ℤ 𝑞 . Bob sendsℎ 𝐵 ≔ 𝑔 𝑦 to Alice and outputs the keyℎ 𝐵 .𝑘 𝐵 ≔ ℎ 𝐴 𝑦 - Alice receives
and outputs the keyℎ 𝐵 .𝑘 𝐴 ≔ ℎ 𝐵 𝑥
We can see the protocol is correct and that both parties arrive at the same value via the following relation:
Attacking the protocol:
Here, we define an experiment in which keys are exchanged. An attacker
- Both parties holding
execute the protocol1 𝑛 . This produces a transcriptΠ containing all messages sent by both parties as well as a keytrans output by each of the parties𝑘 - A uniform bit
is chosen. If𝑏 ∈ { 0 , 1 } , set𝑏 = 0 , otherwise choose a uniform𝑘 ̂ ≔ 𝑘 .𝑘 ̂ ∈ { 0 , 1 } 𝑛 is given𝒜︀ andtrans and outputs a bit𝑘 ̂ .𝑏 ′ - The output of the experiment is defined to be
, returning1 ⟺ 𝑏 ′ = 𝑏 otherwise.0
The exchange protocol is considered secure in the presence of an eavesdropper if for all PPTs
El Gamal Encryption
Taher El Gamal realized that the Diffie-Hellman key-exchange protocol could be repurposed as a full public key encryption scheme, rather than for simply choosing a key
This scheme is used in a symmetric key exchange.
On inputGen : run1 𝑛 to obtain𝒢︀ ( 1 𝑛 ) . Then choose a uniform( 𝔾 , 𝑞 , 𝑔 ) and compute𝑥 ∈ ℤ 𝑞 . The public key isℎ ≔ 𝑔 𝑥 and the private key is⟨ 𝔾 , 𝑞 , 𝑔 , ℎ ⟩ . The message space is⟨ 𝔾 , 𝑞 , 𝑔 , 𝑥 ⟩ .𝔾 Given a public keyEnc : and a message𝑝 𝑘 = ⟨ 𝔾 , 𝑞 , 𝑔 , ℎ ⟩ , choose a uniform𝑚 ∈ 𝔾 and output the ciphertext𝑦 ∈ ℤ 𝑞 .⟨ 𝑔 𝑦 , ℎ 𝑦 ∗ 𝑚 ⟩ Given a private keyDec : and a ciphertext𝑠 𝑘 = ⟨ 𝔾 , 𝑞 , 𝑔 , 𝑥 ⟩ , output⟨ 𝑐 1 , 𝑐 2 ⟩ .𝑚 ̂ ≔ 𝑐 2 / 𝑐 1 𝑥
To showcase that this is a successful scheme, let