-
Notifications
You must be signed in to change notification settings - Fork 237
[WIP] Test ECDSA implementation for Brainpool curves #1351
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
Draft
dignifiedquire
wants to merge
2
commits into
RustCrypto:master
Choose a base branch
from
dignifiedquire:brainpool-sign
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,18 +1,68 @@ | ||
//! Elliptic Curve Digital Signature Algorithm (ECDSA) | ||
//! | ||
//! This module contains support for computing and verifying ECDSA signatures. | ||
//! To use it, you will need to enable the following Cargo feature: `ecdsa` | ||
//! | ||
//! ## Signing/Verification Example | ||
//! | ||
//! This example requires the `ecdsa` Cargo feature is enabled: | ||
//! | ||
//! ``` | ||
//! # #[cfg(feature = "ecdsa")] | ||
//! # { | ||
//! use bp256::{ | ||
//! r1::ecdsa::{SigningKey, Signature, signature::Signer}, | ||
//! }; | ||
//! use rand_core::OsRng; // requires 'os_rng' feature | ||
//! | ||
//! // Signing | ||
//! let signing_key = SigningKey::try_from_rng(&mut OsRng).unwrap(); // Serialize with `::to_bytes()` | ||
//! let message = b"ECDSA proves knowledge of a secret number in the context of a single message"; | ||
//! let signature: Signature = signing_key.sign(message); | ||
//! | ||
//! // Verification | ||
//! use bp256::r1::ecdsa::{VerifyingKey, signature::Verifier}; | ||
//! | ||
//! let verifying_key = VerifyingKey::from(&signing_key); // Serialize with `::to_encoded_point()` | ||
//! assert!(verifying_key.verify(message, &signature).is_ok()); | ||
//! # } | ||
//! ``` | ||
|
||
pub use super::BrainpoolP256r1; | ||
pub use ecdsa::{ | ||
RecoveryId, | ||
signature::{self, Error}, | ||
}; | ||
|
||
/// ECDSA/brainpoolP256r1 signature (fixed-size) | ||
use super::BrainpoolP256r1; | ||
use ecdsa::EcdsaCurve; | ||
|
||
/// ECDSA/Brainpool-256r1 signature (fixed-size) | ||
pub type Signature = ecdsa::Signature<BrainpoolP256r1>; | ||
|
||
/// ECDSA/brainpoolP256r1 signature (ASN.1 DER encoded) | ||
/// ECDSA/Brainpool-256r1 signature (ASN.1 DER encoded) | ||
pub type DerSignature = ecdsa::der::Signature<BrainpoolP256r1>; | ||
|
||
impl ecdsa::EcdsaCurve for BrainpoolP256r1 { | ||
impl EcdsaCurve for BrainpoolP256r1 { | ||
const NORMALIZE_S: bool = false; | ||
} | ||
|
||
/// ECDSA/Brainpool-256r1 signing key | ||
#[cfg(feature = "ecdsa")] | ||
pub type SigningKey = ecdsa::SigningKey<BrainpoolP256r1>; | ||
|
||
/// ECDSA/Brainpool-256r1 verification key (i.e. public key) | ||
#[cfg(feature = "ecdsa")] | ||
pub type VerifyingKey = ecdsa::VerifyingKey<BrainpoolP256r1>; | ||
|
||
#[cfg(feature = "sha256")] | ||
impl ecdsa::hazmat::DigestAlgorithm for BrainpoolP256r1 { | ||
type Digest = sha2::Sha256; | ||
} | ||
|
||
#[cfg(all(test, feature = "ecdsa"))] | ||
mod tests { | ||
mod wycheproof { | ||
use crate::BrainpoolP256r1; | ||
ecdsa::new_wycheproof_test!(wycheproof, "wycheproof", BrainpoolP256r1); | ||
} | ||
} |
Binary file not shown.
This file contains hidden or 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,36 @@ | ||
//! ECDSA tests. | ||
|
||
#![cfg(feature = "ecdsa")] | ||
|
||
use bp256::r1::ecdsa::{ | ||
SigningKey, VerifyingKey, | ||
signature::{Signer, Verifier}, | ||
}; | ||
use proptest::prelude::*; | ||
use rand_chacha::ChaCha8Rng; | ||
use rand_core::SeedableRng; | ||
|
||
prop_compose! { | ||
fn signing_key()(seed in any::<[u8; 32]>()) -> SigningKey { | ||
let mut rng = ChaCha8Rng::from_seed(seed); | ||
SigningKey::try_from_rng(&mut rng).unwrap() | ||
} | ||
} | ||
|
||
proptest! { | ||
#[test] | ||
fn recover_from_msg(sk in signing_key()) { | ||
let msg = b"example"; | ||
let (signature, v) = sk.sign_recoverable(msg).unwrap(); | ||
let recovered_vk = VerifyingKey::recover_from_msg(msg, &signature, v).unwrap(); | ||
prop_assert_eq!(sk.verifying_key(), &recovered_vk); | ||
} | ||
|
||
#[test] | ||
fn sign_roundtrip(sk in signing_key()) { | ||
let msg = b"example"; | ||
let (signature, _v) = sk.try_sign(msg).unwrap(); | ||
let vk = sk.verifying_key(); | ||
prop_assert!(vk.verify(msg, &signature).is_ok()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tests. However, why change the name to
Brainpool-256r1
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no specific reason, I just haven’t cleaned it up yet