⚠️ WARNING: This code has not been audited and is not intended for production use. It is an experimental implementation and should be used for educational or research purposes only.
This project implements the m31jubjub elliptic curve, which is defined over the field
- Prime:
$p = 2^{31} - 1 = 2147483647$ (Mersenne31 prime) - Field:
$\mathbb{F}_{p^8}$
The irreducible polynomial defining
This polynomial is derived from the following relationships, which also define the intermediate field extensions:
From these, we can derive:
These relationships lead to the construction of the irreducible polynomial
The field extensions are constructed as follows:
$\mathbb{F}_{p^2} = \mathbb{F} _p[x] / (x^2 + 1)$ $\mathbb{F}_{p^4} = \mathbb{F} _{p^2}[y] / (y^2 - (x+2))$ $\mathbb{F}_{p^8} = \mathbb{F} _{p^4}[z] / (z^2 - y)$
This tower of extensions allows for efficient field arithmetic and is crucial for the implementation of the m31jubjub curve.
The curve is defined in Montgomery form as:
- Number of points: 452312846898269724422641179697543667437631587593405403658152560327606217112
- Subgroup order: 56539105862283715552830147462192958429703948449175675457269070040950777139
-
G =
$([(1512383752, 193728290), (1651759986, 333124324), (6056932, 984300192), (1212512506, 120323281)],$ $[(58274160, 343110055), (1167380167, 446309175), (95566473, 1702114697), (52647578, 275602113)])$ -
G8 =
$([(1512383752, 193728290), (1651759986, 333124324), (6056932, 984300192), (1212512506, 120323281)],$ $[(765716692, 256913164), (361449063, 1264254179), (1716305770, 402581624), (1791051883, 794190723)])$
The equivalent Edwards curve is defined as:
-
ED_G =
$([(1877637187, 625092471), (853537684, 1907750992), (1052633189, 1084608143), (945110118, 455926870)],$ $[(1167994, 892421824), (143521621, 1692807047), (160338294, 1935691581), (1461160856, 412915271)])$ -
ED_G8 =
$([(1279048008, 1484784720), (586032070, 1548213212), (2250614, 1782435982), (1582651553, 1683330946)],$ $[(1501552815, 1089547304), (1572871942, 1429284693), (1149181451, 1293690843), (2134715099, 1973006813)])$
This project implements the EdDSA (Edwards-curve Digital Signature Algorithm) signature scheme. Here's how to use the sign and verify functions:
use m31jubjub::{
m31::{FqBase, Fs, M31JubJubSigParams},
eddsa::SigParams,
};
use rand::{thread_rng, Rng};
fn main() {
// Create signature parameters
let sig_params = M31JubJubSigParams::default();
// Generate a private key
let private_key: Fs = thread_rng().gen();
// Derive the public key
let public_key = sig_params.public_key(private_key);
// Generate a random message
let message: Vec<FqBase> = (0..10).map(|_| thread_rng().gen()).collect();
// Sign the message
let signature = sig_params.sign(&message, private_key);
// Verify the signature
let is_valid = sig_params.verify(&message, signature, public_key);
assert!(is_valid);
}
-
Signature Parameters: Use
M31JubJubSigParams::default()
to create default signature parameters. -
Key Generation:
- Private Key: Generate using a random number generator.
- Public Key: Derive from the private key using
sig_params.public_key(private_key)
.
-
Message: Create a vector of
FqBase
elements. In this example, we're using random data. -
Signing: Use
sig_params.sign(&message, private_key)
to create a signature. -
Verification: Use
sig_params.verify(&message, signature, public_key)
to verify the signature.
To run tests:
cargo test
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under MIT. Please see the LICENSE file for more details.
This project is based on the following works: