Elliptical Curve Cryptography
Wiki: elliptical curve
Elliptical curves allow smaller keys to provide equivalent security, compared to cryptosystems based on modular exponentiation such as RSA.
A 256-bit ECDH key has approximately the same safety factor as a 128-bit aes key (which is even higher than 2048 bit RSA)
In TLS, Elliptical Curve Cryptography is used primarily for:
- Key Exchange: Generating a shared secret which later form the symmetric key
- Certificate Signing and Verfication: Used to verfiy authenticity of the server using Public Key Infrastructure and X.509 certificates
Elliptical Curve Cryptography on its own can not be used for encryption and decryption. Instead, its always paired with Symmetric Encryption algorithms in cypher suites.
The math
Have a look at this youtube video to understand the math.
In summary:
- The machine generates a random 32 byte number which becomes the private key (pk).
- The generator function (G) is determined based on:
- The curvature (e.g. prime256v1, curve25519)
- Other curve parameters if any
- The public key (P) is derived using the formula:
Notes: - The function G and public key P are part of the public information during any elliptical curve based algorithm.
- Public key can be derived from private key, but vice-versa is impossible.
- Unlike RSA, the public and private keys are not interchangable.
ECDH
Elliptic-curve Diffie–Hellman or ECDH uses DH key exchange, and Elliptical Curve Cryptography method to generate the secret.
ECDHE (where final ‘E’ stands for “ephemeral”) schemes like X25519 are widely used in TLS cypher suite for initial key exchange. Python’s cryptography library has a seperate implementation of X25519 key exchange
General algorithm:
Let’s assume a scenario where 2 systems, A and B wish to communicate securely, for which they need to generate a shared secret using ECDH.
- A creates random private key (), selects elliptical curve parameters which determines generation function , and generates public key () using the formula:
- A sends the and information about elliptical curve params to B.
- B also generates its own random private key (). It uses the ellptical curve params from A to get the same generation function , and computes its own public key :
- B sends its public key to A.
- Finally, similar to standard Diffie-Hellman key exchange, the shared secret is the private key multiplied with the public key of other system.
ECDSA
Elliptical Curve Digital-Signature Algorithms is a family of Digital Signing and Authentication algorithms based on Elliptical curve cryptography..
Ed25519
Ed25519 is an implementation of ECDSA (or EdDSA to be specific) used widely for user authentication, like in ssh. It is based on Edward Curves.
To try hands-on of Ed25519 signing, refer python’s cryptography module documentation
For detailed explaination of Algorithm, visit this note