-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Miscellaneous tidying up * Replace failure with thiserror * Update dependencies * Fix benchmarks Signed-off-by: koushiro <koushiro.cqx@gmail.com>
- Loading branch information
Showing
12 changed files
with
277 additions
and
418 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,73 @@ | ||
#![feature(test)] | ||
extern crate test; | ||
|
||
use test::{black_box, Bencher}; | ||
|
||
use bls_signatures::*; | ||
use rand::{Rng, SeedableRng, XorShiftRng}; | ||
use test::Bencher; | ||
use rand::{Rng, SeedableRng}; | ||
use rand_xorshift::XorShiftRng; | ||
|
||
const SEED: [u8; 16] = [ | ||
0x3d, 0xbe, 0x62, 0x59, 0x8d, 0x31, 0x3d, 0x76, 0x32, 0x37, 0xdb, 0x17, 0xe5, 0xbc, 0x06, 0x54, | ||
]; | ||
|
||
#[bench] | ||
fn bench_serialize_private_key_as_bytes(b: &mut Bencher) { | ||
let rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); | ||
let rng = &mut XorShiftRng::from_seed(SEED); | ||
|
||
let private_key = PrivateKey::generate(rng); | ||
|
||
b.iter(|| test::black_box(private_key.as_bytes())); | ||
b.iter(|| black_box(private_key.as_bytes())); | ||
} | ||
|
||
#[bench] | ||
fn bench_serialize_private_key_from_bytes(b: &mut Bencher) { | ||
let rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); | ||
let rng = &mut XorShiftRng::from_seed(SEED); | ||
|
||
let private_key = PrivateKey::generate(rng); | ||
let bytes = private_key.as_bytes(); | ||
|
||
b.iter(|| test::black_box(PrivateKey::from_bytes(&bytes).unwrap())); | ||
b.iter(|| black_box(PrivateKey::from_bytes(&bytes).unwrap())); | ||
} | ||
|
||
#[bench] | ||
fn bench_serialize_public_key_as_bytes(b: &mut Bencher) { | ||
let rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); | ||
let rng = &mut XorShiftRng::from_seed(SEED); | ||
|
||
let public_key = PrivateKey::generate(rng).public_key(); | ||
|
||
b.iter(|| test::black_box(public_key.as_bytes())); | ||
b.iter(|| black_box(public_key.as_bytes())); | ||
} | ||
|
||
#[bench] | ||
fn bench_serialize_public_key_from_bytes(b: &mut Bencher) { | ||
let rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); | ||
let rng = &mut XorShiftRng::from_seed(SEED); | ||
|
||
let public_key = PrivateKey::generate(rng).public_key(); | ||
let bytes = public_key.as_bytes(); | ||
|
||
b.iter(|| test::black_box(PublicKey::from_bytes(&bytes).unwrap())); | ||
b.iter(|| black_box(PublicKey::from_bytes(&bytes).unwrap())); | ||
} | ||
|
||
#[bench] | ||
fn bench_serialize_signature_as_bytes(b: &mut Bencher) { | ||
let rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); | ||
let rng = &mut XorShiftRng::from_seed(SEED); | ||
|
||
let private_key = PrivateKey::generate(rng); | ||
let msg = (0..64).map(|_| rng.gen()).collect::<Vec<u8>>(); | ||
let signature = private_key.sign(&msg); | ||
|
||
b.iter(|| test::black_box(signature.as_bytes())); | ||
b.iter(|| black_box(signature.as_bytes())); | ||
} | ||
|
||
#[bench] | ||
fn bench_serialize_signature_from_bytes(b: &mut Bencher) { | ||
let rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); | ||
let rng = &mut XorShiftRng::from_seed(SEED); | ||
|
||
let private_key = PrivateKey::generate(rng); | ||
let msg = (0..64).map(|_| rng.gen()).collect::<Vec<u8>>(); | ||
let signature = private_key.sign(&msg); | ||
let bytes = signature.as_bytes(); | ||
|
||
b.iter(|| test::black_box(Signature::from_bytes(&bytes).unwrap())); | ||
b.iter(|| black_box(Signature::from_bytes(&bytes).unwrap())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
#![feature(test)] | ||
extern crate test; | ||
|
||
use test::{black_box, Bencher}; | ||
|
||
use bls_signatures::*; | ||
use rand::{Rng, SeedableRng, XorShiftRng}; | ||
use test::Bencher; | ||
use rand::{Rng, SeedableRng}; | ||
use rand_xorshift::XorShiftRng; | ||
|
||
const SEED: [u8; 16] = [ | ||
0x3d, 0xbe, 0x62, 0x59, 0x8d, 0x31, 0x3d, 0x76, 0x32, 0x37, 0xdb, 0x17, 0xe5, 0xbc, 0x06, 0x54, | ||
]; | ||
|
||
#[bench] | ||
fn sign_64b(b: &mut Bencher) { | ||
let rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); | ||
let rng = &mut XorShiftRng::from_seed(SEED); | ||
|
||
let private_key = PrivateKey::generate(rng); | ||
let msg: Vec<u8> = (0..64).map(|_| rng.gen()).collect(); | ||
|
||
b.iter(|| test::black_box(private_key.sign(&msg))) | ||
b.iter(|| black_box(private_key.sign(&msg))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error("Size mismatch")] | ||
SizeMismatch, | ||
#[error("Io error: {0}")] | ||
Io(#[from] std::io::Error), | ||
#[error("Group decode error: {0}")] | ||
GroupDecode(#[from] groupy::GroupDecodingError), | ||
#[error("Prime field decode error: {0}")] | ||
FieldDecode(#[from] ff::PrimeFieldDecodingError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters