Number Theory
Groups
A group is a set along with a binary operation for which the following conditions hold:
- Closure: For all , .
- Identity: There exists an identity such that , .
- Inverse: For all , there exists an element called the inverse such that .
- Associativity: For all ,
When has a finite number of elements, we say is finite and let denote the order (size) of the group.
We say a group with operation is abelian if it has the property of commutativity: .
For the purposes of this class, we will only deal with finite, abelian groups.
Example Group: Modular Arithmetic (Addition)
We say that two numbers are congruent modulo , denoted
If divides , or in other words, .
For example, all of the following are true.
Addition works in modular space as normal. You perform regular addition, and then take modulo . For example,
Addition has the following properties. Consider the set of numbers :
- Identity: , adding 0 to it yields the same number
- Additive Inverse: , such that , given as .
- Closure: Any addition operations will yield a result that is still inside of .
- Associativity: You can take modulo at any point in the operation. For example,
The set with our addition modulo operator defines a group!
Modular Arithmetic under Multiplication, Prime
In the context of cryptography, we are interested in multiplicative groups over the integers, as this introduces computational problems believed to be hard to solve. One example of this is the multiplication modulo group.
For now, we will only consider prime groups, but we will later generalize to composite groups.
Let , with the multiplication mod operation. For to be a group it must be true that p is prime. Without a prime , we won’t have a multiplicative inverse!
Multiplicative Inverses
We argue below that satisfies the inverse property (the rest are trivial to prove). In other words, , there exists a such that .
Example: Brute Force Inverse
Suppose we want to find the multiplicative inverse of .
One way to do this is to brute-force iteratively try all 10 numbers in to find our inverse. We will consider this brute-force to be exponential time! This is because when we’re using this with respect to binary numbers, the length of our input is on the magnitude of .
However, there’s a faster way to find the multiplicative inverse, through the Euclidean Algorithm! This algorithm is based off the following assertion:
Theorem: Euclidean Algorithm
Let be positive integers. Then, there exists integers such that .
The Euclidean algorithm can be used to compute in polynomial time. We can then extend this to compute in polynomial time.
This algorithm has time complexity , for .
If we can use the Euclidean Algorithm to find , then we can find a multiplicative inverse. This is because for prime, , so for
We can rearrange our terms to find that , telling us that divides . Because of this, we know that
In other words, is our multiplicative inverse for !
Example: Inverses with the Euclidean Algorithm
Suppose we want to find the multiplicative inverse of for . In other words, we want to find
We can do this by iteratively dividing as follows. Let . Every iteration, modular divide by , to get
Then, let and repeat.
Once we find a 0 for , we can work our way back up to find our inverse. If we rearrange every expression (ignoring the last) to be in terms of , we’ll find that
So, starting from the bottom, we can plug each equation back into the previous to get an expression in terms of 5, 23.
Thus, we find our multiplicative inverse as .
Polynomial Time of Multiplicative Inverses
Note that when we use the Euclidean Algorithm, our “b” value is being halved every two rounds. So, our time complexity is . This means our time complexity is polynomial given the input!
Thus, we can not only find multiplicative inverses, but find them efficiently.
Modular Exponentiation
What about Modular Exponentiation? Given , can we efficiently compute ?
This is the result of multiplying by itself times, and taking the modulus of the result.
One way we could compute this is as follows:
def ModExp(a, m, N):
temp = 1
for i in range(1, m + 1)
temp = temp * a % N
return temp
But this has runtime , where could be exponential! For an efficient algorithm, we need our runtime to be on the logarithmic order.
We can, in fact, achieve an efficient algorithm with repreated squaring. Let be the bits of .
def ModExp(a, m, N):
s = a
temp = 1
for i in range(0, n):
if (mi == 1)
temp = temp * s % N
s = s^2 % N
return temp
This has runtime ! So, we can also perform Modular Exponentiation efficiently.
In the context of a prime , we can also use Fermat’s Little Theorem to speed up our computation.
Theorem: Fermat's Little Theorem
For prime , integer , .
Corollary
For prime and such that , .
This theorem can be generalized to any finite group!
Theorem: Generalized Fermat's
Let be a finite group with . Then, for any element , appling the group operation to it times will yield 1.
Recall that for our group , we have elements. So, this is making the same assertion as our previous corollary.
Modular Arithmetic under Multiplication, N Composite
Using primes to construct groups is very limiting, as there are only so many primes we could use. What about multiplicative groups modulo , where is composite? Can we create such groups?
For numbers , only numbers such that have a multiplicative inverse by the Extended Euclidean Algorithm. Because all of the others do not have a multiplicative inverse, to obtain a valid group, we must disclude these values from our group.
So, we will define our group as follows:
Then, is an abelian, multiplicative group.
In practice, we will often create composite groups where , for distinct primes . We can create this group as follows:
- For , remove numbers
- For , remove numbers .
This gives us order, denoted (the Euler totient function)
We add 1 as we’re double counting the element in our removal.
Generalizing this, for , where are distinct primes and , then
This gives us a very easy way to create large groups quickly! We take prime factors, and multiply them together to get a large group!
However, finding this prime factorization of is a very difficult problem!
By this theorem, and using the previous theorems, we know that for any such that ,
This can be used as a “quick / easy” vertification that someone has found !
A corollary of this theorem is that (since every , we wrap around). This makes things easy if we can find the prime factorization of .
Cyclic Groups
For a finite group of order and , consider
Here, always forms a cyclic subgroup of . However, as there may be repeats, may be a subgroup with a smaller order than .
If the order of is equal to , we say that is a cyclic group and is a generator of . In other words, by apply modular exponentiation on , we can cycle between all values in .
Example: Cyclic Group + Generator
Define . Then, 2 is a generator of .
Input Output Input Output 1 12 2 11 4 9 8 5 3 10 6 7 1
Let be a finite group and . The order of is the smallest positive integer such that .
Proposition: Generators
- Let be a finite group, with order . Then, for any integer , we have .
- Let be a finite group and with order . Then, if and only if .
- Let be a finite group of order , and with order . Then, .
Proposition (3) is particularly important! This is because if is prime, then the only generator orders we can get are 1 and ! Furthermore, because is only possible with the identity element, this means all other elements are generators of .
We want to find these prime order groups, as they give us a basis for cryptographic problems.
Theorem
If is prime, then is a cyclic group of order .
Using the above theorem, we can construct a subgroup of that is of prime order!
Prime Order Cyclic Groups
Let , where is a strong prime: , where is also prime. By the above theorem, is a cyclic group of order .
We will cleverly take 1/2 of the elements of , to get a group of order , which is prime!
Because is cyclic, it has a generator . Choose this generator.
By definition of a generator, we can get every element in this group using it! So, let’s take every even power of , giving us a subgroup of order . This gives us a prime order group!
We take even powers, as even if you raise even powers to an exponent, you will still have an even power!
Cryptographic Problems on Cyclic Groups
Cyclic groups form the basis of many cryptographic problems. In particular, there are 3 main problems on cyclic groups, each building on the last.
Discrete Logarithm
We define the Discrete-Log Experiment as follows:
- Run to get , where is a cyclic group of order , and generator .
- Choose a uniformly.
- Adversary is given , and needs to guess the such that .
- The output of the experient is 1 if and 0 otherwise.
As is typically on the magnitude of or , it would be extremely inefficient to do a brute force attack.
We say the Discrete-Logarithm Problem is hard relative to if for all PPT algorithms , there exists a negligible function such that
This is the hardest problem on cyclic groups! All of the following problems are based off of this.
Computational Diffie-Hellman
We define the Computational Diffie-Hellman (CDH) problem as follows.
Given and uniform , , compute .
Note that , which won’t solve our problem.
This problem is based on the Discrete Logarithm problem, as if we could solve Discrete Log, we could solve for in PPT time and compute our result.
However, because Discrete Log is a hard problem, this is also hard.
Decisional Diffie-Hellman
We define the Decisional Diffie-Hellman (DDH) problem as follows.
- Define a distinguisher , who gets one the group , order , generator , and one of the following:
- Ideal World: , 3 independent group elements with no correlation to each other.
- Real World: , 3 group elements where the 3rd is related to the first two through the CDH problem.
- The distinguisher gets one of the worlds, and has to guess the world that they’re in.
We say that the DDH problem is hard if for all PPT adversaries , they can only guess what world they’re in with a negligible probability.
Note that DDH is not hard over for for prime . This is because for , we can compute the Legendre symbol
Which is 1 if is a perfect square in the group (if , then ), and -1 if is not. There exists an algorithm to do this efficiently to distinguish the ideal and real world.
Attack
Note that if we compute the Zegendre symbol on the 3 group elements we’re given, then:
- For , we can get any of the 8 patterns by computing the Zegendre symbol on them.
- For , there are some patterns we cannot get. If ’s symbol is 1, then at least or must have a symbol of 1. If ’s symbol is -1, then and must have a symbol of -1.
If we compute these patterns and match one of the patterns that is possible in the case, we return that we’re in the real world. This gives us a distinguishing algorithm with constant probability.
Elliptic Curves
Here, we will define Elliptic Curve groups. This is another group that can be used for Diffie-Hellman, and is the go-to method in cryptography right now.
Points on the Elliptic Curve
A finite field is a set of elements that can be viewed as a group with respect to two operations: addition and multiplication.
In fields, the identity element for addition (0)is not required to have a multiplicative inverse.
With fields, we now define whole polynomials over the elements in the group!
Let be a finite field for prime . Now consider equation in variables of the form:
Where are constants such that (ensuring the cubic polynomial has no repeated roots).
Define as the set of pairs satisfying the above equation as well as a special value of .
These elements are called the points on the Elliptic Curve , where the special value is called the point at infinity.
Example: Finding Elliptic Curve Points
To find the points on an Elliptic Curve:
- First, find the quadratic residues (squares) over . These will be our possible values , and their values.
- Now, take . Plug in all values for .
Every value of such that is a non-zero quadratic residue yields 2 points on our curve.
Every value of such that is a non-quadratic residue are not on the curve
Every value of such that give 1 point on the curve.
Given an yielding a quadratic residue, we find by matching the result with matching values in (1).
Consider . First, we find our quadratic residues as .
- Take . This is a not a quadratic residue.
- Take . This gives us 1 point on the curve .
- Take . This is not a quadratic residue.
- Take . This is a quadratic residue with roots 2,5, giving us points .
Elliptic Curve Groups
For any elliptic curve, we will guarantee the property that every line intersecting in 2 points, intersects it in exactly 3 points:
- A point is counted 2 times if the line is tangent to the curve at .
- The point at infinity is counted when the line is vertical.
With this property, we will define a group on the Elliptic Curve elements. We define the binary operation addition () as follows:
- For any two points , the result is the 3rd point intersecting the curve from the line between .
- We say is the additive identity, .
Under this operation, we can find that for two points , we can calculate their addition as:
- If , then with
for
- If but , then and so .
- If and , then
- If and , then with
Where .
DDH Over Elliptic Curves
Under this, we can perform Decisional Diffie Hellman over Elliptic Curves. In other words, we want to distinguish from .
Here, is the third point from the line drawn by , and is another randomly chosen third point.
Theorem: Hasse Bound
For prime , and Elliptic Curve , we know that the size of the group is
Diffie Hellman Key Exchange
Using the Diffie-Hellman problems, we can define a key-exchange protocol.
EAV-Security for Key Exchange
First, to define security for this protocol, let’s define the key-exchange experiment .
- Two parties holding execute the protocol, . This gives a transcript containing all messages sent by the parties, and a key output by each of the parties.
- A uniform is chosen. If , set , and if then choose uniformly at random.
- Adversary is given and , and outputs a bit distinguishing what is.
- The output of the experiment is 1 if , and 0 otherwise.
We say a key-exchange protocol is secure in the presence of an eavesdropped if for all PPT adversaries , there exists a negligible function such that
Diffie-Hellman Key Exchange
One protocol satisfying this is the Diffie Hellman Key Exchange. It works as follows.
- Both parties agree ahead of time on some group , order , and generator .
- Alice will randomly choose , and take . Alice sends to Bob.
- Bob will randomly choose , and similarly compute . Bob sends to Alice.
- Alice computes , and Bob computes . This gives them the same key.
- This is secure, as the adversary cannot see ! So, even if the adversary sees , it cannot easily compute as they need to reverse engineer (which is a hard problem).
This is a protocol used everywhere! Typically, we use ECDH, Elliptic Curve Diffie Hellman.
Theorem: Security of Diffie Hellman Key Exchange
If the DDH problem is hard relative to , then the Diffie-Hellman key exchange protocol is secure in the presence of an eavesdropper.
Proof (Sketch)
Intuitively, this is because if the DDH is hard, then a distinguisher has no PPT way of finding given .
MiTM Attack Against Diffie-Hellman Key Exchange
Diffie-Hellman Key Exchange works well, but it assumes that the adversary is only eavesdropping on the communications. If the adversary had the ability to modify the messages in transit, they can perform a man in the middle attack.
- Given , an adversary can complete a key-exchange protocol with both ,.
- Later, when and try to communicate, the adversary can decrypt the messages, and re-encrypt them before sending them to the other party.
The reason this happens is because there’s no way for a client to know who they’re communicating with!
Public Key Encryption
One way we can prevent the aformentioned man-in-the-middle attack is by using public key encryption. A public key encryption scheme is a triplet of PPT algorithms such that:
Gen
takes a security parameter and outputs a pair of keys called the public key, and secret key, respectively.Enc
encrypts the message under the public keyDec
decrypts the ciphertext under the secret key .
CPA-Security for Public Key Encryption
For a public key encryption scheme, we define the CPA experiment :
Gen
is ran to obtain the public key and secret key .- The adversary is given , and returns a pair of equal length messages in the message space.
- A uniform bit is chosen, and is encrypted and sent back to .
- guesses which ciphertext they received.
We say the scheme is CPA-Secure if for all PPT adversaries , there is a negligible function such that
Under a public key encryption scheme, we can send an encrypted message to the other party using . They can then verify their identity by decrypting with the secret key, which only they have.
But how do we create a public key encryption scheme?
El Gamal Encryption
With any key exchange, we can convert it to a public key encryption scheme!
Below, we show how we can convert Diffie-Hellman Key Exchange into a public key scheme called El Gamal Encryption. To see why, consider the following:
- In Diffie-Hellman, sends to , who sends to . Then, both parties to generate a shared key.
- However, after receiving , can already generate the shared key! So, can generate the shared key, and encrypt the message with this shared key. It then sends and this ciphertext to .
- can then generate the shared key, decrypting the ciphertext to get the message.
Formally, El Gamal Encryption works as follows:
Gen
: Obtain . Choose a uniform , and compute . The public key and secret key are defined as follows:Enc
: Given and message , choose a uniform and create ciphertextDec
: Given and ciphertext , we can find message
Note that in decryption, stands for us applying the group operation times (to find h^{xy}), then finding its multiplicative inverse.
Theorem: Security of El Gamal
If the DDH problem is hard relative to , then the El Gamal encryption scheme is CPA-secure.
Digital Signatures
Using public key encryption, we can also define a signature scheme.
We define a digital signature scheme as follows:
Gen
: Takes a security parameter , and outputs a public key and secret key .Sign
: A signing algorithm that takes a private key , and a message from some message space. It outputs a signature .Vrfy
: Takes the public key , a message , and a signature , and output a that is 1 if we have validity, 0 otherwise.
Signature Security
For security, we define the experiment:
Gen
is ran to obtain .- The adversary is given and access to an oracle .
- The adversary outputs . Let denote the set of all queries that asked the oracle.
- succeeds if and only if and (not queried before).
- If succeeds, the experiment is 1.
We say the scheme is secure if
Schnorr Identification Scheme
To construct a signature from the discrete logarithm, we will first construct an identification scheme. This is a scheme which can be used to prove knowledge of a secret key without revealing the secret key.
After this, we will perform a Fiat-Shamir Transform to covert an identification scheme into a signature scheme.
The Schnorr Identification Scheme works as follows. Consider two parties, the prover and the verifier :
- Prover has secret key , and verifier has public key .
- chooses uniform , and computes . sends this to .
- now chooses a challenge, a uniform . sends this to .
- computes , and sends this to .
- can now check whether .
- If the prover is legitimate, then the verifier will find that .
This scheme is secure, and does not actually leak what is. Intuitively, this is because functions as a one-time pad, because is chosen uniformly. This obscures .
To formally show this, we will want to prove the following.
Proof: Prover Knows
We first show that under this scheme, the prover knows . To do this, suppose we have a “knowledge extractor”. This extractor will take a prover who won the scheme. Given this prover, we can use it to compute the discrete log of in polynomial time.
This shows that the prover knows , as a polynomial computation of the discrete log would be impossible otherwise.
What our extractor will do is find two “paths”, starting with , that are accepted in our scheme. After we find these paths, we have for some initial , one path , and another . Using these, we can compute .
This is called the Forking Lemma. We can get 2 accepting transcripts in polynomial time using rewinding.
Proof: No Information is Leaked about
We also show that under this scheme, no information is leaked about . To do this, we will show that we can take a polynomial-time simulation, which, given , can simulate transcripts of identification protocols.
We construct a simulator that outputs correctly distributed transcripts .
- Sample from the marginal distribution over , both selected randomly.
- Sample consistent from the space of , dependent on , which we can compute as .
- By definition of the scheme, we have exactly 1 possible value that works!
These are all successful transcripts of identification protocols.
This is called Honest Verifier Zero Knowledge.
Fiat-Shamir Transform
After constructing an identification scheme, we then apply the Fiat-Shamir Transform to it to obtain a signature scheme.
This transform works as follows, giving us the Schnorr Signature Scheme.
Gen
: Obtain keys .Sign
: Given a private key and message ,- Compute for uniform .
- Instead of a random , compute .
- Use this to compute .
- Return signature .
Vrfy
: Given public key , message , and signature , compute . Rehash , and return 1 if this hash equals our original .