• No results found

Chapter 4 – Basic Concepts in Number Theory and Finite Fields

N/A
N/A
Protected

Academic year: 2020

Share "Chapter 4 – Basic Concepts in Number Theory and Finite Fields"

Copied!
39
0
0

Loading.... (view fulltext now)

Full text

(1)

Cryptography and

Cryptography and

Network Security

Network Security

Chapter 4

Chapter 4

Fifth Edition Fifth Edition

by William Stallings by William Stallings

(2)

Chapter 4 – Basic Concepts in

Chapter 4 – Basic Concepts in

Number Theory and Finite

Number Theory and Finite

Fields

Fields

The next morning at daybreak, Star flew indoors, seemingly keen for The next morning at daybreak, Star flew indoors, seemingly keen for a lesson. I said, "Tap eight." She did a brilliant exhibition, first

a lesson. I said, "Tap eight." She did a brilliant exhibition, first

tapping it in 4, 4, then giving me a hasty glance and doing it in 2, 2, tapping it in 4, 4, then giving me a hasty glance and doing it in 2, 2, 2, 2, before coming for her nut. It is astonishing that Star learned to 2, 2, before coming for her nut. It is astonishing that Star learned to count up to 8 with no difficulty, and of her own accord discovered count up to 8 with no difficulty, and of her own accord discovered that each number could be given with various different divisions, this that each number could be given with various different divisions, this leaving no doubt that she was consciously thinking each number. In leaving no doubt that she was consciously thinking each number. In fact, she did mental arithmetic, although unable, like humans, to fact, she did mental arithmetic, although unable, like humans, to name the numbers. But she learned to recognize their spoken name the numbers. But she learned to recognize their spoken

names almost immediately and was able to remember the sounds of names almost immediately and was able to remember the sounds of the names. Star is unique as a wild bird, who of her own free will

the names. Star is unique as a wild bird, who of her own free will pursued the science of numbers with keen interest and astonishing pursued the science of numbers with keen interest and astonishing intelligence.

intelligence.

(3)

Introduction

Introduction

 will now introduce finite fieldswill now introduce finite fields

 of increasing importance in cryptographyof increasing importance in cryptography

 AES, Elliptic Curve, IDEA, Public KeyAES, Elliptic Curve, IDEA, Public Key

 concern operations on “numbers”concern operations on “numbers”

 where what constitutes a “number” and the where what constitutes a “number” and the type of operations varies considerably

type of operations varies considerably

(4)

Divisors

Divisors

 say a non-zero number say a non-zero number bb dividesdivides aa if for if for

some

some mm have have a=mba=mb ( (a,b,ma,b,m all integers) all integers)

 that is that is bb divides into divides into aa with no remainder with no remainder

 denote this denote this b|ab|a

 and say that and say that bb is a is a divisordivisor of of aa

 eg. all of 1,2,3,4,6,8,12,24 divide 24 eg. all of 1,2,3,4,6,8,12,24 divide 24

(5)

Properties of Divisibility

Properties of Divisibility

 If If a|1, then a = ±1.a|1, then a = ±1.

If a|b and b|a, then a = ±b.If a|b and b|a, then a = ±b.Any b /= 0 divides 0. Any b /= 0 divides 0.

If a | b and b | c, then a | c If a | b and b | c, then a | c

e.g. e.g. 11 | 66 and 66 | 198 so 11 | 19811 | 66 and 66 | 198 so 11 | 198  If If b|g and b|h, then b|(mg + nh)b|g and b|h, then b|(mg + nh)

for arbitrary integers m and n

for arbitrary integers m and n

e.g. b = 7; g = 14; h = 63; m = 3; n = 2

e.g. b = 7; g = 14; h = 63; m = 3; n = 2

7|14 and 7|63 hence 7 | 42+126 = 168

(6)

Division Algorithm

Division Algorithm

 if divide a by n get integer quotient if divide a by n get integer quotient qq and and

integer remainder

integer remainder rr such that: such that:

a = qn + r a = qn + r where where 0 <= r < n; q = floor(a/n)0 <= r < n; q = floor(a/n)

(7)

Greatest Common Divisor (GCD)

Greatest Common Divisor (GCD)

 a common problem in number theorya common problem in number theory

 GCD (a,b) of a and b is the largest integer GCD (a,b) of a and b is the largest integer

that divides evenly into both a and b that divides evenly into both a and b

 eg GCD(60,24) = 12eg GCD(60,24) = 12

define gcd(0, 0) = 0define gcd(0, 0) = 0

 often want often want no common factorsno common factors (except 1) (except 1)

define such numbers as

define such numbers as relatively primerelatively prime  eg GCD(8,15) = 1eg GCD(8,15) = 1

(8)

Euclidean Algorithm

Euclidean Algorithm

 an efficient way to find the GCD(a,b)an efficient way to find the GCD(a,b)  uses theorem that: uses theorem that:

 GCD(a,b) = GCD(b, a mod b)GCD(a,b) = GCD(b, a mod b)

 Euclidean Algorithm to compute GCD(a,b) is: Euclidean Algorithm to compute GCD(a,b) is:

Euclid(a,b) Euclid(a,b)

if (b=0) then return a; if (b=0) then return a;

(9)

Example GCD(1970,1066)

Example GCD(1970,1066)

1970 = 1 x 1066 + 904

1970 = 1 x 1066 + 904 gcd(1066, 904)gcd(1066, 904) 1066 = 1 x 904 + 162

1066 = 1 x 904 + 162 gcd(904, 162)gcd(904, 162) 904 = 5 x 162 + 94

904 = 5 x 162 + 94 gcd(162, 94)gcd(162, 94) 162 = 1 x 94 + 68

162 = 1 x 94 + 68 gcd(94, 68)gcd(94, 68) 94 = 1 x 68 + 26

94 = 1 x 68 + 26 gcd(68, 26)gcd(68, 26) 68 = 2 x 26 + 16

68 = 2 x 26 + 16 gcd(26, 16)gcd(26, 16) 26 = 1 x 16 + 10

26 = 1 x 16 + 10 gcd(16, 10)gcd(16, 10) 16 = 1 x 10 + 6

16 = 1 x 10 + 6 gcd(10, 6)gcd(10, 6) 10 = 1 x 6 + 4

10 = 1 x 6 + 4 gcd(6, 4)gcd(6, 4) 6 = 1 x 4 + 2

6 = 1 x 4 + 2 gcd(4, 2)gcd(4, 2) 4 = 2 x 2 + 0

(10)

GCD(1160718174, 316258250)

GCD(1160718174, 316258250)

Dividend

Dividend DivisorDivisor QuotientQuotient Remainder Remainder a = 1160718174

a = 1160718174 b = 316258250b = 316258250 q1 = 3 q1 = 3 r1 = 211943424 r1 = 211943424 b = 316258250

b = 316258250 r1 = 211943424r1 = 211943424 q2 = 1 q2 = 1 r2 = 104314826 r2 = 104314826 r1 = 211943424

r1 = 211943424 r2 = 104314826r2 = 104314826 q3 = 2 q3 = 2 r3 = 3313772 r3 = 3313772 r2 = 104314826

r2 = 104314826 r3 = 3313772 r3 = 3313772 q4 = 31q4 = 31 r4 = 1587894 r4 = 1587894 r3 = 3313772

r3 = 3313772 r4 = 1587894 r4 = 1587894 q5 = 2 q5 = 2 r5 = 137984 r5 = 137984 r4 = 1587894

r4 = 1587894 r5 = 137984 r5 = 137984 q6 = 11q6 = 11 r6 = 70070 r6 = 70070 r5 = 137984

r5 = 137984 r6 = 70070 r6 = 70070 q7 = 1 q7 = 1 r7 = 67914 r7 = 67914 r6 = 70070

r6 = 70070 r7 = 67914 r7 = 67914 q8 = 1 q8 = 1 r8 = 2156 r8 = 2156 r7 = 67914

r7 = 67914 r8 = 2156 r8 = 2156 q9 = 31q9 = 31 r9 = 1078 r9 = 1078 r8 = 2156

(11)

Modular Arithmetic

Modular Arithmetic

define define modulo operatormodulo operatora mod n”a mod n” to be to be

remainder when a is divided by n

remainder when a is divided by n

 where integer where integer nn is called the is called the modulusmodulusbb is called a is called a residueresidue of of aa mod mod nn

 since with integers can always write: since with integers can always write: a = qn + ba = qn + b  usually chose smallest positive remainder as residueusually chose smallest positive remainder as residue

• ie. ie. 0 <= b <= n-10 <= b <= n-1

 process is known as process is known as modulo reductionmodulo reduction

eg. -12 mod 7 =eg. -12 mod 7 = -5 mod 7 -5 mod 7 == 2 mod 7 2 mod 7 == 9 mod 7 9 mod 7

aa & & bb are are congruentcongruent if: if: a mod n = b mod na mod n = b mod n  when divided by when divided by n,n, a & b have same remainder a & b have same remainder

 eg. 100 mod 11 = 34 mod 11 eg. 100 mod 11 = 34 mod 11

(12)

Modular Arithmetic Operations

Modular Arithmetic Operations

 can perform arithmetic with residuescan perform arithmetic with residues

 uses a finite number of values, and loops uses a finite number of values, and loops

back from either end back from either end

Z

Znn = {0, 1, . . . , ( = {0, 1, . . . , (n – 1)}n – 1)}

 modular arithmetic is when do addition & modular arithmetic is when do addition &

multiplication and modulo reduce answer multiplication and modulo reduce answer

 can do reduction at any point, iecan do reduction at any point, ie

(13)

Modular Arithmetic Operations

Modular Arithmetic Operations

1.

1. [(a mod n) + (b mod n)] mod n [(a mod n) + (b mod n)] mod n

= (a + b) mod n

= (a + b) mod n

2.

2. [(a mod n) – (b mod n)] mod n [(a mod n) – (b mod n)] mod n

= (a – b) mod n

= (a – b) mod n

3.

3. [(a mod n) x (b mod n)] mod n [(a mod n) x (b mod n)] mod n

= (a x b) mod n

= (a x b) mod n e.g.

e.g.

(14)

Modulo 8 Addition Example

Modulo 8 Addition Example

(15)

Modulo 8 Multiplication

Modulo 8 Multiplication

(16)
(17)

Extended Euclidean Algorithm

Extended Euclidean Algorithm

 calculates not only GCD but x & y:calculates not only GCD but x & y:

ax + by = d = gcd(a, b)ax + by = d = gcd(a, b)

 useful for later crypto computationsuseful for later crypto computations

 follow sequence of divisions for GCD but follow sequence of divisions for GCD but

assume at each step i, can find x &y: assume at each step i, can find x &y:

r = ax + by

r = ax + by

 at end find GCD value and also x & yat end find GCD value and also x & y

(18)

Finding Inverses

Finding Inverses

EXTENDED EUCLID(

EXTENDED EUCLID(mm, , bb))

1.

1. (A1, A2, A3)=(1, 0, (A1, A2, A3)=(1, 0, mm); ); (B1, B2, B3)=(0, 1,

(B1, B2, B3)=(0, 1, bb))

2. if

2. if B3 = 0B3 = 0

return

return A3 = gcd(A3 = gcd(mm, , bb); no inverse); no inverse

3. if

3. if B3 = 1 B3 = 1

return

return B3 = gcd(B3 = gcd(mm, , bb); B2 = ); B2 = bb–1–1 mod mod mm

4.

4. Q = A3 div B3Q = A3 div B3

5.

5. (T1, T2, T3)=(A1 – Q B1, A2 – Q B2, A3 – Q B3)(T1, T2, T3)=(A1 – Q B1, A2 – Q B2, A3 – Q B3)

6.

6. (A1, A2, A3)=(B1, B2, B3)(A1, A2, A3)=(B1, B2, B3)

7.

7. (B1, B2, B3)=(T1, T2, T3)(B1, B2, B3)=(T1, T2, T3)

8. goto

(19)

Inverse of 550 in GF(1759)

Inverse of 550 in GF(1759)

Q A1 A2 A3 B1 B2 B3

— 1 0 1759 0 1 550

3 0 1 550 1 –3 109

5 1 –3 109 –5 16 5

21 –5 16 5 106 –339 4

1 106 –339 4 –111 355 1

(20)

Group

Group

 a set S of elements or “numbers”a set S of elements or “numbers”  may be finite or infinitemay be finite or infinite

 with some operation ‘.’ so G=(S,.)with some operation ‘.’ so G=(S,.)  Obeys CAIN:Obeys CAIN:

 Closure: Closure: a,b a,b in S, then in S, then a.b a.b in S in S

 Associative law:Associative law: (a.b).c = a.(b.c)(a.b).c = a.(b.c)

 has Identity has Identity ee:: e.a = a.e = ae.a = a.e = a

 has iNverses has iNverses aa-1-1::a.aa.a-1-1 = e = e  if commutative if commutative a.b = b.aa.b = b.a

(21)

Cyclic Group

Cyclic Group

 define define exponentiationexponentiation as repeated as repeated

application of operator application of operator

 example:example: aa33 = a.a.a = a.a.a

 and let identity be:and let identity be: e=e=aa00

a group is cyclic if every element is a a group is cyclic if every element is a

power of some fixed element power of some fixed element aa

 i.e., i.e., b =b = aakk for some for some aa and every and every bb in group in group

(22)

Ring

Ring

a set of “numbers” a set of “numbers”

 with two operations (addition and multiplication) with two operations (addition and multiplication)

which form:

which form:

an abelian group with addition operation an abelian group with addition operation  and multiplication:and multiplication:

 has closurehas closure  is associativeis associative

 distributive over addition:distributive over addition: a(b+c) = ab + aca(b+c) = ab + ac  if multiplication operation is commutative, it if multiplication operation is commutative, it

forms a

forms a commutative ringcommutative ring

if if multiplication operation has an identity and no multiplication operation has an identity and no

zero divisors, it forms an

(23)

Field

Field

 a set of numbers a set of numbers

 with two operations which form:with two operations which form:

 abelian group for addition abelian group for addition

 abelian group for multiplication (ignoring 0) abelian group for multiplication (ignoring 0)

 ringring

 have hierarchy with more axioms/lawshave hierarchy with more axioms/laws

(24)
(25)

Finite (Galois) Fields

Finite (Galois) Fields

 finite fields play a key role in cryptographyfinite fields play a key role in cryptography

 can show number of elements in a finite can show number of elements in a finite

field

field mustmust be a power of a prime p be a power of a prime pnn

 known as Galois fieldsknown as Galois fields  denoted GF(pdenoted GF(pnn))

 in particular often use the fields:in particular often use the fields:

 GF(p)GF(p)

(26)

Galois Fields GF(p)

Galois Fields GF(p)

 GF(p) is the set of integers {0,1, … , p-1} GF(p) is the set of integers {0,1, … , p-1}

with arithmetic operations modulo prime p with arithmetic operations modulo prime p

 these form a finite fieldthese form a finite field

 since have multiplicative inversessince have multiplicative inverses

 find inverse with Extended Euclidean algorithm find inverse with Extended Euclidean algorithm

 hence arithmetic is “well-behaved” and can hence arithmetic is “well-behaved” and can

do addition, subtraction, multiplication, and do addition, subtraction, multiplication, and

(27)

GF(7) Multiplication Example

GF(7) Multiplication Example

 0 1 2 3 4 5 6

(28)

Polynomial Arithmetic

Polynomial Arithmetic

 can compute using polynomialscan compute using polynomials

f

f((xx) = a) = annxxnn + a + a n-1

n-1xxn-1n-1 + … + a + … + a11x + x + aa00 = ∑ a = ∑ aiixxii

• n.b. not interested in any specific value of xn.b. not interested in any specific value of x

• which is known as the indeterminatewhich is known as the indeterminate

 several alternatives availableseveral alternatives available

 ordinary polynomial arithmeticordinary polynomial arithmetic

 poly arithmetic with coefs mod ppoly arithmetic with coefs mod p

 poly arithmetic with coefs mod p and poly arithmetic with coefs mod p and polynomials mod m(x)

(29)

Ordinary Polynomial Arithmetic

Ordinary Polynomial Arithmetic

 add or subtract corresponding coefficientsadd or subtract corresponding coefficients  multiply all terms by each othermultiply all terms by each other

 egeg let

let ff((xx) = ) = xx33 + + xx22 + 2 and + 2 and gg((xx) = ) = xx22 – x x + 1+ 1

f

f((xx) + ) + gg((xx) = ) = xx33 + 2 + 2xx22 – x x + 3+ 3

f

f((xx) – ) – gg((xx) = ) = xx33 + + x x + 1+ 1

f

(30)

Polynomial Arithmetic with

Polynomial Arithmetic with

Modulo Coefficients

Modulo Coefficients

 when computing value of each coefficient when computing value of each coefficient

do calculation modulo some value do calculation modulo some value

 forms a polynomial ringforms a polynomial ring

 could be modulo any primecould be modulo any prime

 but we are most interested in mod 2but we are most interested in mod 2  ie all coefficients are 0 or 1ie all coefficients are 0 or 1

 eg. let eg. let ff((xx) = ) = xx33 + + xx22 and and gg((xx) = ) = xx22 + + x x + 1+ 1

f

f((xx) + ) + gg((xx) = ) = xx33 + + x x + 1+ 1

f

(31)

Polynomial Division

Polynomial Division

 can write any polynomial in the form:can write any polynomial in the form:ff((xx) = ) = qq((xx) ) gg((xx) + ) + rr((xx))

 can interpret can interpret rr((xx) ) as being a remainderas being a remainder  rr((xx) = ) = ff((xx) mod ) mod gg((xx))

 if have no remainder say if have no remainder say gg((xx) divides ) divides ff((xx))  if if gg((xx) has no divisors other than itself & 1 ) has no divisors other than itself & 1

say it is

say it is irreducibleirreducible (or prime) polynomial (or prime) polynomial

 arithmetic modulo an irreducible arithmetic modulo an irreducible

(32)

Polynomial GCD

Polynomial GCD

 can find greatest common divisor for polyscan find greatest common divisor for polys

c(x)c(x) = GCD( = GCD(a(x), b(x)a(x), b(x)) if ) if c(x)c(x) is the poly of greatest is the poly of greatest

degree which divides both

degree which divides both a(x), b(x)a(x), b(x)

 can adapt Euclid’s Algorithm to find it:can adapt Euclid’s Algorithm to find it:

Euclid(

Euclid(aa((xx)), b, b((xx))) ) if (

if (bb((xx))=0) then return =0) then return aa((xx)); ; else return

else return

Euclid(

Euclid(bb((xx), ), aa((xx)) mod mod

b

b((xx))););

(33)

Modular Polynomial

Modular Polynomial

Arithmetic

Arithmetic

 can compute in field GF(2can compute in field GF(2nn) )

 polynomials with coefficients modulo 2polynomials with coefficients modulo 2

 whose degree is less than nwhose degree is less than n

 hence must reduce modulo an irreducible poly hence must reduce modulo an irreducible poly of degree n (for multiplication only)

of degree n (for multiplication only)

form a finite fieldform a finite field

 can always find an inversecan always find an inverse

(34)

Example GF(2

(35)

Computational

Computational

Considerations

Considerations

 since coefficients are 0 or 1, can represent since coefficients are 0 or 1, can represent

any such polynomial as a bit string any such polynomial as a bit string

 addition becomes XOR of these bit stringsaddition becomes XOR of these bit strings  multiplication is shift & XORmultiplication is shift & XOR

 cf long-hand multiplicationcf long-hand multiplication

 modulo reduction done by repeatedly modulo reduction done by repeatedly

substituting highest power with remainder substituting highest power with remainder

(36)

Computational Example

Computational Example

in in GF(2GF(233) have ) have (x(x22+1) is 101+1) is 101 2

2 & (x & (x22+x+1) is 111+x+1) is 11122

 so addition isso addition is

 (x(x22+1) + (x+1) + (x22+x+1) = x +x+1) = x  101 XOR 111 = 010101 XOR 111 = 010

2

2

 and multiplication isand multiplication is

 (x+1).(x(x+1).(x22+1) = x.(x+1) = x.(x22+1) + 1.(x+1) + 1.(x22+1) +1)

= x

= x33+x+x+x+x22+1 = x+1 = x33+x+x22+x+1 +x+1

 011.101 = (101)<<1 XOR (101)<<0 = 011.101 = (101)<<1 XOR (101)<<0 =

1010 XOR 101 = 1111

(37)

Computational Example (con't)

Computational Example (con't)

in in GF(2GF(233) have ) have (x(x22+1) is 101+1) is 101 2

2 & (x & (x22+x+1) is 111+x+1) is 11122

 polynomial modulo reduction (get q(x) & r(x)) ispolynomial modulo reduction (get q(x) & r(x)) is  (x(x33+x+x22+x+1 ) mod (x+x+1 ) mod (x33+x+1) = 1.(x+x+1) = 1.(x33+x+1) + (x+x+1) + (x22) = x) = x22  1111 mod 1011 = 1111 XOR 1011 = 01001111 mod 1011 = 1111 XOR 1011 = 0100

2

(38)

Using a Generator

Using a Generator

 equivalent definition of a finite fieldequivalent definition of a finite field  a a generatorgenerator g is an element whose g is an element whose

powers generate all non-zero elements powers generate all non-zero elements

 in F have 0, gin F have 0, g00, g, g11, …, g, …, gq-2q-2

 can create generator from can create generator from rootroot of the of the

irreducible polynomial irreducible polynomial

 then implement multiplication by adding then implement multiplication by adding

(39)

Summary

Summary

 have considered:have considered:

 divisibility & GCDdivisibility & GCD

 modular arithmetic with integersmodular arithmetic with integers

 concept of groups, rings, fieldsconcept of groups, rings, fields

 Euclid’s algorithm for GCD & InverseEuclid’s algorithm for GCD & Inverse

 finite fields GF(p)finite fields GF(p)

References

Related documents

Security properties and program Remopla model are input to Moped in order to detect security violations and provide witness paths leading to them.. Moped allows the verification

Regarding the poor consideration paid to the role of per- sonality traits in factors related to general health and no conducted study on the relationship between

A smooth irreducible representation whose matrix coefficients are all compactly supported modulo the center is

In line with the findings for previous public speaking anxiety treatments [ 9 ], and the effectiveness of inoculation messages for protecting recipients’ perceptions [ 30 ],

If n divides a positive integer m, then every congruence class modulo n is the union of m/n congruence classes modulo m.. Hence the set of all congruence classes modulo n is the

This study, the first to investigate ovarian reserve func- tion in women with MetS, found that ovarian reserve, as determined by ovarian volume, was significantly lower in patients

The conditional means of individual connections are plotted against their true values (over all simulations) in Figure 8, for the full model (upper left panel) and selected

In Section 1.3, we study conjugates of an element and roots of irreducible polynomials and determine the number of monic irreducible polynomials of given degree over a finite field..