Professional Documents
Culture Documents
Agenda
Cryptography
Chapter 1: Mathematics for Cryptography
Modular Arithmetic Euclidean Algorithms Euler's Function Fermat Theorem Chinese Remainder Theorem Chapter 2: Symmetric Cryptography Chapter 3: Asymmetric Cryptography Chapter 4: Authentication Chapter 5: Key Distribution
-
Agenda
Chapter 1: Mathematics for Cryptography
-
Modular Arithmetic
Division Congruence n Arithmetic
! ! !
Division
Let a ! and n !
-
a=q!n+r
! !
0"r<n q = "a/n#
If a, n !
!
and n > 0
a = "a/n# + (a mod n)
Division (2)
Modulo example
-
a = 59; n = 7
! !
59 = 8 ! 7 + 3
r = 3, q = 8 59 mod 7 = 3
Division (3)
Let a, b, and m !
-
Division (4)
Properties
-
Demonstrating Prop. 4
-
if a|1 then a = 1 if a|b and b|a then a = b any b " 0 divides 0 if b|g and b|h then b|(mg + nh), for any m, n if a = 0 mod n then n|a if b|g, then g = b ! g1 if b|h, then h = b ! h1 it comes
Division (5)
Divisibility criteria
-
2|n if n ends with 0, 2, 4, 6, 8 3|n if the sum of n numbers are divisible by 3 4|n if last 2 n numbers are divisible by 4
example: 256,628
Congruence
Two integers, a and b, are said equal modulo n if
n|a-b Two integers, a and b, are said congruent modulo n if a mod n = b mod n
-
Notation
!
a # b mod n
Congruence (2)
Congruence examples
-
26 # 12 mod 7
26 mod 7 = 5 12 mod 7 = 5
! !
21 # -9 mod 10
! !
21 mod 10 = 1 -9 mod 10 = 1
10
Congruence (3)
Properties
-
a # b mod n iff n|a-b a # b mod n iff ca # cb mod cn a # b mod n iff ac # bc mod n a # b mod n iff b # a mod n if a # b mod n, then (a-b) mod n = 0 if a # b mod n, then b # a mod n
symmetry transitivity
11
Congruence (4)
Examples
! !
26 # 12 mod 7
(26-12) mod 7 = 14 mod 7 = 0 12 # 26 mod 7 car 12 mod 7 = 26 mod 7
26 mod 7 = 5 19 mod 7 = 5
12
Congruence (5)
Properties (cont.)
-
(54+49) mod 15 = 103 mod 15 = 13 54 mod 15 = 9 49 mod 15 = 4 (54 mod 15 + 49 mod 15) = 9 + 4 = 13
!
13 mod 15 = 13
!
" " " "
19 mod 15 = 4
INFO0045 - ULg - 2013/2014 - Benoit Donnet 13
Properties (cont.)
-
Congruence (6)
(x ! y) mod n = (x mod n ! y mod n) mod n modular multiplication examples ! (49 ! 54) mod 15 (49 ! 54) mod 15 = 2646 mod 15 = 6
" " " "
36 mod 15 = 6
!
" " " "
84 mod 15 = 9
14
Congruence (7)
Properties (cont.)
-
it is possible to extend the modular multiplication (a ! b ! c) mod n ! = ((a mod n) ! (b mod n) ! (c mod n)) mod n ! = (((a mod n) ! (b mod n) mod n) ! c mod n)) mod n (a ! b ! c ! d) mod n ! = ((a mod n) ! (b mod n) ! (c mod n) ! (d mod n)) mod n (a ! b ! c ! d ! e) mod n etc.
15
Congruence (8)
Example: (42 ! 56 ! 98 ! 108) mod 15 Brute force approach
-
(42 ! 56 ! 98 ! 108) mod 15 = 234,893,568 mod 15 = 3 42 mod 15 = 12 56 mod 15 = 11 98 mod 15 = 8 108 mod 15 = 3
16
Congruence (9)
Smart approach, v.2
1. (42 ! 56) mod 15 ! ((42 mod 15) ! (56 mod 15)) mod 15 = (12 ! 11) mod 15 = 12 2. (42 ! 56 ! 98) mod 15
! !
(12 ! 98) mod 15 = ((12 mod 15) ! (98 mod 15)) mod 15 (12 ! 8) mod 15 = 6 (6 ! 108) mod 15 = ((6 mod 15) ! (108 mod 15)) mod 15 (6 ! 3) mod 15 = 3
17
Congruence (10)
Modular exponentiation
!
ai 2i
ai 2
n 1 Y i=0
i
(b2 )ai
Congruence (11)
Example: 541 mod 9 Brute force approach
-
! !
(51 ! 51) mod 9 = (5 ! 5) mod 9 = 25 mod 9 = 7 (52 ! 52) mod 9 = ((52 mod 9) ! (52 mod 9)) mod 9 49 mod 9 = 4
INFO0045 - ULg - 2013/2014 - Benoit Donnet 19
54 mod 9
! !
Congruence (12)
!
58 mod 9
! !
(54 ! 54) mod 9 = (54 mod 9 ! 54 mod 9) mod 9 (4 ! 4) mod 9 = 7 (58 ! 58) mod 9 = (58 mod 9 ! 58 mod 9) mod 9 (7 ! 7) mod 9 = 4 (516 ! 516) mod 9 = (516 mod 9 ! 516 mod 9) mod 9 (4 ! 4) mod 9 = 7
516 mod 9
! !
532 mod 9
! !
it comes
!
541 mod 9
! ! ! ! !
n Arithmetic
The modulo n operator maps all integers
-
(negatives and positives) that are congruent modulo n in the set {0, 1, ..., n-1}
residue class modulo n mathematical notation:
n
[r] = {a: a ! , a # r mod n} [0] = {..., -16, -12, -8, -4, 0, 4, 8, 12, 16, ...} [1] = {..., -15, -11, -7, -3, 1, 5, 9, 13, 17, ...} [2] = {..., -14, -10, -6, -2, 2, 6, 10, 14, 18, ...} [3] = {..., -13, -9, -5, -1, 3, 7, 11, 15, 19, ...}
INFO0045 - ULg - 2013/2014 - Benoit Donnet 21
n Arithmetic
Properties of modular arithmetic in
-
(2)
n
commutativity
! !
(w + x) mod n = (x + w) mod n (w ! x) mod n = (x ! w) mod n [(w + x) + y] mod n = [w + (x + y)] mod n [(w ! x) ! y] mod n = [w ! (x ! y)] mod n [w ! (x + y)] mod n = [(w ! x) + (w ! y)] mod n (0 + w) mod n = w mod n (1 ! w) mod n = w mod n for each w !
n,
associativity
! !
distributivity
!
identity
! !
n Arithmetic
Properties of modular arithmetic in
-
(2)
n (cont.)
addition
! !
(a + b) # (a + c) mod n $ b # c mod n example: (5 + 23) # (5 + 7) mod 8 $ 23 # 7 mod 8 if a and n relatively prime, then a ! b # a ! c mod n $ b # c mod n the condition must be satisfied otherwise, the property does not hold example:
" "
multiplication
! !
23
Agenda
Chapter 1: Mathematics for Cryptography
-
! ! !
24
GCD
Greatest Common Divisor Let c ! , c = gcd(a, b) if
-
Equivalent definition
-
c is a divisor of a and b any divisor of a and b is a divisor of c gcd(a, b) = max{k, such that k|a and k|b} gcd(a, b) = gcd(a, -b) = gcd(-a, b) = gcd(-a, -b) gcd(a, b) = gcd(|a|, |b|)
INFO0045 - ULg - 2013/2014 - Benoit Donnet
25
GCD (2)
Interesting use of gcd
-
two integers are relatively prime if their only common factor is 1 let a and c be relatively prime
(a, c) = 1 gcd(a, c) = 1
! !
26
GCD (3)
Euclidean algorithm for finding the gcd
gcd(int a, int b){ if(b == 0) return a; else return gcd(b, a mod b); }//end gcd()
27
GCD (4)
Example: gcd(1970, 1066)
Step
1 2 3 4 10
a
1066 904 162 94 2
b
1970 mod 1066 = 904 1066 mod 904 = 162 904 mod 162 = 94 162 mod 94 = 68 a few recursive calls later... 0
INFO0045 - ULg - 2013/2014 - Benoit Donnet
call
gcd(1066, 904) gcd(904, 162) gcd(162, 94) gcd(94, 68)
28
Extended Euclide
There exists an extension to the Euclidean
algorithm
! !
it not only finds the gcd but also two additional integers, x and y, satisfying
ax + by = gcd(a, b) Bezout's identity
29
30
a
53 30 23 7 2 1
b
30 23 7 2 1 0
x
0 1 -1 4 -13 30
lastx
1 0 1 -1 4 -13
y
1 -1 2 -7 23 -53
lasty
0 1 -1 2 -7 23
31
Equation
Euclide allows us to solve equations of the form
-
How to solve?
-
ax # b mod n algorithm
equation(a, b, n){ (d, x', y') = extended_euclidean(a, n); if(d|b) x0 = (x' " (b/d)) mod n for i=0 until d-1 write (x0 + i " (n/d)) mod n else write "no solution" }//end equation()
32
Equation (2)
Example:
-
Solution
!
3 is a divisor of 9
! !
i=0, 9 mod 15 i=1, 9 + (15/3) mod 15 => 14 mod 15 i=2, 9 + 2 ! (15/3) mod 15 => 19 mod 15
33
Agenda
Chapter 1: Mathematics for Cryptography
-
Modular Arithmetic Euclidean Algorithms Euler's Function Fermat's Theorem Chinese Remainder Theorem
34
Euler's Function
Euler's Totient Function
-
$(n) number of integers between 0 and n-1 that are prime with n
Example
!
"!#
"
#"
$"
%"
&"
'"
("
!"
!
INFO0045 - ULg - 2013/2014 - Benoit Donnet 36
if n and m !
! ! !
si n = p ! q, p et q premiers
!
37
Agenda
Chapter 1: Mathematics for Cryptography
-
Modular Arithmetic Euclidean Algorithms Euler's Function Fermat's Theorem Chinese Remainder Theorem
38
Fermat
Little Fermat's Theorem
!
If gcd(a, m) = 1
then a$(m) # 1 mod m
if gcd(a, m) = 1
! !
the multiplicative inverse of a in the modulo class m is a$(m)-1 a$(m)-1 # a-1 mod m in the particular case in which m is prime
!
Agenda
Chapter 1: Mathematics for Cryptography
-
Modular Arithmetic Euclidean Algorithms Euler's Function Fermat's Theorem Chinese Remainder Theorem
40
Chinese Remainder
Let m1, m2, ..., mr, all positive integers and
x x ... x
y1 = 2 y2 = 1 y3 = 1