Elliptic Curve Cryptography

Index

Using the Elliptic Curve Cryptography

The following section of this document is related to the usage of ECC – Elliptic Curve Cryptography. ECC is an approach to public-key cryptography based on the algebraic structure of elliptic curves over finite fields. ECC allows smaller keys compared to non-EC cryptography (based on plain Galois fields) to provide equivalent security. Elliptic curves are applicable for key agreement, digital signatures, pseudo-random generators and other tasks. Indirectly, they can be used for encryption by combining the key agreement with a symmetric encryption scheme. Elliptic curves are also used in several integer factorization algorithms based on elliptic curves that have applications in cryptography, such as Lenstra elliptic-curve factorization.

Listing the available curves

The first think that is necessary to do is to select the appropriate curve to work with. In order to do that, the following command can be used:

openssl ecparam -list_curves

As a result, we obtain a list of possible curves (this is just a small sample):

secp112r1 : SECG/WTLS curve over a 112 bit prime field
secp112r2 : SECG curve over a 112 bit prime field
secp128r1 : SECG curve over a 128 bit prime field
secp128r2 : SECG curve over a 128 bit prime field
secp160k1 : SECG curve over a 160 bit prime field
secp160r1 : SECG curve over a 160 bit prime field
secp160r2 : SECG/WTLS curve over a 160 bit prime field
secp192k1 : SECG curve over a 192 bit prime field
secp224k1 : SECG curve over a 224 bit prime field
secp224r1 : NIST/SECG curve over a 224 bit prime field
secp256k1 : SECG curve over a 256 bit prime field
secp384r1 : NIST/SECG curve over a 384 bit prime field
secp521r1 : NIST/SECG curve over a 521 bit prime field
prime192v1: NIST/X9.62/SECG curve over a 192 bit prime field
prime192v2: X9.62 curve over a 192 bit prime field
prime192v3: X9.62 curve over a 192 bit prime field
prime239v1: X9.62 curve over a 239 bit prime field
prime239v2: X9.62 curve over a 239 bit prime field
prime239v3: X9.62 curve over a 239 bit prime field
prime256v1: X9.62/SECG curve over a 256 bit prime field

Generate a private key using ECC

Let us generate a private key using ECC and an appropriate curve (in this case, we are going to use prime256v1 [1] [2]).

If needed, it may be stored on a file:

The contents of the file:

Display the parameters of the private key:

The contents of the private key:

Generate a public key using ECC

Next what we need to do is to create a public key from an ECC private key:

This is the content of the public key:

Let’s visualize the parameters of the public key:

This is the content of the public key:

Encrypt with ECC

As mentioned before, ECC can be used to do some key agreement between two parties, to derive a common key that might be used for encryption and decryption, using an appropriate symmetric cryptography algorithm.

Let’s imagine that you have Alice and Bob that want to use ECC to create a common shared key. The following should be done.

Alice, creates a private key and extracts the public key:

Bob, creates a private key and extracts the public key:

Alice and Bob, exchange their public keys. So Alice sends alice-public-key.pem to Bob, and Bob sends bob-public-key.pem to Alice.

In Alice, creates a shared key (alice_shared_key.bin):

In Bob, creates a shared key (bob_shared_key.bin):

If we verify, both alice_shared_key.bin and bob_shared_key.bin are identical:

So, this common 256-bit shared key (102c0553628d9448f0bd34100653c22de3d0cf31c14a2deba7f13c5ed23c3117) can be used to encrypt and decrypt data.

Encrypt:

Decrypt:

Last updated