Skip to content

Commit

Permalink
Update libsecp256k1 requirement from 0.3.1 to 0.5.0 (#72)
Browse files Browse the repository at this point in the history
* Update libsecp256k1 requirement from 0.3.1 to 0.5.0

Updates the requirements on [libsecp256k1](https://github.com/paritytech/libsecp256k1) to permit the latest version.
- [Release notes](https://github.com/paritytech/libsecp256k1/releases)
- [Changelog](https://github.com/paritytech/libsecp256k1/blob/master/CHANGELOG.md)
- [Commits](https://github.com/paritytech/libsecp256k1/commits)

Signed-off-by: dependabot[bot] <support@github.com>

* Use 'parse_standard'.

* Fix compilation.

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tomasz Drwięga <tomusdrw@gmail.com>
  • Loading branch information
dependabot[bot] and tomusdrw authored May 19, 2021
1 parent cf115ae commit c58169f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ parity-crypto = { version = "0.8", optional = true }
serde = { version = "1.0", features = ["derive"]}

# Libraries for for pure-rust crypto
libsecp256k1 = { package="libsecp256k1", version = "0.3.1", optional = true }
libsecp256k1 = { package="libsecp256k1", version = "0.5.0", optional = true }
ethsign-crypto = { version = "0.2.1", path = "./ethsign-crypto", optional = true }

[dev-dependencies]
Expand Down
8 changes: 4 additions & 4 deletions src/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ mod secp256k1 {
Ok((rec_id.serialize(), sig.serialize()))
}

fn to_signature(r: &[u8; 32], s: &[u8; 32]) -> libsecp256k1::Signature {
fn to_signature(r: &[u8; 32], s: &[u8; 32]) -> Result<libsecp256k1::Signature, Error> {
let mut data = [0u8; 64];
data[0..32].copy_from_slice(r);
data[32..64].copy_from_slice(s);

libsecp256k1::Signature::parse(&data)
Ok(libsecp256k1::Signature::parse_standard(&data)?)
}

/// Recover the signer of the message.
pub fn recover(v: u8, r: &[u8; 32], s: &[u8; 32], message: &[u8]) -> Result<[u8; 65], Error> {
let rec_id = libsecp256k1::RecoveryId::parse(v)?;
let sig = to_signature(r, s);
let sig = to_signature(r, s)?;
let msg = libsecp256k1::Message::parse_slice(message)?;
let pubkey = libsecp256k1::recover(&msg, &sig, &rec_id)?;

Expand All @@ -126,7 +126,7 @@ mod secp256k1 {
/// Checks ECDSA validity of `signature(r, s)` for `message` with `public` key.
/// Returns `Ok(true)` on success.
pub fn verify(public: &[u8], _v: u8, r: &[u8; 32], s: &[u8; 32], message: &[u8]) -> Result<bool, Error> {
let sig = to_signature(r, s);
let sig = to_signature(r, s)?;
let msg = libsecp256k1::Message::parse_slice(message)?;

Ok(libsecp256k1::verify(&msg, &sig, &to_pubkey(public)?))
Expand Down

0 comments on commit c58169f

Please sign in to comment.