Download presentation
Published byEmmeline Freeman Modified over 8 years ago
1
Implementation of Public Key Encryption Algorithms
CSCI 5857: Encoding and Encryption
2
Outline Fast modular exponentiation Finding very large prime numbers
Rearranging multiplication and mod The square and multiply method Finding very large prime numbers Generate and test method The Miller-Rabin test
3
Modular Exponentiation
Must compute C = P E mod n and P = C D mod n for very large n, E, D, P, and C Example: Problem: P E is a really big number! Too large for fast computation or even storage on most systems Note: Final result P E mod n ≤ n
4
Modular Multiplication Properties
Solution: Keep value smaller by taking mod n throughout computation (instead of at end) Useful property of modular arithmetic: a b mod n = ((a mod n) (b mod n)) mod n Example: mod 17 = (37 58) mod = (37 mod 17)(58 mod 17) mod = 3 7 mod 17 = 4
5
Square and Multiply Method
Break exponent E into product of powers of 2 Example: P22 = P16 P4 P2 Can be represented as “bits”: 22 10110 Use squaring to compute powers of 2 quickly P P 2 P 4 P 8 P 16 Multiply by running total if corresponding bit = 1
6
Fast Modular Exponentiation
Algorithm to compute PE mod n: result = 1 for (i = 0 to number of bits in E - 1) { if (ith bit == 1) result = (result * P) mod n P = P2 mod n }
7
Fast Modular Exponentiation Example
Example: 1722 mod 21 i ith bit P result 17 (unchanged) 1 172 mod 21 = 16 1 * 16 mod 21 = 16 2 174 mod 21 = 162 mod 21 = 4 16 * 4 mod 21 = 1 3 178 mod 21 = 42 mod 21 = 16 4 1716 mod 21 = 162 mod 21 = 4 1 * 4 mod 21 = 4
8
Finding Large Primes Need very large primes (hundreds of digits) for key generation Problem: No simple way to generate an arbitrarily large prime number Usual method: generate and test Generate a sufficiently large odd number Test it for primality
9
Frequency of Primes How many might we need to test before finding a prime? Primes of size s are spaced about every ln(s) ln(s) = natural logarithm = loge(s) Example: Finding prime of size 2200 would require testing on average ln(2200) 138 numbers
10
Miller-Rabin Test Basic idea: many primes are of form p = 2kq + 1 for some k, q Miller-Rabin test: If p is prime then for all a < p – 1 either: a q mod p = 1 One of a q, a 2q, a 4q, … a 2k-1q mod p = -1
11
Probabilistic Testing
Problem: No way to test all possible values of a 2200 possible values of a for primes of size 2200 Probabilistic approach: Try enough values of a to be as sure as necessary that p is prime Odds that non-prime p passes test for some a: 1/4 Odds that non-prime p passes t different tests: (1/4)t p passes15 tests odds are 1 in a billion that it is not prime
12
Algorithm for Finding Large Primes
Possible algorithm: Generate sufficiently large p = 2kq + 1 for some k, q Test for divisibility by small primes (3, 5, 7, 11, 13, 17) Quick elimination of most failed candidates Choose a set of test a’s for Miller-Rabin test Enough to be as sure as necessary Example: 15 for % certainty If p passes test for all a’s, p can be used as prime
13
What’s Next Let me know if you have any questions
Continue on to the next lecture on Attacks on Public Key Encryption
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.