Skip to content

Commit

Permalink
k256: fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri committed Jan 11, 2024
1 parent 9621f37 commit ad020be
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
40 changes: 22 additions & 18 deletions k256/benches/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,39 @@ use ecdsa_core::{
elliptic_curve::group::prime::PrimeCurveAffine,
hazmat::{SignPrimitive, VerifyPrimitive},
};
use k256::{
elliptic_curve::{array::arr, group::ff::PrimeField},
AffinePoint, FieldBytes, Scalar,
};
use k256::{elliptic_curve::group::ff::PrimeField, AffinePoint, FieldBytes, Scalar};

fn test_scalar_d() -> Scalar {
Scalar::from_repr(arr![u8;
0xbb, 0x48, 0x8a, 0xef, 0x41, 0x6a, 0x41, 0xd7, 0x68, 0x0d, 0x1c, 0xf0, 0x1d, 0x70,
0xf5, 0x9b, 0x60, 0xd7, 0xf5, 0xf7, 0x7e, 0x30, 0xe7, 0x8b, 0x8b, 0xf9, 0xd2, 0xd8,
0x82, 0xf1, 0x56, 0xa6,
])
Scalar::from_repr(
[
0xbb, 0x48, 0x8a, 0xef, 0x41, 0x6a, 0x41, 0xd7, 0x68, 0x0d, 0x1c, 0xf0, 0x1d, 0x70,
0xf5, 0x9b, 0x60, 0xd7, 0xf5, 0xf7, 0x7e, 0x30, 0xe7, 0x8b, 0x8b, 0xf9, 0xd2, 0xd8,
0x82, 0xf1, 0x56, 0xa6,
]
.into(),
)
.unwrap()
}

fn test_scalar_k() -> Scalar {
Scalar::from_repr(arr![u8;
0x67, 0xe2, 0xf6, 0x80, 0x71, 0xed, 0x82, 0x81, 0xe8, 0xae, 0xd6, 0xbc, 0xf1, 0xc5,
0x20, 0x7c, 0x5e, 0x63, 0x37, 0x22, 0xd9, 0x20, 0xaf, 0xd6, 0xae, 0x22, 0xd0, 0x6e,
0xeb, 0x80, 0x35, 0xe3,
])
Scalar::from_repr(
[
0x67, 0xe2, 0xf6, 0x80, 0x71, 0xed, 0x82, 0x81, 0xe8, 0xae, 0xd6, 0xbc, 0xf1, 0xc5,
0x20, 0x7c, 0x5e, 0x63, 0x37, 0x22, 0xd9, 0x20, 0xaf, 0xd6, 0xae, 0x22, 0xd0, 0x6e,
0xeb, 0x80, 0x35, 0xe3,
]
.into(),
)
.unwrap()
}

fn test_scalar_z() -> FieldBytes {
arr![u8;
0xe3, 0x35, 0x80, 0xeb, 0x6e, 0xd0, 0x22, 0xae, 0xd6, 0xaf, 0x20, 0xd9, 0x22, 0x37,
0x63, 0x5e, 0x7c, 0x20, 0xc5, 0xf1, 0xbc, 0xd6, 0xae, 0xe8, 0x81, 0x82, 0xed, 0x71,
0x80, 0xf6, 0xe2, 0x67
[
0xe3, 0x35, 0x80, 0xeb, 0x6e, 0xd0, 0x22, 0xae, 0xd6, 0xaf, 0x20, 0xd9, 0x22, 0x37, 0x63,
0x5e, 0x7c, 0x20, 0xc5, 0xf1, 0xbc, 0xd6, 0xae, 0xe8, 0x81, 0x82, 0xed, 0x71, 0x80, 0xf6,
0xe2, 0x67,
]
.into()
}

fn bench_ecdsa(c: &mut Criterion) {
Expand Down
30 changes: 17 additions & 13 deletions k256/benches/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,31 @@ use criterion::{
};
use hex_literal::hex;
use k256::{
elliptic_curve::{
array::arr, group::ff::PrimeField, ops::LinearCombination, ops::MulByGenerator,
},
elliptic_curve::{group::ff::PrimeField, ops::LinearCombination, ops::MulByGenerator},
ProjectivePoint, Scalar,
};

fn test_scalar_x() -> Scalar {
Scalar::from_repr(arr![u8;
0xbb, 0x48, 0x8a, 0xef, 0x41, 0x6a, 0x41, 0xd7, 0x68, 0x0d, 0x1c, 0xf0, 0x1d, 0x70,
0xf5, 0x9b, 0x60, 0xd7, 0xf5, 0xf7, 0x7e, 0x30, 0xe7, 0x8b, 0x8b, 0xf9, 0xd2, 0xd8,
0x82, 0xf1, 0x56, 0xa6,
])
Scalar::from_repr(
[
0xbb, 0x48, 0x8a, 0xef, 0x41, 0x6a, 0x41, 0xd7, 0x68, 0x0d, 0x1c, 0xf0, 0x1d, 0x70,
0xf5, 0x9b, 0x60, 0xd7, 0xf5, 0xf7, 0x7e, 0x30, 0xe7, 0x8b, 0x8b, 0xf9, 0xd2, 0xd8,
0x82, 0xf1, 0x56, 0xa6,
]
.into(),
)
.unwrap()
}

fn test_scalar_y() -> Scalar {
Scalar::from_repr(arr![u8;
0x67, 0xe2, 0xf6, 0x80, 0x71, 0xed, 0x82, 0x81, 0xe8, 0xae, 0xd6, 0xbc, 0xf1, 0xc5,
0x20, 0x7c, 0x5e, 0x63, 0x37, 0x22, 0xd9, 0x20, 0xaf, 0xd6, 0xae, 0x22, 0xd0, 0x6e,
0xeb, 0x80, 0x35, 0xe3,
])
Scalar::from_repr(
[
0x67, 0xe2, 0xf6, 0x80, 0x71, 0xed, 0x82, 0x81, 0xe8, 0xae, 0xd6, 0xbc, 0xf1, 0xc5,
0x20, 0x7c, 0x5e, 0x63, 0x37, 0x22, 0xd9, 0x20, 0xaf, 0xd6, 0xae, 0x22, 0xd0, 0x6e,
0xeb, 0x80, 0x35, 0xe3,
]
.into(),
)
.unwrap()
}

Expand Down

0 comments on commit ad020be

Please sign in to comment.