Skip to content
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
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ sha1 = { version = "0.10.5", optional = true, default-features = false, features
sha2 = { version = "0.10.6", optional = true, default-features = false, features = ["oid"] }
serde = { version = "1.0.184", optional = true, default-features = false, features = ["derive"] }

[target.'cfg(all(target_os = "zkvm", target_arch = "riscv32"))'.dependencies]
risc0-circuit-bigint = { git = "https://github.com/risc0/risc0", default-features = false, features = [ "bigint-dig-shim" ] }
risc0-zkvm = { git = "https://github.com/risc0/risc0", default-features = false }

[dev-dependencies]
base64ct = { version = "1", features = ["alloc"] }
hex-literal = "0.4.1"
Expand Down Expand Up @@ -64,3 +68,8 @@ rustdoc-args = ["--cfg", "docsrs"]

[profile.dev]
opt-level = 2

# TODO: Point to a version tag once necessary features have stabilized
[patch.'https://github.com/risc0/risc0.git']
risc0-circuit-bigint = { git = "https://github.com/risc0/risc0", rev = "e0338f6ce66ac3eba780e045d25df94145a03399" }
risc0-zkvm = { git = "https://github.com/risc0/risc0", rev = "e0338f6ce66ac3eba780e045d25df94145a03399" }
9 changes: 9 additions & 0 deletions src/algorithms/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ use crate::traits::{PrivateKeyParts, PublicKeyParts};
/// or signature scheme. See the [module-level documentation][crate::hazmat] for more information.
#[inline]
pub fn rsa_encrypt<K: PublicKeyParts>(key: &K, m: &BigUint) -> Result<BigUint> {
#[cfg(all(target_os = "zkvm", target_arch = "riscv32"))]
{
// If we're in the RISC Zero zkVM, try to use its RSA accelerator circuit
if *key.e() == BigUint::new(vec![65537]) {
return Ok(risc0_circuit_bigint::rsa::modpow_65537(m, key.n())
.expect("Unexpected failure to run RSA accelerator"));
}
// Fall through when the exponent does not match the accelerator
}
Ok(m.modpow(key.e(), key.n()))
}

Expand Down
1 change: 1 addition & 0 deletions src/pkcs1v15/signature.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(unused_imports)]
Copy link
Member

Choose a reason for hiding this comment

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

Wondering why we need this?

Copy link
Author

Choose a reason for hiding this comment

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

My hypothesis was that upstream was only warning on unused_imports whereas the risc0 repo has it set to error. But I'm not very familiar with how Rust warning/error settings work so I'm not sure if this sort of cross-crate setting contamination can even happen.

pub use ::signature::{
hazmat::{PrehashSigner, PrehashVerifier},
DigestSigner, DigestVerifier, Error, Keypair, RandomizedDigestSigner, RandomizedSigner, Result,
Expand Down
1 change: 1 addition & 0 deletions src/pss/signature.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(unused_imports)]
pub use ::signature::{
hazmat::{PrehashSigner, PrehashVerifier},
DigestSigner, DigestVerifier, Error, Keypair, RandomizedDigestSigner, RandomizedSigner, Result,
Expand Down