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
1 change: 0 additions & 1 deletion Cargo.lock

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

11 changes: 7 additions & 4 deletions packages/ic-certificate-verification/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ homepage.workspace = true

[dependencies]
candid.workspace = true
nom.workspace = true
thiserror.workspace = true
leb128.workspace = true
cached.workspace = true
cached = { workspace = true, optional = true }
sha2.workspace = true
lazy_static.workspace = true
parking_lot.workspace = true
lazy_static = { workspace = true, optional = true }
parking_lot = { workspace = true, optional = true }

ic-certification = { workspace = true }
ic-cbor.workspace = true
Expand All @@ -41,3 +40,7 @@ rand.workspace = true
rand_chacha.workspace = true

ic-types.workspace = true

[features]
default = ["signature_cache"]
signature_cache = ["cached", "lazy_static", "parking_lot"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use self::signature_cache::{SignatureCache, SignatureCacheEntry};
use crate::CertificateVerificationError;
use ic_verify_bls_signature::verify_bls_signature;

#[cfg(feature = "cached")]
mod signature_cache;

#[cfg(test)]
Expand All @@ -10,11 +10,14 @@ mod reproducible_rng;
#[cfg(test)]
mod tests;

#[cfg(feature = "cached")]
pub fn verify_signature(
pk: &[u8],
sig: &[u8],
msg: &[u8],
) -> Result<(), CertificateVerificationError> {
use self::signature_cache::{SignatureCache, SignatureCacheEntry};

let entry = SignatureCacheEntry::new(pk, sig, msg);

if SignatureCache::global().contains(&entry) {
Expand All @@ -28,3 +31,12 @@ pub fn verify_signature(
SignatureCache::global().insert(&entry);
Ok(())
}

#[cfg(not(feature = "cached"))]
pub fn verify_signature(
pk: &[u8],
sig: &[u8],
msg: &[u8],
) -> Result<(), CertificateVerificationError> {
verify_bls_signature(sig, msg, pk).map_err(|_| CertificateVerificationError::SignatureVerificationFailed)
}
Loading