mirror of
https://github.com/arnaucube/ark-curves-cherry-picked.git
synced 2026-01-09 07:21:30 +01:00
Add the secp256k1 and secq256k1 curves (#122)
Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu> Co-authored-by: onewayfunc <onewayfunc@gmail.com>
This commit is contained in:
31
secq256k1/Cargo.toml
Normal file
31
secq256k1/Cargo.toml
Normal file
@@ -0,0 +1,31 @@
|
||||
[package]
|
||||
name = "ark-secq256k1"
|
||||
version = "0.4.0-alpha.1"
|
||||
authors = [ "arkworks contributors" ]
|
||||
description = "The secq256k1 curve"
|
||||
homepage = "https://arkworks.rs"
|
||||
repository = "https://github.com/arkworks-rs/curves"
|
||||
documentation = "https://docs.rs/ark-secp256k1/"
|
||||
keywords = ["cryptography", "finite-fields", "elliptic-curves" ]
|
||||
categories = ["cryptography"]
|
||||
include = ["Cargo.toml", "src", "LICENSE-APACHE", "LICENSE-MIT"]
|
||||
license = "MIT/Apache-2.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
ark-ff = { version = "0.4.0-alpha", default-features = false }
|
||||
ark-ec = { version = "0.4.0-alpha", default-features = false }
|
||||
ark-r1cs-std = { version = "0.4.0-alpha", default-features = false, optional = true }
|
||||
ark-std = { version = "0.4.0-alpha", default-features = false }
|
||||
ark-secp256k1 = { path = "../secp256k1" }
|
||||
|
||||
[dev-dependencies]
|
||||
ark-relations = { version = "0.4.0-alpha", default-features = false }
|
||||
ark-serialize = { version = "0.4.0-alpha", default-features = false }
|
||||
ark-algebra-test-templates = { version = "0.4.0-alpha", default-features = false }
|
||||
ark-curve-constraint-tests = { path = "../curve-constraint-tests", default-features = false }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
std = [ "ark-std/std", "ark-ff/std", "ark-ec/std" ]
|
||||
r1cs = [ "ark-r1cs-std" ]
|
||||
1
secq256k1/LICENSE-APACHE
Symbolic link
1
secq256k1/LICENSE-APACHE
Symbolic link
@@ -0,0 +1 @@
|
||||
../LICENSE-APACHE
|
||||
1
secq256k1/LICENSE-MIT
Symbolic link
1
secq256k1/LICENSE-MIT
Symbolic link
@@ -0,0 +1 @@
|
||||
../LICENSE-MIT
|
||||
10
secq256k1/src/constraints/curves.rs
Normal file
10
secq256k1/src/constraints/curves.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use crate::{constraints::FqVar, *};
|
||||
use ark_r1cs_std::groups::curves::short_weierstrass::ProjectiveVar;
|
||||
|
||||
/// A group element in the secq256k1 curve.
|
||||
pub type GVar = ProjectiveVar<Parameters, FqVar>;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
ark_curve_constraint_tests::curves::sw_test::<Parameters, GVar>().unwrap();
|
||||
}
|
||||
11
secq256k1/src/constraints/fields.rs
Normal file
11
secq256k1/src/constraints/fields.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use ark_r1cs_std::fields::fp::FpVar;
|
||||
|
||||
use crate::fq::Fq;
|
||||
|
||||
/// A variable that is the R1CS equivalent of `crate::Fq`.
|
||||
pub type FqVar = FpVar<Fq>;
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
ark_curve_constraint_tests::fields::field_test::<_, _, FqVar>().unwrap();
|
||||
}
|
||||
7
secq256k1/src/constraints/mod.rs
Normal file
7
secq256k1/src/constraints/mod.rs
Normal file
@@ -0,0 +1,7 @@
|
||||
//! This module implements the R1CS equivalent of `ark_secq256k1`.
|
||||
|
||||
mod curves;
|
||||
mod fields;
|
||||
|
||||
pub use curves::*;
|
||||
pub use fields::*;
|
||||
52
secq256k1/src/curves/mod.rs
Normal file
52
secq256k1/src/curves/mod.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use ark_ec::{
|
||||
models::CurveConfig,
|
||||
short_weierstrass::{self as sw, SWCurveConfig},
|
||||
};
|
||||
use ark_ff::{Field, MontFp, Zero};
|
||||
|
||||
use crate::{fq::Fq, fr::Fr};
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub type Affine = sw::Affine<Parameters>;
|
||||
pub type Projective = sw::Projective<Parameters>;
|
||||
|
||||
#[derive(Copy, Clone, Default, PartialEq, Eq)]
|
||||
pub struct Parameters;
|
||||
|
||||
impl CurveConfig for Parameters {
|
||||
type BaseField = Fq;
|
||||
type ScalarField = Fr;
|
||||
|
||||
/// COFACTOR = 1
|
||||
const COFACTOR: &'static [u64] = &[0x1];
|
||||
|
||||
/// COFACTOR_INV = COFACTOR^{-1} mod r = 1
|
||||
#[rustfmt::skip]
|
||||
const COFACTOR_INV: Fr = Fr::ONE;
|
||||
}
|
||||
|
||||
impl SWCurveConfig for Parameters {
|
||||
/// COEFF_A = 0
|
||||
const COEFF_A: Fq = Fq::ZERO;
|
||||
|
||||
/// COEFF_B = 7
|
||||
const COEFF_B: Fq = MontFp!("7");
|
||||
|
||||
/// GENERATOR = (G_GENERATOR_X, G_GENERATOR_Y)
|
||||
const GENERATOR: Affine = Affine::new_unchecked(G_GENERATOR_X, G_GENERATOR_Y);
|
||||
|
||||
#[inline(always)]
|
||||
fn mul_by_a(_: Self::BaseField) -> Self::BaseField {
|
||||
Self::BaseField::zero()
|
||||
}
|
||||
}
|
||||
|
||||
/// G_GENERATOR_X = 53718550993811904772965658690407829053653678808745171666022356150019200052646
|
||||
pub const G_GENERATOR_X: Fq =
|
||||
MontFp!("53718550993811904772965658690407829053653678808745171666022356150019200052646");
|
||||
|
||||
/// G_GENERATOR_Y = 28941648020349172432234515805717979317553499307621291159490218670604692907903
|
||||
pub const G_GENERATOR_Y: Fq =
|
||||
MontFp!("28941648020349172432234515805717979317553499307621291159490218670604692907903");
|
||||
4
secq256k1/src/curves/tests.rs
Executable file
4
secq256k1/src/curves/tests.rs
Executable file
@@ -0,0 +1,4 @@
|
||||
use crate::Projective;
|
||||
use ark_algebra_test_templates::*;
|
||||
|
||||
test_group!(g1; Projective; sw);
|
||||
2
secq256k1/src/fields/fq.rs
Normal file
2
secq256k1/src/fields/fq.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub use ark_secp256k1::Fr as Fq;
|
||||
pub use ark_secp256k1::FrConfig as FqConfig;
|
||||
2
secq256k1/src/fields/fr.rs
Normal file
2
secq256k1/src/fields/fr.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub use ark_secp256k1::Fq as Fr;
|
||||
pub use ark_secp256k1::FqConfig as FrConfig;
|
||||
5
secq256k1/src/fields/mod.rs
Normal file
5
secq256k1/src/fields/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
pub mod fq;
|
||||
pub use self::fq::*;
|
||||
|
||||
pub mod fr;
|
||||
pub use self::fr::*;
|
||||
27
secq256k1/src/lib.rs
Normal file
27
secq256k1/src/lib.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
#![deny(
|
||||
warnings,
|
||||
unused,
|
||||
future_incompatible,
|
||||
nonstandard_style,
|
||||
rust_2018_idioms
|
||||
)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
//! This library implements the secq256k1 curve.
|
||||
//! Source: <https://moderncrypto.org/mail-archive/curves/2018/000992.html>
|
||||
//!
|
||||
//! Curve information:
|
||||
//! * Base field: q =
|
||||
//! 115792089237316195423570985008687907852837564279074904382605163141518161494337
|
||||
//! * Scalar field: r =
|
||||
//! 115792089237316195423570985008687907853269984665640564039457584007908834671663
|
||||
//! * Curve equation: y^2 = x^3 + 7
|
||||
|
||||
#[cfg(feature = "r1cs")]
|
||||
pub mod constraints;
|
||||
mod curves;
|
||||
mod fields;
|
||||
|
||||
pub use curves::*;
|
||||
pub use fields::*;
|
||||
Reference in New Issue
Block a user