Skip to content
Open
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
26 changes: 23 additions & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions guest_libs/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ceno_keccak = { path = "../keccak" }
ceno_sha2 = { path = "../sha2" }
ceno_syscall.workspace = true
k256 = { git = "https://github.com/scroll-tech/elliptic-curves", branch = "ceno/k256-13.4", default-features = false, features = ["std", "ecdsa"] }
p256 = { git = "https://github.com/scroll-tech/elliptic-curves", branch = "ceno/k256-13.4", default-features = false, features = ["std", "ecdsa"] }
thiserror.workspace = true

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion guest_libs/crypto/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ macro_rules! ceno_crypto {
sig: &[u8; 64],
pk: &[u8; 64],
) -> bool {
$crate::secp256r1::secp256r1_verify_signature(msg, sig, pk)
$crate::secp256r1::secp256r1_verify_signature(msg, sig, pk).is_some()
}
}

Expand Down
27 changes: 25 additions & 2 deletions guest_libs/crypto/src/secp256r1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
use p256::{
EncodedPoint,
ecdsa::{Signature, VerifyingKey, signature::hazmat::PrehashVerifier},
};

/// secp256r1 (P-256) signature verification.
#[inline]
pub fn secp256r1_verify_signature(_msg: &[u8; 32], _sig: &[u8; 64], _pk: &[u8; 64]) -> bool {
unimplemented!()
pub fn secp256r1_verify_signature(msg: &[u8; 32], sig: &[u8; 64], pk: &[u8; 64]) -> Option<()> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[cfg(feature = "profiling")]
ceno_syscall::syscall_phantom_log_pc_cycle("secp256r1_verify_signature start");
// Can fail only if the input is not exact length.
let signature = Signature::from_slice(sig).ok()?;
// Decode the public key bytes (x,y coordinates) using EncodedPoint
let encoded_point = EncodedPoint::from_untagged_bytes(pk.into());
// Create VerifyingKey from the encoded point
let public_key = VerifyingKey::from_encoded_point(&encoded_point).ok()?;

#[cfg(feature = "profiling")]
{
let res = public_key.verify_prehash(msg, &signature).ok();
ceno_syscall::syscall_phantom_log_pc_cycle("secp256r1_verify_signature end");
res
}
#[cfg(not(feature = "profiling"))]
{
public_key.verify_prehash(msg, &signature).ok()
}
}