On Saturday, June 11 2016, the Turing Award is being presented to Whitfield Diffie and Martin Hellman whose 1976 paper "New Directions in Cryptography" showed how people who had not made previous arrangements could communicate privately over an open channel.

Describing the accomplishment, Professor Jonathan Katz says "The invention of public-key encryption was a revolution in cryptography."

Some of the biggest innovations we will see in the next decade will come in the field of "applied cryptography." This will bring functions we are not used to seeing in the digital world where we expect everything can be copied freely and nothing can really be proven. It will start to become important to understand what digital signatures are, and what they are not. As democracy starts to move online it will become important to understand some of the foundational ideas of cryptography. This quick post will outline five simple ideas that I hope will make cryptography feel more familiar.

The five ideas: Simple but less common math, Hash functions, XOR, Public Key Exchange, Digital Signatures

Simple but less common math

Some of the relatively simple math we learned in school we use regularly and remain familiar. Some fades. We remember addition, subtraction, and multiplication. We don't often think about using remainders in daily life, and we tend to forget that not all math is easily reversible. If you know the remainder of a number divided by five is two, you do not know if the number is seven or five thousand and seven.

The log is simply the inverse of the exponent.

2^2 = 2 * 2 = 4; 2^3 = 2 * 2 * 2 = 8

log2( 8) = 3

A key aspect of logarithms is how they are used to express scale. 10^3 is 1000, 10^6 is 1000000. When numbers represent logarithmic values our intuitive sense of proportion can be thrown off. Used to express scale, 256 is not always twice as big as 128.



Hash functions

Check digits use the Luhn algorithm to validate date entry. The digits of an account number are treated separately, every other one is doubled. The sum of all the digits is multiplied by nine. The last digit of the product is the check digit. This algorithm is very good as catching transposition errors and is very effective at improving data entry quality. The concept is used on checks that are printed for your bank account, also the credit card numbers.

For the purpose of cryptography, a single digit checksum is not enough. Cryptographic hash functions do get complicated, but you don't need to know how it works in order to use it.

A hash function will take a string or a file then produce a fixed-length number. The same input will always produce the same output. But any change, even a tiny one will produce a completely different output value. It is difficult to distinguish the hash value from a random one.



XOR

This is a binary function. It is a very simple function at the level of ones and zeroes.

0 XOR 0 is 0; 0 XOR 1 is 1; 1 XOR 1 is 0.

Where you can reverse addition with subtraction, you can reverse XOR with another XOR.

Furthermore, if you XOR something with a value that looks random, the result will also look random.

This is particularly useful if you believe as Claude Shannon did that all information can be coded in binary format. And for many purposes is best understood that way.

In practice XOR can be used as follows:

[ MESSAGE ] XOR [ RANDOM LOOKING PAD ] --> [ CYPHER ]

then

[ CYPHER ] XOR [ SAME RANDOM LOOKING PAD ] --> [ MESSAGE ]



Diffie-Hellman Key Exchange

We want to find a way to use an open public network to communicate privately. We have some useful looking tools, but the critical thing we need is a mechanism to have a shared secret with another party so we can initiate communications. This is what Diffie & Hellman came up with. They combine exponentiation with the modulus of a large prime number to create a function that can be shared in a special way and is very difficult to reverse.



There are some simple examples that use parameters 23, and 5. I am going to use slightly bigger numbers because scale is important to understanding why this works.

We will use 251 as our exponent base with each calculation we will take the modulus of 8147. These parameters are public.



Our first character, Whitfield chooses a random number between one and 8147, say 680. This is a secret key. Whitfield calculates the public key by raising 251 to the power of 680 then taking the modulus 8147.

In python that looks like this:

(251 ** 680) % 8147

>> 3235

If you are using python, look at the number of digits in number before taking the modulus. (251 ^^ 680) This shows you how much information is being thrown away for the amount of information we keep and gives you an insight into how hard it would be to reverse the operation.



Our second character, Martin choses the secret key 5709 and calculates the public key 89.

(251 ** 5709) % 8147

>> 89



An attacker, Ralph intercepting their communications would know the system parameters 251 and 8147. Ralph would also know the two public keys 3235 and 89. But it would be difficult for him to calculate either private key or the shared secret without testing every single possible value. In practice, the parameters are MUCH larger than this example.

Whitfield calculates the shared secret by raising Martin's public key to the power of his own private key.

(89 ** 680) % 8147

>> 6737



Martin also calculates the shared secret:

(3235 ** 5709) % 8147

>> 6737



Each can feed the shared secret into a cryptographic hash function to get a random-looking pad.



In this example, it would be possible to program a computer to test every possible secret key. Breaking the system with brute force. However, it is difficult to find a short cut. When the parameters are expanded further to use 20 digit numbers the brute force approach becomes unpractical.



Digital Signatures

Diffie and Hellman expected a similar algorithm could be used to create digital signatures, and this turned out to be true. The algorithm has similar complexity to the one outlined above. It is characterized as "hash and sign" but the algorithm is not directly similar to the one above. The hash of the document is the basis of the signature. The signature is created with a private key and can be validated using a public key. Digital signatures can be used to validate that documents have not been altered or software updates are legitimate. They are foundational for digital currencies. They can also be used to validate digital coupons.

Resources:

Wikipedia has a reasonably good introduction

en.wikipedia.org/wiki/Diffie-Hellman_key_exchange

To learn the basics of cryptography the MOOC by Dan Boneh does a fantastic job of explaining the concepts.

www.coursera.org/learn/cryptographic

As a referance, the book I've been reading

Introduction to Modern Cryptography second edition by Jonathan Katz and Yehuda Lindell

Another reasonable book I have used is

Understanding Cryptography by Christof Parr and Jan Pelzl

If you are interested join the Toronto Linux User group this Thursday for a talk about cryptocrrencies:

https://gtalug.org/meeting/2016-06/