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

runtime-sdk: Bump k256 to 0.13.1 #1426

Merged
merged 2 commits into from
Aug 7, 2023
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
250 changes: 169 additions & 81 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contract-sdk/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cbor = { version = "0.5.1", package = "oasis-cbor" }
oasis-runtime-sdk = { path = "../../runtime-sdk" }

# Third party.
k256 = { version = "0.10.4", default-features = false, features = ["keccak256", "ecdsa"] }
k256 = "0.13.1"
thiserror = "1.0.30"
x25519-dalek = "1.1.0"
sha2 = "0.9.8"
Expand Down
15 changes: 7 additions & 8 deletions contract-sdk/crypto/src/ecdsa.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::convert::TryInto;

use k256::{
ecdsa::{recoverable, Signature},
elliptic_curve::{sec1::ToEncodedPoint, IsHigh},
ecdsa::{RecoveryId, Signature, VerifyingKey},
elliptic_curve::scalar::IsHigh,
};
use thiserror::Error;

Expand Down Expand Up @@ -41,17 +41,16 @@ pub fn recover(input: &[u8]) -> Result<[u8; 65], Error> {
s[0..].copy_from_slice(&input[64..96]);

let signature = Signature::from_scalars(r, s).map_err(|_| Error::MalformedSignature)?;
let signature = recoverable::Signature::new(
&signature,
recoverable::Id::new(v).map_err(|_| Error::MalformedSignature)?,
)
.map_err(|_| Error::MalformedSignature)?;
let recid = RecoveryId::from_byte(v).ok_or(Error::MalformedSignature)?;

if recid.is_x_reduced() {
return Err(Error::MalformedSignature);
}
if signature.s().is_high().into() {
return Err(Error::MalformedSignature);
}

match signature.recover_verify_key_from_digest_bytes(&msg.into()) {
match VerifyingKey::recover_from_prehash(&msg, &signature, recid) {
Ok(recovered_key) => {
let key = recovered_key.to_encoded_point(false);

Expand Down
Loading
Loading