mirror of
https://github.com/arnaucube/arkeddsa.git
synced 2026-01-11 16:01:27 +01:00
tidy
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -255,6 +255,7 @@ dependencies = [
|
||||
"ark-std",
|
||||
"blake2",
|
||||
"digest",
|
||||
"hex",
|
||||
"rand",
|
||||
"rand_core",
|
||||
"sha2",
|
||||
|
||||
16
Cargo.toml
16
Cargo.toml
@@ -1,17 +1,18 @@
|
||||
[package]
|
||||
edition = "2021"
|
||||
name = "arkeddsa"
|
||||
rust-version = "1.75.0"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
|
||||
ark-crypto-primitives = {version = "^0.4.0", default-features = false, features = ["sponge", "crh"]}
|
||||
ark-ec = "0.4"
|
||||
ark-ec = "^0.4.0"
|
||||
ark-ed-on-bn254 = {version = "0.4.0"}
|
||||
ark-ff = "0.4"
|
||||
ark-serialize = "0.4"
|
||||
ark-std = "0.4"
|
||||
digest = "0.10.7"
|
||||
ark-ff = "^0.4.0"
|
||||
ark-serialize = {version = "^0.4.0", default-features = false}
|
||||
ark-std = "^0.4.0"
|
||||
digest = "0.10"
|
||||
rand = "0.8"
|
||||
rand_core = {version = "0.6", default-features = false}
|
||||
|
||||
@@ -19,8 +20,9 @@ rand_core = {version = "0.6", default-features = false}
|
||||
ark-algebra-test-templates = "0.4.2"
|
||||
ark-ed-on-bls12-381 = {version = "0.4.0"}
|
||||
ark-ed-on-bls12-381-bandersnatch = {version = "0.4.0"}
|
||||
blake2 = "0.10.6"
|
||||
sha2 = "0.10.8"
|
||||
blake2 = "0.10"
|
||||
hex = "0.4.3"
|
||||
sha2 = "0.10"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
1
rust-toolchain
Normal file
1
rust-toolchain
Normal file
@@ -0,0 +1 @@
|
||||
1.75.0
|
||||
@@ -6,6 +6,10 @@ use ark_ff::MontFp;
|
||||
pub type EdwardsAffine = Affine<EdwardsConfig>;
|
||||
pub type EdwardsProjective = Projective<EdwardsConfig>;
|
||||
|
||||
pub use ark_ed_on_bn254::{Fq, Fr};
|
||||
pub type BaseField = ark_ed_on_bn254::Fq;
|
||||
pub type ScalarField = ark_ed_on_bn254::Fr;
|
||||
|
||||
/// Twist of `Baby-JubJub` is a twist of twisted Edwards curve. These curves have equations of the
|
||||
/// form: ax² + y² = 1 + dx²y².
|
||||
/// over some base finite field BaseField.
|
||||
@@ -18,27 +22,27 @@ pub struct EdwardsConfig;
|
||||
ark_algebra_test_templates::test_group!(te; EdwardsProjective; te);
|
||||
|
||||
impl CurveConfig for EdwardsConfig {
|
||||
type BaseField = ark_ed_on_bn254::Fq;
|
||||
type ScalarField = ark_ed_on_bn254::Fr;
|
||||
type BaseField = BaseField;
|
||||
type ScalarField = ScalarField;
|
||||
|
||||
/// COFACTOR = 8
|
||||
const COFACTOR: &'static [u64] = &[8];
|
||||
|
||||
/// COFACTOR^(-1) mod r =
|
||||
/// 2394026564107420727433200628387514462817212225638746351800188703329891451411
|
||||
const COFACTOR_INV: ark_ed_on_bn254::Fr =
|
||||
const COFACTOR_INV: ScalarField =
|
||||
MontFp!("2394026564107420727433200628387514462817212225638746351800188703329891451411");
|
||||
}
|
||||
|
||||
impl TECurveConfig for EdwardsConfig {
|
||||
const COEFF_A: ark_ed_on_bn254::Fq = MontFp!("168700");
|
||||
const COEFF_A: BaseField = MontFp!("168700");
|
||||
|
||||
#[inline(always)]
|
||||
fn mul_by_a(elem: Self::BaseField) -> Self::BaseField {
|
||||
elem * <Self as TECurveConfig>::COEFF_A
|
||||
}
|
||||
|
||||
const COEFF_D: ark_ed_on_bn254::Fq = MontFp!("168696");
|
||||
const COEFF_D: BaseField = MontFp!("168696");
|
||||
|
||||
const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);
|
||||
|
||||
@@ -47,21 +51,21 @@ impl TECurveConfig for EdwardsConfig {
|
||||
|
||||
impl MontCurveConfig for EdwardsConfig {
|
||||
/// COEFF_A = 168698
|
||||
const COEFF_A: ark_ed_on_bn254::Fq = MontFp!("168698");
|
||||
const COEFF_A: BaseField = MontFp!("168698");
|
||||
/// COEFF_B = 168700
|
||||
const COEFF_B: ark_ed_on_bn254::Fq = MontFp!("1");
|
||||
const COEFF_B: BaseField = MontFp!("1");
|
||||
|
||||
type TECurveConfig = EdwardsConfig;
|
||||
}
|
||||
|
||||
/// GENERATOR_X =
|
||||
/// 19698561148652590122159747500897617769866003486955115824547446575314762165298
|
||||
pub const GENERATOR_X: ark_ed_on_bn254::Fq =
|
||||
pub const GENERATOR_X: BaseField =
|
||||
MontFp!("5299619240641551281634865583518297030282874472190772894086521144482721001553");
|
||||
|
||||
/// GENERATOR_Y =
|
||||
/// 19298250018296453272277890825869354524455968081175474282777126169995084727839
|
||||
pub const GENERATOR_Y: ark_ed_on_bn254::Fq =
|
||||
pub const GENERATOR_Y: BaseField =
|
||||
MontFp!("16950150798460657717958625567821834550301663161624707787222815936182638968203");
|
||||
|
||||
#[test]
|
||||
@@ -77,7 +81,7 @@ fn test_twist() {
|
||||
|
||||
fn untwist(curve: EdwardsAffine) -> ark_ed_on_bn254::EdwardsAffine {
|
||||
use ark_ff::Field;
|
||||
const A: ark_ed_on_bn254::Fq = MontFp!("168700");
|
||||
const A: BaseField = MontFp!("168700");
|
||||
let sqrt_a = A.sqrt().unwrap();
|
||||
ark_ed_on_bn254::EdwardsAffine {
|
||||
x: curve.x * sqrt_a,
|
||||
@@ -86,7 +90,6 @@ fn test_twist() {
|
||||
}
|
||||
|
||||
use ark_ec::{AffineRepr, CurveGroup};
|
||||
use ark_ed_on_bn254::Fr;
|
||||
use ark_std::UniformRand;
|
||||
use rand_core::OsRng;
|
||||
|
||||
|
||||
21
src/eddsa.rs
21
src/eddsa.rs
@@ -29,6 +29,14 @@ impl SecretKey {
|
||||
let x = prune_buffer(buffer);
|
||||
(x, hash_prefix)
|
||||
}
|
||||
|
||||
pub fn to_bytes(&self) -> [u8; 32] {
|
||||
self.0
|
||||
}
|
||||
|
||||
pub fn from_bytes(bytes: [u8; 32]) -> Self {
|
||||
Self(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
@@ -37,6 +45,15 @@ pub struct PublicKey<A: AffineRepr>(A)
|
||||
where
|
||||
A::Config: TECurveConfig;
|
||||
|
||||
impl<A: AffineRepr> PublicKey<A>
|
||||
where
|
||||
A::Config: TECurveConfig,
|
||||
{
|
||||
pub fn xy(&self) -> (&A::BaseField, &A::BaseField) {
|
||||
self.0.xy().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
/// `SigningKey` produces EdDSA signatures for given message
|
||||
pub struct SigningKey<A: AffineRepr>
|
||||
@@ -73,8 +90,8 @@ where
|
||||
Self::new::<D>(&secret_key)
|
||||
}
|
||||
|
||||
pub fn public_key(&self) -> PublicKey<A> {
|
||||
self.public_key
|
||||
pub fn public_key(&self) -> &PublicKey<A> {
|
||||
&self.public_key
|
||||
}
|
||||
|
||||
pub fn sign<D: Digest, E: Absorb>(
|
||||
|
||||
23
src/lib.rs
23
src/lib.rs
@@ -1,6 +1,5 @@
|
||||
pub mod ed_on_bn254_twist;
|
||||
pub mod eddsa;
|
||||
pub mod poseidon;
|
||||
pub mod signature;
|
||||
|
||||
use ark_ff::PrimeField;
|
||||
@@ -21,20 +20,38 @@ pub enum Error {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use crate::SigningKey;
|
||||
use ark_crypto_primitives::sponge::poseidon::{find_poseidon_ark_and_mds, PoseidonConfig};
|
||||
use ark_crypto_primitives::sponge::Absorb;
|
||||
use ark_ec::{twisted_edwards::TECurveConfig, AffineRepr};
|
||||
use ark_ff::PrimeField;
|
||||
use digest::Digest;
|
||||
use rand_core::OsRng;
|
||||
|
||||
use crate::SigningKey;
|
||||
/// Generates poseidon constants and returns the config
|
||||
pub fn poseidon_config<F: PrimeField>(
|
||||
rate: usize,
|
||||
full_rounds: usize,
|
||||
partial_rounds: usize,
|
||||
) -> PoseidonConfig<F> {
|
||||
let prime_bits = F::MODULUS_BIT_SIZE as u64;
|
||||
let (ark, mds) = find_poseidon_ark_and_mds(
|
||||
prime_bits,
|
||||
rate,
|
||||
full_rounds as u64,
|
||||
partial_rounds as u64,
|
||||
0,
|
||||
);
|
||||
PoseidonConfig::new(full_rounds, partial_rounds, 5, mds, ark, rate, 1)
|
||||
}
|
||||
|
||||
fn run_test<A: AffineRepr, D: Digest>()
|
||||
where
|
||||
A::BaseField: Absorb + PrimeField,
|
||||
A::Config: TECurveConfig,
|
||||
{
|
||||
let poseidon = crate::poseidon::poseidon_config(4, 8, 55);
|
||||
let poseidon = poseidon_config(4, 8, 55);
|
||||
let signing_key = SigningKey::<A>::generate::<D>(&mut OsRng).unwrap();
|
||||
let message = b"xxx yyy <<< zzz >>> bunny";
|
||||
let signature = signing_key.sign::<D, _>(&poseidon, &message[..]);
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
use ark_crypto_primitives::sponge::poseidon::{find_poseidon_ark_and_mds, PoseidonConfig};
|
||||
use ark_ff::PrimeField;
|
||||
|
||||
/// Generates poseidon constants and returns the config
|
||||
pub fn poseidon_config<F: PrimeField>(
|
||||
rate: usize,
|
||||
full_rounds: usize,
|
||||
partial_rounds: usize,
|
||||
) -> PoseidonConfig<F> {
|
||||
let prime_bits = F::MODULUS_BIT_SIZE as u64;
|
||||
let (ark, mds) = find_poseidon_ark_and_mds(
|
||||
prime_bits,
|
||||
rate,
|
||||
full_rounds as u64,
|
||||
partial_rounds as u64,
|
||||
0,
|
||||
);
|
||||
PoseidonConfig::new(full_rounds, partial_rounds, 5, mds, ark, rate, 1)
|
||||
}
|
||||
Reference in New Issue
Block a user