CS/ECE Advanced Network Security Dr. Attila Altay Yavuz

Slides:



Advertisements
Similar presentations
1 Lect. 12: Number Theory. Contents Prime and Relative Prime Numbers Modular Arithmetic Fermat’s and Euler’s Theorem Extended Euclid’s Algorithm.
Advertisements

Computer Science CSC 474Dr. Peng Ning1 CSC 474 Information Systems Security Topic 2.3 Basic Number Theory.
Cryptography and Network Security
Chapter 8 – Introduction to Number Theory. Prime Numbers prime numbers only have divisors of 1 and self –they cannot be written as a product of other.
The Integers and Division. Outline Division: Factors, multiples Exercise 2.3 Primes: The Fundamental Theorem of Arithmetic. The Division Algorithm Greatest.
Chapter 8 Introduction To Number Theory. Prime Numbers Prime numbers only have divisors of 1 and Prime numbers only have divisors of 1 and self. self.
Chapter 8 Introduction to Number Theory. Prime Numbers prime numbers only have divisors of 1 and self –they cannot be written as a product of other numbers.
Primality Testing Patrick Lee 12 July 2003 (updated on 13 July 2003)
1 Section 2.4 The Integers and Division. 2 Number Theory Branch of mathematics that includes (among other things): –divisibility –greatest common divisor.
Notation Intro. Number Theory Online Cryptography Course Dan Boneh
CNS2010handout 8 :: introduction to number theory1 computer and network security matt barrie.
CSC2110 Discrete Mathematics Tutorial 5 GCD and Modular Arithmetic
1 Chapter 7– Introduction to Number Theory Instructor: 孫宏民 Room: EECS 6402, Tel: , Fax :
The RSA Cryptosystem and Factoring Integers (II) Rong-Jaye Chen.
6/20/2015 5:05 AMNumerical Algorithms1 x x1x
Complexity1 Pratt’s Theorem Proved. Complexity2 Introduction So far, we’ve reduced proving PRIMES  NP to proving a number theory claim. This is our next.
Chapter 4 – Finite Fields Introduction  will now introduce finite fields  of increasing importance in cryptography AES, Elliptic Curve, IDEA, Public.
Cryptography & Number Theory
Chapter 8 – Introduction to Number Theory Prime Numbers  prime numbers only have divisors of 1 and self they cannot be written as a product of other numbers.
Lecture 3.2: Public Key Cryptography II CS 436/636/736 Spring 2012 Nitesh Saxena.
Chapter 8 – Introduction to Number Theory Prime Numbers
Chapter 8 – Introduction to Number Theory Prime Numbers  prime numbers only have divisors of 1 and self they cannot be written as a product of other numbers.
Integers Number Theory = Properties of Integers

Great Theoretical Ideas in Computer Science.
COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)
Module :MA3036NI Cryptography and Number Theory Lecture Week 7
1 Cryptography and Network Security Third Edition by William Stallings Lecture slides by Lawrie Brown Chapter 4 – Finite Fields.
Information Security and Management 4. Finite Fields 8
Prelude to Public-Key Cryptography Rocky K. C. Chang, February
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 31.
Basic Number Theory Divisibility Let a,b be integers with a≠0. if there exists an integer k such that b=ka, we say a divides b which is denoted by a|b.
The RSA Algorithm. Content Review of Encryption RSA An RSA example.
YSLInformation Security -- Public-Key Cryptography1 Prime and Relatively Prime Numbers Divisors: We say that b  0 divides a if a = mb for some m, where.
Greatest Common Divisor Jordi Cortadella Department of Computer Science.
Fall 2002CS 395: Computer Security1 Chapters 4 and 8: The Mathematics Required for Public Key Cryptography In case you’re beginning to worry that this.
CSE 311: Foundations of Computing Fall 2014 Lecture 12: Primes, GCD.
Information Security Lab. Dept. of Computer Engineering 87/121 PART I Symmetric Ciphers CHAPTER 4 Finite Fields 4.1 Groups, Rings, and Fields 4.2 Modular.
Lecture 6.1: Misc. Topics: Number Theory CS 250, Discrete Structures, Fall 2011 Nitesh Saxena.
9/22/15UB Fall 2015 CSE565: S. Upadhyaya Lec 7.1 CSE565: Computer Security Lecture 7 Number Theory Concepts Shambhu Upadhyaya Computer Science & Eng. University.
MA/CSSE 473 Day 08 Extended Euclid's Algorithm Modular Division Fermat's little theorem.
Cryptography and Network Security Chapter 4. Introduction  will now introduce finite fields  of increasing importance in cryptography AES, Elliptic.
Tuesday’s lecture: Today’s lecture: One-way permutations (OWPs)
Ref: Pfleeger96, Ch.31 Properties of Arithmetic Reference: Pfleeger, Charles P., Security in Computing, 2nd Edition, Prentice Hall, 1996.
Lecture 3.1: Public Key Cryptography I CS 436/636/736 Spring 2015 Nitesh Saxena.
Pertemuan #5 Pengantar ke Number Theory Kuliah Pengaman Jaringan.
Dan Boneh Intro. Number Theory Fermat and Euler Online Cryptography Course Dan Boneh.
Introduction to Number Theory Department of Computer Engineering Sharif University of Technology 3/8/2006.
CSE 311: Foundations of Computing Fall 2013 Lecture 12: Primes, GCD, modular inverse.
CS480 Cryptography and Information Security
Number-Theoretic Algorithms
Discrete Math II Howon Kim
Introduction to Number Theory
Advanced Algorithms Analysis and Design
Prelude to Public-Key Cryptography
Lecture 3.2: Public Key Cryptography II
Numerical Algorithms x x-1 Numerical Algorithms
Number-Theoretic Algorithms (UNIT-4)
Introduction to Number Theory
Number Theory and Modular Arithmetic
Numerical Algorithms x x-1
Number Theory (Chapter 7)
Cryptography and Network Security
Prime and Relatively Prime Numbers
Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching
刘振 上海交通大学 计算机科学与工程系 电信群楼3-509
Lecture 3.1: Public Key Cryptography I
Mathematical Background for Cryptography
Patrick Lee 12 July 2003 (updated on 13 July 2003)
Number Theory.
Presentation transcript:

CS/ECE Advanced Network Security Dr. Attila Altay Yavuz Topic 4 Basic Number Theory Credit: Prof. Dr. Peng Ning Advanced Network Security Dr. Attila Altay Yavuz Fall 2014

Outline GCD Totient (Euler-Phi), relative primes Euclid and Extended Euclid Algorithm Little Fermat, Generalized Fermat Theorem Order of element/group, Lagrange Theorem Modular Exponentiation Discrete Logarithms

Greatest Common Divisor (GCD) gcd(a,b) = max{k | k|a and k|b} Observations gcd(a,b) = gcd(|a|, |b|) gcd(a,b)  min(|a|, |b|) if 0  n, then gcd(an, bn) = n*gcd(a,b) For all positive integers d, a, and b… …if d | ab …and gcd(a,d) = 1 …then d|b Example: gcd(60,24) = 12, gcd(a,0) = a

GCD (Cont’d) Computing GCD by hand: if a = p1a1 p2a2 … prar and b = p1b1 p2b2 … prbr , …where p1 < p2 < … < pr are prime, …and ai and bi are nonnegative, …then gcd(a, b) = p1 min(a1, b1) p2 min(a2, b2) … pr min(ar, br) Slow way to find the GCD requires factoring a and b first (which, as we will see, can be slow)

Relatively Prime Integers a and b are relatively prime iff gcd(a,b) = 1 example: 8 and 15 are relatively prime Integers n1,n2,…nk are pairwise relatively prime if gcd(ni,nj) = 1 for all i  j

The Totient Function (Euler-Phi Function) (n) = |Zn*| = the number of integers less than n and relatively prime to n if n is prime, then (n) = n-1 if n = p, where p is prime and  > 0, then (n) = (p-1)*p-1 if n=pq, and p, q are relatively prime, then (n) = (p)*(q) Example: (7) = 6 Example: (25) = (52) = 4*51 = 20 Example: (15) = (5*3) = (5) * (3) = 4 * 2 = 8

Multiplicative Group Zn* Let Zn* be the set of numbers between 1 and n-1 that are relatively prime to n Zn* is closed under multiplication mod n Ex.: Z8* = {1,3,5,7} * 1 3 5 7 * 1 3 5 7

Euclid’s Algorithm for GCD Insight: gcd(x, y) = gcd(y, x mod y) Procedure euclid(x, y): r[0] = x, r[1] = y, n = 1; while (r[n] != 0) { n = n+1; r[n] = r[n-2] % r[n-1]; } return r[n-1];

Example n rn 595 1 408 2 595 mod 408 = 187 3 408 mod 187 = 34 4 187 mod 34 = 17 5 34 mod 17 = 0 gcd(595,408) = 17

Running Time Running time is logarithmic in size of x and y Worst case occurs when ??? Enter x and y: 102334155 63245986 Step 1: r[i] = 39088169 Step 2: r[i] = 24157817 Step 3: r[i] = 14930352 Step 4: r[i] = 9227465 … Step 35: r[i] = 3 Step 36: r[i] = 2 Step 37: r[i] = 1 Step 38: r[i] = 0 gcd of 102334155 and 63245986 is 1 Worst case occurs when a and b are Fibonacci numbers running time logarithmic in size of a or b otherwise, running time is less

Extended Euclid’s Algorithm Let LC(x,y) = {ux+vy : x,y  Z} be the set of linear combinations of x and y Theorem: if x and y are any integers > 0, then gcd(x,y) is the smallest positive element of LC(x,y) Euclid’s algorithm can be extended to compute u and v, as well as gcd(x,y) Procedure exteuclid(x, y): (next page…)

Extended Euclid’s Algorithm r[0] = x, r[1] = y, n = 1; u[0] = 1, u[1] = 0; v[0] = 0, v[1] = 1; while (r[n] != 0) { n = n+1; r[n] = r[n-2] % r[n-1]; q[n] = (int) (r[n-2] / r[n-1]); u[n] = u[n-2] – q[n]*u[n-1]; v[n] = v[n-2] – q[n]*v[n-1]; } return r[n-1], u[n-1], v[n-1]; floor function Exercise: Show r[n]=u[n]x+v[n]y CSC/ECE 574 Dr. Peng Ning

Extended Euclid’s Example qn rn un vn - 595 1 408 2 187 -1 3 34 -2 4 5 17 11 -16 -24 35 gcd(595,408) = 17 = 11*595 + -16*408

Finding the Multiplicative Inverse Given m and n, how do you find m-1 mod n? Extended Euclid’s Algorithm exteuclid(m,n): m-1 mod n = vn-1 if gcd(m,n)  1 there is no multiplicative inverse m-1 mod n

Example 12-1 mod 35 = 3 (i.e., 12*3 mod 35 = 1) n qn rn un vn - 35 1 - 35 1 12 2 11 -2 3 -1 4 -35 gcd(35,12) = 1 = -1*35 + 3*12 12-1 mod 35 = 3 (i.e., 12*3 mod 35 = 1)

Euler’s Theorem For every a and n that are relatively prime, aø(n)  1 mod n Example: For a = 3, n = 10, which relatively prime: (10) = 4 3 (10) = 34 = 81  1 mod 10 Example: For a = 2, n = 11, which are relatively prime: (11) = 10 2 (11) = 210 = 1024  1 mod 11

More Euler… Variant: for all n, a k(n)+1  a mod n for all a in Zn*, and all non-negative k Generalized Euler’s Theorem: for n = pq (p and q distinct primes), a k(n)+1  a mod n for all a in Zn, and all non-negative k Example: for n = 20, a = 7, (n) = 8, and k = 3: 7 3*8+1  7 mod 20 Example: for n = 15, a = 6, (n) = 8, and k = 3: 6 3*8+1  6 mod 15

Fermat’s “Little” Theorem If p is prime …and a is a positive integer not divisible by p, …then ap-1  1 (mod p) Example: 11 is prime, 3 not divisible by 11, so 311-1 = 59049  1 (mod 11) Example: 37 is prime, 51 not divisible by 37, so 5137-1  1 (mod 37) Useful?

Modular Exponentiation xy mod n  xy mod (n) mod n by this, if y  1 mod (n), then xy mod n  x mod n Example: x = 5, y = 7, n = 6, (6) = 2 57 mod 6 = 57 mod 2 mod 6 = 5 mod 6 Example: x = 2, y = 101, n = 33, (33) = 20, 101 mod 20 = 1 2101 mod 33 = 2 mod 33 This is not right - there is some condition on x, y, and n that must be fulfilled for this to hold true

The Powers of An Integer, Modulo n Consider the expression am  1 mod n If a and n are relatively prime, then there is at least one integer m that satisfies the above equation Ex: for a = 3 and n = 7, what is m? i 3i mod 7 1 2 3 4 5 6 7 8 9

The Power (Cont’d) The least positive exponent m for which the above equation holds is referred to as… the order of a (mod n), or the length of the period generated by a

Understanding Order of a (mod n) Powers of some integers a modulo 19  order a a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 1 2 4 8 16 13 7 14 9 18 17 15 11 3 6 12 5 10 1 18 9 3 6 2

Observations on The Previous Table The length of each period divides 18= (19) i.e., the lengths are 1, 2, 3, 6, 9, 18 Some of the sequences are of length 18 e.g., the base 2 generates (via powers) all members of Zn* The base is called the primitive root The base is also called the generator when n is prime

Reminder of Results Totient function: if n is prime, then (n) = n-1 if n = p, where p is prime and  > 0, then (n) = (p-1)*p-1 if n=pq, and p, q are relatively prime, then (n) = (p)*(q) Example: (7) = 6 Example: (15) = (5*3) = (5) * (3) = 4 * 2 = 8 Example: (25) = (52) = 4*51 = 20

Reminder (Cont’d) Fermat: If p is prime and a is positive integer not divisible by p, then ap-1  1 (mod p) Example: 11 is prime, 3 not divisible by 11, so 311-1 = 59049  1 (mod 11) Euler: For every a and n that are relatively prime, then aø(n)  1 mod n Example: For a = 3, n = 10, which relatively prime: (10) = 4, 3 (10) = 34 = 81  1 mod 10 Variant: for all a in Zn*, and all non-negative k, a k(n)+1  a mod n Example: for n = 20, a = 7, (n) = 8, and k = 3: 7 3*8+1  7 mod 20 Generalized Euler’s Theorem: for n = pq (p and q are distinct primes), all a in Zn , and all non-negative k, a k(n)+1  a mod n Example: for n = 15, a = 6, (n) = 8, and k = 3: 6 3*8+1  6 mod 15 xy mod n  xy mod (n) mod n Example: x = 5, y = 7, n = 6, (6) = 2, 57 mod 6 = 57 mod 2 mod 6 = 5 mod 6

Computing Modular Powers Efficiently The repeated squaring algorithm for computing ab (mod n) Let bi represent the ith bit of b (total of k bits)

at each iteration, not just at end Computing (Cont’d) Algorithm modexp(a,b,n) d = 1; for i = k downto 1 do d = (d * d) % n; /* square */ if (bi == 1) d = (d * a) % n; /* step 2 */ endif enddo return d; at each iteration, not just at end Requires time  k = logarithmic in b

Example Compute ab (mod n) = 7560 mod 561 = 1 mod 561 56010 = 10001100002 i 10 9 8 7 6 5 4 3 2 1 bi d 49 157 526 160 241 298 166 67 Answer: either slide 32 or 33 would do it more easily Nope, not for this example, as 561 is not prime. 561 = 3*11*17, phi(561)=2*10*16=320 But this would help: xy mod n  xy mod (n) mod n step 2 Q: Can some other result be used to compute this particular example more easily? (Note: 561 = 3*11*17.)

Discrete Logarithms

Square Roots x is a non-trivial square root of 1 mod n if it satisfies the equation x2  1 mod n, but x is neither 1 nor -1 mod n Theorem: if there exists a non-trivial square root of 1 mod n, then n is not a prime i.e., prime numbers will not have non-trivial square roots Ex: 6 is a square root of 1 mod 35 since 62  1 mod 35

Roots (Cont’d) If n = 20 p11 p22 … pkk , where p1…pk are distinct primes > 2, then the number of square roots (including trivial square roots) are: 2k if 0  1 2k+1 if 0 = 2 2k+2 if 0 > 2 Example: for n = 70 = 21 * 51 * 71 , 0 = 1, k = 2, and the number of square roots = 22 = 4 (1,29,41,69) Example: for n = 60 = 22 * 31 * 51, k = 2, the number of square roots = 23 = 8 (1,11,19,29,31,41,49,59) Example: for n = 24 = 23 * 31, k = 1, the number of square roots = 23 = 8 (1,5,7,11,13,17,19,23)

Primitive Roots Reminder: the highest possible order of a (mod n) is (n) If the order of a (mod n) is (n), then a is referred to as a primitive root of n for a prime number p, if a is a primitive root of p, then a, a2, …, ap-1 are all distinct numbers mod p No simple general formula to compute primitive roots modulo n there are methods to locate a primitive root faster than trying out all candidates No simple general formula to compute primitive roots modulo n is known. There are however methods to locate a primitive root that are faster than simply trying out all candidates. If the multiplicative order of a number m modulo n is equal to \phi\left(n\right) (the order of Zn*), then it is a primitive root. In fact the converse is true: If m is a primitive root modulo n then the multiplicative order of m is \phi\left(n\right). We can use this to test for primitive roots. First, compute \phi\left(n\right). Then determine the different prime factors of \phi\left(n\right), say p1,...,pk. Now, for every element m of Zn*, compute m^{\phi(n)/p_i}\mod n \qquad\mbox{ for } i=1,\ldots,k using the fast exponentiation by squaring. A number m for which these k results are all different from 1 is a primitive root. The number of primitive roots modulo n, if there are any, is equal to \phi\left(\phi\left(n\right)\right) since, in general, a cyclic group with r elements has \phi\left(r\right) generators.

Discrete Logarithms For a primitive root a of a number p, where ai ≡ b mod p, for some 0  i  p-1 the exponent i is referred to as the index of b for the base a (mod p), denoted as inda,p(b) i is also referred to as the discrete logarithm of b to the base a, mod p

ind2,19 (b) = log(b) base 2 mod 19 Logarithms (Cont’d) Example: 2 is a primitive root of 19. The powers of 2 mod 19 = b 1 2 3 4 5 6 7 8 9 ind2,19 (b) = log(b) base 2 mod 19 13 16 14 10 11 12 13 14 15 16 17 18 5 7 4 9 Given a, i, and p, computing b = ai mod p is straightforward

Computing Discrete Logarithms However, given a, b, and p, computing i = inda,p(b) is difficult Used as the basis of some public key cryptosystems

Computing (Cont’d) Some properties of discrete logarithms inda,p(1) = 0 because a0 mod p = 1 inda,p(a) = 1 because a1 mod p = a inda,p(yz) = (inda,p(y) + inda,p(z)) mod (p) inda,p(yr) = (r inda,p(y)) mod (p) warning: (p), not p! Example: ind2,19(5*3) = (ind2,19(5) + ind2,19(3)) = 11 mod 18 Example: ind2,19(33) = (3*ind2,19(3))= 3 mod 18

More on Discrete Logarithms Consider: x  ainda,p(x) mod p, y  ainda,p(y) mod p, and xy  ainda,p(xy) mod p ainda,p(xy) mod p  (ainda,p(x) mod p)(ainda,p(y) mod p) ainda,p(xy) mod p  (ainda,p(x)+inda,p(y) ) mod p by Euler’s theorem: azaq mod p iff z q mod (p) Ex: 3 = 213 mod 19 Ex: 5 = 216 mod 19 Ex: 3*5 = 211 mod 19 Ex: 15 = 3 * 5 Ex: 15 = 213+16 mod 19 Ex: 15 = 211 mod 19 = 229 mod 19  11  29 mod 18