vera.lgbt

CMSC456 - Cryptography

CMSC456 - Cryptography

Published with the permission of Professor Jonathan Katz

Randomness

Pseudorandom Functions (PRFs)

Func𝑛= all functions that map from {0,1}𝑛 to {0,1}𝑛

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 (1), or a ZERO function (0). 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
0…000 2𝑛 possibilities
0…001 2𝑛 possibilities
0…010 2𝑛 possibilities
0…100 2𝑛 possibilities
… …
1…111 2𝑛 possibilities

Because there are 2𝑛 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:

| Func 𝑛 | = ( 2 𝑛 ) 2 𝑛 = 2 𝑛 2 𝑛

𝐹 is a pseudorandom function if 𝐹𝑘 for uniform key 𝑘∈{0,1}𝑛 is indistinguishable from a uniform function 𝑓∈Func𝑛.

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 𝑓∈Func𝑛. 𝑓 is a PRP if it is a bijection, meaning that the inverse (𝑓−1) exists.

Let Perm𝑛⊂Func𝑛 be the set of permutations. What is |Perm𝑛|?

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 2𝑛! 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.

Pr[𝐸]: probability of event E

Conditional Probability

Probability that one event 𝐴 occurs, given that some other event 𝐵 occurred.

Pr [ 𝐴 | 𝐵 ] = Pr [ 𝐴 ∧ 𝐵 ] Pr [ 𝐵 ]

Bayes Theorem

Relatedly, Bayes Theorem shows us how to rearrange such probabilities:

Pr [ 𝐴 | 𝐵 ] = Pr [ 𝐵 | 𝐴 ] ∗ Pr [ 𝐴 ] Pr [ 𝐵 ]

Independence

Two random variables 𝑋,𝑌 are independent iff

for all 𝑥,𝑦:Pr[𝑋=𝑥|𝑌=𝑦]=Pr[𝑋=𝑥]

In other words, the probability of 𝑋 having value 𝑥 is the same, regardless of 𝑌’s value

Law of Total Probability

Say that 𝐸1,…𝐸𝑛 are a partition of all possibilities. Then for any 𝐴:

Pr [ 𝐴 ] = ∑ 𝑖 Pr [ 𝐴 ∧ 𝐸 𝑖 ] = ∑ 𝑖 Pr [ 𝐴 | 𝐸 𝑖 ] ∗ Pr [ 𝐸 𝑖 ]

Negligible Probabilities (negls)

function𝑓:ℕ→ℝ is negligible ⟺ for every polynomial 𝑝 there is an 𝑁 such that for all 𝑛<𝑁 it holds that 𝑓(𝑛)<1𝑝(𝑛). Typically, we denote arbitrary negligible functions as ‘negl’s.

Let negl1 and negl2 be negligible functions. It follows that

  • Defining negl3←negl1+negl2 implies a third negligible function.
  • Similarly, negl4←𝑝(𝑛)∗negl1 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 ⟨𝑔⟩={𝑔0,𝑔1,𝑔2,…,𝑔𝑚−1}. We expect that 𝑔𝑚 will simply produce 𝑔0 since we are generating mod𝑚. 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 log𝑔𝑖, we define 𝑔 as the generator and 𝑖 as the index within the group.

  • Example 1: Given ℤ12, find log55:

    • ⟨5⟩={0,5,10,3,8,1,6,11,4,9,2,7}∴log55=1
  • Example: Given ℤ11∗, find log89:

    • ⟨8⟩={1,8,9,6,4,10,3,2,5,7}∴log89=2

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 𝑝−1

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:

DH 𝑔 ( ℎ 1 , ℎ 2 ) = DH 𝑔 ( 𝑔 𝑥 , 𝑔 𝑦 ) = 𝑔 𝑥 𝑦 = ℎ 1 𝑦 = ℎ 2 𝑥

Computational Diffie-Hellman Problem (CDH):

Given DH𝑔(ℎ1,ℎ2), find the result

Decisional Diffie-Hellman Problem (DDH):

Given the result DH𝑔(𝑔𝑥,𝑔𝑦), 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 𝑝=𝑘𝑞+1 for 𝑝,𝑞 prime
  • So ℤ𝑝∗ has order 𝑝−1=𝑘𝑞
  • Take the subgroup of 𝑘th powers ie

    • 𝐺={[𝑥𝑘mod𝑝]|𝑥∈ℤ𝑝∗}⊂ℤ𝑝∗
    • 𝐺 is a group
    • Can show that it has order (𝑝−1)/𝑘=𝑞
    • 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 ∘=+mod𝑁, their order is simply |ℤ𝑁|=𝑁.
  • For groups where ∘=∗mod𝑁, it is less clear. For these, we denote their order as |ℤ𝑁∗|=𝜑(𝑁).

    • If 𝑁 is prime, then we know all elements of ℤ𝑁∗ are Invertible mod𝑁, therefore 𝜑(𝑁)=𝑁−1.
    • If 𝑁=𝑝𝑞 for 𝑝,𝑞 distinct primes, then the invertible elements are the integers from 1 to 𝑁−1 that are not multiples of 𝑝 or 𝑞. Therefore 𝜑(𝑁)=(𝑝−1)(𝑞−1).
    • 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 𝑔1,𝑔2∈𝔾 we have 𝑓(𝑔1∘𝔾𝑔2)=𝑓(𝑔1)∘ℍ𝑓(𝑔2)

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 𝑝,𝑞>1 are relatively prime, we can conclude that

ℤ 𝑁 ≃ ℤ 𝑝 × ℤ 𝑞 and ℤ 𝑁 ∗ ≃ ℤ 𝑝 ∗ × ℤ 𝑞 ∗

Moreover, let 𝑓 be the function that maps elements 𝑥∈{0,…,𝑁−1} to pairs (𝑥𝑝,𝑥𝑞) where 𝑥𝑝∈{0,…,𝑝−1} and 𝑥𝑞∈{0,…,𝑞−1} defined by

𝑓 ( 𝑥 ) ≝ ( [ 𝑥 mod 𝑝 ] , [ 𝑥 mod 𝑞 ] )

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 0, we know that we are done. Otherwise, we recurse, using 𝑏mod𝑎 in place of 𝑎 and 𝑎 in place of 𝑏. When 𝑎 reaches 0, 𝑏 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 𝑎𝑏mod𝑁=1. Therefore to determine if integer 𝑏 is Invertible, we simply need to find a value 𝑎 which satisfies this condition. The resulting value 𝑎 is written 𝑎=[𝑏−1mod𝑁].

We can test for Invertibility succinctly by asserting that [𝑏−1mod𝑁] is valid ⟺ GCD(𝑏,𝑁)=1, meaning that 𝑏 and 𝑁 share no common factors.

Division Mod N

If an expression is written [𝑐/𝑏mod𝑁], it is only valid so long as we know 𝑏 is Invertible mod𝑁. To evaluate, first solve 𝑥=[𝑏−1mod𝑁] then plug into [𝑐𝑥mod𝑁].

[ 𝑐 / 𝑏 mod 𝑁 ] { [ 𝑐 ∗ [ 𝑏 − 1 mod 𝑁 ] mod 𝑁 ] GCD ( 𝑏 , 𝑁 ) = 1 Error GCD ( 𝑏 , 𝑁 ) ≠ 1

Modular Exponentiation

If an expression is written [𝑎𝑏mod𝑁] for some base 𝑎∈ℤ𝑁 and an integer exponent 𝑏>0, 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 [𝑏mod𝜑(𝑁)], meaning we can rewrite our full expression as [𝑎[𝑏mod𝜑(𝑁)]mod𝑁]. 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:

[ 𝑎 𝑏 mod 𝑁 ] = 𝑎 ∗ 𝑎 𝑏 − 1 mod 𝑁

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:

[ 𝑎 𝑏 mod 𝑁 ] = { ( 𝑎 𝑏 2 ) 2 mod 𝑁 𝑏 mod 2 = 0 𝑎 ∗ ( 𝑎 𝑏 − 1 2 ) 2 mod 𝑁 𝑏 mod 2 = 1

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 1 (successful attack) rather than a 0 (failed attack). For an attacker to be viable, we must showcase that this probability is greater than Pr[12] (random) for selecting the bit 𝑏 of the encoded message 𝑚𝑏, plus a negl. Formally, an attacker is successful iff Pr[𝐴=1]>Pr[12+negl].

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 𝑘 for any given scheme attempting perfect secrecy to contain the same quantity of information as the message 𝑚, that is, to have the same length. |𝑘|=|𝑚|. To showcase that a scheme does not comply with perfect security, one simply needs to showcase that observing the ciphertext changes the likelihood with which you are able to guess the plaintext.

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:

PrivK𝐴,Π𝐶𝑃𝐴(𝑛):

  1. 𝑘←Gen(1𝑛)
  2. 𝐴(1𝑛) interacts with an encryption oracle Enc𝑘(), outputting 𝑚0,𝑚1 where |𝑚0|=|𝑚1|.
  3. 𝑏←{0,1},𝑐←Enc𝑘(𝑚𝑏). give 𝑐 to 𝐴
  4. 𝐴 can continue to interact with Enc𝑘()
  5. 𝐴 outputs 𝑏′; 𝐴 succeeds if 𝑏=𝑏′ and experiment evaluates to 1 in this case

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 𝐴, as being allowed to decrypt it outright would defeat the point of the exercise.

Attacker:

PrivK𝐴,Π𝐶𝐶𝐴(𝑛):

  1. 𝑘←Gen(1𝑛)
  2. 𝐴(1𝑛) interacts with an encryption oracle Enc𝑘() and decryption oracle Dec𝑘(), outputting 𝑚0,𝑚1 where |𝑚0|=|𝑚1|.
  3. 𝑏←{0,1},𝑐←Enc𝑘(𝑚𝑏). give 𝑐 to 𝐴.
  4. 𝐴 can continue to interact with Enc𝑘() and Dec𝑘()
  5. 𝐴 outputs 𝑏′; 𝐴 succeeds if 𝑏=𝑏′ and experiment evaluates to 1 in this case

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 𝒜︀ is able to, given access to the encryption oracle Enc𝑘, create a new ciphertext that is successfully decrypted without error and that we never fed the encryption oracle.

Enc_Forge𝐴,Π(𝑛):

  1. 𝑘←Gen(1𝑛)
  2. 𝐴(1𝑛) interacts with an encryption oracle Enc𝑘(), eventually outputting ciphertext 𝑐.
  3. 𝑚≔Dec(𝑐) and let 𝑄 denote the set of all queries that 𝐴 submitted to the encryption oracle.
  4. iff 𝑚≠⊥ and 𝑚∉𝑄 output 1, otherwise output 0.

A private-key encryption scheme Π is unforgeable if for all PPT adversaries 𝐴, there is a negligible function negl such that: Pr[Enc_Forge𝐴,Π(𝑛)=1]≤ negl(𝑛).

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 𝑛, the scheme designer can alter the probability of breaking the scheme and the duration of computation required to achieve that probability. Because increasing 𝑛 increases the compute time for encryption and decryption, the value is to be minimized while still protecting against potential threats. Approximately, we are looking for probabilities of 2−60 (𝜀) for cracking the scheme within 200 years (𝑡).

  • function𝑓:ℕ→ℝ⟺∃𝑐where𝑓(𝑛)<𝑛𝑐for all𝑛
  • algorithm𝐴: Runs in polynomial time ⟺ there exists a polynomial 𝑝 such that for all input 𝑥∈{0,1}∗ the computation of 𝐴(𝑥) 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 𝑛 single-bit registers 𝑠𝑛−1,…,𝑠0, along with a set of 𝑛 boolean feedback coefficients 𝑐𝑛−1,…,𝑐0. The size 𝑛 of the array is referred to as the degree of the LFSR. This specification makes LFSRs extremely hardware efficient. After each ‘clock tick’, the value of 𝑠0 is output as 𝑦𝑖 for the 𝑖th clock tick and the states of each register are updated, register 𝑠𝑖+1 passing its value on to register 𝑠𝑖. The initial register 𝑠𝑛−1 is overwritten using the feedback coefficients.

Note that the superscript 𝑡 in 𝑠𝑖𝑡 represents the clock tick. To describe the way each register updates on each clock tick, we write

{ 𝑠 𝑖 ( 𝑡 + 1 ) = 𝑠 𝑖 ( 𝑡 ) 𝑖 = 0 , … , 𝑛 − 2 𝑠 𝑛 − 1 ( 𝑡 + 1 ) = ⨁ 𝑖 = 0 𝑛 − 1 𝑐 𝑖 𝑠 𝑖 ( 𝑡 )

To denote the outputs of an LFSR as 𝑦0,𝑦1,…, where 𝑦𝑖=𝑠0(𝑖), we write

{ 𝑦 𝑖 = 𝑠 𝑖 ( 0 ) 𝑖 = 0 , … , 𝑛 − 1 𝑦 𝑖 = ⨁ 𝑗 = 0 𝑛 − 1 𝑐 𝑗 𝑦 𝑖 − 𝑛 + 𝑗 𝑖 > 𝑛 − 1

One way to conceptualize this is to realize the first 𝑛 output bits are the initial state of the registers 𝑠0…𝑠𝑛−1.

LFSR
Figure 1: An example of a simple LFSR

LFSRs can be used to construct stream ciphers of the form (Init,Next) in an organic way- give them an initial state and produce a new value by executing a single clock tick.

Note that a degree-𝑛 LFSR has at most 2𝑛 possible states that correspond to the possible values of each register. A degree-𝑛 LFSR will eventually repeat a previous state. Once it does, it will then repeatedly cycle through this same set of states and their corresponding outputs.

An LFSR is said to have maximum length if it cycles through all 2𝑛−1 nonzero states before repeating. Note that this is the ideal case.


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 𝑛 bits of output from a degree-𝑛 LFSR will reveal the initial state of the LFSR, which functions as the key. Once known, all future output can be predicted. See formal definition above if confused.

Even if the feedback coefficients are hidden to an attacker, the initial state can still be deduced in only 2𝑛 output bits. As before, the first 𝑛 output bits reveal the initial state. Given the next 𝑛 output bits, we can construct a system of equations for which there is only one solution, revealing each feedback coefficient.

𝑦 𝑛 = 𝑐 𝑛 − 1 𝑦 𝑛 − 1 ⊕ ⋯ ⊕ 𝑐 0 𝑦 0 ⋮ 𝑦 2 𝑛 − 1 = 𝑐 𝑛 − 1 𝑦 2 𝑛 − 2 ⊕ ⋯ ⊕ 𝑐 0 𝑦 𝑛 − 1

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 𝑠𝑛−1 is now determined nonlinearly.

    Given some arbitrary nonlinear function 𝑔 that operates on the collection of registers, the FSR is able to generate a new state for 𝑠𝑛−1. For security, we posit that for 𝑔 to be “balanced”, Pr[𝑔(𝑠𝑛−1,…,𝑠0)=1]≈1/2 where the probability is computed over uniformly selected states. In practice, we often see the use of ANDs and ORs.

    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 Init function, Trivium is run for 4 * 288 clock ticks with discarded output to ensure its initial state cannot be deduced.

Trivium

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 𝑚𝑛 block of a message 𝑚 will not modify any blocks of the ciphertext seldom 𝑐𝑛.

CTR Mode

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 𝑚𝑛 will modify all subsequent blocks 𝑚𝑥 where 𝑥>𝑛.

CBC Mode

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 𝐹𝑘−1, but others will become predictably modified because they are also being ⊕‘d with information outside of the inverse function.

Cipher Block Chaining Message Authentication Code (CBC-MAC)

A message, 𝑚1 is input into a function 𝐹𝑘, its ouput is ⊕‘d with 𝑚2 before 𝑚2 is run through 𝐹𝑘. Once all messages have been run through 𝐹𝑘, its final output is 𝑡, which should prove integrity.

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 𝐼𝑉 because its use reveals too much information to adversaries.

CBC MAC

The methodology of Vrfy𝑘(𝑚,𝑡) is simply to compare the output of this scheme with 𝑡. As long as 𝑘 remains secret this is valid.


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.

CBC MAC Length Prefix

Confusion-Diffusion Paradigm

The CDP is, simply, a paradigm for constructing concise and random-looking permutations. The goal is to construct a PRP 𝐹 with a large block length from many smaller PRPs {𝑓𝑖} with a smaller block length.

Through the use of numerous PRPs {𝑓𝑖}, the scheme is said to introduce confusion into 𝐹.

On its own, this definition is not enough. Assuming the input on 𝐹𝑘(𝑥) is split into the 𝑛 components that will be fed to 𝑛 sub functions, changes to a single component in 𝑥 will produce predictable changes in 𝐹𝑘(𝑥).

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, 𝐹 becomes indistinguishable from a PRP.

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 𝑥≔𝑆1(𝑥1)‖…‖𝑆𝑛(𝑥𝑛) where 𝑥𝑖 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:

  1. Changing a single input bit for any given 𝑆-box changes at least two of the resulting output bits.
  2. 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.

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 ℓ-bit block length, the 𝑖th round function 𝑓𝑖̂ takes as input a sub-key 𝑘𝑖 and an ℓ/2-bit string and generates an ℓ/2-bit output. A single master key 𝑘 can be used to derive each sub-key.

  • 𝑓𝑖:{0,1}ℓ/2→{0,1}ℓ/2 via 𝑓𝑖(𝑅)≝𝑓𝑖̂(𝑘𝑖,𝑅)

    • Note that the functions 𝑓𝑖̂ are public and known- it is only the keys used for them that are kept a secret.
  • 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

Feistel

Attacking Feistel Networks:

  • In the one round case:

    • 𝐹𝑘(𝐿0,𝑅0)=(𝑅0,𝑓1(𝑅0)⊕𝐿0) where 𝑓1 is in some way dependent on 𝑘.
    • 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:

    • 𝐹𝑘(𝐿0,𝑅0)=(𝑓1(𝑅0)⊕𝐿0,𝑅0⊕𝑓2(𝑓1(𝑅0)⊕𝐿0)) where 𝑓1,𝑓2 are in some way dependent on 𝑘.
    • 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 𝑓̂ is used in each of the 16 rounds. The round function takes a 48-bit sub-key and a 32-input (half a block). The key schedule of DES is used to derive a sequence of 48-bit sub-keys 𝑘1,…,𝑘16 from the 56-bit master key.

By the DES definition, each of the sub-keys 𝑘𝑖 is simply a permuted subset of 48 bits of the master key.


The DES round function 𝑓̂, sometimes called the mangler function, is a practical implementation of an SPN with the slight variation that the 𝑆-boxes in this case do not need to be invertible since they are being utilized in the greater context of a Feistel Network. Indeed, the entire round function 𝑓̂ does not need to be invertible. The entirety of this scheme is publicly known, it is only the master key that is kept secret.

DES Mangler
Figure 9: A graphical representation of the DES mangler.

𝑆-box properties under DES:

  • 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

ℎ:{0,1}ℓ by ℎ(𝑘,𝑥)≝𝐹𝑘(𝑥)⊕𝑥.

Davies Meyer
Figure 10: A graphical representation of the equation for constructing the compression function.

Proving collision resistance based on the assumption that 𝐹 is a strong PRP is not possible as far as we know. If, however, we model 𝐹 as an ideal cipher, such a proof does become possible. In this case, the scheme is collision resistant so long as ℓ is sufficiently large.

Hash Functions

Hash Functions Formal Definition

Put simply, hash functions transform arbitrary length inputs ({0,1}∗) into fixed length outputs ({0,1}ℓ(𝑛)). Because of the implied utility of hash functions though, we expect them to not cause collisions, or at least to do so with a vanishing probability. Collisions occur when two distinct inputs 𝑥,𝑥′ produce the same output, meaning 𝐻(𝑥)=𝐻(𝑥′).

Collision Resistance:

Formally, we look at keyed hash functions.

𝐻𝑠(𝑥)=𝐻(𝑠,𝑥). It must be difficult to find a collision for a randomly generated key 𝑠. In the case of hash functions, the key is generally not kept secret, unlike the keyed functions we’ve seen prior. An attacker wishes simply to find a collision.

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 1, otherwise outputs 0.

To insist that a hash function is collision resistant is to show that the probability of this attacker outputting 1 is negligible, or 𝑃[𝐴=1]≤ negl.

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 𝐻 for two inputs 𝑥,𝑥′ where 𝑥≠𝑥′.

Preimage resistance: For an attacker given 𝑠,𝑦 where 𝑦=𝐻𝑠(𝑥) for a uniform 𝑥, it is infeasible for a PPT adversary to find a value 𝑥′ such that 𝑥′≠𝑥 and 𝑦=𝐻𝑠(𝑥′).

Hash-and-MAC

By applying a hash function 𝐻 to some message 𝑚, we can effortlessly generate a MAC tag 𝑡 for the given message. This is secure because the attacker 𝐴 cannot output any new hash values, and 𝐻 being collision resistant ensures the attacker will be unable to find new messages with a matching hash. The MAC utilized here is based on CBC-MAC.

  • Gen′: Choose 𝑘 uniformly from {0,1}𝑛; 𝑠←Gen𝐻(1𝑛)
  • Mac′: Given 𝑘,𝑠, for some message 𝑚∈{0,1}∗, output 𝑡←Mac𝑘(𝐻𝑠(𝑚))
  • Vrfy′: Given 𝑘,𝑠, for some message 𝑚∈{0,1}∗, and some tag 𝑡, output 1 iff 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.

HMAC
  • Gen(1𝑛): Choose 𝑘 uniformly from {0,1}𝑛′; 𝑠←Gen𝐻(1𝑛)
  • Mac′: Given 𝑘,𝑠, for some message 𝑚∈{0,1}∗, output

    𝑡≔𝐻𝑠((𝑘⊕opad)‖𝐻𝑠((𝑘⊕ipad)‖𝑚))

  • Vrfy′: Given 𝑘,𝑠, for some message 𝑚∈{0,1}∗, and some tag 𝑡, output 1 iff

    𝑡=𝐻𝑠((𝑘⊕opad)‖𝐻𝑠((𝑘⊕ipad)‖𝑚)).

Merkle-Damgård Transform

The purpose of this scheme is to transform fixed length hash functions into arbitrary length hash functions.

Let (Gen,ℎ) be a compression function for inputs of length 𝑛+𝑛′≥2𝑛 with output length 𝑛. Fix ℓ≤𝑛′ and 𝐼𝑉∈{0,1}𝑛. Construct hash function (Gen,𝐻) as follows:

  • Gen: remains unchanged
  • 𝐻: receiving input of key 𝑠 and string 𝑥∈{0,1}∗ of length 𝐿<2ℓ, do:

    1. Append a 1 to 𝑥, 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,…,𝑥𝐵.
    2. Set 𝑧0≔𝐼𝑉.
    3. For 𝑖=1,…,𝐵, compute 𝑧𝑖≔ℎ𝑠(𝑧𝑖−1‖𝑥𝑖).
    4. Output 𝑧𝐵.

If (Gen,ℎ) is collision-resistant, then so is (Gen,𝐻). Explained simply, we are breaking the input up into respective chunks and running each of these chunks through the fixed length hash function, using a variation of chained CBC-Mode.

Merkle Damgard

Likelihood of Collision

Given a positive integer 𝑁, say that some 𝑞≤2𝑁 elements 𝑦1,…,𝑦𝑞 are chosen uniformly an d independently from a set of size 𝑁. We can then assert that

𝑞 ∗ ( 𝑞 − 1 ) 4 𝑁 ≤ 1 − 𝑒 − 𝑞 ( 𝑞 − 1 ) / 2 𝑁 ≤ coll ( 𝑞 , 𝑁 ) ≤ 𝑞 ∗ ( 𝑞 − 1 ) 2 𝑁

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 𝑏>0 be the number of bytes that need to be appended to the message to get length as multiple of L

    • 1≤𝑏≤𝐿; note 𝑏≠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

Receiver:

  • Extract the final number from the the Encoded Data. This number will be interpreted as 𝑏. This is why 𝑏 must always be ≥1, 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.
  • Use CBC-Mode decryption to obtain the encoded data
  • Say the final byte of encoded data has value 𝑏

    • If 𝑏=0 or 𝑏>𝐿 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

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 𝑐 has proper formatting, we can actually decode the entirety of the message. Knowing that neither method we’ve discussed for block ciphers are CCA-Secure, this should make sense. In both cases, we can devise a methodology for producing predictable changes to the final block of decrypted data, thus giving us the opportunity to modify the padding content. By finding the number of padding bytes through trial and error, we can then create modifications that increase this number, moving on to the previous bit as the bit to modify. Through some clever XORing, we can uncover the entirety of the plaintext this way.

Formal Assumptions

The Factoring Assumption

Let GenModulus be a PPT algorithm that, on input 1𝑛, outputs (𝑁,𝑝,𝑞) where 𝑁=𝑝𝑞 and 𝑝,𝑞 are 𝑛-bit prime numbers. This is allowed to fail with negl probability.


Here we define an experiment in which an attacker 𝒜︀ is given an integer 𝑁 and is asked to deduce the prime factorization that produced the number.

Factor𝒜︀,GenModulus(𝑛):

  1. (𝑁,𝑝,𝑞)←GenModulus(1𝑛)
  2. 𝒜︀ is given 𝑁 and outputs 𝑝′,𝑞′>1
  3. The output of the experiment is defined to be 1⟺𝑝′∗𝑞′=𝑁, returning 0 otherwise.

Note that if the experiment evaluates to 1, {𝑝′,𝑞′}={𝑝,𝑞}.


The Factoring Assumption states that for all PPTs 𝒜︀ there exists a negl such that

Pr [ Factor 𝒜︀ , GenModulus ( 𝑛 ) = 1 ] ≤ negl ( 𝑛 )

RSA Assumption

Given a modulus 𝑁 and an integer 𝑒>2 relatively prime to 𝜑(𝑁), we know that exponentiation to the 𝑒th power modulo 𝑁 is a permutation. Therefore for any 𝑦∈ℤ𝑁∗ we can define [𝑦1/𝑒mod𝑁] to be the unique element of ℤ𝑁∗ that yields 𝑦 when raised to the 𝑒th power modulo 𝑁.
𝑥=[𝑦1/𝑒mod𝑁]⟺𝑥𝑒=[𝑦mod𝑁]

Informally, our task is to compute 𝑥 for a modulus 𝑁 of unknown factorization.


Let GenRSA be a PPT algorithm that, given input 1𝑛 outputs a modulus 𝑁 that is the product of two 𝑛-bit primes, as well as two integers 𝑒,𝑑 where 𝑒,𝑑>1 and GCD(𝑒,𝜑(𝑁))=1 and 𝑒𝑑=[1mod𝜑(𝑁)]. This is allowed to fail with negl probability.


Here we define an experiment in which the attacker 𝒜︀ is given modulo 𝑁, exponent 𝑒, and a uniformly chosen 𝑦∈ℤ𝑁∗, and asked to produce the value 𝑥 which, when raised to the 𝑒th power produces [𝑦mod𝑁].

RSAinv𝒜︀,GenRSA(𝑛):

  1. (𝑁,𝑒,𝑑)←GenRSA(1𝑛)
  2. Choose a uniform 𝑦∈ℤ𝑁∗
  3. 𝒜︀ is given (𝑁,𝑒,𝑦) and outputs 𝑥∈ℤ𝑛∗
  4. The output of the experiment is defined to be 1⟺𝑥𝑒=[𝑦mod𝑁], returning 0 otherwise.

The RSA Assumption states that for all PPTs 𝒜︀ there exists a negl such that

Pr [ RSAinv 𝒜︀ , GenRSA ( 𝑛 ) = 1 ] ≤ negl ( 𝑛 )

Discrete-Logarithm / Diffie-Hellman Assumptions

Let 𝒢︀ denote a generic PPT algorithm for group generation. Given input of size 1𝑛, 𝒢︀ outputs a description of a cyclic group 𝔾 as well as its order 𝑞 where ‖𝑞‖=𝑛 and a generator 𝑔∈𝔾. Assume that we can perform group operations and check if a given bit-string is an element of 𝔾 in PPT. Despite all cyclic groups of the same order being isomorphic (comprised of the same elements), their representation will determine the complexity of the operations.


Here we define an experiment in which the attacker 𝒜︀ is given the cyclic group 𝔾, its order 𝑞, its generator 𝑔, and a uniformly selected member of ℎ∈𝔾. The attacker’s goal is to find a value 𝑥 such that 𝑔𝑥=ℎ. In other words, to what power is the generator 𝑔 raised such that it produces the uniformly chosen value ℎ? The value 𝑥 is guaranteed to exist since all values in 𝔾 are found by raising 𝑔 to some power mod𝑞.

DLog𝒜︀,𝒢︀(𝑛):

  1. (𝔾,𝑞,𝑔)←𝒢︀(1𝑛)
  2. Choose a uniform ℎ∈𝔾
  3. 𝒜︀ is given (𝔾,𝑞,𝑔,ℎ) and outputs some 𝑥∈ℤ𝑞
  4. The output of the experiment is defined to be 1⟺𝑔𝑥=ℎ, returning 0 otherwise.

The DLog Assumption states that for all PPTs 𝒜︀ there exists a negl such that

Pr [ DLog 𝒜︀ , 𝒢︀ ( 𝑛 ) = 1 ] ≤ negl ( 𝑛 )

Encryption Schemes

Private-Key Encryption

Formal Definition for Private Key Encryption

A private-key encryption scheme contains three probabilistic functions, Gen, Enc, & Dec such that:

  • 𝑘←Gen(1𝑛) we assume that this key satisfies |𝑘|≥𝑛.
  • 𝑐←Enc𝑘(𝑚) where 𝑚∈{0,1}∗
  • 𝑚←Dec𝑘(𝑐) where 𝑚∈{0,1}∗ or an error, denoted ⊥

We require, simply, that 𝑚=Dec𝑘(Enc𝑘(𝑚))

If, for some reason, we specify the Message Space (ℳ︀) to be 𝑚∈{0,1}ℓ(𝑛), we then say that the set of these functions can be referred to as a fixed length private key encryption scheme of length ℓ(𝑛).

We also make a few assumptions moving forwards:

  • Dec is actually deterministic
  • Calls to Enc are probabilistically independent from one another
  • 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}𝑛
  • Gen: choose a uniform key 𝑘∈{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 GenRSA as it is referenced in the RSA Assumption.

GenRSA:

  1. (𝑁,𝑝,𝑞)←GenModulus(1𝑛)
  2. 𝜑(𝑛)≔(𝑝−1)∗(𝑞−1)
  3. Choose some 𝑒>1 such that GCD(𝑒,𝜑(𝑁))=1
  4. Compute 𝑑≔[𝑒−1mod𝜑(𝑁)]
  5. Return (𝑁,𝑒,𝑑)

Now, with GenRSA in hand, we define the public key encryption scheme as follows:

  • Gen: on input 1𝑛 run (𝑁,𝑒,𝑑)←GenRSA(1𝑛). ⟨𝑁,𝑒⟩ is the public key. ⟨𝑁,𝑑⟩ is the private key.
  • Enc: on input a public key 𝑝𝑘=⟨𝑁,𝑒⟩ and a message 𝑚∈ℤ𝑁∗, compute the ciphertext 𝑐≔[𝑚𝑒mod𝑁].
  • Dec: on input a private key 𝑠𝑘=⟨𝑁,𝑑⟩ and a ciphertext 𝑐∈ℤ𝑁∗, compute the message 𝑚≔[𝑐𝑑mod𝑁].

If the message is not chosen uniformly from ℤ𝑁∗, we risk exposing information about the message. Moreover, this algorithm is deterministic and so by definition cannot be CPA-Secure.

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 𝒢︀, a PPT algorithm that when given input 1𝑛 outputs a description of a cyclic group 𝔾, its order 𝑞 (where ‖𝑞‖=𝑛), and a generator 𝑔∈𝔾.

The protocol is defined formally as follows:

  1. Alice performs (𝔾,𝑞,𝑔)←𝒢︀(1𝑛)
  2. Alice chooses a uniform 𝑥∈ℤ𝑞 and computes ℎ𝐴≔𝑔𝑥.
  3. Alice sends (𝔾,𝑞,𝑔,ℎ𝐴) to Bob.
  4. Receiving (𝔾,𝑞,𝑔,ℎ𝐴), Bob chooses a uniform 𝑦∈ℤ𝑞 and computes ℎ𝐵≔𝑔𝑦. Bob sends ℎ𝐵 to Alice and outputs the key 𝑘𝐵≔ℎ𝐴𝑦.
  5. 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:

𝑘 𝐵 = ℎ 𝐴 𝑦 = ( 𝑔 𝑥 ) 𝑦 = 𝑔 𝑥 𝑦 𝑘 𝐴 = ℎ 𝐵 𝑥 = ( 𝑔 𝑦 ) 𝑥 = 𝑔 𝑥 𝑦
Diffie Hellman
Figure 13: A graphical representation of the formalized protocol

Attacking the protocol:

Here, we define an experiment in which keys are exchanged. An attacker 𝐴 is given a either a uniformly chosen bit-string of length 𝑛, or the real key 𝑘 that was generated during execution. If the attacker is unable to distinguish the two with better than random probability, the scheme is secure.

KE𝒜︀,Πeav(𝑛):

  1. Both parties holding 1𝑛 execute the protocol Π. This produces a transcript trans containing all messages sent by both parties as well as a key 𝑘 output by each of the parties
  2. A uniform bit 𝑏∈{0,1} is chosen. If 𝑏=0, set 𝑘̂≔𝑘, otherwise choose a uniform 𝑘̂∈{0,1}𝑛.
  3. 𝒜︀ is given trans and 𝑘̂ and outputs a bit 𝑏′.
  4. The output of the experiment is defined to be 1⟺𝑏′=𝑏, returning 0 otherwise.

The exchange protocol is considered secure in the presence of an eavesdropper if for all PPTs 𝒜︀ there exists a negl such that

Pr [ KE 𝒜︀ , Π eav ( 𝑛 ) ≔ 1 ] ≤ 1 2 + negl ( 𝑛 )

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 𝑘. To do this, we perform our operations as before. Once a key 𝑘 is agreed upon, Bob is able to encrypt a message 𝑚∈𝔾 simply by sending 𝑘∗𝑚 to Alice, who can easily recover 𝑚 using her knowledge of 𝑘. By extension, we argue that the eavesdropper learned nothing about 𝑚.

This scheme is used in a symmetric key exchange.

  • Gen: On input 1𝑛 run 𝒢︀(1𝑛) to obtain (𝔾,𝑞,𝑔). Then choose a uniform 𝑥∈ℤ𝑞 and compute ℎ≔𝑔𝑥. The public key is ⟨𝔾,𝑞,𝑔,ℎ⟩ and the private key is ⟨𝔾,𝑞,𝑔,𝑥⟩. The message space is 𝔾.
  • Enc: Given a public key 𝑝𝑘=⟨𝔾,𝑞,𝑔,ℎ⟩ and a message 𝑚∈𝔾, choose a uniform 𝑦∈ℤ𝑞 and output the ciphertext ⟨𝑔𝑦,ℎ𝑦∗𝑚⟩.
  • Dec: Given a private key 𝑠𝑘=⟨𝔾,𝑞,𝑔,𝑥⟩ and a ciphertext ⟨𝑐1,𝑐2⟩, output 𝑚̂≔𝑐2/𝑐1𝑥.

To showcase that this is a successful scheme, let ⟨𝑐1,𝑐2⟩=⟨𝑔𝑦,ℎ𝑦∗𝑚⟩ where ℎ=𝑔𝑥. Then consider the equivalence

𝑚 ̂ = 𝑐 2 𝑐 1 𝑥 = ℎ 𝑦 ∗ 𝑚 ( 𝑔 𝑦 ) 𝑥 = ( 𝑔 𝑥 ) 𝑦 ∗ 𝑚 𝑔 𝑥 𝑦 = 𝑔 𝑥 𝑦 ∗ 𝑚 𝑔 𝑥 𝑦 = 𝑚