arrow-left

All pages
gitbookPowered by GitBook
1 of 3

Loading...

Loading...

Loading...

Discrete Log Problem

hashtag
Discrete log problem

Given any groupGGGand elementsa,ba,ba,bsuch that an=ba^n=ban=b, the problem of solving fornnnis known as the disctete log problem (DLP). In sage, this can be done for general groups by calling discrete_log

hashtag
Discrete log over

Typically, one considers the discrete log problem in , i.e. the multiplicative group of integers. Explicitly, the problem asks forgiven . This can be done by calling b.log(a) in sage:

This section is devoted to helping the reader understand which functions are called when for this specific instance of DLP.

Whenis composite and not a prime power, discrete_log() will be used, which uses generic algorithms to solve DLP (e.g. Pohlig-Hellman and baby-step giant-step).

When is a prime, Pari znlog will be used, which uses a linear sieve index calculus method, suitable for .

When , SageMath will fall back on the generic implementation discrete_log()which can be slow. However, Pari znlog can handle this as well, again using the linear sieve index calculus method. To call this within SageMath we can use either of the following (the first option being a tiny bit faster than the second)

hashtag
Example

Given a small prime, we can compare the Pari method with the Sage defaults

We can also solve this problem with even larger primes in a very short time

hashtag
Discrete log over

// elliptic curve discrete log functions

sage: G = DihedralGroup(99)
sage: g = G.random_element()
sage: discrete_log(g^9,g) # note that if the order of g is less than 9 we would get 9 mod g.order()
9

Another take on groups

// Visual

// Symmetries

// Permutations

(Z/nZ)βˆ—\left(\mathbb Z/n\mathbb Z\right)^*(Z/nZ)βˆ—
(Z/nZ)βˆ—\left(\mathbb Z/n\mathbb Z\right)^*(Z/nZ)βˆ—
modΒ n\text{mod }nmodΒ n
xxx
ax=b(modn)a^x=b\pmod nax=b(modn)
nnn
n=pn=pn=p
p<1050∼2166p < 10^{50} \sim 2 ^{166}p<1050∼2166
n=pkn = p^kn=pk
E(k)E(k)E(k)
sage: R = Integers(99)
sage: a = R(4)
sage: b = a^9
sage: b.log(a)
9
x = int(pari(f"znlog({int(b)},Mod({int(a)},{int(n)}))"))
x = gp.znlog(b, gp.Mod(a, n))
p = getPrime(36)
n = p^2
K = Zmod(n)
a = K.multiplicative_generator()
b = a^123456789

time int(pari(f"znlog({int(b)},Mod({int(a)},{int(n)}))")) 
# CPU times: user 879 Β΅s, sys: 22 Β΅s, total: 901 Β΅s
# Wall time: 904 Β΅s
# 123456789

time b.log(a)
# CPU times: user 458 ms, sys: 17 ms, total: 475 ms
# Wall time: 478 ms
# 123456789

time discrete_log(b,a)
# CPU times: user 512 ms, sys: 24.5 ms, total: 537 ms
# Wall time: 541 ms
# 123456789
p = getPrime(100)
n = p^2
K = Zmod(n)
a = K.multiplicative_generator()
b = a^123456789

time int(pari(f"znlog({int(b)},Mod({int(a)},{int(n)}))")) 
# CPU times: user 8.08 s, sys: 82.2 ms, total: 8.16 s
# Wall time: 8.22 s
# 123456789

Groups

Authors: Ariana, Zademn Reviewed by:

hashtag
Introduction

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 sets M,K\mathcal{M}, \mathcal{K}M,K and C\mathcal{C}C.

Furthermore, to get a ciphertext we usually perform some operations with the message and the key.

circle-check

For example in AES128 since the input, output and key spaces are 128 bits. We also have the encryption and decryption operations:

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.

hashtag
Definition

A setpaired with a binary operation is a group if the following requirements hold:

  • Closure: For all - Applying the operation keeps the element in the set

  • Associativity: For all

  • Identity: There exists an elementsuch that

For , means when and when . For , .

If , then is commutative and the group is called abelian. We often denote the group operation by instead of and we typically use instead of .

Remark

  • The identity element of a group is also denoted with or just if only one groups is present

Examples of groups

Integers modulo (remainders) under modular addition . Let's look if the group axioms are satisfied

  1. . Because of the modulo reduction

  2. Modular addition is associative

  3. is the identity element

Therefore we can conclude that the integers mod with the modular addition form a group.

Example of non-groups

is not a group because we can find the element that doesn't have an inverse for the identity . is not a group because we can find elements that don't have an inverse for the identity

Exercise

Is a group? If yes why? If not, are there values for that make it a group?

sΙΉosα΄‰ΚŒα΄‰p uoΙ―Ι―oΙ” puɐ sǝɯᴉɹd Κ‡noqɐ ʞuᴉΙ₯β”΄ :Κ‡uᴉH

hashtag
Proprieties

  1. The identity of a group is unique

  2. The inverse of every element is unique

  3. . The inverse of the inverse of the element is the element itself

hashtag
Orders

In abstract algebra we have two notions of order: Group order and element order

Group order

The order of a group is the number of the elements in that group. Notation:

Element order

The order of an element is the smallest integer such that . If such a number doesn't exist we say the element has order . Notation:

circle-check

We said our messages lay in some group . The order of this group is the number of possible messages that we can have. For we have possible messages.

circle-check

Let be some message. The order of means how many different messages we can generate by applying the group operation on

hashtag
Subgroups

Definition

Let be a group. We say is a subgroup of if is a subset of and forms a group. Notation:

Proprieties

  1. The identity of is also in

  2. The inverses of the elements in are found in

How to check ? Let's look at a 2 step test

  1. Closed under operation:

  2. Closed under inverses:

hashtag
Generators

Let be a group,an element and . Consider the following set:

This set paired the group operation form a subgroup of generated by an element .

circle-check

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 and we use an element to generate them.

If an elementwith a small order is used then it can generate only possible values and if

Example

For now, trust us that if given a prime , a value and we compute for a secret , finding is a hard problem. We will tell you why a bit later.

hashtag
Examples

// subgroups, quotient groups

// cyclic groups

for all
  • Inverse: For all elements a∈Ga\in Ga∈G, there exists some b∈Gb\in Gb∈Gsuch that bβ‹…a=aβ‹…b=eb\cdot a=a\cdot b=ebβ‹…a=aβ‹…b=e. We usually denotebbbas aβˆ’1a^{-1}aβˆ’1

  • βœ“\checkmarkβœ“βˆ€a∈Z/nZ\forall a \in \mathbb{Z}/ n\mathbb{Z} βˆ€a∈Z/nZwe take nβˆ’aβ€Šmodβ€Šnn - a \bmod nnβˆ’amodnto be the inverse of aaa. We check that

    a+nβˆ’a≑n≑0β€Šmodβ€Šna + n - a \equiv n \equiv 0 \bmod na+nβˆ’a≑n≑0modn

    nβˆ’a+a≑n≑0β€Šmodβ€Šnn - a + a \equiv n \equiv 0 \bmod nnβˆ’a+a≑n≑0modn

    βˆ€a,b∈G:\forall a, b \in G: βˆ€a,b∈G: (ab)βˆ’1=bβˆ’1aβˆ’1(ab)^{-1} = b^{-1}a^{-1}(ab)βˆ’1=bβˆ’1aβˆ’1

    Proof: (ab)(bβˆ’1aβˆ’1)=a(bbβˆ’1)aβˆ’1=aaβˆ’1=e.(ab)(b^{βˆ’1}a^{βˆ’1}) =a(bb^{βˆ’1})a^{βˆ’1}=aa^{βˆ’1}= e.(ab)(bβˆ’1aβˆ’1)=a(bbβˆ’1)aβˆ’1=aaβˆ’1=e.

    is small enough an attacker can do a brute force attack.
    K=M=C={0,1}128\mathcal{K} = \mathcal{M} = \mathcal{C} = \{0, 1\}^{128}K=M=C={0,1}128
    Enc:K×M→CDec:K×C→MEnc: \mathcal{K} \times \mathcal{M} \to \mathcal{C} \\ Dec: \mathcal{K} \times \mathcal{C} \to \mathcal{M}Enc:K×M→CDec:K×C→M
    GGG
    ⋅:G×G→G\cdot:G\times G\to G⋅:G×G→G
    a,b∈G: a, b \in G: \ a,b∈G: 
    aβ‹…b∈Ga\cdot b \in Gaβ‹…b∈G
    a,b,c∈G:a, b, c \in G: a,b,c∈G:
    (aβ‹…b)β‹…c=aβ‹…(bβ‹…c)(a \cdot b) \cdot c=a\cdot (b\cdot c)(aβ‹…b)β‹…c=aβ‹…(bβ‹…c)
    e∈Ge\in Ge∈G
    aβ‹…e=eβ‹…a=aa\cdot e=e\cdot a=aaβ‹…e=eβ‹…a=a
    n∈Zn\in\mathbb Zn∈Z
    ana^nan
    aβ‹…a…⋅a⏟nΒ times\underbrace{a\cdot a\dots{}\cdot a}_{n\text{ times}}nΒ timesaβ‹…a…⋅a​​
    n>0n>0n>0
    (aβˆ’n)βˆ’1\left(a^{-n}\right)^{-1}(aβˆ’n)βˆ’1
    n<0n<0n<0
    n=0n=0n=0
    an=ea^n=ean=e
    ab=baab=baab=ba
    β‹…\cdotβ‹…
    +++
    β‹…\cdotβ‹…
    nanana
    ana^nan
    GGG
    1G1_G1G​
    111
    nnn
    =(Z/nZ,+)= (\mathbb{Z} / n \mathbb{Z}, +)=(Z/nZ,+)
    Z/nZ={0,1,...,nβˆ’1}\mathbb{Z} / n \mathbb{Z} = \{0, 1, ..., n -1\}Z/nZ={0,1,...,nβˆ’1}
    βœ“\checkmarkβœ“
    βˆ€a,b∈Z/nZΒ letΒ c≑a+bβ€Šmodβ€Šn\forall a, b \in \mathbb{Z}/ n\mathbb{Z} \text{ let } c \equiv a + b \bmod nβˆ€a,b∈Z/nZΒ letΒ c≑a+bmodn
    c<nβ‡’c∈Z/nZc < n \Rightarrow c \in \mathbb{Z}/ n\mathbb{Z} c<nβ‡’c∈Z/nZ
    βœ“\checkmarkβœ“
    βœ“\checkmark βœ“
    0+a≑a+0≑aβ€Šmodβ€Šnβ‡’00 + a \equiv a + 0 \equiv a \bmod n \Rightarrow 00+a≑a+0≑amodnβ‡’0
    nnn
    (Q,β‹…)(\mathbb{Q}, \cdot)(Q,β‹…)
    000
    111
    (Z,β‹…)(\mathbb{Z}, \cdot)(Z,β‹…)
    111
    (Z/nZβˆ–{0},β‹…)(\mathbb{Z} / n \mathbb{Z} \smallsetminus \{0\}, \cdot)(Z/nZβˆ–{0},β‹…)
    nnn
    βˆ€\forallβˆ€
    a∈GΒ :(aβˆ’1)βˆ’1=ga \in G \ : \left(a^{-1} \right) ^{-1} = ga∈GΒ :(aβˆ’1)βˆ’1=g
    GGG
    ∣G∣|G|∣G∣
    a∈Ga \in Ga∈G
    nnn
    an=1Ga^n = 1_Gan=1G​
    nnn
    ∞\infty∞
    ∣a∣|a|∣a∣
    M\mathcal{M}M
    ∣M∣|\mathcal{M}|∣M∣
    M={0,1}128\mathcal{M} = \{0,1\}^{128}M={0,1}128
    ∣M∣=2128|\mathcal{M}| = 2^{128}∣M∣=2128
    m∈Mm \in \mathcal{M}m∈M
    mmm
    mmm
    (G,β‹…)(G, \cdot)(G,β‹…)
    HHH
    GGG
    HHH
    GGG
    (H,β‹…)(H, \cdot)(H,β‹…)
    H≀GH \leq GH≀G
    GGG
    H:H: H:
    1H=1G1_H = 1_G1H​=1G​
    HHH
    HHH
    H≀GH \leq GH≀G
    βˆ€a,b∈Hβ†’ab∈H\forall a, b \in H \to ab \in Hβˆ€a,b∈Hβ†’ab∈H
    βˆ€a∈Hβ†’aβˆ’1∈H\forall a \in H \to a^{-1} \in Hβˆ€a∈Hβ†’aβˆ’1∈H
    GGG
    g∈Gg \in Gg∈G
    ∣g∣=n|g| = n∣g∣=n
    {1,g,g2,...,gnβˆ’1}=denoted⟨g⟩.\{1, g, g^2, ..., g^{n-1}\} \overset{\text{denoted}}{=} \langle g\rangle.{1,g,g2,...,gnβˆ’1}=denoted⟨g⟩.
    GGG
    ggg
    GGG
    ggg
    g∈Gg \in Gg∈G
    nnn
    nnn
    nnn
    ppp
    g∈Z/pZg \in \mathbb{Z} / p \mathbb{Z}g∈Z/pZ
    y=gxβ€Šmodβ€Špy = g^x \bmod py=gxmodp
    xxx
    xxx
    a∈Ga\in Ga∈G
    Z5 = Zmod(5) # Technically it's a ring but we'll use the addition here
    print(Z5.list())
    # [0, 1, 2, 3, 4]
    
    print(Z5.addition_table(names = 'elements'))
    # +  0 1 2 3 4
    #  +----------
    # 0| 0 1 2 3 4
    # 1| 1 2 3 4 0
    # 2| 2 3 4 0 1
    # 3| 3 4 0 1 2
    # 4| 4 0 1 2 3
    
    a, b = Z5(14), Z5(3)
    print(a, b)
    # 4 3
    print(a + b)
    # 2
    print(a + 0)
    # 4
    print(a + (5 - a))
    # 0
    
    n = 11
    Zn = Zmod(n)
    a, b = Zn(5), Zn(7)
    print(n - (a + b))
    # 10
    print((n - a) + (n - b))
    # 10
    Z12 = Zmod(12) # Residues modulo 12
    print(Z12.order()) # The additive order 
    # 12
    a, b= Z12(6), Z12(3)
    print(a.order(), b.order())
    # 2 4
    print(a.order() * a)
    # 0
    
    print(ZZ.order()) # The integers under addition is a group of infinite order
    # +Infinity
    p = 101 # prime
    Zp = Zmod(p) 
    H_list = Zp.multiplicative_subgroups() # Sage can get the subgroup generators for us
    print(H_list)
    # ((2,), (4,), (16,), (32,), (14,), (95,), (10,), (100,), ())
    
    g1 = H_list[3][0] # Weak generator
    print(g1, g1.multiplicative_order())
    # 32 20
    
    g2 = Zp(3) # Strong generator
    print(g2, g2.multiplicative_order())
    # 3 100
    
    
    ## Consider the following functions
    def brute_force(g, p, secret_value):
        """
        Brute forces a secret value, returns number of attempts
        """
        for i in range(p-1):
            t = pow(g, i, p)
            if t == secret_value:
                break
        return i
        
    def mean_attempts(g, p, num_keys):
        """
        Tries `num_keys` times to brute force and 
        returns the mean of the number of attempts
        """
        total_attempts = 0
        for _ in range(num_keys):
            k = random.randint(1, p-1)
            sv = pow(g, k, p) # sv = secret value
            total_attempts += brute_force(g, p, sv)
        return 1. * total_attempts / num_keys
        
    ## Let's try with our generators
    print(mean_attempts(g1, p, 100)) # Weak generator
    # 9.850
    print(mean_attempts(g2, p, 100)) # Strong generator
    # 49.200