Modern cryptography is based on the assumption that some problems are hard (unfeasable to solve). Since the we do not have infinite computational power and storage we usually work with finite messages, keys and ciphertexts and we say they lay in some finite setsM,K and C.
Furthermore, to get a ciphertext we usually perform some operations with the message and the key.
For example in AES128 K=M=C={0,1}128since the input, output and key spaces are 128 bits. We also have the encryption and decryption operations:
Enc:K×M→CDec:K×C→M
The study of sets, and different types of operations on them is the target of abstract algebra.
In this chapter we will learn the underlying building blocks of cryptosystems and some of the hard problems that the cryptosystems are based on.
Definition
A setGpaired with a binary operation ⋅:G×G→Gis a group if the following requirements hold:
Closure: For all a,b∈G:a⋅b∈G - Applying the operation keeps the element in the set
Associativity: For all a,b,c∈G:(a⋅b)⋅c=a⋅(b⋅c)
Identity: There exists an elemente∈Gsuch that a⋅e=e⋅a=afor all a∈G
Inverse: For all elements a∈G, there exists some b∈Gsuch that b⋅a=a⋅b=e. We usually denotebas a−1
For n∈Z, anmeans n timesa⋅a…⋅awhen n>0and (a−n)−1when n<0. For n=0, an=e.
If ab=ba, then ⋅is commutative and the group is called abelian. We often denote the group operation by +instead of ⋅and we typically use nainstead of an.
Remark
The identity element of a group G is also denoted with 1G or just 1 if only one groups is present
Examples of groups
Integers modulo n (remainders) under modular addition =(Z/nZ,+).
Z/nZ={0,1,...,n−1}
Let's look if the group axioms are satisfied
✓∀a,b∈Z/nZ let c≡a+bmodn.
Because of the modulo reduction c<n⇒c∈Z/nZ
✓Modular addition is associative
✓0+a≡a+0≡amodn⇒0 is the identity element
✓∀a∈Z/nZwe take n−amodnto be the inverse of a. We check that
a+n−a≡n≡0modn
n−a+a≡n≡0modn
Therefore we can conclude that the integers mod n with the modular addition form a group.
(Q,⋅) is not a group because we can find the element 0 that doesn't have an inverse for the identity 1.
(Z,⋅)is not a group because we can find elements that don't have an inverse for the identity 1
Exercise
Is (Z/nZ∖{0},⋅)a group? If yes why? If not, are there values for nthat make it a group?
sɹosᴉʌᴉp uoɯɯoɔ puɐ sǝɯᴉɹd ʇnoqɐ ʞuᴉɥ┴ :ʇuᴉH
Proprieties
The identity of a group is unique
The inverse of every element is unique
∀a∈G:(a−1)−1=g. The inverse of the inverse of the element is the element itself
∀a,b∈G:(ab)−1=b−1a−1
Proof: (ab)(b−1a−1)=a(bb−1)a−1=aa−1=e.
n =11Zn =Zmod(n)a, b =Zn(5),Zn(7)print(n - (a + b))# 10print((n - a) + (n - b))# 10
Orders
In abstract algebra we have two notions of order: Group order and element order
Group order
The order of a group Gis the number of the elements in that group. Notation: ∣G∣
Element order
The order of an element a∈G is the smallest integer n such that an=1G. If such a number n doesn't exist we say the element has order ∞. Notation: ∣a∣
Z12 =Zmod(12)# Residues modulo 12print(Z12.order())# The additive order # 12a, b=Z12(6),Z12(3)print(a.order(), b.order())# 2 4print(a.order() * a)# 0print(ZZ.order())# The integers under addition is a group of infinite order# +Infinity
We said our messages lay in some group M. The order of this group ∣M∣ is the number of possible messages that we can have. For M={0,1}128we have ∣M∣=2128 possible messages.
Let m∈Mbe some message. The order of m means how many different messages we can generate by applying the group operation on m
Subgroups
Definition
Let (G,⋅) be a group. We say His a subgroup of G if H is a subset of G and (H,⋅)forms a group.
Notation: H≤G
Proprieties
The identity of G is also in H:1H=1G
The inverses of the elements in Hare found in H
How to check H≤G? Let's look at a 2 step test
Closed under operation: ∀a,b∈H→ab∈H
Closed under inverses: ∀a∈H→a−1∈H
Generators
Let Gbe a group,g∈Gan element and ∣g∣=n. Consider the following set:
{1,g,g2,...,gn−1}=denoted⟨g⟩.
This set paired the group operation form a subgroup of Ggenerated by an element g.
Why do we care about subgroups? We praise the fact that some problems are hard because the numbers we use are huge and exhaustive space searches are too hard in practice.
Suppose we have a big secret values space Gand we use an element gto generate them.
If an elementg∈Gwith a small order n is used then it can generate only n possible values and if n is small enough an attacker can do a brute force attack.
Example
For now, trust us that if given a prime p, a value g∈Z/pZ and we compute y=gxmodp for a secret x, finding x is a hard problem. We will tell you why a bit later.
p =101# primeZp =Zmod(p)H_list = Zp.multiplicative_subgroups()# Sage can get the subgroup generators for usprint(H_list)# ((2,), (4,), (16,), (32,), (14,), (95,), (10,), (100,), ())g1 = H_list[3][0] # Weak generatorprint(g1, g1.multiplicative_order())# 32 20g2 =Zp(3)# Strong generatorprint(g2, g2.multiplicative_order())# 3 100## Consider the following functionsdefbrute_force(g,p,secret_value):""" Brute forces a secret value, returns number of attempts """for i inrange(p-1): t =pow(g, i, p)if t == secret_value:breakreturn idefmean_attempts(g,p,num_keys):""" Tries `num_keys` times to brute force and returns the mean of the number of attempts """ total_attempts =0for _ inrange(num_keys): k = random.randint(1, p-1) sv =pow(g, k, p)# sv = secret value total_attempts +=brute_force(g, p, sv)return1.* total_attempts / num_keys## Let's try with our generatorsprint(mean_attempts(g1, p, 100))# Weak generator# 9.850print(mean_attempts(g2, p, 100))# Strong generator# 49.200