13.06.2014 Views

the role of number theory in modern cryptography - Rivier University

the role of number theory in modern cryptography - Rivier University

the role of number theory in modern cryptography - Rivier University

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

InSight: RIVIER ACADEMIC JOURNAL, VOLUME 8, NUMBER 2, FALL 2012<br />

THE ROLE OF NUMBER THEORY IN MODERN CRYPTOGRAPHY<br />

Robert R. Marceau*<br />

M.S. Program <strong>in</strong> Computer Science, <strong>Rivier</strong> College<br />

Keywords: bully children<br />

Abstract<br />

The basic premise <strong>of</strong> <strong>modern</strong> <strong>cryptography</strong> is that <strong>the</strong> encryption and decryption processes should be<br />

computationally easy when <strong>the</strong> secret key is known, but very difficult without <strong>the</strong> key. Very difficult may well mean<br />

that with <strong>the</strong> current state <strong>of</strong> computation, it would take longer than <strong>the</strong> estimated age <strong>of</strong> <strong>the</strong> universe. One typical<br />

problem <strong>of</strong> this class is <strong>the</strong> factor<strong>in</strong>g <strong>of</strong> a large composite <strong>in</strong>teger that was generated by <strong>the</strong> multiplication <strong>of</strong> two<br />

large prime <strong>number</strong>s. The multiplication <strong>of</strong> <strong>in</strong>tegers consist<strong>in</strong>g <strong>of</strong> hundreds <strong>of</strong> digits is trivial for a computer. The<br />

factor<strong>in</strong>g <strong>of</strong> a similar size <strong>number</strong> is a very difficult problem.<br />

1 Historical Notes<br />

Number <strong>the</strong>ory may be traced back to <strong>the</strong> Greeks. Diophantus (c. 250) was <strong>in</strong>terested <strong>in</strong> <strong>in</strong>teger solutions<br />

to various equations. Several o<strong>the</strong>r great ma<strong>the</strong>maticians have made contributions to <strong>number</strong> <strong>the</strong>ory<br />

<strong>in</strong>clud<strong>in</strong>g Fermat, Gauss, and Euler. [1, page 120] It is only recently that great <strong>in</strong>terest <strong>in</strong> <strong>number</strong> <strong>the</strong>ory<br />

has developed due to its application to <strong>cryptography</strong>.<br />

2 Prelim<strong>in</strong>aries<br />

2.1 Prime<br />

The <strong>number</strong> , with is called prime if and only if <strong>the</strong> only positive factors <strong>of</strong> are and . If<br />

is not prime, it is called composite. [2, page 210] [3, page 109]<br />

2.2 Greatest Common Divisor<br />

Let , not both . The largest such that is called <strong>the</strong> greatest common divisor <strong>of</strong><br />

and . [2, page 215] [1, page 80<br />

2.3 Fundamental Theorem <strong>of</strong> Arithmetic<br />

Every positive <strong>in</strong>teger greater than can be written uniquely as a prime or <strong>the</strong> product <strong>of</strong> two or more<br />

primes where <strong>the</strong> prime factors are written <strong>in</strong> order <strong>of</strong> nondecreas<strong>in</strong>g size. [2, page 211] [4, page 210] [3,<br />

page 110] [1, page 97]<br />

2.4 Inf<strong>in</strong>ite <strong>number</strong> <strong>of</strong> primes<br />

A pro<strong>of</strong> <strong>of</strong> this <strong>the</strong>orem was provided by Euclid. [2, page 212] [4, page 11] This pro<strong>of</strong> illustrates <strong>the</strong><br />

classic “pro<strong>of</strong> by contradiction” method.<br />

Copyright © 2012 by Robert R. Marceau. Published by <strong>Rivier</strong> <strong>University</strong>, with permission. 1<br />

ISSN 1559-9388 (onl<strong>in</strong>e version), ISSN 1559-9396 (CD-ROM version).


Robert R. Marceau<br />

Assume <strong>the</strong> contrary, that <strong>the</strong>re is only a f<strong>in</strong>ite <strong>number</strong> <strong>of</strong> primes, n. These prime <strong>number</strong>s may be<br />

listed as . Consider <strong>the</strong> <strong>number</strong> . This <strong>number</strong> yields a rema<strong>in</strong>der <strong>of</strong> when<br />

it is divided by any prime. We have just produced a <strong>number</strong> that is not divisible by any prime on<br />

our list. This contradiction leads us to <strong>the</strong> conclusion that our <strong>in</strong>itial assumption is false and that<br />

<strong>the</strong>re are <strong>in</strong> fact an <strong>in</strong>f<strong>in</strong>ite <strong>number</strong> <strong>of</strong> primes.<br />

An alternative direct pro<strong>of</strong> is found <strong>in</strong> [1, pages 66–67]:<br />

Consider <strong>the</strong> value . This value is not divisible by any <strong>in</strong>teger from to . By <strong>the</strong><br />

Fundamental Theorem <strong>of</strong> Arithmetic, it must be ei<strong>the</strong>r prime or divisible by a prime. Ei<strong>the</strong>r way, it<br />

has a prime factor , which must be greater than . S<strong>in</strong>ce we have found a prime greater than n, for<br />

every positive <strong>in</strong>teger , <strong>the</strong>re must be <strong>in</strong>f<strong>in</strong>itely many primes.<br />

2.5 Pseudo-prime to <strong>the</strong> base b<br />

Let , composite. If <strong>the</strong>n is called a pseudo-prime to <strong>the</strong> base . [2, page<br />

240] [5, pages 95–97] [4, page 36]<br />

2.6 Carmichael Number<br />

If a composite <strong>in</strong>teger is a pseudo-prime such that <strong>the</strong>n is called a Carmichael<br />

<strong>number</strong>. [2, page 240] [4, page 37] [1, page 207–208]<br />

2.7 Inverse modulo m<br />

If are relatively prime, <strong>the</strong>n such that . (If two <strong>in</strong>tegers , and<br />

have no common divisors, <strong>the</strong>n <strong>the</strong>re is a unique <strong>in</strong>teger such that times has a rema<strong>in</strong>der <strong>of</strong> 1 when<br />

divided by ). [2, page 234][4, page 24] [1, pages 140, 200]<br />

2.8 Euler’s Totient ϕ function<br />

The Totient function is def<strong>in</strong>ed as <strong>the</strong> <strong>number</strong> <strong>of</strong> positive <strong>in</strong>tegers less than or equal to n that are<br />

relatively prime to . Two <strong>number</strong>s and are said to be relatively prime to each o<strong>the</strong>r if and only if <strong>the</strong><br />

Greatest Common Divisor <strong>of</strong> and is . [3, page 104] [4, page 30] [5, page 129–131]<br />

2.9 Multiplicative function<br />

If a function def<strong>in</strong>ed for all positive <strong>in</strong>tegers is called multiplicative if<br />

whenever and are relatively prime. [1, page 222]<br />

2.10 Mersenne Numbers<br />

A Mersenne Number, is def<strong>in</strong>ed as where is a non-negative <strong>in</strong>teger. [5, pages 51–53]<br />

2


THE ROLE OF NUMBER THEORY IN MODERN CRYPTOGRAPHY<br />

3 Totient Function ϕ(n)<br />

If is a prime, <strong>the</strong>n . All <strong>of</strong> <strong>the</strong> <strong>number</strong>s from through are relatively prime to . There<br />

are <strong>of</strong> <strong>the</strong>se <strong>number</strong>s. It should be noted that <strong>the</strong> converse is also true: If <strong>the</strong>re are <strong>number</strong>s<br />

relatively prime to that are less than , <strong>the</strong>n must be prime. O<strong>the</strong>rwise, would have a factor greater<br />

than and less than . [3, page 104] [4, page 30] [5, page 129–131]<br />

The Totient function is a Multiplicative function. If n and m are relatively prime, <strong>the</strong>n<br />

. [1, page 224] It is <strong>the</strong>se two properties <strong>of</strong> <strong>the</strong> Totient function that make <strong>the</strong><br />

calculation <strong>of</strong> <strong>the</strong> Totient function computationally equivalent to factor<strong>in</strong>g a <strong>number</strong>. If and are two<br />

large prime <strong>number</strong>s, factor<strong>in</strong>g is prohibitly expensive.<br />

4 Mersenne Numbers<br />

If is a Mersenne Number, and n is composite, <strong>the</strong>n is also composite. [5, page 52] Consider<br />

, where and are positive <strong>in</strong>tegers. Then we have:<br />

If divides , <strong>the</strong>n divides . The converse, however, is not true. Consider <strong>the</strong> Mersenne <strong>number</strong><br />

. The <strong>number</strong> is prime, however, .<br />

5 Prime Test<strong>in</strong>g<br />

5.1 Fermat’s Little Theorem<br />

If p is a prime and a is a positive <strong>in</strong>teger where p does not divide a (s<strong>in</strong>ce p is a prime, this is <strong>the</strong> same as<br />

<strong>the</strong> condition that a and p have no common factors greater than 1) <strong>the</strong>n . [3, pages 128,<br />

135, 190] [1, pages 199–201]<br />

Fermat’s Little Theorem may be used to prove a given <strong>number</strong> is composite. Unfortunately, <strong>the</strong><br />

converse is not true. A counter example is provided by <strong>the</strong> <strong>number</strong> 341. We have 2 340 ≡ 1 (mod 341), but<br />

341 = 11・31 is clearly composite.<br />

For any chosen base, <strong>the</strong>re are Pseudo-primes to that base. It has been proved that <strong>the</strong>re exists an <strong>in</strong>f<strong>in</strong>ite<br />

<strong>number</strong> <strong>of</strong> Pseudo-primes. [1, page 206]<br />

5.2 Euler’s Theorem<br />

If m is a positive <strong>in</strong>teger and a is an <strong>in</strong>teger that is relatively prime to m, <strong>the</strong>n<br />

. It<br />

should be noted that this is a generalization <strong>of</strong> Fermat’s Little <strong>the</strong>orem, replac<strong>in</strong>g <strong>the</strong> restriction that <strong>the</strong><br />

modulus be prime with <strong>the</strong> condition that a and m have no common factors greater than 1. This is true<br />

s<strong>in</strong>ce 1 for all prime <strong>number</strong>s p. [5, pages 25–26] [1, page 217]<br />

3


Robert R. Marceau<br />

5.3 Lucas-Lehmer Test<br />

The Lucas-Lehmer Test may be used to determ<strong>in</strong>e if a Mersenne <strong>number</strong> is prime or composite. [5,<br />

pages 146-149] [3, page 193] [1, page 243] A sequence <strong>of</strong> positive <strong>in</strong>tegers is def<strong>in</strong>ed recursively as:<br />

Let p be a prime <strong>number</strong>. The Mersenne <strong>number</strong> is prime if and only if .<br />

5.4 Miller Test<br />

As seen by Fermat’s Little <strong>the</strong>orem,<br />

is sufficient to demonstrate that <strong>the</strong> <strong>number</strong> p is<br />

not prime. The pseudo-prime <strong>number</strong>s (and <strong>the</strong> Carmichael <strong>number</strong>s <strong>in</strong> particular) demonstrate that it<br />

does not lead to a test for primeness. The Miller Test will elim<strong>in</strong>ate some additional composite <strong>number</strong><br />

from consideration, but, like Fermat’s Little Theorem, it can only prove some <strong>number</strong>s are composite.<br />

The test proceeds as follows (given an odd <strong>number</strong> and a base , where ): [5, pages<br />

100–102] [1, pages 209–210]<br />

1. Divide n−1 by 2 until an odd factor, q is found. We now have .<br />

2. Set i = 0 and .<br />

3. If i = 0 and r = 1 term<strong>in</strong>ate <strong>the</strong> test with an <strong>in</strong>conclusive result.<br />

4. If i ≥ 0 and r = n − 1 term<strong>in</strong>ate <strong>the</strong> test with an <strong>in</strong>conclusive result.<br />

5. Increase i by 1 and set<br />

6. If i < k proceed to step 4, o<strong>the</strong>rwise, n is composite.<br />

6 Diffie–Hellman<br />

As strange as it may seem, it is possible for two <strong>in</strong>dividuals to decide on a secret <strong>number</strong> by only<br />

exchang<strong>in</strong>g public messages. Us<strong>in</strong>g <strong>the</strong> typical Bob and Alice <strong>cryptography</strong> character names, <strong>the</strong><br />

procedure works as follows: [4, pages 50–51] [3, pages 270–271] [1, pages 299–300] [6, pages 188–<br />

190]<br />

Alice and Bob first agree on a large prime and an <strong>in</strong>teger with such that <strong>the</strong> order<br />

<strong>of</strong> is sufficiently high. The order <strong>of</strong> is def<strong>in</strong>ed as <strong>the</strong> smallest <strong>in</strong>teger such that<br />

. It should be noted that for all a has a unique <strong>in</strong>verse, . The<br />

values and are publicly known. Alice also chooses a random positive <strong>in</strong>teger and<br />

calculates<br />

. The value A is transmitted to Bob (over <strong>the</strong> <strong>in</strong>secure channel), while <strong>the</strong><br />

exponent a is kept secret. Bob chooses a random positive <strong>in</strong>teger<br />

and<br />

calculates<br />

, which is <strong>the</strong>n transmitted to Alice.<br />

Both Alice and Bob are able to now calculate <strong>the</strong> common key K. Alice, know<strong>in</strong>g a <strong>in</strong> addition to<br />

and calculates , which is equal to . In a similar manner, Bob calculates ,<br />

which is also equal to . (The multiplication <strong>of</strong> <strong>the</strong> exponents and is commutative).<br />

The selection <strong>of</strong> deserves fur<strong>the</strong>r discussion. If is a primitive root mod p, <strong>the</strong>n it has an order <strong>of</strong><br />

. For a given prime, , <strong>the</strong>re are primitive roots mod [6, page 66]. F<strong>in</strong>d<strong>in</strong>g one <strong>of</strong> <strong>the</strong>se<br />

4


THE ROLE OF NUMBER THEORY IN MODERN CRYPTOGRAPHY<br />

primitive roots is computationally equivalent to factor<strong>in</strong>g <strong>the</strong> <strong>in</strong>teger . Give <strong>the</strong> size <strong>of</strong> ,<br />

factor<strong>in</strong>g is <strong>in</strong> general <strong>in</strong>tractable. However, if p is chosen such that is also prime, say ,<br />

we can use an efficient method to test whe<strong>the</strong>r a randomly chosen g is a primitive root. (We have chosen<br />

such that we know <strong>the</strong> prime factorization <strong>of</strong> ).<br />

The <strong>number</strong> <strong>of</strong> primitive roots mod is , but s<strong>in</strong>ce , we can calculate<br />

. Roughly half <strong>of</strong> <strong>the</strong> values between and are<br />

primitive roots. A randomly chosen can be quickly tested by calculat<strong>in</strong>g and . If both<br />

<strong>of</strong> <strong>the</strong>se values are not equal to 1, <strong>the</strong>n g is a primitive root mod p.<br />

7 RSA<br />

Two large prime <strong>number</strong>s p and q are chosen and kept secret. The product is calculated and<br />

ano<strong>the</strong>r small <strong>in</strong>teger which is relatively prime to is chosen. is easy to calculate if and are<br />

known, s<strong>in</strong>ce . The pair <strong>of</strong> <strong>number</strong>s ( ) is <strong>the</strong> public key. Two<br />

functions are def<strong>in</strong>ed:<br />

The function is used to encrypt <strong>the</strong> message (which has been broken <strong>in</strong>to a sequence <strong>of</strong> <strong>number</strong>s ,<br />

with ). The <strong>number</strong> is <strong>the</strong> <strong>in</strong>verse <strong>of</strong> . We know such an <strong>in</strong>verse exists s<strong>in</strong>ce<br />

and are relatively prime. The extended Euclidean algorithm may be used to easily calculate ,<br />

provided and are known. The public key is <strong>the</strong> pair ( ) which may be used by anyone to encrypt<br />

a message. The private key is <strong>the</strong> pair ( ), which is required to decrypt a message. Comb<strong>in</strong><strong>in</strong>g results,<br />

we have:<br />

However, is <strong>the</strong> <strong>in</strong>verse <strong>of</strong> modulo . It can fur<strong>the</strong>r be shown that and<br />

. At this po<strong>in</strong>t, we have divides . S<strong>in</strong>ce , we f<strong>in</strong>ally have .<br />

[5, pages 163–171]<br />

Calculat<strong>in</strong>g know<strong>in</strong>g only and ( ) is computationally equivalent to factor<strong>in</strong>g . It may also<br />

be viewed as <strong>the</strong> discrete logarithm problem. That is determ<strong>in</strong>e <strong>the</strong> value such that . [3,<br />

page 205] [1, pages 332–333] [6, pages 186–187, 213–214]<br />

8 Exponentiation mod n<br />

There is a very efficient method to calculate . It is rem<strong>in</strong>iscent <strong>of</strong> Horner’s rule to evaluate a<br />

polynomial for a particular value <strong>of</strong> . [6, page 46] [4, pages 34–35] The procedure is as follows:<br />

The exponent is expressed <strong>in</strong> b<strong>in</strong>ary, where each is chosen such that . (Each<br />

is a b<strong>in</strong>ary digit for <strong>the</strong> b<strong>in</strong>ary expansion <strong>of</strong> , be<strong>in</strong>g <strong>the</strong> least significant bit. Here is <strong>the</strong> <strong>number</strong><br />

<strong>of</strong> bits required to represent <strong>in</strong> b<strong>in</strong>ary). The follow<strong>in</strong>g equations illustrate how may be calculated:<br />

5


Robert R. Marceau<br />

The follow<strong>in</strong>g pseudo-code demonstrates how this may be done:<br />

<strong>in</strong>t power(<strong>in</strong>t base, <strong>in</strong>t exponent)<br />

{<br />

<strong>in</strong>t result = 1;<br />

while (e > 0) {<br />

if (exponent & 1)<br />

result = result * base;<br />

base = base * base;<br />

exponent = exponent / 2;<br />

}<br />

return result;<br />

}<br />

The process only requires multiplications and divisions, plus ano<strong>the</strong>r multiplications, where is <strong>the</strong><br />

<strong>number</strong> <strong>of</strong> one bits <strong>in</strong> <strong>the</strong> b<strong>in</strong>ary expansion <strong>of</strong> <strong>the</strong> exponent. For cryptographic purposes, <strong>the</strong> result and<br />

base would be reduced modulus after each iteration. The runn<strong>in</strong>g time for <strong>the</strong> procedure above to<br />

calculate is . This is a substantial improvement over <strong>the</strong> naïve approach which has a runn<strong>in</strong>g<br />

time <strong>of</strong> .<br />

9 Conclusion<br />

As seen <strong>in</strong> <strong>the</strong> sections describ<strong>in</strong>g Diffie–Hellman key exchanges and <strong>the</strong> RSA encryption algorithm, <strong>the</strong><br />

ability to f<strong>in</strong>d large (200 decimal digits) prime <strong>number</strong>s is <strong>of</strong> critical importance. Methods to perform<br />

modular arithmetic, <strong>in</strong> particular rais<strong>in</strong>g a <strong>number</strong> to a very large power are also necessary. The security<br />

relies upon <strong>the</strong> fact that calculat<strong>in</strong>g <strong>the</strong> Totient function for a large <strong>number</strong> is equivalent to f<strong>in</strong>d<strong>in</strong>g <strong>the</strong><br />

prime factorization <strong>of</strong> <strong>the</strong> <strong>number</strong>. In <strong>the</strong> applications discussed above, two large primes are multiplied<br />

to give a <strong>number</strong> n for which calculat<strong>in</strong>g <strong>the</strong> Totient function is very difficult.<br />

References<br />

[1] Kenneth H. Rosen. Elementary Number Theory and Its Applications (4 th Edition). Addison Wesley, 2000.<br />

[2] Kenneth Rosen. Discrete Ma<strong>the</strong>matics and Its Applications. McGraw-Hill Science/Eng<strong>in</strong>eer<strong>in</strong>g/Math, 2006.<br />

[3] James A. Anderson and James M. Bell. Number Theory with Applications. Prentice Hall, 1997.<br />

6


THE ROLE OF NUMBER THEORY IN MODERN CRYPTOGRAPHY<br />

[4] William Ste<strong>in</strong>. Elementary Number Theory: Primes, Congruences, and Secrets: A Computational Approach<br />

(Undergraduate Texts <strong>in</strong> Ma<strong>the</strong>matics). Spr<strong>in</strong>ger, 2008.<br />

[5] S.C. Cout<strong>in</strong>ho. The Ma<strong>the</strong>matics <strong>of</strong> Ciphers: Number Theory and RSA Cryptography. A K Peters/CRC Press,<br />

1999.<br />

[6] Johannes Buchmann. Introduction to Cryptography (Undergraduate Texts <strong>in</strong> Ma<strong>the</strong>matics). Spr<strong>in</strong>ger, 2004.<br />

[7] John Stillwell. Elements <strong>of</strong> Number Theory. Spr<strong>in</strong>ger, 2002.<br />

[8] Underwood Dudley. Elementary Number Theory: Second Edition. Dover Publications, 2008.<br />

[9] William J. LeVeque. Fundamentals <strong>of</strong> Number Theory. Dover Publications, 1996.<br />

[10] G. Everest and Thomas Ward. An Introduction to Number Theory (Graduate Texts <strong>in</strong> Ma<strong>the</strong>matics).<br />

Spr<strong>in</strong>ger, 2005.<br />

[11] Gareth A. Jones and Joseph<strong>in</strong>e M. Jones. Elementary Number Theory. Spr<strong>in</strong>ger, 1998.<br />

[12] Ronald S. Irv<strong>in</strong>g. Integers, Polynomials, and R<strong>in</strong>gs: A Course <strong>in</strong> Algebra (Undergraduate Texts <strong>in</strong><br />

Ma<strong>the</strong>matics). Spr<strong>in</strong>ger, 2003.<br />

___________________<br />

* ROBERT MARCEAU wrote his first computer program <strong>in</strong> October, 1969 on a DEC PDP-8/I runn<strong>in</strong>g TSS/8. S<strong>in</strong>ce that<br />

time, he has earned a B.S. and M.S. <strong>in</strong> Ma<strong>the</strong>matics from <strong>the</strong> <strong>University</strong> <strong>of</strong> Massachusetts - Lowell and is currently<br />

enrolled <strong>in</strong> <strong>the</strong> Computer Science Ph.D. program <strong>the</strong>re. He is also expect<strong>in</strong>g to complete his M.S. <strong>in</strong> Computer Science at<br />

<strong>Rivier</strong> <strong>University</strong> <strong>in</strong> spr<strong>in</strong>g 2013. He has spent over thirty years <strong>in</strong> <strong>the</strong> s<strong>of</strong>tware <strong>in</strong>dustry and is currently an Adjunct<br />

Faculty member at Nashua Community College teach<strong>in</strong>g a variety <strong>of</strong> Ma<strong>the</strong>matics and Computer Science courses.<br />

7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!