Skip to main content

Reference implementation of Curve25519 and Curve448 (goldilocks) as specified in RFC7748

Project description

This package contains a simple reference implementation of Curve25519 and Curve448 (goldilocks) as specified in RFC7748.

Caution: this implementation is inadvisable for use if timing invariance matters. Future versions of this package may implement a C backend.

eccsnacks is a play on the word ecchacks, a cool site by djb and Tanja Lange.

Installation

pip install eccsnacks

Usage

These examples demonstrate the Diffie-Hellman operation for each curve.

Curve25519:

from os import urandom
from eccsnacks.curve25519 import scalarmult, scalarmult_base

# Private keys in Curve25519 can be any 32-byte string.
a = urandom(32)
a_pub = scalarmult_base(a)

b = urandom(32)
b_pub = scalarmult_base(b)

# perform Diffie-Hellman computation for alice and bob
k_ab = scalarmult(a, b_pub)
k_ba = scalarmult(b, a_pub)

# keys should be the same
assert k_ab == k_ba

Curve448:

from os import urandom
from eccsnacks.curve448 import scalarmult, scalarmult_base

# Private keys in Curve448 can be any 32-byte string.
a = urandom(56)
a_pub = scalarmult_base(a)

b = urandom(56)
b_pub = scalarmult_base(b)

# perform Diffie-Hellman computation for alice and bob
k_ab = scalarmult(a, b_pub)
k_ba = scalarmult(b, a_pub)

# keys should be the same
assert k_ab == k_ba

Todo

  • Fast timing invariant implementation of both curves in C.

  • More curves.

Alternatives

Acknowledgements

  • Matthew Dempsky for slownacl which initially served as a baseline when implementing Curve25519.

  • djb for Curve25519

  • Mike Hamburg for Curve448

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eccsnacks-1.0.1.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distribution

eccsnacks-1.0.1-py3.5.egg (7.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page