CPSC 467b: Cryptography and Computer Security

Similar documents
CPSC 467: Cryptography and Computer Security

CPSC 467b: Cryptography and Computer Security

CPSC 467: Cryptography and Computer Security

CPSC 467: Cryptography and Computer Security

Lecture 2 Algorithms with numbers

Overview. Public Key Algorithms I

Algorithms (III) Yijia Chen Shanghai Jiaotong University

Algorithms (III) Yijia Chen Shanghai Jiaotong University

Algorithms (III) Yu Yu. Shanghai Jiaotong University

RSA (material drawn from Avi Kak Lecture 12, Lecture Notes on "Computer and Network Security" Used in asymmetric crypto.

CS Network Security. Nasir Memon Polytechnic University Module 7 Public Key Cryptography. RSA.

Introduction to Cryptography and Security Mechanisms. Abdul Hameed

Public Key Algorithms

CS669 Network Security

Dr. Jinyuan (Stella) Sun Dept. of Electrical Engineering and Computer Science University of Tennessee Fall 2010

! Addition! Multiplication! Bigger Example - RSA cryptography

CS 161 Computer Security

Public Key Cryptography and the RSA Cryptosystem

Study Guide to Mideterm Exam

Lecture 3 Algorithms with numbers (cont.)

Applied Cryptography and Network Security

Public Key Cryptography

What did we talk about last time? Public key cryptography A little number theory

CPSC 467b: Cryptography and Computer Security

CPSC 467: Cryptography and Computer Security

Chapter 3 Public Key Cryptography

Lecture 2 Applied Cryptography (Part 2)

Cryptography Worksheet

RSA (Rivest Shamir Adleman) public key cryptosystem: Key generation: Pick two large prime Ô Õ ¾ numbers È.

ICT 6541 Applied Cryptography. Hossen Asiful Mustafa

RSA. Public Key CryptoSystem

Introduction to Cryptography and Security Mechanisms: Unit 5. Public-Key Encryption

RSA (Rivest Shamir Adleman) public key cryptosystem: Key generation: Pick two large prime Ô Õ ¾ numbers È.

Great Theoretical Ideas in Computer Science. Lecture 27: Cryptography

RSA (algorithm) History

CPSC 467b: Cryptography and Computer Security

Applied Cryptography and Computer Security CSE 664 Spring 2018

Public-key encipherment concept

This chapter continues our overview of public-key cryptography systems (PKCSs), and begins with a description of one of the earliest and simplest

Channel Coding and Cryptography Part II: Introduction to Cryptography

Chapter 9. Public Key Cryptography, RSA And Key Management

Chapter 9 Public Key Cryptography. WANG YANG

Senior Math Circles Cryptography and Number Theory Week 1

Public Key Algorithms

Public-Key Cryptography. Professor Yanmin Gong Week 3: Sep. 7

Public Key Cryptography and RSA

Encryption Providing Perfect Secrecy COPYRIGHT 2001 NON-ELEPHANT ENCRYPTION SYSTEMS INC.

ISA 562: Information Security, Theory and Practice. Lecture 1

Uzzah and the Ark of the Covenant

Number Theory and RSA Public-Key Encryption

CSCI 454/554 Computer and Network Security. Topic 5.2 Public Key Cryptography

Secure Multiparty Computation

Computer Security. 08. Cryptography Part II. Paul Krzyzanowski. Rutgers University. Spring 2018

Outline. CSCI 454/554 Computer and Network Security. Introduction. Topic 5.2 Public Key Cryptography. 1. Introduction 2. RSA

Kurose & Ross, Chapters (5 th ed.)

Blum-Blum-Shub cryptosystem and generator. Blum-Blum-Shub cryptosystem and generator

Outline. Public Key Cryptography. Applications of Public Key Crypto. Applications (Cont d)

Primality Testing! 1

Lecturers: Mark D. Ryan and David Galindo. Cryptography Slide: 24

10.1 Introduction 10.2 Asymmetric-Key Cryptography Asymmetric-Key Cryptography 10.3 RSA Cryptosystem

CS 161 Computer Security

Modern cryptography 2. CSCI 470: Web Science Keith Vertanen

An overview and Cryptographic Challenges of RSA Bhawana

ASYMMETRIC CRYPTOGRAPHY

ח'/סיון/תשע "א. RSA: getting ready. Public Key Cryptography. Public key cryptography. Public key encryption algorithms

Intro to Public Key Cryptography Diffie & Hellman Key Exchange

CPSC 467b: Cryptography and Computer Security

CPSC 467b: Cryptography and Computer Security

Lecture 6 - Cryptography

Lecture 6: Overview of Public-Key Cryptography and RSA

Introduction to Cryptology Dr. Sugata Gangopadhyay Department of Computer Science and Engineering Indian Institute of Technology, Roorkee

Encryption. INST 346, Section 0201 April 3, 2018

Cryptography and Network Security. Sixth Edition by William Stallings

INTERNATIONAL JOURNAL OF ELECTRONICS AND COMMUNICATION ENGINEERING & TECHNOLOGY (IJECET)

Introduction to Cryptography Lecture 7

Introduction to Cryptography Lecture 7

CS61A Lecture #39: Cryptography

Study Guide for the Final Exam

Crypto CS 485/ECE 440/CS 585 Fall 2017

Introduction. Cambridge University Press Mathematics of Public Key Cryptography Steven D. Galbraith Excerpt More information

Public-Key Cryptography

CS 161 Computer Security

CS573 Data Privacy and Security. Cryptographic Primitives and Secure Multiparty Computation. Li Xiong

Cryptography Symmetric Cryptography Asymmetric Cryptography Internet Communication. Telling Secrets. Secret Writing Through the Ages.

Elements of Cryptography and Computer and Networking Security Computer Science 134 (COMPSCI 134) Fall 2016 Instructor: Karim ElDefrawy

Public Key Encryption. Modified by: Dr. Ramzi Saifan

6.001 Notes: Section 4.1

Distributed Systems. 26. Cryptographic Systems: An Introduction. Paul Krzyzanowski. Rutgers University. Fall 2015

CS 6324: Information Security More Info on Key Establishment: RSA, DH & QKD

1.264 Lecture 28. Cryptography: Asymmetric keys

Notes for Lecture 10

Introduction. CSE 5351: Introduction to cryptography Reading assignment: Chapter 1 of Katz & Lindell

L2. An Introduction to Classical Cryptosystems. Rocky K. C. Chang, 23 January 2015

Computer Security 3/23/18

A Tour of Classical and Modern Cryptography

EE 595 (PMP) Introduction to Security and Privacy Homework 1 Solutions

Activity Guide - Public Key Cryptography

Key Exchange. Secure Software Systems

Lecture 30. Cryptography. Symmetric Key Cryptography. Key Exchange. Advanced Encryption Standard (AES) DES. Security April 11, 2005

Lecture IV : Cryptography, Fundamentals

Transcription:

CPSC 467b: Cryptography and Computer Security Michael J. Fischer Lecture 7 January 30, 2012 CPSC 467b, Lecture 7 1/44

Public-key cryptography RSA Factoring Assumption Computing with Big Numbers Fast Exponentiation Algorithms Number theory Division Modular Arithmetic CPSC 467b, Lecture 7 2/44

Public-key cryptography Classical cryptography uses a single key for both encryption and decryption. This is also called a symmetric or 1-key cryptography. There is no logical reason why the encryption and decryption keys should be the same. Allowing them to differ gives rise to asymmetric cryptography, also known as public-key or 2-key cryptography. CPSC 467b, Lecture 7 3/44

Asymmetric cryptosystems An asymmetric cryptosystem has a pair k = (k e, k d ) of related keys, the encryption key k e and the decryption key k d. Alice encrypts a message m by computing c = E ke (m). Bob decrypts c by computing m = D kd (c). We sometimes write e instead of k e and d instead of k d, e.g., E e (m) and D d (c). We sometimes write k instead of k e or k d where the meaning is clear from context, e.g., E k (m) and D k (c). In practice, it isn t generally as confusing as all this, but the potential for misunderstanding is there. As always, the decryption function inverts the encryption function, so m = D d (E e (m)). CPSC 467b, Lecture 7 4/44

Security requirement Should be hard for Eve to find m given c = E e (m) and e. The system remains secure even if the encryption key e is made public! e is said to be the public key and d the private key. Reason to make e public. Anybody can send an encrypted message to Bob. Sandra obtains Bob s public key e and sends c = E e (m) to Bob. Bob recovers m by computing D d (c), using his private key d. This greatly simplifies key management. No longer need a secure channel between Alice and Bob for the initial key distribution (which I have carefully avoided talking about so far). CPSC 467b, Lecture 7 5/44

Man-in-the-middle attack against 2-key cryptosystem An active adversary Mallory can carry out a nasty man-in-the-middle attack. Mallory sends his own encryption key to Sandra when she attempts to obtain Bob s key. Not knowing she has been duped, Sandra encrypts her private data using Mallory s public key, so Mallory can read it (but Bob cannot)! To keep from being discovered, Mallory intercepts each message from Sandra to Bob, decrypts using his own decryption key, re-encrypts using Bob s public encryption key, and sends it on to Bob. Bob, receiving a validly encrypted message, is none the wiser. CPSC 467b, Lecture 7 6/44

Passive attacks against a 2-key cryptosystem Making the encryption key public also helps a passive attacker. 1. Chosen-plaintext attacks are available since Eve can generate as many plaintext-ciphertext pairs as she wishes using the public encryption function E e (). 2. The public encryption function also gives Eve a foolproof way to check the validity of a potential decryption. Namely, Eve can verify D d (c) = m 0 for some candidate message m 0 by checking that c = E e (m 0 ). Redundancy in the set of meaningful messages is no longer necessary for brute force attacks. CPSC 467b, Lecture 7 7/44

Facts about asymmetric cryptosystems Good asymmetric cryptosystems are much harder to design than good symmetric cryptosystems. All known asymmetric systems are orders of magnitude slower than corresponding symmetric systems. CPSC 467b, Lecture 7 8/44

Hybrid cryptosystems Asymmetric and symmetric cryptosystems are often used together. Let (E 2, D 2 ) be a 2-key cryptosystem and (E 1, D 1 ) be a 1-key cryptosystem. Here s how Alice sends a secret message m to Bob. Alice generates a random session key k. Alice computes c 1 = E 1 k (m) and c 2 = E 2 e (k), where e is Bob s public key, and sends (c 1, c 2 ) to Bob. Bob computes k = D 2 d (c 2) using his private decryption key d and then computes m = D 1 k (c 1). This is much more efficient than simply sending E 2 e (m) in the usual case that m is much longer than k. Note that the 2-key system is used to encrypt random strings! CPSC 467b, Lecture 7 9/44

RSA CPSC 467b, Lecture 7 10/44

Overview of RSA Probably the most commonly used asymmetric cryptosystem today is RSA, named from the initials of its three inventors, Rivest, Shamir, and Adelman. Unlike the symmetric systems we have been talking about so far, RSA is based not on substitution and transposition but on arithmetic involving very large integers numbers that are hundreds or even thousands of bits long. To understand why RSA works requires knowing a bit of number theory. However, the basic ideas can be presented quite simply, which I will do now. CPSC 467b, Lecture 7 11/44

RSA spaces The message space, ciphertext space, and key space for RSA is the set of integers Z n = {0,..., n 1} for some very large integer n. For now, think of n as a number so large that its binary representation is 1024 bits long. Such a number is unimaginably big. It is bigger than 2 1023 10 308. For comparison, the number of atoms in the observable universe 1 is estimated to be only 10 80. 1 Wikipedia, https://en.wikipedia.org/wiki/observable universe CPSC 467b, Lecture 7 12/44

Encoding bit strings by integers To use RSA as a block cipher on bit strings, Alice must convert each block to an integer m Z n, and Bob must convert m back to a block. Many such encodings are possible, but perhaps the simplest is to prepend a 1 to the block x and regard the result as a binary integer m. To decode m to a block, write out m in binary and then delete the initial 1 bit. To ensure that m < n as required, we limit the length of our blocks to 1022 bits. CPSC 467b, Lecture 7 13/44

RSA key generation Here s how Bob generates an RSA key pair. Bob chooses two sufficiently large distinct prime numbers p and q and computes n = pq. For security, p and q should be about the same length (when written in binary). He computes two numbers e and d with a certain number-theoretic relationship. The public key is the pair k e = (e, n). The private key is the pair k d = (d, n). The primes p and q are no longer needed and should be discarded. CPSC 467b, Lecture 7 14/44

RSA encryption and decryption To encrypt, Alice computes c = m e mod n. 2 To decrypt, Bob computes m = c d mod n. Here, a mod n denotes the remainder when a is divided by n. This works because e and d are chosen so that, for all m, m = (m e mod n) d mod n. (1) That s all there is to it, once the keys have been found. Most of the complexity in implementing RSA has to do with key generation, which fortunately is done only infrequently. 2 For now, assume all messages and ciphertexts are integers in Z n. CPSC 467b, Lecture 7 15/44

RSA questions You should already be asking yourself the following questions: How does one find n, e, d such that equation 1 is satisfied? Why is RSA believed to be secure? How can one implement RSA on a computer when most computers only support arithmetic on 32-bit or 64-bit integers, and how long does it take? How can one possibly compute m e mod n for 1024 bit numbers. m e, before taking the remainder, has size roughly ( 2 1024 ) 2 1024 = 2 1024 21024 = 2 210 2 1024 = 2 21034. This is a number that is roughly 2 1034 bits long! No computer has enough memory to store that number, and no computer is fast enough to compute it. CPSC 467b, Lecture 7 16/44

Tools needed to answer RSA questions Two kinds of tools are needed to understand and implement RSA. Algorithms: Need clever algorithms for primality testing, fast exponentiation, and modular inverse computation. Number theory: Need some theory of Z n, the integers modulo n, and some special properties of numbers n that are the product of two primes. CPSC 467b, Lecture 7 17/44

Factoring Assumption CPSC 467b, Lecture 7 18/44

Factoring assumption The factoring problem is to find a prime divisor of a composite number n. The factoring assumption is that there is no probabilistic polynomial-time algorithm for solving the factoring problem, even for the special case of an integer n that is the product of just two distinct primes The security of RSA is based on the factoring assumption. No feasible factoring algorithm is known, but there is no proof that such an algorithm does not exist. CPSC 467b, Lecture 7 19/44

How big is big enough? The security of RSA depends on n, p, q being sufficiently large. What is sufficiently large? That s hard to say, but n is typically chosen to be at least 1024 bits long, or for better security, 2048 bits long. The primes p and q whose product is n are generally chosen be roughly the same length, so each will be about half as long as n. CPSC 467b, Lecture 7 20/44

Computing with Big Numbers CPSC 467b, Lecture 7 21/44

Algorithms for arithmetic on big numbers The arithmetic built into typical computers can handle only 32-bit or 64-bit integers. Hence, all arithmetic on large integers must be performed by software routines. The straightforward algorithms for addition and multiplication have time complexities O(N) and O(N 2 ), respectively, where N is the length (in bits) of the integers involved. Asymptotically faster multiplication algorithms are known, but they involve large constant factor overheads. It s not clear whether they are practical for numbers of the sizes we are talking about. CPSC 467b, Lecture 7 22/44

Big number libraries A lot of cleverness is possible in the careful implementation of even the O(N 2 ) multiplication algorithms, and a good implementation can be many times faster in practice than a poor one. They are also hard to get right because of many special cases that must be handled correctly! Most people choose to use big number libraries written by others rather than write their own code. Two such libraries that you can use in this course: 1. GMP (GNU Multiple Precision Arithmetic Library); 2. The big number routines in the openssl crypto library. CPSC 467b, Lecture 7 23/44

GMP GMP provides a large number of highly-optimized function calls for use with C and C++. It is preinstalled on all of the Zoo nodes and supported by the open source community. Type info gmp at a shell for documentation. CPSC 467b, Lecture 7 24/44

Openssl crypto package OpenSSL is a cryptography toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) network protocols and related cryptography standards required by them. It is widely used and pretty well debugged. The protocols require cryptography, and OpenSSL implements its own big number routines which are contained in its crypto library. Type man crypto for general information about the library, and man bn for specifics of the big number routines. CPSC 467b, Lecture 7 25/44

Fast Exponentiation Algorithms CPSC 467b, Lecture 7 26/44

Modular exponentiation The basic operation of RSA is modular exponentiation of big numbers, i.e., computing m e mod n for big numbers m, e, and n. The obvious way to compute this would be to compute first t = m e and then t mod n. CPSC 467b, Lecture 7 27/44

Difficulty of modular exponentiation 1. The number m e is too big to store! This number, when written in binary, is about 1024 2 1024 bits long, a number far larger than the number of atoms in the universe (which is estimated to be only around 10 80 2 266 ). 2. The simple iterative loop to compute m e requires e multiplications, or about 2 1024 operations in all. This computation would run longer than the current age of the universe (which is estimated to be 15 billion years). Assuming one loop iteration could be done in one microsecond (very optimistic seeing as each iteration requires computing a product and remainder of big numbers), only about 30 10 12 iterations could be performed per year, and only about 450 10 21 iterations in the lifetime of the universe. But 450 10 21 2 79, far less than e 1. CPSC 467b, Lecture 7 28/44

Controlling the size of intermediate results The trick to get around the first problem is to do all arithmetic modulo n, that is, reduce the result modulo n after each arithmetic operation. The product of two length l numbers is only length 2l before reduction mod n, so in this way, one never has to deal with numbers longer than about 2048 bits. Question to think about: Why is it correct to do this? CPSC 467b, Lecture 7 29/44

Efficient exponentiation The trick here is to use a more efficient exponentiation algorithm based on repeated squaring. For the special case of e = 2 k, one computes m e mod n as follows: m 0 = m m 1 = (m 0 m 0 ) mod n m 2 = (m 1 m 1 ) mod n Clearly, m i = m 2i mod n for all i.. m k = (m k 1 m k 1 ) mod n. CPSC 467b, Lecture 7 30/44

Combining the m i for general e For values of e that are not powers of 2, m e mod n can be obtained as the product modulo n of certain m i s. Express e in binary as e = (b s b s 1... b 2 b 1 b 0 ) 2. Then e = i 2b i, so m e = m P i 2b i = m 2bi. i Hence, m e mod n = i m 2b i mod n = m i mod n. i : b I =1 since each b i {0, 1}. Thus, we include those m i in the final product for which b i = 1. CPSC 467b, Lecture 7 31/44

Towards greater efficiency It is not necessary to perform this computation in two phases. Rather, the two phases can be combined together, resulting in slicker and simpler algorithms that do not require the explicit storage of the m i s. We give both a recursive and an iterative version. CPSC 467b, Lecture 7 32/44

A recursive exponentiation algorithm Here is a recursive version written in C notation, but it should be understood that the C programs only work for numbers smaller than 2 16. To handle larger numbers requires the use of big number functions. /* computes m^e mod n recursively */ int modexp( int m, int e, int n) { int r; if ( e == 0 ) return 1; /* m^0 = 1 */ r = modexp(m*m % n, e/2, n); /* r = (m^2)^(e/2) mod n */ if ( (e&1) == 1 ) r = r*m % n; /* handle case of odd e */ return r; } CPSC 467b, Lecture 7 33/44

An iterative exponentiation algorithm This same idea can be expressed iteratively to achieve even greater efficiency. /* computes m^e mod n iteratively */ int modexp( int m, int e, int n) { int r = 1; while ( e > 0 ) { if ( (e&1) == 1 ) r = r*m % n; e /= 2; m = m*m % n; } return r; } CPSC 467b, Lecture 7 34/44

Correctness The loop invariant is e > 0 (m e 0 0 mod n = rme mod n) (2) where m 0 and e 0 are the initial values of m and e, respectively. Proof of correctness: It is easily checked that (2) holds at the start of each iteration. If the loop exits, then e = 0, so r mod n is the desired result. Termination is ensured since e gets reduced during each iteration. CPSC 467b, Lecture 7 35/44

A minor optimization Note that the last iteration of the loop computes a new value of m that is never used. A slight efficiency improvement results from restructuring the code to eliminate this unnecessary computation. Following is one way of doing so. /* computes m^e mod n iteratively */ int modexp( int m, int e, int n) { int r = ( (e&1) == 1 )? m % n : 1; e /= 2; while ( e > 0 ) { m = m*m % n; if ( (e&1) == 1 ) r = r*m % n; e /= 2; } return r; } CPSC 467b, Lecture 7 36/44

Number theory CPSC 467b, Lecture 7 37/44

Number theory overview In this and following sections, we review some number theory that is needed for understanding RSA. I will provide only a high-level overview. Further details are contained in course handouts and the textbooks. CPSC 467b, Lecture 7 38/44

Division Quotient and remainder Theorem (division theorem) Let a, b be integers and assume b > 0. There are unique integers q (the quotient) and r (the remainder) such that a = bq + r and 0 r < b. Write the quotient as a b and the remainder as a mod b. Then a = b (a b) + (a mod b). Equivalently, a mod b = a b (a b). a b = a/b. 3 3 Here, / is ordinary real division and x, the floor of x, is the greatest integer x. In C, / is used for both and / depending on its operand types. CPSC 467b, Lecture 7 39/44

Division mod for negative numbers When either a or b is negative, there is no consensus on the definition of a mod b. By our definition, a mod b is always in the range [0... b 1], even when a is negative. Example, ( 5) mod 3 = ( 5) 3 (( 5) 3) = 5 3 ( 2) = 1. In the C programming language, the mod operator % is defined differently, so (a % b) (a mod b) when a is negative and b is positive. 4 4 For those of you who are interested, the C standard defines a % b to be the number satisfying the equation (a/b) b + (a % b) = a. C also defines a/b to be the result of rounding the real number a/b towards zero, so 5/3 = 1. Hence, 5 % 3 = 5 ( 5/3) 3 = 5 + 3 = 2 in C. CPSC 467b, Lecture 7 40/44

Division Divides We say that b divides a (exactly) and write b a in case a mod b = 0. Fact If d (a + b), then either d divides both a and b, or d divides neither of them. To see this, suppose d (a + b) and d a. Then by the division theorem, a + b = dq 1 and a = dq 2 for some integers q 1 and q 2. Substituting for a and solving for b, we get b = dq 1 dq 2 = d(q 1 q 2 ). But this implies d b, again by the division theorem. CPSC 467b, Lecture 7 41/44

Modular Arithmetic The mod relation We just saw that mod is a binary operation on integers. Mod is also used to denote a relationship on integers: a b (mod n) iff n (a b). That is, a and b have the same remainder when divided by n. An immediate consequence of this definition is that a b (mod n) iff (a mod n) = (b mod n). Thus, the two notions of mod aren t so different after all! We sometimes write a n b to mean a b (mod n). CPSC 467b, Lecture 7 42/44

Modular Arithmetic Mod is an equivalence relation The two-place relationship n is an equivalence relation. Its equivalence classes are called residue classes modulo n and are denoted by [b] n = {a a b (mod n)} or simply by [b]. For example, if n = 7, then [10] = {... 11, 4, 3, 10, 17,...}. Fact [a] = [b] iff a b (mod n). CPSC 467b, Lecture 7 43/44

Modular Arithmetic Canonical names If x [b], then x is said to be a representative or name of the equivalence class [b]. Obviously, b is a representative of [b]. Thus, [ 11], [ 4], [3], [10], [17] are all names for the same equivalence class. The canonical or preferred name for the class [b] is the unique integer in [b] {0, 1,..., n 1}. Thus, the canonical name for [10] is 10 mod 7 = 3. CPSC 467b, Lecture 7 44/44