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.

Filename, size & hash SHA256 hash help File type Python version Upload date
eccsnacks-1.0.1.tar.gz (6.0 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page