Public-Key Encryption
Transcript
Okay, so let's look at public-key encryption. Public-key encryption was set up - or the foundations of it were laid - in a classic paper by Diffie and Hellman on a key exchange method and where it was proposed that we could set up a trapdoor method that would allow us to be able to create a function where if we knew a secret we would fall through this trap door and reveal something.
That was in 1976, and Rivest, Shamir and Adleman - in 1977 - came up with the RSA method and which is still used these days. So let's have a look at the main methods that we have for our public-key encryption. Obviously, we have what's called a difficult problem to solve. If we don't have a secret then we cannot solve the problem in a reasonable time and it is very expensive to solve. But if we do have a secret, it makes it fairly easy to solve the puzzle.
With public-key encryption, we have a key pair and the key pair is that we have a private key and then we have a public key. Bob and Alice can have their own key pairs. Everyone can know Bob's public key but he keeps his a private key secret.
The three main methods that are often used when it comes to public-key encryption - or the three main puzzles that we need to solve - are integer factorization, discrete logs and elliptic curve methods. The discrete log method is hardly ever used these days because it is becoming more computationally difficult but we still use the RSA method, and it is typically used in identifying websites. So the method here is called ElGamal that we can use and it's kinda still used because we use it in terms of
digital signatures. For elliptic curve, we have curves such as Curve 25519 and secp256k1 - one as we get in Bitcoin. So these are the three main methods that we use. When it comes to this (RSA) the difficult problem is that we have two prime numbers and we create what's called a modulus and the difficulty is to find the two prime numbers which created a given modulus.
With this method, we use discrete logs such as with g - a generator value - and is typically two or three or five to the power of a secret and then we use (mod p) where p is a large prime number - typically a few thousand bits. The difficulty is to find the value of x even although we know y, g, and p.
Elliptic curve methods use a curve that looks like this and this gives us amazing performance compared to the other two methods. So when we talk about thousands of bits for the prime numbers here, we might only talk about 160 bits or 256 bits for elliptic curve methods. These are seen to be much more efficient these days compared to these ones but, of course, they are all at risk against quantum computers which do not see these methods as a hard problem anymore. So we probably need to move away from these methods, eventually. Let's
look at what we do with public-key encryption. These are the methods so let's look at the usage. There are three main things that we do with public-key encryption. The first one is where we encrypt data so here's Bob and here is Alice, so if we have some data to encrypt.
Then if we use these keys Then Alice has a private key and she has her public key To encrypt data for Alice, Bob will take Alice's public key and encrypt the data.
When that's sent over it is then it is the private key which is then used to decrypt the data. Okay so in this way we can encrypt data for Alice with our public key and then use our private key. The downside of this is that because of the maths and the complexity of the methods used, then if this is large amounts of data it can be computationally difficult and we would typically not use this method to encrypt large amounts of data what we typically do with something else (symmetric key). So if we have Bob and Alice again one way that we can share a secret key that they might use let's say that we have this key here
so let's say that Bob wants to get this encryption key over to Alice and this is going to be the key that they'll use to encrypt data or to encrypt their communication so for this again what we can do is that we can take Alice's public key and we can encrypt this secret key here over to Alice and then Alice would just use her private key
to be able to decrypt the resulting encrypted value back to the shared symmetric key so we'll perhaps show this it's a different type of key this is our symmetric key here we want to for the use and that will be something like a symmetric key so this is known as key exchange this is known as public-key encryption first usage second usage and the third usage is in proof of identity
where Bob can prove his identity by signing with his private key. Let's take Bob and Alice again and Alice and now Bob wants to prove that he signed a message to Alice so what he does is he takes the data and then he will take a hash of the data and then he'll encrypt it with his the hash with his private key. So he will take his private key here
and encrypt the hash with his private key then on the other side Alice will take the data and recreate the hash so we get the data we create the hash and then we'll take Bob's encrypted hash version there and decrypt that with his public key so if we have this public key here which is known as we'll take that public key decrypt the hash and then check that the hashes are the same if they are the same then she has proven that it was Bob who signed the message
so that's the third form that we use public-key encryption for proof of identity key exchange and encryption so now let's look a little bit in more detail at the main methods involved okay so these are the methods that we have there's the usage there we have a signing process this is also known as signing this is key exchange and this is encryption it's the main methods that we use in terms of getting the keys for Bob and Alice
well what we can have is we have digital certificates and a digital certificate is something that has been signed by a trusted entity but contains the keys that we require so we can get one that contains the private key and also the public key this is a secret digital certificate and it's only used when we need to sign for something or within keys change typically we would export that certificate into a form that only contained the public key
and this is in a distributable form that we have for exposing Bob's public key to Alice again this will be signed by a trusted entity trent that both Bob and Alice trust so when Bob wants to pass his public key to alice he will send over a digital certificate signed by trent and she will check that it has been signed by trent just like here and then we'll be able to get Bob's public key from there the other way we can do this is that we can have a key ring with all of the public keys that Alice might use so she doesn't have to keep requesting them so Bob could
publish his public key on a repository or send it to alice and she would put it onto her keyring so that when she was sending information to Bob she would just take she would look at the public key on her keyring and along with this she could obviously have as long as it was secure her private key on the same key ring here so this would be kept secure and where she had all the public keys that she wanted to use and had her own private key for signing
So that's how we would distribute the public key to Alice, now let's look at the methods that we use and the first method is good old RSA. With RSA, we start off with two prime numbers p and q and we create a modulus from that. We typically define this modulus as n which is p times q. The difficulty is that for this modulus it is difficult to find p and q if p and q are large. Typically these might be a thousand-bit prime number and this would give a 2,000-bit modulus - we would define that as 2K RSA.
The next thing that we need to do is we need to define our encryption keys. RSA is an exponential cipher. We take our message and we raise it to the power of an encryption key and take mod of n for the cipher and to get the message back. We take the cipher to the power of d and (mod n) - remember that (mod n) is the remainder of our division by n. We are not interested in the actual value that is but only in the remainder. Okay, so this is the way that we would do our encryption and our decryption. So we need to find e and d.
So the first thing that we do is that we work out a value called PHI - and PHI is (p-1) times (q-1) and it gives us a result then we select a value of e which does not share any factors with PHI we would often write that the gcd of PHI and e is equal to 1. So there is no factor in e that's in the value of phi which is (p - 1) x (q - 1). then we work out d this here
to make sure that d times e mod of PHI is equal to 1 and this will make this work and d the calculation d is actually an inverse mod of e the inverse of e mod n this is a standard calculation that we often do in public-key encryption and it basically finds the value when you multiply e by that value then take the modify you'll end up with one and this will make this part correct
so let's take a simple example of this let's that's that one there from there okay so a simple example can be where we have a value of say p
equal to 3 and q equal to 11. so the N becomes 33. so the modulus, in this case, is a value of 33. then we can work out 5 and 5 is equal to 2 times 10 which is 20. the factors that we get in 20 are 2, not 3, 4, of course 5, and so on. So we can't pick these values for e so we might pick a value of 3.
so 3 is our encryption key 3 and 33 is the encryption key now d times e mod of 20 is equal to 1. and rather than doing this function. Here it's quite simple to see that if d is 7 times 3 is 21 mod 20 equals 1. so our decryption key is (7, 33). Okay so when we take our message
and raise it to the power of 3 then take (mod 33) that gives us our cipher we then take that cipher and raise it to the power of 7 then take mod of 33, and we will get our message back again. The is the power of the RSA algorithm, and it's still highly relevant these days. But the computing power that we need is actually quite large the method that we most often use these days is called elliptic curve cryptography (ECC). With ECC, we have y^2 is equal to x^3+ax+b (mod p). This is the standard equation that we have for our elliptic curve - or one of the
equations that we have for elliptic curve cryptography. The (mod p) makes sure that we're only dealing with integer values for our elliptic curve, where the curve shape in the non-mod form will look a bit like this, and where we have a point here and when we add points on the elliptic curve we'll also always get another point on the elliptic curve So the elliptic curve itself has basic parameters a, b, p - the prime number - n - which is the number of points that we can have on the elliptic curve - and is called the order.
This is the order. p is the prime number, a and b are here, and G is what's called the base point and it's almost like the starting point for all our elliptic curve operations that both Bob and Alice know. So this gives us our basic parameter for our curve. Common curves are Curve 25519 that uses a prime number of 2^{255-19} and also secp256k1 - which is used in Bitcoin transactions.
So that gives us our basic curve for that and how do we actually use this well the way that we do this is that we come up with our prime number where our private key value n is our private key. What we then do is that we come up with our public key (P) which is equal to n times G. So we take our base point (G) and we add G to itself n times so we end up with a point on the elliptic curve P=nG.
here an (x,y) point that's equal to nG where n is our private key G is the base point. P is G added n times on elliptic curve. The adding operation is a very easy operation to do and we also end up with another point in the elliptic curve. So with this anyone can know our public key (P), anyone can know our value of G, anyone can know the parameters here, but no one should know this private key. Only with this private key can we actually sign for messages. One way that we do this is with what's called the ECDSA or EC digital signature algorithm. With this, we take a private key and we can sign for our transaction and generate our public key so we don't have to create prime
numbers. What we do is we create a random number and then we can create our public key from that the way that bitcoin works is that when Bob wants to send Alice a transaction. Then Bob will take the bitcoin will take his private key value and then sign the transaction with his private key and then his identity is actually derived from his signature so that everyone can know his public key so that that transaction can be instantly known that it relates back to his private key here
so that's Elliptic Curve Diffie Hellman (ECDH) we have here let's see if we can now use all of these elements together to see if we can send some trusted data from Bob to Alice okay so for this we'll look at what's called Pretty Good Privacy or PGP but it's really just an example of how we can integrate all of these methods together so initially, we'll have some data and then Bob takes a hash of that data
and then we'll create an encrypted hashed version using his private key. Okay so we take the data the message we take a hash of it and then we will create an encrypted version of the hash this is really a signature that we have so now what we'll do is it will take this data and we'll add on the encrypted hash into the message and now this could be a large amount of data so what we want to do is to then encrypt this
with symmetric key encryption so this is our encryption here and we have our data in there and the encrypted hash and then Bob will create a new symmetric key especially for this this this message here and we'll encrypt the whole thing with the symmetric key now Bob then takes that symmetric key and then encrypts with Alice's public key so if we have Alice here and Alice's public key
will be used to encrypt this symmetric key and the whole thing can be sent over to Alice to then read and decrypt so here we have the encrypted message and we also have encrypted symmetric key which has been encrypted with analysis public key so the easy thing now is now that Alice can decrypt that key symmetric key with her a private key so she will take our private key
and then decrypt this to give the symmetric key which will then open up the data she does that and in the end, she'll end up with a message and also the signed version of Bob's hash of the message she can then read the message now but then she'll take our own hash of the message she then takes Bob's signature and then using Bob's public key she will then be able to decrypt
this hash and then end up with the same hash here. If the two hashes match then she knows it was Bob who has signed for the message and knows that the message has not been changed in the transmission Okay, so this has been an overview of public key encryption. encryption

Ask anything
We've read this whole study set, so questions about it get the best answers.