diff --git a/Cargo.lock b/Cargo.lock index e7e53f7..aa16549 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -471,11 +471,13 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "risc0-bigint2" -version = "1.2.0-alpha.1" -source = "git+https://github.com/risc0/risc0?rev=8fc8437633f08a66e0fbacce947f41d01b074774#8fc8437633f08a66e0fbacce947f41d01b074774" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f4c185a3bfaee681eed5bfac1440128184bf0b6544c345fb4d7bd4317c909fb" dependencies = [ "include_bytes_aligned", "num-bigint-dig", + "stability", ] [[package]] @@ -646,6 +648,16 @@ dependencies = [ "der", ] +[[package]] +name = "stability" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d904e7009df136af5297832a3ace3370cd14ff1546a232f4f185036c2736fcac" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "subtle" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index 67ed6d2..d5794e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ sha2 = { version = "0.10.6", optional = true, default-features = false, features serde = { version = "1.0.184", optional = true, default-features = false, features = ["derive"] } [target.'cfg(target_os = "zkvm")'.dependencies] -risc0-bigint2 = { git = "https://github.com/risc0/risc0", rev = "8fc8437633f08a66e0fbacce947f41d01b074774", default-features = false, features = ["num-bigint-dig"] } +risc0-bigint2 = { version = "1.2.0", default-features = false, features = ["num-bigint-dig", "unstable"] } [dev-dependencies] base64ct = { version = "1", features = ["alloc"] } diff --git a/src/algorithms/rsa.rs b/src/algorithms/rsa.rs index e230522..a2c71d7 100644 --- a/src/algorithms/rsa.rs +++ b/src/algorithms/rsa.rs @@ -21,9 +21,14 @@ use crate::traits::{PrivateKeyParts, PublicKeyParts}; pub fn rsa_encrypt(key: &K, m: &BigUint) -> Result { #[cfg(target_os = "zkvm")] { + use risc0_bigint2::ToBigInt2Buffer; // If we're in the RISC Zero zkVM, try to use an accelerated version. if *key.e() == BigUint::new(vec![65537]) { - return Ok(risc0_bigint2::rsa::modpow_65537(m, key.n())); + let m = m.to_u32_array(); + let n = key.n().to_u32_array(); + let mut result = [0u32; 128]; + risc0_bigint2::rsa::modpow_65537(&m, &n, &mut result); + return Ok(BigUint::from_u32_array(result)); } // Fall through when the exponent does not match the accelerator }