https://github.com/ellectroid/ecdh-binarycurves-basic
A small library for doing elliptic curve Diffie-Hellman key exchange using binary curves (NOT CONSTANT TIME)
https://github.com/ellectroid/ecdh-binarycurves-basic
Last synced: 6 months ago
JSON representation
A small library for doing elliptic curve Diffie-Hellman key exchange using binary curves (NOT CONSTANT TIME)
- Host: GitHub
- URL: https://github.com/ellectroid/ecdh-binarycurves-basic
- Owner: ellectroid
- License: unlicense
- Created: 2025-07-09T12:38:32.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-07-09T13:32:05.000Z (7 months ago)
- Last Synced: 2025-07-09T14:43:30.908Z (7 months ago)
- Language: C++
- Size: 18.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ECDH-binarycurves-basic
A small library for doing elliptic curve Diffie-Hellman key exchange using binary curves.
## WARNING
This library is not a constant time library. It only gives algebraically correct results!
## Description
A tiny recreational elliptic curve Diffie-Hellman key exchange library.
Dependencies: none. Doesn't use standard libraries, doesn't use any runtime libraries (even no memset or memcpy), doesn't #include anything at all.
It should be fully C-compatible C++ code.
Should work on any platform for which one can compile C or C++.
Min language requirements: C11/C++11 (only because of alignas)
There is room for optimization of underlying algorithms for better use of CPU time
This library can work as a reference
Tested with curves K-163, B-163, K-233, K-283 (Binary curves only! Prime curves not supported!)
Tested on desktop
Tested on ARM Cortex-M7 STM32F746 @ 216MHz:
- ~1.35KiB peak RAM usage with keys and calculations with 37 bytes allocated per GF(2) vector (e.g. with K-283)
- ~1.15KiB peak RAM usage with keys and calculations with 32 bytes allocated per GF(2) vector (e.g. with K-233)
- ~6.5KiB ROM use for debug build
- ~2.9KiB ROM use for release build
- Calculating a public key from a private key took around 25 seconds using curve K-233 (curves greater than K-233 seem impractical for it)
## Usage
The library doesn't provide curve parameters, but this repository includes library test code that contains parameters for K-163, B-163, K-233 and K-283.
Make sure to adjust compile-time value GF2_VECTOR_MAX_BYTELEN in galois_field2.h to make sure it fits your GF(2) vector. Use one byte more than required to fit the entire vector.
By default it's 32, so it won't fit K-283 without adjustment.