Security II: Cryptography exercises

Similar documents
Chapter 8 Public-key Cryptography and Digital Signatures

Lemma 1.2. (1) If p is prime, then ϕ(p) = p 1. (2) If p q are two primes, then ϕ(pq) = (p 1)(q 1).

Notes. Number Theory: Applications. Notes. Number Theory: Applications. Notes. Hash Functions I

Number Theory: Applications. Number Theory Applications. Hash Functions II. Hash Functions III. Pseudorandom Numbers

CPSC 467: Cryptography and Computer Security

Definition: For a positive integer n, if 0<a<n and gcd(a,n)=1, a is relatively prime to n. Ahmet Burak Can Hacettepe University

Topics in Cryptography. Lecture 5: Basic Number Theory

Asymmetric Encryption

Addition. Ch1 - Algorithms with numbers. Multiplication. al-khwārizmī. al-khwārizmī. Division 53+35=88. Cost? (n number of bits) 13x11=143. Cost?

Pseudo-random Number Generation. Qiuliang Tang

Question: Total Points: Score:

Lecture V : Public Key Cryptography

Chapter 4 Asymmetric Cryptography

Asymmetric Cryptography

CHALMERS GÖTEBORGS UNIVERSITET. TDA352 (Chalmers) - DIT250 (GU) 11 April 2017, 8:30-12:30

1 Number Theory Basics

Math/Mthe 418/818. Review Questions

Introduction to Public-Key Cryptosystems:

Public-Key Cryptosystems CHAPTER 4

Lecture 1: Introduction to Public key cryptography

Introduction to Cybersecurity Cryptography (Part 4)

Introduction to Cybersecurity Cryptography (Part 5)

Introduction to Cybersecurity Cryptography (Part 4)

5199/IOC5063 Theory of Cryptology, 2014 Fall

Public Key Cryptography

RSA. Ramki Thurimella

CSc 466/566. Computer Security. 5 : Cryptography Basics

CPSC 467b: Cryptography and Computer Security

CPE 776:DATA SECURITY & CRYPTOGRAPHY. Some Number Theory and Classical Crypto Systems

CIS 551 / TCOM 401 Computer and Network Security

Introduction to Cryptography. Lecture 6

Mathematical Foundations of Public-Key Cryptography

Slides by Kent Seamons and Tim van der Horst Last Updated: Oct 1, 2013

Univ.-Prof. Dr. rer. nat. Rudolf Mathar. Written Examination. Cryptography. Tuesday, August 29, 2017, 01:30 p.m.

Numbers. Çetin Kaya Koç Winter / 18

Cryptography IV: Asymmetric Ciphers

Number Theory. Modular Arithmetic

ECE596C: Handout #11

Discrete mathematics I - Number theory

Public Key Algorithms

CPSC 467b: Cryptography and Computer Security

ICS141: Discrete Mathematics for Computer Science I

CRYPTOGRAPHY AND NUMBER THEORY

Number Theory and Algebra: A Brief Introduction

Number Theory and Group Theoryfor Public-Key Cryptography

Introduction to Cryptography k. Lecture 5. Benny Pinkas k. Requirements. Data Integrity, Message Authentication

Lecture Notes, Week 6

Overview. Background / Context. CSC 580 Cryptography and Computer Security. March 21, 2017

Introduction to Modern Cryptography. Benny Chor

Public Key Cryptography

Public Key Encryption

Cryptography and Network Security Prof. D. Mukhopadhyay Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Public Key 9/17/2018. Symmetric Cryptography Review. Symmetric Cryptography: Shortcomings (1) Symmetric Cryptography: Analogy

Practice Final Exam Winter 2017, CS 485/585 Crypto March 14, 2017

Number Theory & Modern Cryptography

Lecture 4 Chiu Yuen Koo Nikolai Yakovenko. 1 Summary. 2 Hybrid Encryption. CMSC 858K Advanced Topics in Cryptography February 5, 2004

Network Security Technology Spring, 2018 Tutorial 3, Week 4 (March 23) Due Date: March 30

Algorithmic Number Theory and Public-key Cryptography

10 Public Key Cryptography : RSA

Logic gates. Quantum logic gates. α β 0 1 X = 1 0. Quantum NOT gate (X gate) Classical NOT gate NOT A. Matrix form representation

10 Modular Arithmetic and Cryptography

Applied Cryptography and Computer Security CSE 664 Spring 2018

1 Recommended Reading 1. 2 Public Key/Private Key Cryptography Overview RSA Algorithm... 2

Exam Security January 19, :30 11:30

2. Cryptography 2.5. ElGamal cryptosystems and Discrete logarithms

CIS 6930/4930 Computer and Network Security. Topic 5.2 Public Key Cryptography

Public Key Cryptography. All secret key algorithms & hash algorithms do the same thing but public key algorithms look very different from each other.

This is a recursive algorithm. The procedure is guaranteed to terminate, since the second argument decreases each time.

Basic elements of number theory

Basic elements of number theory

Discrete Mathematics GCD, LCM, RSA Algorithm

Fundamentals of Modern Cryptography

Introduction to Information Security

Introduction to Elliptic Curve Cryptography

Information Security

TECHNISCHE UNIVERSITEIT EINDHOVEN Faculty of Mathematics and Computer Science Exam Cryptology, Tuesday 30 October 2018

Number Theory. CSS322: Security and Cryptography. Sirindhorn International Institute of Technology Thammasat University CSS322. Number Theory.

RSA RSA public key cryptosystem

CSC 5930/9010 Modern Cryptography: Number Theory

Mathematics of Cryptography

Ex1 Ex2 Ex3 Ex4 Ex5 Ex6

Applied Cryptography and Computer Security CSE 664 Spring 2017

Introduction to Elliptic Curve Cryptography. Anupam Datta

Introduction to Cryptography. Lecture 8

OWO Lecture: Modular Arithmetic with Algorithmic Applications

Implementation Tutorial on RSA

MATH 158 FINAL EXAM 20 DECEMBER 2016

ECS 189A Final Cryptography Spring 2011

Lecture 6: Cryptanalysis of public-key algorithms.,

Cryptography. P. Danziger. Transmit...Bob...

YALE UNIVERSITY DEPARTMENT OF COMPUTER SCIENCE

Cryptography and Security Midterm Exam

Chapter 9 Mathematics of Cryptography Part III: Primes and Related Congruence Equations

The RSA cryptosystem and primality tests

14 Diffie-Hellman Key Agreement

Candidates must show on each answer book the type of calculator used. Only calculators permitted under UEA Regulations may be used.

CPSC 467b: Cryptography and Computer Security

Elementary Number Theory MARUCO. Summer, 2018

Number theory (Chapter 4)

CHAPMAN & HALL/CRC CRYPTOGRAPHY AND NETWORK SECURITY ALGORITHMIC CR YPTAN ALY51S. Ant nine J aux

Transcription:

Security II: Cryptography exercises Markus Kuhn Lent 2015 Part II Some of the exercises require the implementation of short programs. The model answers use Perl (see Part IB Unix Tools course), but you can use any language you prefer, as long as it supports an arbitrary-length integer type and offers a SHA-1 function. Include both your source code and the required output into your answers. Before starting any programming exercise, first estimate of how many minutes the solution will take you. Please include in your answers both this estimate, as well as the actual time you required. Exercise 1: Explain the collision resistance requirement for the hash function used in a digital signature scheme. Exercise 2: Your colleagues urgently need a collision-resistant hash function. Their code contains already an existing implementation of ECBC-MAC, using a block cipher with 256-bit block size. Therefore, they suggest to use ECBC-MAC with fixed keys K 1 = K 2 = 0 l as a hash function. Show that this construction is not even pre-image resistant. Exercise 3: Show how the DES block cipher can be used to build a 64-bit hash function. Is the result collision resistant? Exercise 4: A one-time password authentication system generates 6-character passwords formed using only the set of 64 characters a-za-z0-9.,. The first of these passwords is hashed with SHA-1, the resulting hash value is truncated to the first 5 bytes, which are then used to form the next password. After how many passwords is there a better than 50% probability that this hash chain has entered a cycle? Write a program that finds two passwords that lead to a collision in the first 5 bytes of SHA-1 and provide an example collision. Chose a programming language that offers a SHA-1 implementation in its standard library. One example collision: $ perl -e 'use Digest::SHA qw(sha1_hex);while($_=shift @ARGV) {print sha1_hex($_),"\n"' scqfni KAHgNI c379d58af1012b03a5b72f5430b663c730499508 c379d58af1123a44e7a1828eaa42a995e44a4634 Exercise 5: Use Euclid s algorithm to calculate gcd(36, 24). 1

Exercise 6: The following Perl program implements a non-recursive form of the Euclidean algorithm: #!/usr/bin/perl use bigint; sub gcd { my ($a0, $b0) = @_; my ( $a, $b) = @_; # use arbitrary-length integer type while (1) { my $q = $a / $b; if ($a == $b * $q) { print "gcd($a0,$b0) = $b\n"; return $b; ($a, $b) = ($b, $a-$b*$q); gcd(2250,360); Modify it, such that it implements a non-recursive form of the extended Euclidean algorithm. To do so, first define two additional local variables my ($aa, $ab) = (1, 0); my ($ba, $bb) = (0, 1); that record how $a and $b can be represented as linear combinations of their initial values $a0 and $b0, by maintaining the following invariant: $a == $a0 * $aa + $b0 * $ab $b == $a0 * $ba + $b0 * $bb (a) Extend the final 2-tuple assignment ($a, $b) = ($b, $a-$b*$q); into a 6-tuple assignment ($a, $aa, $ab, $b, $ba, $bb) = ($b,... ); that maintains the above invariant. (b) Extend the print and return statements to output the gcd result also as a linear combination of the input values. (c) If your function is called with egcd(2250,360) it should output gcd(2250,360) = 90 = 2250 * 1 + 360 * -6 What is the output of your function if called with the following values? gcd(733810016255931844845,1187329547587210582322) Exercise 7: Show how the following two basic properties of every group (G, ) follow from the group axions given on slide 47: (a) The neutral element of any group is unique. In other words: if both e and e are neutral elements of the group, with g e = g = e g and g e = g = e g for every group element g, then show that this implies e = e. 2

(b) The inverse element of any group element is unique. In other words: if e is the neutral element of a group and if we have group elements g, f, h where f and h are inverse elements of g, that is g f = e = f g and g h = e = g h, show that this implies f = h. Exercise 8: Let (F,, ) be a field. The definition of a field requires that is leftdistributive over, which means that for any a, b, c F: a (b c) = (a b) (a c). Show that this requirement implies the right-distributive property (a b) c = (a c) (b c). Exercise 9: (a) Convert your implementation of the extended Euclidean algorithm from Exercise 6 into an implementation of a function modinv(a, n) that returns a 1 such that aa 1 mod n = 1, or aborts with an error if no such a 1 exists. Verify that it outputs modinv(806515533049393, 1304969544928657) = 806515533049393 and fails for modinv(4505490,7290036). (b) Which calculation steps of the extended Euclidean algorithm can be dropped for this application? (c) What is modinv(892302390667940581330701, 1208925819614629174706111)? Exercise 10: Use Euler s theorem to calculate the inverse (a) 5 1 mod 7 (b) 5 1 mod 12 (c) 5 1 mod 15 Exercise 11: Given an abelian group (G, ), let H be the set of its quadratic residues, that is H = {g 2 g G. Show that (H, ) is a subgroup of (G, ). Exercise 12: Name two advantages of using cyclic groups of prime order in cryptographic schemes that rely on the difficulty of the Discrete Logarithm problem or the Diffie Hellman problems. 3

Exercise 13: Slide 66 shows how to construct a prime-order subgroup G Z p, for use with cryptosystems that rely on the discrete-logarithm problem being hard. It contains half of all elements of Z p, namely the G = q = (p 1)/2 quadratic residues (with p, q prime). However, sometimes we want to choose q much smaller than p. (a) What different criteria apply to choosing the bit-length of p and q, and what are the main advantages of having q much smaller than p? (b) We can construct a smaller subgroup G Z p with prime order q = (p 1)/r for any pair of primes p, q with p = rq + 1 (Schnorr group). For arbitrary h Z p \ {1, the value g = h r mod p will be a generator of this group. (The construction on slide 66 merely shows the case r = 2). (i) Show that G = {h r mod p h Z p is a subgroup of Z p. (ii) Show that G = {h r mod p h Z p has q = (p 1)/r elements, by showing that the function f r : Z p G with f r (x) = x r mod p is an r-to-1 function. [Hint: Let g be a generator of Z p such that {g 0, g 1,..., g p 2 = Z p. Under what condition for i, j is (g i ) r (g j ) r (mod p)? For any fixed j {0,..., p 2 = Z p 1, what values of i Z p 1 fulfill that condition, and how many such values i are there?] (iii)sometimes, if we receive a value a from an untrusted source, we should first verify that a G = {h r mod p h Z p before using it further. Show that for any a Z p we have a G if and only if a q mod p = 1. [Hint: Assume a = g i where g is a generator of Z p and i {0,..., p 2. Then show that a q 1 mod p iff r i.] Exercise 14: Implement a function modexp(g, e, m) that calculates g e mod m using the square-and-multiply algorithm for modular exponentiation. Test your implementation on 123456789 987654321 mod (2 80 1) = 785446763117418429158664 and then use it to calculate (7 2521 1 mod (2 3217 1)) mod 10 8 Exercise 15: Let G(1 l ) be a polynomial-time group generator that outputs an l-bit prime p and a generator g of Z p. Show that the DDH problem is not hard relative to G. [Hint: Recall that Euler s criterion allows efficient detection of quadratic residues.] Exercise 16: With RSA encryption, it is common practice to choose e as a small number (e.g., 3, 17, 2 16 + 1). (a) How does this affect the speed of encryption? (b) If you wanted to make decryption faster, could you simply set d to one of these three values instead? (c) How else can RSA decryption be calculated more efficiently using the Chinese Remainder Theorem and Fermat s little theorem? 4

Exercise 17: In the textbook RSA encryption scheme, with n = pq being a product of two different primes and ed mod ϕ(n) = 1, the identity m ed mod n = m, which states that we obtain the same plaintext m after encryption and decryption, is only guaranteed by Euler s theorem for any m Z n, that is if gcd(n, m) = 1. (a) Show that it actually also holds for any m Z n. [Hint: CRT] (b) Conversely, if we instead had chosen n = p 2 being the square of a prime number (i.e., p = q), show a simple example for the fact that in this case ed mod ϕ(n) = 1 does not imply m ed mod n = m for all m Z n. Exercise 18: A device vendor uses the DSA signature scheme to digitally sign configuration updates. The system parameters are p = 0x8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5 d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80291 q = 0xc773218c737ec8ee993b4f2ded30f48edace915f g = 0x626d027839ea0a13413163a55b4cb500299d5522956cefcb3bff10f399ce2c2e 71cb9de5fa24babf58e5b79521925c9cc42e9f6f464b088cc572af53e6d78802 and the vendor s public key is y = 0xeb772a91db3b69af90c5da844d7733f24270bdd11aac373b26f58ff528ef2678 94b1e746e3f20b8b89ce9e5d641abbff3e3fa7dedd3264b1b313d7cd569656c The vendor has already signed two messages: H(m 1 ) = SHA-1("Monday") = 0x932eeb1076c85e522f02e15441fa371e3fd000ac r 1 = 0x8f4378d1b2877d8aa7c0687200640d4bba72f2e5 s 1 = 0x696de4ffb102249aef907f348fb10ca704a4b186 H(m 2 ) = SHA-1("Tuesday") = 0x42e43b612a5dfae57ddf5929f0fb945ae83cbf61 r 2 = 0x8f4378d1b2877d8aa7c0687200640d4bba72f2e5 s 2 = 0x25f87cbb380eb4d7244963e65b76677bc968297e (a) Calculate g q mod p. (b) Verify that the two signatures are valid under the given public key y. (Preferably perform the required calculations using the modinv and modexp routines that you implemented yourself in exercises 9 and 14. Alternatively, download a computeralgebra system, such as Sage or PARI/GP.) (c) What mistake did the vendor make when generating these two signatures? (d) Exploit this mistake to reconstruct the secrets k and x used to generate these signatures. [Hint: Start by subtracting the two defining equations for s 1 and s 2 from each other.] (e) Use this information to falsify a signature for the new message H(m 3 ) = SHA-1("Wednesday") = 0x932eeb1076c85e522f02e15441fa371e3fd000ac and then verify its correctness against public key y. 5