Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bign256] Digital signature #935

Merged
merged 43 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1390f26
Implement bign-curve256v1
makavity Mar 22, 2023
5897e4e
[WIP] bign256: add ecdsa
makavity Mar 22, 2023
a9cd24c
bign256: fix/primeorder path
makavity Mar 22, 2023
cbdb71a
bign256: fix/primeorder path
makavity Mar 22, 2023
be9f6d3
bign256: fix/workflow name
makavity Mar 22, 2023
8065961
Merge remote-tracking branch 'origin/master'
makavity Apr 4, 2023
b1a8724
bign256: fixes + remove ecdsa
makavity Apr 5, 2023
ffb72ab
Merge remote-tracking branch 'origin/master'
makavity Apr 5, 2023
6ba6c22
Merge branch 'RustCrypto:master' into master
makavity Apr 5, 2023
e8a8e90
Merge remote-tracking branch 'fork/master'
makavity Apr 5, 2023
29d4f83
bign256: fixes - doc + workflow
makavity Apr 5, 2023
fc84dfc
bign256: impl sqrt for FE + Scalar
makavity Apr 7, 2023
a8060ec
bign256: fix/cargo fmt
makavity Apr 7, 2023
6feb368
Merge remote-tracking branch 'origin/master'
makavity May 2, 2023
66541a9
bign256: fix/field sqrt by pow_vartime
makavity May 2, 2023
59fae68
bign256: fix/scalar sqrt by pow_vartime
makavity May 2, 2023
9f86731
Remove release note
makavity May 13, 2023
273de03
Remove version
makavity May 13, 2023
cee2ca4
Update repository
makavity May 13, 2023
ac54e91
Fix documentation
makavity May 13, 2023
20e5fef
Fix documentation
makavity May 13, 2023
1264c79
bign256: remove dead code (sqn)
makavity May 13, 2023
5929a30
Merge remote-tracking branch 'origin/master'
makavity May 13, 2023
20ad013
Merge branch 'master' of github.com:makavity/elliptic-curves
makavity May 13, 2023
b95af42
bign256: add test vectors + tests
makavity May 15, 2023
a812423
bign256: remove ecdsa from readme
makavity May 15, 2023
0b13b93
bign256: cargo fmt
makavity May 15, 2023
950497d
bign256: cleanup + gate features
makavity May 22, 2023
0d86bf2
bign256: fix doc link
makavity May 22, 2023
607beaf
Merge branch 'master' into master
makavity May 22, 2023
6604c7b
Merge branch 'master' into master
tarcieri May 30, 2023
ca2b357
Merge branch 'RustCrypto:master' into master
makavity Jun 13, 2023
b17d2de
Merge branch 'RustCrypto:master' into master
makavity Jun 28, 2023
261a768
Merge branch 'RustCrypto:master' into master
makavity Sep 25, 2023
44e4bec
add dsa + fixes
makavity Oct 3, 2023
f013414
Merge branch 'master' of github.com:RustCrypto/elliptic-curves
makavity Oct 3, 2023
9c5b5c4
impl dsa for bign256
makavity Oct 3, 2023
c62390d
Merge branch 'master' of github.com:makavity/elliptic-curves
makavity Oct 3, 2023
595e6c5
fix cargo.lock
makavity Oct 3, 2023
c8dcd9e
fix gate test
makavity Oct 3, 2023
3d4f279
readme fix
makavity Oct 4, 2023
ebb2893
Merge branch 'RustCrypto:master' into master
makavity Nov 10, 2023
7354601
Merge branch 'master' into master
tarcieri Dec 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions bign256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,26 @@ elliptic-curve = { version = "0.13.6", features = ["hazmat", "sec1"] }

# optional dependencies
primeorder = { version = "0.13.1", optional = true, path = "../primeorder" }
signature = { version = "2", optional = true }
belt-hash = { version = "0.1.0", optional = true, default-features = false }
crypto-bigint = { version = "0.5.3", optional = true }
rfc6979 = { version = "0.4", optional = true }


[dev-dependencies]
criterion = "0.5"
hex-literal = "0.4"
proptest = "1"
rand_core = { version = "0.6", features = ["getrandom"] }
hex = {version = "*" }


[features]
default = ["arithmetic", "pkcs8", "std"]
default = ["arithmetic", "pkcs8", "std", "dsa"]
alloc = ["elliptic-curve/alloc"]
std = ["alloc", "elliptic-curve/std"]
std = ["alloc", "elliptic-curve/std", "signature?/std"]

dsa = ["arithmetic", "dep:rfc6979", "dep:signature", "dep:belt-hash", "dep:crypto-bigint"]
arithmetic = ["dep:primeorder", "elliptic-curve/arithmetic"]
pkcs8 = ["elliptic-curve/pkcs8"]

Expand Down
17 changes: 7 additions & 10 deletions bign256/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ USE AT YOUR OWN RISK!

## About BIGN P-256

BIGN P-256 is a Weierstrass curve specified in [STB 34.101.45-2013]:
Recommendations for Discrete Logarithm-based Cryptography:
Elliptic Curve Domain Parameters.

BIGN P-256 is a Weierstrass curve specified in [STB 34.101.45-2013].
Also known as bign-curve256v1.

## Minimum Supported Rust Version
Expand Down Expand Up @@ -65,12 +62,12 @@ dual licensed as above, without any additional terms or conditions.

[//]: # (badges)

[crate-image]: https://buildstats.info/crate/p224
[crate-link]: https://crates.io/crates/p224
[docs-image]: https://docs.rs/p224/badge.svg
[docs-link]: https://docs.rs/p224/
[build-image]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p224.yml/badge.svg
[build-link]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/p224.yml
[crate-image]: https://buildstats.info/crate/bign256
[crate-link]: https://crates.io/crates/bign256
[docs-image]: https://docs.rs/bign256/badge.svg
[docs-link]: https://docs.rs/bign256/
[build-image]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/bign256.yml/badge.svg
[build-link]: https://github.com/RustCrypto/elliptic-curves/actions/workflows/bign256.yml
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.65+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
Expand Down
13 changes: 6 additions & 7 deletions bign256/benches/field.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! bign-curve256v1 field element benchmarks

use bign256::elliptic_curve::Field;
use bign256::FieldElement;
use bign256::arithmetic::FieldElement;
use criterion::{
criterion_group, criterion_main, measurement::Measurement, BenchmarkGroup, Criterion,
};
Expand All @@ -21,23 +20,23 @@ fn test_field_element_y() -> FieldElement {
.unwrap()
}

fn bench_field_element_mul<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
fn bench_field_element_mul<M: Measurement>(group: &mut BenchmarkGroup<M>) {
let x = test_field_element_x();
let y = test_field_element_y();
group.bench_function("mul", |b| b.iter(|| &x * &y));
group.bench_function("mul", |b| b.iter(|| x * y));
}

fn bench_field_element_square<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
fn bench_field_element_square<M: Measurement>(group: &mut BenchmarkGroup<M>) {
let x = test_field_element_x();
group.bench_function("square", |b| b.iter(|| x.square()));
}

fn bench_field_element_sqrt<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
fn bench_field_element_sqrt<M: Measurement>(group: &mut BenchmarkGroup<M>) {
let x = test_field_element_x();
group.bench_function("sqrt", |b| b.iter(|| x.sqrt()));
}

fn bench_field_element_invert<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
fn bench_field_element_invert<M: Measurement>(group: &mut BenchmarkGroup<M>) {
let x = test_field_element_x();
group.bench_function("invert", |b| b.iter(|| x.invert()));
}
Expand Down
20 changes: 10 additions & 10 deletions bign256/benches/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,37 @@ fn test_scalar_y() -> Scalar {
.unwrap()
}

fn bench_point_mul<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
fn bench_point_mul<M: Measurement>(group: &mut BenchmarkGroup<M>) {
let p = ProjectivePoint::GENERATOR;
let m = test_scalar_x();
let s = Scalar::from_repr(m.into()).unwrap();
group.bench_function("point-scalar mul", |b| b.iter(|| &p * &s));
group.bench_function("point-scalar mul", |b| b.iter(|| p * s));
}

fn bench_scalar_sub<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
fn bench_scalar_sub<M: Measurement>(group: &mut BenchmarkGroup<M>) {
let x = test_scalar_x();
let y = test_scalar_y();
group.bench_function("sub", |b| b.iter(|| &x - &y));
group.bench_function("sub", |b| b.iter(|| x - y));
}

fn bench_scalar_add<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
fn bench_scalar_add<M: Measurement>(group: &mut BenchmarkGroup<M>) {
let x = test_scalar_x();
let y = test_scalar_y();
group.bench_function("add", |b| b.iter(|| &x + &y));
group.bench_function("add", |b| b.iter(|| x + y));
}

fn bench_scalar_mul<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
fn bench_scalar_mul<M: Measurement>(group: &mut BenchmarkGroup<M>) {
let x = test_scalar_x();
let y = test_scalar_y();
group.bench_function("mul", |b| b.iter(|| &x * &y));
group.bench_function("mul", |b| b.iter(|| x * y));
}

fn bench_scalar_negate<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
fn bench_scalar_negate<M: Measurement>(group: &mut BenchmarkGroup<M>) {
let x = test_scalar_x();
group.bench_function("negate", |b| b.iter(|| -x));
}

fn bench_scalar_invert<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
fn bench_scalar_invert<M: Measurement>(group: &mut BenchmarkGroup<M>) {
let x = test_scalar_x();
group.bench_function("invert", |b| b.iter(|| x.invert()));
}
Expand Down
6 changes: 3 additions & 3 deletions bign256/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ pub(crate) mod scalar;

pub use self::scalar::Scalar;

use self::field::FieldElement;
pub use self::field::FieldElement;
use crate::BignP256;
use elliptic_curve::{CurveArithmetic, PrimeCurveArithmetic};
use primeorder::{point_arithmetic, PrimeCurveParams};
pub use elliptic_curve::{CurveArithmetic, PrimeCurveArithmetic};
pub use primeorder::{point_arithmetic, PrimeCurveParams};

/// Elliptic curve point in affine coordinates.
pub type AffinePoint = primeorder::AffinePoint<BignP256>;
Expand Down
4 changes: 2 additions & 2 deletions bign256/src/arithmetic/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
clippy::cast_possible_wrap,
clippy::cast_sign_loss,
clippy::cast_possible_truncation,
clippy::integer_arithmetic,
clippy::arithmetic_side_effects,
clippy::should_implement_trait,
clippy::suspicious_op_assign_impl,
clippy::unused_unit,
Expand All @@ -35,8 +35,8 @@ use core::{
iter::{Product, Sum},
ops::{AddAssign, MulAssign, Neg, SubAssign},
};
use elliptic_curve::bigint::Limb;
use elliptic_curve::{
bigint::Limb,
ff::PrimeField,
subtle::{Choice, ConstantTimeEq, CtOption},
};
Expand Down
4 changes: 2 additions & 2 deletions bign256/src/arithmetic/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
clippy::cast_sign_loss,
clippy::cast_possible_truncation,
clippy::identity_op,
clippy::integer_arithmetic,
clippy::arithmetic_side_effects,
clippy::too_many_arguments,
clippy::unnecessary_cast
)]
Expand Down Expand Up @@ -63,7 +63,7 @@ use core::ops::{Add, Mul, Sub};
///
/// Please see the documentation for the relevant traits for more information.
#[derive(Clone, Copy, Debug, PartialOrd, Ord)]
pub struct Scalar(U256);
pub struct Scalar(pub U256);

primeorder::impl_mont_field_element!(
BignP256,
Expand Down
Loading
Loading