ecdsa: bump elliptic-curve to v0.13.0-pre; MSRV 1.61 (#631)

Sourced from git
This commit is contained in:
Tony Arcieri
2023-01-22 10:21:14 -07:00
committed by GitHub
parent 049ec44928
commit 773e490a18
18 changed files with 237 additions and 185 deletions
+2 -2
View File
@@ -24,7 +24,7 @@ jobs:
- thumbv7em-none-eabi
- wasm32-unknown-unknown
toolchain:
- 1.60.0 # MSRV
- 1.61.0 # MSRV
- stable
steps:
- uses: actions/checkout@v3
@@ -43,7 +43,7 @@ jobs:
- macos-latest
- windows-latest
toolchain:
- 1.60.0 # MSRV
- 1.61.0 # MSRV
- stable
runs-on: ${{ matrix.platform }}
steps:
+2 -2
View File
@@ -26,7 +26,7 @@ jobs:
- thumbv7em-none-eabi
- wasm32-unknown-unknown
rust:
- 1.60.0 # MSRV
- 1.61.0 # MSRV
- stable
steps:
- uses: actions/checkout@v3
@@ -44,7 +44,7 @@ jobs:
strategy:
matrix:
rust:
- 1.60.0 # MSRV
- 1.61.0 # MSRV
- stable
steps:
- uses: actions/checkout@v3
+2 -2
View File
@@ -24,7 +24,7 @@ jobs:
- thumbv7em-none-eabi
- wasm32-unknown-unknown
rust:
- 1.60.0 # MSRV
- 1.61.0 # MSRV
- stable
steps:
- uses: actions/checkout@v3
@@ -41,7 +41,7 @@ jobs:
strategy:
matrix:
rust:
- 1.60.0 # MSRV
- 1.61.0 # MSRV
- stable
steps:
- uses: actions/checkout@v3
Generated
+60 -10
View File
@@ -108,6 +108,18 @@ dependencies = [
"zeroize",
]
[[package]]
name = "crypto-bigint"
version = "0.5.0-pre.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "753eaa5e38b15c84bd939057ae9cee3d12eb52fff0ddf93d40ba5febcc0eb9ee"
dependencies = [
"generic-array",
"rand_core 0.6.4",
"subtle",
"zeroize",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
@@ -186,7 +198,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82508ce57bd2b245e9914411800f87fd8fc8288f501bb26919cb9b2ee964028f"
dependencies = [
"der",
"elliptic-curve",
"elliptic-curve 0.12.3",
"signature 2.0.0",
]
@@ -195,7 +207,7 @@ name = "ecdsa"
version = "0.16.0-pre"
dependencies = [
"der",
"elliptic-curve",
"elliptic-curve 0.13.0-pre",
"hex-literal",
"rfc6979",
"serdect",
@@ -258,12 +270,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3"
dependencies = [
"base16ct",
"crypto-bigint",
"crypto-bigint 0.4.9",
"der",
"digest 0.10.6",
"ff",
"ff 0.12.1",
"generic-array",
"group",
"group 0.12.1",
"rand_core 0.6.4",
"sec1",
"subtle",
"zeroize",
]
[[package]]
name = "elliptic-curve"
version = "0.13.0-pre"
source = "git+https://github.com/RustCrypto/traits.git#778e6f4368422f87ba5d667095673423f8abccda"
dependencies = [
"base16ct",
"crypto-bigint 0.5.0-pre.1",
"digest 0.10.6",
"ff 0.13.0",
"generic-array",
"group 0.13.0",
"hex-literal",
"pem-rfc7468",
"pkcs8",
@@ -284,6 +313,16 @@ dependencies = [
"subtle",
]
[[package]]
name = "ff"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449"
dependencies = [
"rand_core 0.6.4",
"subtle",
]
[[package]]
name = "generic-array"
version = "0.14.6"
@@ -322,7 +361,18 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7"
dependencies = [
"ff",
"ff 0.12.1",
"rand_core 0.6.4",
"subtle",
]
[[package]]
name = "group"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63"
dependencies = [
"ff 0.13.0",
"rand_core 0.6.4",
"subtle",
]
@@ -447,7 +497,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49c124b3cbce43bcbac68c58ec181d98ed6cc7e6d0aa7c3ba97b2563410b0e55"
dependencies = [
"ecdsa 0.15.0",
"elliptic-curve",
"elliptic-curve 0.12.3",
"primeorder",
]
@@ -458,7 +508,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "630a4a9b2618348ececfae61a4905f564b817063bf2d66cdfc2ced523fe1d2d4"
dependencies = [
"ecdsa 0.15.0",
"elliptic-curve",
"elliptic-curve 0.12.3",
"primeorder",
]
@@ -493,7 +543,7 @@ version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49b7e10b3a364b1c813238b1c9a749336cbe51fd4265cd99f57cf29302c90af7"
dependencies = [
"elliptic-curve",
"elliptic-curve 0.12.3",
]
[[package]]
@@ -589,7 +639,7 @@ dependencies = [
name = "rfc6979"
version = "0.4.0-pre"
dependencies = [
"crypto-bigint",
"crypto-bigint 0.5.0-pre.1",
"hmac",
"sha2 0.10.6",
"zeroize",
+3
View File
@@ -9,3 +9,6 @@ members = [
[profile.dev]
opt-level = 2
[patch.crates-io.elliptic-curve]
git = "https://github.com/RustCrypto/traits.git"
+1 -1
View File
@@ -12,7 +12,7 @@ readme = "README.md"
repository = "https://github.com/RustCrypto/signatures/tree/master/dsa"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "nist", "signature"]
rust-version = "1.60"
rust-version = "1.61"
[dependencies]
digest = "0.10"
+2 -2
View File
@@ -30,7 +30,7 @@ USE AT YOUR OWN RISK!
## Minimum Supported Rust Version
This crate requires **Rust 1.60** at a minimum.
This crate requires **Rust 1.61** at a minimum.
We may change the MSRV in the future, but it will be accompanied by a minor
version bump.
@@ -59,7 +59,7 @@ dual licensed as above, without any additional terms or conditions.
[build-image]: https://github.com/RustCrypto/signatures/actions/workflows/dsa.yml/badge.svg
[build-link]: https://github.com/RustCrypto/signatures/actions/workflows/dsa.yml
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.60+-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.61+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260048-signatures
+3 -3
View File
@@ -13,10 +13,10 @@ readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "nist", "secp256k1", "signature"]
edition = "2021"
rust-version = "1.60"
rust-version = "1.61"
[dependencies]
elliptic-curve = { version = "0.12", default-features = false, features = ["digest", "sec1"] }
elliptic-curve = { version = "=0.13.0-pre", default-features = false, features = ["digest", "sec1"] }
signature = { version = "2.0, <2.1", default-features = false, features = ["rand_core"] }
# optional dependencies
@@ -25,7 +25,7 @@ rfc6979 = { version = "=0.4.0-pre", optional = true, path = "../rfc6979" }
serdect = { version = "0.1", optional = true, default-features = false, features = ["alloc"] }
[dev-dependencies]
elliptic-curve = { version = "0.12", default-features = false, features = ["dev"] }
elliptic-curve = { version = "=0.13.0-pre", default-features = false, features = ["dev"] }
hex-literal = "0.3"
sha2 = { version = "0.10", default-features = false }
+2 -2
View File
@@ -41,7 +41,7 @@ USE AT YOUR OWN RISK!
## Minimum Supported Rust Version
This crate requires **Rust 1.60** at a minimum.
This crate requires **Rust 1.61** at a minimum.
We may change the MSRV in the future, but it will be accompanied by a minor
version bump.
@@ -70,7 +70,7 @@ dual licensed as above, without any additional terms or conditions.
[build-image]: https://github.com/RustCrypto/signatures/actions/workflows/ecdsa.yml/badge.svg
[build-link]: https://github.com/RustCrypto/signatures/actions/workflows/ecdsa.yml
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.60+-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.61+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260048-signatures
+4 -4
View File
@@ -7,7 +7,7 @@ use core::{
};
use der::{asn1::UIntRef, Decode, Encode, Reader};
use elliptic_curve::{
bigint::Encoding as _,
bigint::Integer,
consts::U9,
generic_array::{ArrayLength, GenericArray},
FieldSize, PrimeCurve,
@@ -181,7 +181,7 @@ where
fn try_from(input: &[u8]) -> Result<Self> {
let (r, s) = decode_der(input).map_err(|_| Error::new())?;
if r.as_bytes().len() > C::UInt::BYTE_SIZE || s.as_bytes().len() > C::UInt::BYTE_SIZE {
if r.as_bytes().len() > C::Uint::BYTES || s.as_bytes().len() > C::Uint::BYTES {
return Err(Error::new());
}
@@ -213,9 +213,9 @@ where
fn try_from(sig: Signature<C>) -> Result<super::Signature<C>> {
let mut bytes = super::SignatureBytes::<C>::default();
let r_begin = C::UInt::BYTE_SIZE.saturating_sub(sig.r().len());
let r_begin = C::Uint::BYTES.saturating_sub(sig.r().len());
let s_begin = bytes.len().saturating_sub(sig.s().len());
bytes[r_begin..C::UInt::BYTE_SIZE].copy_from_slice(sig.r());
bytes[r_begin..C::Uint::BYTES].copy_from_slice(sig.r());
bytes[s_begin..].copy_from_slice(sig.s());
Self::try_from(bytes.as_slice())
}
+4 -4
View File
@@ -34,13 +34,13 @@ macro_rules! new_signing_test {
use $crate::{
elliptic_curve::{
bigint::Encoding, generic_array::GenericArray, group::ff::PrimeField, Curve,
ProjectiveArithmetic, Scalar,
CurveArithmetic, Scalar,
},
hazmat::SignPrimitive,
};
fn decode_scalar(bytes: &[u8]) -> Option<Scalar<$curve>> {
if bytes.len() == <$curve as Curve>::UInt::BYTE_SIZE {
if bytes.len() == <$curve as Curve>::Uint::BYTES {
Scalar::<$curve>::from_repr(GenericArray::clone_from_slice(bytes)).into()
} else {
None
@@ -71,7 +71,7 @@ macro_rules! new_verification_test {
generic_array::GenericArray,
group::ff::PrimeField,
sec1::{EncodedPoint, FromEncodedPoint},
AffinePoint, ProjectiveArithmetic, Scalar,
AffinePoint, CurveArithmetic, Scalar,
},
hazmat::VerifyPrimitive,
Signature,
@@ -145,7 +145,7 @@ macro_rules! new_wycheproof_test {
fn element_from_padded_slice<C: elliptic_curve::Curve>(
data: &[u8],
) -> elliptic_curve::FieldBytes<C> {
let point_len = C::UInt::BYTE_SIZE;
let point_len = C::Uint::BYTES;
if data.len() >= point_len {
let offset = data.len() - point_len;
for v in data.iter().take(offset) {
+19 -20
View File
@@ -12,7 +12,7 @@
use crate::{Error, Result};
use core::cmp;
use elliptic_curve::{bigint::Encoding, FieldBytes, PrimeCurve};
use elliptic_curve::{bigint::Integer, FieldBytes, PrimeCurve};
#[cfg(feature = "arithmetic")]
use {
@@ -22,8 +22,7 @@ use {
group::Curve as _,
ops::{Invert, LinearCombination, Reduce},
subtle::CtOption,
AffineArithmetic, AffineXCoordinate, Field, Group, ProjectiveArithmetic, ProjectivePoint,
Scalar, ScalarArithmetic,
AffineXCoordinate, CurveArithmetic, Field, Group, ProjectivePoint, Scalar,
},
};
@@ -43,16 +42,16 @@ use crate::{elliptic_curve::generic_array::ArrayLength, Signature};
use signature::digest::FixedOutput;
#[cfg(feature = "rfc6979")]
use elliptic_curve::ScalarCore;
use elliptic_curve::ScalarPrimitive;
/// Try to sign the given prehashed message using ECDSA.
///
/// This trait is intended to be implemented on a type with access to the
/// secret scalar via `&self`, such as particular curve's `Scalar` type.
#[cfg(feature = "arithmetic")]
pub trait SignPrimitive<C>: Field + Into<FieldBytes<C>> + Reduce<C::UInt> + Sized
pub trait SignPrimitive<C>: Field + Into<FieldBytes<C>> + Reduce<C::Uint> + Sized
where
C: PrimeCurve + ProjectiveArithmetic + ScalarArithmetic<Scalar = Self>,
C: PrimeCurve + CurveArithmetic + CurveArithmetic<Scalar = Self>,
SignatureSize<C>: ArrayLength<u8>,
{
/// Try to sign the prehashed message.
@@ -118,13 +117,13 @@ where
ad: &[u8],
) -> Result<(Signature<C>, Option<RecoveryId>)>
where
Self: From<ScalarCore<C>>,
C::UInt: for<'a> From<&'a Self>,
Self: From<ScalarPrimitive<C>>,
C::Uint: for<'a> From<&'a Self>,
D: Digest + BlockSizeUser + FixedOutput<OutputSize = FieldSize<C>> + FixedOutputReset,
{
let x = C::UInt::from(self);
let k = rfc6979::generate_k::<D, C::UInt>(&x, &C::ORDER, &z, ad);
let k = Self::from(ScalarCore::<C>::new(*k).unwrap());
let x = C::Uint::from(self);
let k = rfc6979::generate_k::<D, C::Uint>(&x, &C::ORDER, &z, ad);
let k = Self::from(ScalarPrimitive::<C>::new(*k).unwrap());
self.try_sign_prehashed(k, z)
}
@@ -139,8 +138,8 @@ where
ad: &[u8],
) -> Result<(Signature<C>, Option<RecoveryId>)>
where
Self: From<ScalarCore<C>>,
C::UInt: for<'a> From<&'a Self>,
Self: From<ScalarPrimitive<C>>,
C::Uint: for<'a> From<&'a Self>,
D: Digest + BlockSizeUser + FixedOutput<OutputSize = FieldSize<C>> + FixedOutputReset,
{
self.try_sign_prehashed_rfc6979::<D>(msg_digest.finalize_fixed(), ad)
@@ -153,10 +152,10 @@ where
/// the affine point represeting the public key via `&self`, such as a
/// particular curve's `AffinePoint` type.
#[cfg(feature = "arithmetic")]
pub trait VerifyPrimitive<C>: AffineXCoordinate<C> + Copy + Sized
pub trait VerifyPrimitive<C>: AffineXCoordinate<FieldRepr = FieldBytes<C>> + Copy + Sized
where
C: PrimeCurve + AffineArithmetic<AffinePoint = Self> + ProjectiveArithmetic,
Scalar<C>: Reduce<C::UInt>,
C: PrimeCurve + CurveArithmetic<AffinePoint = Self> + CurveArithmetic,
Scalar<C>: Reduce<C::Uint>,
SignatureSize<C>: ArrayLength<u8>,
{
/// Verify the prehashed message against the provided signature
@@ -235,21 +234,21 @@ where
/// [SEC1]: https://www.secg.org/sec1-v2.pdf
pub fn bits2field<C: PrimeCurve>(bits: &[u8]) -> Result<FieldBytes<C>> {
// Minimum allowed bits size is half the field size
if bits.len() < C::UInt::BYTE_SIZE / 2 {
if bits.len() < C::Uint::BYTES / 2 {
return Err(Error::new());
}
let mut field_bytes = FieldBytes::<C>::default();
match bits.len().cmp(&C::UInt::BYTE_SIZE) {
match bits.len().cmp(&C::Uint::BYTES) {
cmp::Ordering::Equal => field_bytes.copy_from_slice(bits),
cmp::Ordering::Less => {
// If bits is smaller than the field size, pad with zeroes on the left
field_bytes[(C::UInt::BYTE_SIZE - bits.len())..].copy_from_slice(bits);
field_bytes[(C::Uint::BYTES - bits.len())..].copy_from_slice(bits);
}
cmp::Ordering::Greater => {
// If bits is larger than the field size, truncate
field_bytes.copy_from_slice(&bits[..C::UInt::BYTE_SIZE]);
field_bytes.copy_from_slice(&bits[..C::Uint::BYTES]);
}
}
+15 -15
View File
@@ -88,9 +88,9 @@ use core::{
ops::Add,
};
use elliptic_curve::{
bigint::Encoding as _,
bigint::Integer,
generic_array::{sequence::Concat, ArrayLength, GenericArray},
FieldBytes, FieldSize, ScalarCore,
FieldBytes, FieldSize, ScalarPrimitive,
};
#[cfg(feature = "alloc")]
@@ -99,7 +99,7 @@ use alloc::vec::Vec;
#[cfg(feature = "arithmetic")]
use {
core::str,
elliptic_curve::{IsHigh, NonZeroScalar, ScalarArithmetic},
elliptic_curve::{CurveArithmetic, IsHigh, NonZeroScalar},
};
#[cfg(feature = "serde")]
@@ -135,8 +135,8 @@ pub type SignatureBytes<C> = GenericArray<u8, SignatureSize<C>>;
/// formats, and a hexadecimal encoding when used with text formats.
#[derive(Clone, Eq, PartialEq)]
pub struct Signature<C: PrimeCurve> {
r: ScalarCore<C>,
s: ScalarCore<C>,
r: ScalarPrimitive<C>,
s: ScalarPrimitive<C>,
}
impl<C> Signature<C>
@@ -168,7 +168,7 @@ where
/// Serialize this signature as bytes.
pub fn to_bytes(&self) -> SignatureBytes<C> {
let mut bytes = SignatureBytes::<C>::default();
let (r_bytes, s_bytes) = bytes.split_at_mut(C::UInt::BYTE_SIZE);
let (r_bytes, s_bytes) = bytes.split_at_mut(C::Uint::BYTES);
r_bytes.copy_from_slice(&self.r.to_be_bytes());
s_bytes.copy_from_slice(&self.s.to_be_bytes());
bytes
@@ -195,7 +195,7 @@ where
#[cfg(feature = "arithmetic")]
impl<C> Signature<C>
where
C: PrimeCurve + ScalarArithmetic,
C: PrimeCurve + CurveArithmetic,
SignatureSize<C>: ArrayLength<u8>,
{
/// Get the `r` component of this signature
@@ -222,7 +222,7 @@ where
if s.is_high().into() {
let mut result = self.clone();
result.s = ScalarCore::from(-s);
result.s = ScalarPrimitive::from(-s);
Some(result)
} else {
None
@@ -280,13 +280,13 @@ where
type Error = Error;
fn try_from(bytes: &[u8]) -> Result<Self> {
if bytes.len() != C::UInt::BYTE_SIZE * 2 {
if bytes.len() != C::Uint::BYTES * 2 {
return Err(Error::new());
}
let (r_bytes, s_bytes) = bytes.split_at(C::UInt::BYTE_SIZE);
let r = ScalarCore::from_be_slice(r_bytes).map_err(|_| Error::new())?;
let s = ScalarCore::from_be_slice(s_bytes).map_err(|_| Error::new())?;
let (r_bytes, s_bytes) = bytes.split_at(C::Uint::BYTES);
let r = ScalarPrimitive::from_be_slice(r_bytes).map_err(|_| Error::new())?;
let s = ScalarPrimitive::from_be_slice(s_bytes).map_err(|_| Error::new())?;
if r.is_zero().into() || s.is_zero().into() {
return Err(Error::new());
@@ -335,13 +335,13 @@ where
#[cfg(feature = "arithmetic")]
impl<C> str::FromStr for Signature<C>
where
C: PrimeCurve + ScalarArithmetic,
C: PrimeCurve + CurveArithmetic,
SignatureSize<C>: ArrayLength<u8>,
{
type Err = Error;
fn from_str(hex: &str) -> Result<Self> {
if hex.as_bytes().len() != C::UInt::BYTE_SIZE * 4 {
if hex.as_bytes().len() != C::Uint::BYTES * 4 {
return Err(Error::new());
}
@@ -354,7 +354,7 @@ where
return Err(Error::new());
}
let (r_hex, s_hex) = hex.split_at(C::UInt::BYTE_SIZE * 2);
let (r_hex, s_hex) = hex.split_at(C::Uint::BYTES * 2);
let r = r_hex
.parse::<NonZeroScalar<C>>()
+11 -11
View File
@@ -12,8 +12,8 @@ use {
generic_array::ArrayLength,
ops::{Invert, LinearCombination, Reduce},
sec1::{self, FromEncodedPoint, ToEncodedPoint},
AffinePoint, DecompressPoint, FieldSize, Group, PrimeCurve, PrimeField,
ProjectiveArithmetic, ProjectivePoint, Scalar,
AffinePoint, CurveArithmetic, DecompressPoint, FieldSize, Group, PrimeCurve, PrimeField,
ProjectivePoint, Scalar,
},
signature::{digest::Digest, hazmat::PrehashVerifier},
};
@@ -82,11 +82,11 @@ impl RecoveryId {
signature: &Signature<C>,
) -> Result<Self>
where
C: DigestPrimitive + PrimeCurve + ProjectiveArithmetic,
C: DigestPrimitive + PrimeCurve + CurveArithmetic,
AffinePoint<C>:
DecompressPoint<C> + FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
FieldSize<C>: sec1::ModulusSize,
Scalar<C>: Reduce<C::UInt>,
Scalar<C>: Reduce<C::Uint>,
SignatureSize<C>: ArrayLength<u8>,
{
Self::trial_recovery_from_digest(verifying_key, C::Digest::new_with_prefix(msg), signature)
@@ -101,12 +101,12 @@ impl RecoveryId {
signature: &Signature<C>,
) -> Result<Self>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
D: Digest,
AffinePoint<C>:
DecompressPoint<C> + FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
FieldSize<C>: sec1::ModulusSize,
Scalar<C>: Reduce<C::UInt>,
Scalar<C>: Reduce<C::Uint>,
SignatureSize<C>: ArrayLength<u8>,
{
Self::trial_recovery_from_prehash(verifying_key, &digest.finalize(), signature)
@@ -121,11 +121,11 @@ impl RecoveryId {
signature: &Signature<C>,
) -> Result<Self>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
AffinePoint<C>:
DecompressPoint<C> + FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
FieldSize<C>: sec1::ModulusSize,
Scalar<C>: Reduce<C::UInt>,
Scalar<C>: Reduce<C::Uint>,
SignatureSize<C>: ArrayLength<u8>,
{
for id in 0..=Self::MAX {
@@ -159,11 +159,11 @@ impl From<RecoveryId> for u8 {
#[cfg(feature = "verifying")]
impl<C> VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
AffinePoint<C>:
DecompressPoint<C> + FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>,
FieldSize<C>: sec1::ModulusSize,
Scalar<C>: Reduce<C::UInt>,
Scalar<C>: Reduce<C::Uint>,
SignatureSize<C>: ArrayLength<u8>,
{
/// Recover a [`VerifyingKey`] from the given message, signature, and
@@ -204,7 +204,7 @@ where
recovery_id: RecoveryId,
) -> Result<Self> {
let (r, s) = signature.split_scalars();
let z = <Scalar<C> as Reduce<C::UInt>>::from_be_bytes_reduced(bits2field::<C>(prehash)?);
let z = <Scalar<C> as Reduce<C::Uint>>::from_be_bytes_reduced(bits2field::<C>(prehash)?);
let R = AffinePoint::<C>::decompress(&r.to_repr(), u8::from(recovery_id.is_y_odd()).into());
if R.is_none().into() {
+69 -69
View File
@@ -11,7 +11,7 @@ use elliptic_curve::{
ops::{Invert, Reduce},
subtle::{Choice, ConstantTimeEq, CtOption},
zeroize::{Zeroize, ZeroizeOnDrop},
FieldBytes, FieldSize, NonZeroScalar, PrimeCurve, ProjectiveArithmetic, Scalar, SecretKey,
CurveArithmetic, FieldBytes, FieldSize, NonZeroScalar, PrimeCurve, Scalar, SecretKey,
};
use signature::{
digest::{core_api::BlockSizeUser, Digest, FixedOutput, FixedOutputReset},
@@ -41,13 +41,13 @@ use {crate::VerifyingKey, elliptic_curve::PublicKey, signature::KeypairRef};
/// ECDSA signing key. Generic over elliptic curves.
///
/// Requires an [`elliptic_curve::ProjectiveArithmetic`] impl on the curve, and a
/// Requires an [`elliptic_curve::CurveArithmetic`] impl on the curve, and a
/// [`SignPrimitive`] impl on its associated `Scalar` type.
#[derive(Clone)]
pub struct SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
/// ECDSA signing keys are non-zero elements of a given curve's scalar field.
@@ -60,8 +60,8 @@ where
impl<C> SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
/// Generate a cryptographically random [`SigningKey`].
@@ -105,10 +105,10 @@ where
impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C::UInt: for<'a> From<&'a Scalar<C>>,
C: PrimeCurve + CurveArithmetic,
C::Uint: for<'a> From<&'a Scalar<C>>,
D: Digest + BlockSizeUser + FixedOutput<OutputSize = FieldSize<C>> + FixedOutputReset,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
@@ -126,10 +126,10 @@ where
impl<C> PrehashSigner<Signature<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
C::Digest: FixedOutput<OutputSize = FieldSize<C>>,
C::UInt: for<'a> From<&'a Scalar<C>>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C::Uint: for<'a> From<&'a Scalar<C>>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn sign_prehash(&self, prehash: &[u8]) -> Result<Signature<C>> {
@@ -145,8 +145,8 @@ where
impl<C> Signer<Signature<C>> for SigningKey<C>
where
Self: DigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn try_sign(&self, msg: &[u8]) -> Result<Signature<C>> {
@@ -156,10 +156,10 @@ where
impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C::UInt: for<'a> From<&'a Scalar<C>>,
C: PrimeCurve + CurveArithmetic,
C::Uint: for<'a> From<&'a Scalar<C>>,
D: Digest + BlockSizeUser + FixedOutput<OutputSize = FieldSize<C>> + FixedOutputReset,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
/// Sign message prehash using an ephemeral scalar (`k`) derived according
@@ -182,8 +182,8 @@ where
impl<C> RandomizedSigner<Signature<C>> for SigningKey<C>
where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn try_sign_with_rng(&self, rng: &mut impl CryptoRngCore, msg: &[u8]) -> Result<Signature<C>> {
@@ -194,10 +194,10 @@ where
#[cfg(feature = "der")]
impl<C> PrehashSigner<der::Signature<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
C::Digest: FixedOutput<OutputSize = FieldSize<C>>,
C::UInt: for<'a> From<&'a Scalar<C>>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C::Uint: for<'a> From<&'a Scalar<C>>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
der::MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<der::MaxOverhead> + ArrayLength<u8>,
@@ -211,8 +211,8 @@ where
impl<C> Signer<der::Signature<C>> for SigningKey<C>
where
Self: DigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
der::MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<der::MaxOverhead> + ArrayLength<u8>,
@@ -225,10 +225,10 @@ where
#[cfg(feature = "der")]
impl<C, D> RandomizedDigestSigner<D, der::Signature<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C::UInt: for<'a> From<&'a Scalar<C>>,
C: PrimeCurve + CurveArithmetic,
C::Uint: for<'a> From<&'a Scalar<C>>,
D: Digest + BlockSizeUser + FixedOutput<OutputSize = FieldSize<C>> + FixedOutputReset,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
der::MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<der::MaxOverhead> + ArrayLength<u8>,
@@ -247,8 +247,8 @@ where
impl<C> RandomizedSigner<der::Signature<C>> for SigningKey<C>
where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
der::MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<der::MaxOverhead> + ArrayLength<u8>,
@@ -269,8 +269,8 @@ where
#[cfg(feature = "verifying")]
impl<C> AsRef<VerifyingKey<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn as_ref(&self) -> &VerifyingKey<C> {
@@ -280,8 +280,8 @@ where
impl<C> ConstantTimeEq for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn ct_eq(&self, other: &Self) -> Choice {
@@ -291,8 +291,8 @@ where
impl<C> Debug for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -302,8 +302,8 @@ where
impl<C> Drop for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn drop(&mut self) {
@@ -314,8 +314,8 @@ where
/// Constant-time comparison
impl<C> Eq for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
}
@@ -323,8 +323,8 @@ where
/// Constant-time comparison
impl<C> PartialEq for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn eq(&self, other: &SigningKey<C>) -> bool {
@@ -334,8 +334,8 @@ where
impl<C> From<NonZeroScalar<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn from(secret_scalar: NonZeroScalar<C>) -> Self {
@@ -352,8 +352,8 @@ where
impl<C> From<SecretKey<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn from(secret_key: SecretKey<C>) -> Self {
@@ -363,8 +363,8 @@ where
impl<C> From<&SecretKey<C>> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn from(secret_key: &SecretKey<C>) -> Self {
@@ -374,8 +374,8 @@ where
impl<C> From<SigningKey<C>> for SecretKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn from(key: SigningKey<C>) -> Self {
@@ -385,8 +385,8 @@ where
impl<C> From<&SigningKey<C>> for SecretKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn from(secret_key: &SigningKey<C>) -> Self {
@@ -396,8 +396,8 @@ where
impl<C> TryFrom<&[u8]> for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
type Error = Error;
@@ -409,8 +409,8 @@ where
impl<C> ZeroizeOnDrop for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
}
@@ -418,8 +418,8 @@ where
#[cfg(feature = "verifying")]
impl<C> From<SigningKey<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn from(signing_key: SigningKey<C>) -> VerifyingKey<C> {
@@ -430,8 +430,8 @@ where
#[cfg(feature = "verifying")]
impl<C> From<&SigningKey<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn from(signing_key: &SigningKey<C>) -> VerifyingKey<C> {
@@ -442,8 +442,8 @@ where
#[cfg(feature = "verifying")]
impl<C> KeypairRef for SigningKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
C: PrimeCurve + CurveArithmetic,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
type VerifyingKey = VerifyingKey<C>;
@@ -452,10 +452,10 @@ where
#[cfg(feature = "pkcs8")]
impl<C> TryFrom<pkcs8::PrivateKeyInfo<'_>> for SigningKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic,
C: PrimeCurve + AssociatedOid + CurveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
type Error = pkcs8::Error;
@@ -468,10 +468,10 @@ where
#[cfg(feature = "pem")]
impl<C> EncodePrivateKey for SigningKey<C>
where
C: AssociatedOid + PrimeCurve + ProjectiveArithmetic,
C: AssociatedOid + PrimeCurve + CurveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
fn to_pkcs8_der(&self) -> pkcs8::Result<SecretDocument> {
@@ -482,10 +482,10 @@ where
#[cfg(feature = "pem")]
impl<C> FromStr for SigningKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic,
C: PrimeCurve + AssociatedOid + CurveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
type Err = Error;
@@ -498,10 +498,10 @@ where
#[cfg(feature = "pkcs8")]
impl<C> DecodePrivateKey for SigningKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic,
C: PrimeCurve + AssociatedOid + CurveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::Uint> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
{
}
+34 -34
View File
@@ -9,7 +9,7 @@ use elliptic_curve::{
generic_array::ArrayLength,
ops::Reduce,
sec1::{self, EncodedPoint, FromEncodedPoint, ToEncodedPoint},
AffinePoint, FieldSize, PointCompression, PrimeCurve, ProjectiveArithmetic, PublicKey, Scalar,
AffinePoint, CurveArithmetic, FieldSize, PointCompression, PrimeCurve, PublicKey, Scalar,
};
use signature::{
digest::{Digest, FixedOutput},
@@ -34,7 +34,7 @@ use serdect::serde::{de, ser, Deserialize, Serialize};
/// ECDSA verification key (i.e. public key). Generic over elliptic curves.
///
/// Requires an [`elliptic_curve::ProjectiveArithmetic`] impl on the curve, and a
/// Requires an [`elliptic_curve::CurveArithmetic`] impl on the curve, and a
/// [`VerifyPrimitive`] impl on its associated `AffinePoint` type.
///
/// # `serde` support
@@ -48,14 +48,14 @@ use serdect::serde::{de, ser, Deserialize, Serialize};
#[derive(Clone, Debug)]
pub struct VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
{
pub(crate) inner: PublicKey<C>,
}
impl<C> VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
@@ -101,10 +101,10 @@ where
impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
D: Digest + FixedOutput<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
Scalar<C>: Reduce<C::Uint>,
SignatureSize<C>: ArrayLength<u8>,
{
fn verify_digest(&self, msg_digest: D, signature: &Signature<C>) -> Result<()> {
@@ -114,9 +114,9 @@ where
impl<C> PrehashVerifier<Signature<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
Scalar<C>: Reduce<C::Uint>,
SignatureSize<C>: ArrayLength<u8>,
{
fn verify_prehash(&self, prehash: &[u8], signature: &Signature<C>) -> Result<()> {
@@ -127,10 +127,10 @@ where
impl<C> Verifier<Signature<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
C::Digest: FixedOutput<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
Scalar<C>: Reduce<C::Uint>,
SignatureSize<C>: ArrayLength<u8>,
{
fn verify(&self, msg: &[u8], signature: &Signature<C>) -> Result<()> {
@@ -141,10 +141,10 @@ where
#[cfg(feature = "der")]
impl<C, D> DigestVerifier<D, der::Signature<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
D: Digest + FixedOutput<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
Scalar<C>: Reduce<C::Uint>,
SignatureSize<C>: ArrayLength<u8>,
der::MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<der::MaxOverhead> + ArrayLength<u8>,
@@ -158,9 +158,9 @@ where
#[cfg(feature = "der")]
impl<C> PrehashVerifier<der::Signature<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
Scalar<C>: Reduce<C::Uint>,
SignatureSize<C>: ArrayLength<u8>,
der::MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<der::MaxOverhead> + ArrayLength<u8>,
@@ -174,10 +174,10 @@ where
#[cfg(feature = "der")]
impl<C> Verifier<der::Signature<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
C::Digest: FixedOutput<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
Scalar<C>: Reduce<C::Uint>,
SignatureSize<C>: ArrayLength<u8>,
der::MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<der::MaxOverhead> + ArrayLength<u8>,
@@ -194,7 +194,7 @@ where
impl<C> AsRef<AffinePoint<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
@@ -203,11 +203,11 @@ where
}
}
impl<C> Copy for VerifyingKey<C> where C: PrimeCurve + ProjectiveArithmetic {}
impl<C> Copy for VerifyingKey<C> where C: PrimeCurve + CurveArithmetic {}
impl<C> From<&VerifyingKey<C>> for EncodedPoint<C>
where
C: PrimeCurve + ProjectiveArithmetic + PointCompression,
C: PrimeCurve + CurveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
@@ -216,11 +216,11 @@ where
}
}
impl<C> Eq for VerifyingKey<C> where C: PrimeCurve + ProjectiveArithmetic {}
impl<C> Eq for VerifyingKey<C> where C: PrimeCurve + CurveArithmetic {}
impl<C> PartialEq for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
{
fn eq(&self, other: &Self) -> bool {
self.inner.eq(&other.inner)
@@ -229,7 +229,7 @@ where
impl<C> From<PublicKey<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
{
fn from(public_key: PublicKey<C>) -> VerifyingKey<C> {
VerifyingKey { inner: public_key }
@@ -238,7 +238,7 @@ where
impl<C> From<&PublicKey<C>> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
{
fn from(public_key: &PublicKey<C>) -> VerifyingKey<C> {
(*public_key).into()
@@ -247,7 +247,7 @@ where
impl<C> From<VerifyingKey<C>> for PublicKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
{
fn from(verifying_key: VerifyingKey<C>) -> PublicKey<C> {
verifying_key.inner
@@ -256,7 +256,7 @@ where
impl<C> From<&VerifyingKey<C>> for PublicKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
{
fn from(verifying_key: &VerifyingKey<C>) -> PublicKey<C> {
(*verifying_key).into()
@@ -265,7 +265,7 @@ where
impl<C> PartialOrd for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
@@ -276,7 +276,7 @@ where
impl<C> Ord for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
@@ -287,7 +287,7 @@ where
impl<C> TryFrom<&[u8]> for VerifyingKey<C>
where
C: PrimeCurve + ProjectiveArithmetic,
C: PrimeCurve + CurveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
@@ -301,7 +301,7 @@ where
#[cfg(feature = "pkcs8")]
impl<C> TryFrom<pkcs8::SubjectPublicKeyInfo<'_>> for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
@@ -315,7 +315,7 @@ where
#[cfg(feature = "pkcs8")]
impl<C> DecodePublicKey for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
@@ -324,7 +324,7 @@ where
#[cfg(feature = "pem")]
impl<C> EncodePublicKey for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
@@ -336,7 +336,7 @@ where
#[cfg(feature = "pem")]
impl<C> FromStr for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
@@ -350,7 +350,7 @@ where
#[cfg(all(feature = "pem", feature = "serde"))]
impl<C> Serialize for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
@@ -365,7 +365,7 @@ where
#[cfg(all(feature = "pem", feature = "serde"))]
impl<'de, C> Deserialize<'de> for VerifyingKey<C>
where
C: PrimeCurve + AssociatedOid + ProjectiveArithmetic + PointCompression,
C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
FieldSize<C>: sec1::ModulusSize,
{
+2 -2
View File
@@ -12,10 +12,10 @@ readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["dsa", "ecdsa", "signature"]
edition = "2021"
rust-version = "1.60"
rust-version = "1.61"
[dependencies]
crypto-bigint = { version = "0.4", default-features = false, features = ["generic-array", "zeroize"] }
crypto-bigint = { version = "=0.5.0-pre.1", default-features = false, features = ["generic-array", "zeroize"] }
hmac = { version = "0.12", default-features = false, features = ["reset"] }
zeroize = { version = "1", default-features = false }
+2 -2
View File
@@ -17,7 +17,7 @@ Algorithm described in RFC 6979 § 3.2:
## Minimum Supported Rust Version
This crate requires **Rust 1.60** at a minimum.
This crate requires **Rust 1.61** at a minimum.
We may change the MSRV in the future, but it will be accompanied by a minor
version bump.
@@ -46,7 +46,7 @@ dual licensed as above, without any additional terms or conditions.
[build-image]: https://github.com/RustCrypto/signatures/actions/workflows/rfc6979.yml/badge.svg
[build-link]: https://github.com/RustCrypto/signatures/actions/workflows/rfc6979.yml
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.60+-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.61+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260048-signatures