Skip to content

Commit

Permalink
Merge branch 'RustCrypto:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
makavity authored Jul 10, 2024
2 parents 1d0bc55 + e6ea0bd commit e5fb1ff
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 37 deletions.
16 changes: 7 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bign256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ general purpose curve arithmetic
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/bign256"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/bign256"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/bign256"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "stb", "bign-curve256v1", "bignp256"]
Expand Down
3 changes: 2 additions & 1 deletion bp256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ description = "Brainpool P-256 (brainpoolP256r1 and brainpoolP256t1) elliptic cu
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/bp256"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/bp256"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/bp256"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["brainpool", "crypto", "ecc"]
Expand Down
3 changes: 2 additions & 1 deletion bp384/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ description = "Brainpool P-384 (brainpoolP384r1 and brainpoolP384t1) elliptic cu
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/bp384"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/bp384"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/bp384"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["brainpool", "crypto", "ecc"]
Expand Down
7 changes: 4 additions & 3 deletions k256/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "k256"
version = "0.14.0-pre"
version = "0.14.0-pre.0"
description = """
secp256k1 elliptic curve library written in pure Rust with support for ECDSA
signing/verification/public-key recovery, Taproot Schnorr signatures (BIP340),
Expand All @@ -10,7 +10,8 @@ curve group operations which can be used to implement arbitrary protocols
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/k256"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/k256"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/k256"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "cryptography::cryptocurrencies", "no-std"]
keywords = ["bitcoin", "crypto", "ecc", "ethereum", "secp256k1"]
Expand All @@ -36,7 +37,7 @@ ecdsa-core = { version = "=0.17.0-pre.5", package = "ecdsa", default-features =
hex-literal = "0.4"
num-bigint = "0.4"
num-traits = "0.2"
proptest = "1.4"
proptest = "1.5"
rand_core = { version = "0.6", features = ["getrandom"] }
sha3 = { version = "=0.11.0-pre.3", default-features = false }

Expand Down
60 changes: 48 additions & 12 deletions k256/src/schnorr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ impl Signature {
fn split(&self) -> (&FieldElement, &NonZeroScalar) {
(self.r(), self.s())
}

/// Parse a Secp256k1 signature from a byte array.
pub fn from_bytes(bytes: &SignatureBytes) -> Result<Self> {
let (r_bytes, s_bytes) = bytes.split_at(Self::BYTE_SIZE / 2);

let r: FieldElement =
Option::from(FieldElement::from_bytes(FieldBytes::from_slice(r_bytes)))
.ok_or_else(Error::new)?;

// one of the rules for valid signatures: !is_infinite(R);
if r.is_zero().into() {
return Err(Error::new());
}

let s = NonZeroScalar::try_from(s_bytes).map_err(|_| Error::new())?;

Ok(Self { r, s })
}

/// Parse a Secp256k1 signature from a byte slice.
pub fn from_slice(bytes: &[u8]) -> Result<Self> {
SignatureBytes::try_from(bytes)
.map_err(|_| Error::new())?
.try_into()
}
}

impl Eq for Signature {}
Expand All @@ -139,24 +164,27 @@ impl PartialEq for Signature {
}
}

impl TryFrom<&[u8]> for Signature {
impl TryFrom<SignatureBytes> for Signature {
type Error = Error;

fn try_from(bytes: &[u8]) -> Result<Signature> {
let (r_bytes, s_bytes) = bytes.split_at(Self::BYTE_SIZE / 2);
fn try_from(signature: SignatureBytes) -> Result<Signature> {
Signature::from_bytes(&signature)
}
}

let r: FieldElement =
Option::from(FieldElement::from_bytes(FieldBytes::from_slice(r_bytes)))
.ok_or_else(Error::new)?;
impl TryFrom<&SignatureBytes> for Signature {
type Error = Error;

// one of the rules for valid signatures: !is_infinite(R);
if r.is_zero().into() {
return Err(Error::new());
}
fn try_from(signature: &SignatureBytes) -> Result<Signature> {
Signature::from_bytes(signature)
}
}

let s = NonZeroScalar::try_from(s_bytes).map_err(|_| Error::new())?;
impl TryFrom<&[u8]> for Signature {
type Error = Error;

Ok(Self { r, s })
fn try_from(bytes: &[u8]) -> Result<Signature> {
Signature::from_slice(bytes)
}
}

Expand Down Expand Up @@ -509,4 +537,12 @@ mod tests {
);
}
}

#[test]
fn try_from() {
// Pass an invalid signature (shorter than Self::BYTES / 2) and make sure
// it does not panic, but return Err
let invalid_signature = [111; 24];
assert_eq!(Signature::try_from(&invalid_signature[..]).is_err(), true);
}
}
3 changes: 2 additions & 1 deletion p192/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ as defined in SP 800-186
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/p192"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/p192"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/p192"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "nist", "secp192r1"]
Expand Down
3 changes: 2 additions & 1 deletion p224/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ as defined in SP 800-186
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/p224"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/p224"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/p224"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "nist", "secp224r1"]
Expand Down
3 changes: 2 additions & 1 deletion p256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ signing/verification, and general purpose curve arithmetic
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/p256"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/p256"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/p256"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "nist", "prime256v1", "secp256r1"]
Expand Down
5 changes: 3 additions & 2 deletions p384/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and general purpose curve arithmetic support.
authors = ["RustCrypto Developers", "Frank Denis <[email protected]>"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/p384"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/p384"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/p384"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "nist", "secp384r1"]
Expand All @@ -32,7 +33,7 @@ criterion = "0.5"
ecdsa-core = { version = "=0.17.0-pre.5", package = "ecdsa", default-features = false, features = ["dev"] }
hex-literal = "0.4"
primeorder = { version = "=0.14.0-pre.0", features = ["dev"], path = "../primeorder" }
proptest = "1.4"
proptest = "1.5"
rand_core = { version = "0.6", features = ["getrandom"] }

[features]
Expand Down
5 changes: 3 additions & 2 deletions p521/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ as defined in SP 800-186
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/p521"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/p521"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/p521"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "nist", "secp521r1"]
Expand All @@ -33,7 +34,7 @@ blobby = "0.3"
ecdsa-core = { version = "=0.17.0-pre.5", package = "ecdsa", default-features = false, features = ["dev"] }
hex-literal = "0.4"
primeorder = { version = "=0.14.0-pre.0", features = ["dev"], path = "../primeorder" }
proptest = "1.4"
proptest = "1.5"
rand_core = { version = "0.6", features = ["getrandom"] }
criterion = "0.5.1"

Expand Down
3 changes: 2 additions & 1 deletion primefield/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ description = "Macros for generating prime field implementations"
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/primeorder"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/primefield"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/primefield"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "field", "prime"]
Expand Down
3 changes: 2 additions & 1 deletion primeorder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ equation coefficients
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/primeorder"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/primeorder"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/primeorder"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc"]
Expand Down
3 changes: 2 additions & 1 deletion sm2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ the SM2DSA Digital Signature Algorithm.
authors = ["RustCrypto Developers"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/sm2"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/sm2"
homepage = "https://github.com/RustCrypto/elliptic-curves/tree/master/sm2"
repository = "https://github.com/RustCrypto/elliptic-curves"
readme = "README.md"
categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "shangmi", "signature"]
Expand Down

0 comments on commit e5fb1ff

Please sign in to comment.