Random math for cryptography

Greatest common divisor

Given two integers aa and bb, with b≠0b \neq 0, we say that bb divides aa if ∃\exists and integer cc such that the following equality is satisfied:

a=bca = bc

If that cc exists, then we write b∣ab \mid a, otherwise b∤ab \nmid a.

Despite we are used to consider the concept of division fairly simple, it plays a fundamental role in modern cryptography and it deserve additional attention.

[Proposition]

Let a,b,c∈Za, b, c \in \mathbb{Z} be three integers:

  1. If a∣ba \mid b and b∣cb \mid c ⇒a∣c\Rightarrow a \mid c
  2. If a∣ba \mid b and b∣ab \mid a ⇒a±b\Rightarrow a \pm b
  3. If a∣ba \mid b and a∣aa \mid a ⇒a∣(b+c)\Rightarrow a \mid (b + c) and a∣(b−c)a \mid (b - c)

Amongst all the divisors that are in common between two numbers, we are particularly interested in the greatest common division.

[Definition] Greatest common division

Let a,b∈Za, b \in \mathbb{Z} be two integers, we define the greatest common divisor as the largest integer dd such that:

d∣a,d∣bd \mid a,\quad d \mid b

The greatest common divisor between two numbers is commonly written as. gcd⁡(a,b)\gcd(a,b)

When the gcd⁡(a,b)=1\gcd(a,b) = 1, then we say that the two numbers are relatively prime.

Is it possible to compute efficiently the gcd⁡(a,b)\gcd(a,b) using the method of long division, also called the Euclidean algorithm. To understand how the algorithm works, it is useful to consider the generic division form between two numbers:

a=bq+rwith0≤r<ba = bq + r \quad \text{with} \quad 0 \le r < b

In this case, qq is called the quotient, and rr is the reminder. With this equation, we can present an equality used in the next theorem:

gcd⁡(a,b)=gcd⁡(b,r)\gcd(a,b) = \gcd(b,r)

This equality states that the greatest common divisor between two numbers, is equal to the greatest common divisor between the lowest of the two, and the reminder of their division.

[Theorem] The Euler Algorithm

Let aa and bb two positive numbers in Z\mathbb{Z} such that a≥ba \ge b. We can compute the gcd⁡(a,b)\gcd(a,b) in a finite number of steps with the following algorithm:

  1. Let r0=ar_0 = a, r1=br_1=b, and set i=1i=1.
  2. Divide ri−1r_{i-1} by rir_i to get the quotient qq and the reminder ri+1r_{i+1};
ri−1=ri⋅q+ri+1r_{i-1} = r_i \cdot q + r_{i+1}
  1. We have to situations here:
    1. If the reminder is equal to zero, we terminate with:

      gcd⁡(a,b)=ri\gcd(a,b) = r_i
    2. Otherwise, we set i=i+1i = i +1 and go back to point 2.

From the application of the Euclidean algorithm, we can obtain another important theorem for cryptography, which allows us to write the gcd⁡(a,b)\gcd(a,b) as a linear combination of aa and bb.

[Theorem] Extended Euclidean Algorithm

Let aa and bb two positive numbers in Z\mathbb{Z}. The following combination has always a solution with uu and vv in Z\mathbb{Z}:

au+bv=gcd⁡(a,b)au + bv = \gcd(a,b)

An interesting alternative formulation of the same equation, is the one for relatively prime numbers:

Agcd⁡(A,B)u+Bgcd⁡(A,B)v=1\frac{A}{\gcd(A,B)}u + \frac{B}{\gcd(A,B)}v = 1

Before we mentioned that we have an algorithm to compute the gcd⁡\gcd efficiently. But, what does it mean to compute something in an efficient way?

The Euclidean algorithm has O(log⁡2n)\mathcal{O}(\log_2n) complexity since it is possible to demonstrate that ri+2<rir_{i+2} < r_i, so every two steps we have a reduction by half.

The fast powering algorithm

TODO

References

  1. Hoffstein, Pipher, Silverman, An Introduction to Mathematical Cryptography, Chapter 2