In part two we went over the differences between block / stream ciphers and their modes of operation. We also discussed modular arithmetic and the basics of the data encryption standard (DES). This part is going to go over a basic introduction of elliptic curve crypto systems and the OpenSSL cryptography library. To start, let’s go over what elliptic curves are (this is just a tl;dr version; elliptic curve crypto is too complicated to go over in just a single blog post). While Wolfram Mathworld gives a complete definition of elliptic curves here, we are going to define elliptic curves with this equation: y2= x3+ax+b mod p where 4a3+27b2 ? 0 mod p (if you do not understand what mod p means, read the previous part in this series). This is called the Weierstrass normal form for elliptic curves. The values a and b determine the shape of the curve.
Why are elliptic curves so important to cryptography? One of the most important pieces of elliptic curves in relation to crypto is the discrete logarithm problem. The discrete logarithm is sometimes known as a “one-way function”. This means that given a function f(x), but given y it is not possible to find x with y=f(x). There is no known efficient discrete logarithm solving problem, beyond the generic algorithms that work on every group. Because of this, we get a secure system as soon as p approaches 160 bits in length. In addition to better security, we get better speed. Unlike RSA, elliptic curves are easy to compute on embedded devices such as smart cards.
There are two popular crypto algorithms that use ECC: ECDSA (elliptic curve digital signature algorithm), and ECDH (elliptic curve diffie-hellman). While all of them sound the same, they are actually different from one another. ECDH is the elliptic curve form of the Diffie-Hellman protocol. It is a form of key agreement; both people can establish a secret value by sending their public key to the other person. As the name implies, ECDSA is the elliptic curve version of DSA. In the TLS protocol, ECDSA can be used to authenticate the handshake part of the process (there is a good PDF here on TLS and SSL if you are not sure what it is).
We have now gone over enough material to start applying this information, and learn the OpenSSL library. OpenSSL is an open-source crypto suite that can be used for a large variety of tasks such as Public Key Infrastructure (PKI), and HTTPS. While OpenSSL includes an SDK for developers, writing code is out of scope for this tutorial and we will only be covering the command line utility. We are also going to be using Windows 7 for this tutorial.
As stated by the OpenSSL website, OpenSSL does not distribute any binaries. To run OpenSSL on Windows, you have to compile the source code yourself or download a third party engine. In this tutorial, we are not going to compile the source code and only use precompiled binaries. Before we download the binaries, we are first going to have to install the VC++ 2008 runtime redistributable from Microsoft. Go ahead and download that from here: https://www.microsoft.com/en-us/download/details.aspx?id=29. The installation for the VC++ runtime is easy; just click next until the wizard is completed.
After the download for VC++ has been completed, open it and click next until you have completed the installation. To install OpenSSL, first download it from https://www.openssl.org/community/binaries.html. It is important to note that you need to download the OpenSSL that corresponds to the version of VC++ you downloaded (32 bit or 64 bit). Installing OpenSSL is as easy as installing VC++: just click next until the wizard finishes. Even though OpenSSL has now been installed, we first have to configure the environment variables and create a folder to store the output from OpenSSL. To do this, go to the C: drive and create a new folder called Certificates. Afterwards, navigate to the start menu and open up an administrator command prompt. Once that is open, type in the following:
– set RANDFILE=C:Certificates.rnd
– set OPENSSL_CONF=C:OpenSSL-Win32binopenssl.cfg
OpenSSL is now ready to be started. To start OpenSSL, type in C:OpenSSL-Win32binopenssl.exe. If everything is successful, you will notice that your drive letter has changed from a letter to OpenSSL. This allows us to type in commands specific to OpenSSL. The first step is to create the 4096-bit long RSA key and call it ca.key (if you wish to add a password to it, you can add the option –des3):
– genrsa -out ca.key 4096
Next, we are going to generate a self-signed CA certificate:
– req -new -x509 -days 1826 -key ca.key -out ca.crt
Let’s go over what the above command means. We specify –x509 because we are creating a new self-signed certificate, and 1826 means that the certificate is valid for five years. Now that we have created the certificate, we are going to create another CA that will actually be used for signing.
We first generate the key:
genrsa -out ia.key 4096
After, we request a certificate for that key we just generated:
req -new -key ia.key -out ia.csr
Note that it is important to have the key name be different from the previous key; otherwise you will get an error when you create the pkcs12 file. The next to last step in the process is to generate the request for the subordinate certificate authority. Run this command:
x509 -req -days 730 -in ia.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out ia.crt
The final step in creating a certificate is to package the keys and certs in a PKCS12 file:
– pkcs12 -export -out ia.p12 -inkey ia.key -in ia.crt -chain -CAfile ca.crt
That’s it. We can now use the .crt files in Windows. To install it, double-click on the crt file and click “Install Certificate”. I hope that this tutorial has been useful for someone. If you have any questions or comments, please email me at [email protected]