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

ecdsa: remove FieldBytes bounds #227

Merged
merged 1 commit into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions ecdsa/src/hazmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use elliptic_curve::{generic_array::ArrayLength, weierstrass::Curve};
pub trait SignPrimitive<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
SignatureSize<C>: ArrayLength<u8>,
{
Expand All @@ -65,7 +64,6 @@ where
pub trait RecoverableSignPrimitive<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
SignatureSize<C>: ArrayLength<u8>,
{
Expand All @@ -87,7 +85,6 @@ impl<C, T> SignPrimitive<C> for T
where
C: Curve + ProjectiveArithmetic,
T: RecoverableSignPrimitive<C>,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
SignatureSize<C>: ArrayLength<u8>,
{
Expand All @@ -111,7 +108,6 @@ where
pub trait VerifyPrimitive<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
SignatureSize<C>: ArrayLength<u8>,
{
Expand Down
1 change: 0 additions & 1 deletion ecdsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ where
impl<C> CheckSignatureBytes for C
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'a> From<&'a Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
SignatureSize<C>: ArrayLength<u8>,
{
Expand Down
1 change: 0 additions & 1 deletion ecdsa/src/rfc6979.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ pub fn generate_k<C, D>(
where
C: ProjectiveArithmetic,
D: FixedOutput<OutputSize = C::FieldSize> + BlockInput + Clone + Default + Reset + Update,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>:
PrimeField<Repr = FieldBytes<C>> + FromDigest<C> + Invert<Output = Scalar<C>> + Zeroize,
{
Expand Down
29 changes: 9 additions & 20 deletions ecdsa/src/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ use core::str::FromStr;
pub struct SigningKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>
+ FromDigest<C>
+ Invert<Output = Scalar<C>>
Expand All @@ -64,7 +63,6 @@ where
impl<C> SigningKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>
+ FromDigest<C>
+ Invert<Output = Scalar<C>>
Expand Down Expand Up @@ -108,7 +106,6 @@ where
impl<C> From<SecretKey<C>> for SigningKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>
+ ConstantTimeEq
+ FromDigest<C>
Expand All @@ -125,13 +122,12 @@ where
impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
D: FixedOutput<OutputSize = C::FieldSize> + BlockInput + Clone + Default + Reset + Update,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>
+ FromDigest<C>
+ Invert<Output = Scalar<C>>
+ SignPrimitive<C>
+ Zeroize,
D: FixedOutput<OutputSize = C::FieldSize> + BlockInput + Clone + Default + Reset + Update,
SignatureSize<C>: ArrayLength<u8>,
{
/// Sign message prehash using a deterministic ephemeral scalar (`k`)
Expand All @@ -149,15 +145,14 @@ where

impl<C> signature::Signer<Signature<C>> for SigningKey<C>
where
Self: DigestSigner<C::Digest, Signature<C>>,
C: Curve + ProjectiveArithmetic + DigestPrimitive,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>
+ FromDigest<C>
+ Invert<Output = Scalar<C>>
+ SignPrimitive<C>
+ Zeroize,
SignatureSize<C>: ArrayLength<u8>,
Self: DigestSigner<C::Digest, Signature<C>>,
{
fn try_sign(&self, msg: &[u8]) -> Result<Signature<C>, signature::Error> {
self.try_sign_digest(C::Digest::new().chain(msg))
Expand All @@ -167,13 +162,12 @@ where
impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
D: FixedOutput<OutputSize = C::FieldSize> + BlockInput + Clone + Default + Reset + Update,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>
+ FromDigest<C>
+ Invert<Output = Scalar<C>>
+ SignPrimitive<C>
+ Zeroize,
D: FixedOutput<OutputSize = C::FieldSize> + BlockInput + Clone + Default + Reset + Update,
SignatureSize<C>: ArrayLength<u8>,
{
/// Sign message prehash using an ephemeral scalar (`k`) derived according
Expand All @@ -198,15 +192,14 @@ where

impl<C> RandomizedSigner<Signature<C>> for SigningKey<C>
where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: Curve + ProjectiveArithmetic + DigestPrimitive,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>
+ FromDigest<C>
+ Invert<Output = Scalar<C>>
+ SignPrimitive<C>
+ Zeroize,
SignatureSize<C>: ArrayLength<u8>,
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
{
fn try_sign_with_rng(
&self,
Expand All @@ -220,7 +213,6 @@ where
impl<C> From<NonZeroScalar<C>> for SigningKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>
+ FromDigest<C>
+ Invert<Output = Scalar<C>>
Expand All @@ -239,14 +231,13 @@ where
impl<C> From<&SigningKey<C>> for VerifyingKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
AffinePoint<C>: Copy + Clone + Debug + Default,
ProjectivePoint<C>: From<AffinePoint<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>
+ FromDigest<C>
+ Invert<Output = Scalar<C>>
+ SignPrimitive<C>
+ Zeroize,
AffinePoint<C>: Copy + Clone + Debug + Default,
ProjectivePoint<C>: From<AffinePoint<C>>,
SignatureSize<C>: ArrayLength<u8>,
{
fn from(signing_key: &SigningKey<C>) -> VerifyingKey<C> {
Expand All @@ -259,13 +250,12 @@ where
impl<C> FromPrivateKey for SigningKey<C>
where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
AffinePoint<C>: Copy + Clone + Debug + Default,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>
+ FromDigest<C>
+ Invert<Output = Scalar<C>>
+ SignPrimitive<C>
+ Zeroize,
AffinePoint<C>: Copy + Clone + Debug + Default,
SignatureSize<C>: ArrayLength<u8>,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
Expand All @@ -282,14 +272,13 @@ where
impl<C> FromStr for SigningKey<C>
where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
AffinePoint<C>: Copy + Clone + Debug + Default,
SignatureSize<C>: ArrayLength<u8>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>
+ FromDigest<C>
+ Invert<Output = Scalar<C>>
+ SignPrimitive<C>
+ Zeroize,
AffinePoint<C>: Copy + Clone + Debug + Default,
SignatureSize<C>: ArrayLength<u8>,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
{
Expand Down
39 changes: 13 additions & 26 deletions ecdsa/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,18 @@ use core::str::FromStr;
pub struct VerifyingKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
AffinePoint<C>: Copy + Clone + Debug,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
{
pub(crate) inner: PublicKey<C>,
}

impl<C> VerifyingKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
AffinePoint<C>: Copy + Clone + Debug + Default + FromEncodedPoint<C> + ToEncodedPoint<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
{
Expand Down Expand Up @@ -77,10 +75,9 @@ impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>
where
C: Curve + ProjectiveArithmetic,
D: Digest<OutputSize = C::FieldSize>,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C>,
AffinePoint<C>: Copy + Clone + Debug + VerifyPrimitive<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn verify_digest(&self, digest: D, signature: &Signature<C>) -> Result<(), Error> {
Expand All @@ -94,10 +91,9 @@ impl<C> signature::Verifier<Signature<C>> for VerifyingKey<C>
where
C: Curve + ProjectiveArithmetic + DigestPrimitive,
C::Digest: Digest<OutputSize = C::FieldSize>,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C>,
AffinePoint<C>: Copy + Clone + Debug + VerifyPrimitive<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn verify(&self, msg: &[u8], signature: &Signature<C>) -> Result<(), Error> {
Expand All @@ -108,10 +104,9 @@ where
impl<C> From<&VerifyingKey<C>> for EncodedPoint<C>
where
C: Curve + ProjectiveArithmetic + point::Compression,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
AffinePoint<C>: Copy + Clone + Debug + Default + FromEncodedPoint<C> + ToEncodedPoint<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
{
Expand All @@ -123,9 +118,8 @@ where
impl<C> From<PublicKey<C>> for VerifyingKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
AffinePoint<C>: Copy + Clone + Debug,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
{
fn from(public_key: PublicKey<C>) -> VerifyingKey<C> {
VerifyingKey { inner: public_key }
Expand All @@ -135,9 +129,8 @@ where
impl<C> From<&PublicKey<C>> for VerifyingKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
AffinePoint<C>: Copy + Clone + Debug,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
{
fn from(public_key: &PublicKey<C>) -> VerifyingKey<C> {
public_key.clone().into()
Expand All @@ -147,9 +140,8 @@ where
impl<C> From<VerifyingKey<C>> for PublicKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
AffinePoint<C>: Copy + Clone + Debug,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
{
fn from(verify_key: VerifyingKey<C>) -> PublicKey<C> {
verify_key.inner
Expand All @@ -159,9 +151,8 @@ where
impl<C> From<&VerifyingKey<C>> for PublicKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
AffinePoint<C>: Copy + Clone + Debug,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
{
fn from(verify_key: &VerifyingKey<C>) -> PublicKey<C> {
verify_key.clone().into()
Expand All @@ -171,10 +162,9 @@ where
impl<C> Eq for VerifyingKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
AffinePoint<C>: Copy + Clone + Debug + Default + FromEncodedPoint<C> + ToEncodedPoint<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
{
Expand All @@ -183,10 +173,9 @@ where
impl<C> PartialEq for VerifyingKey<C>
where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
AffinePoint<C>: Copy + Clone + Debug + Default + FromEncodedPoint<C> + ToEncodedPoint<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
{
Expand All @@ -200,10 +189,9 @@ where
impl<C> FromPublicKey for VerifyingKey<C>
where
C: Curve + AlgorithmParameters + ProjectiveArithmetic + point::Compression,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
AffinePoint<C>: Copy + Clone + Debug + Default + FromEncodedPoint<C> + ToEncodedPoint<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
{
Expand All @@ -217,10 +205,9 @@ where
impl<C> FromStr for VerifyingKey<C>
where
C: Curve + AlgorithmParameters + ProjectiveArithmetic + point::Compression,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
AffinePoint<C>: Copy + Clone + Debug + Default + FromEncodedPoint<C> + ToEncodedPoint<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
{
Expand Down