Skip to content

Commit cb42fd2

Browse files
authored
Update bigint2 impl with 4096 bit support (#4)
* update acceleration to use latest version of bigint2 (with 4096 bit support) * bump version * bump to 1.2
1 parent fa372e9 commit cb42fd2

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Cargo.lock

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ sha2 = { version = "0.10.6", optional = true, default-features = false, features
3232
serde = { version = "1.0.184", optional = true, default-features = false, features = ["derive"] }
3333

3434
[target.'cfg(target_os = "zkvm")'.dependencies]
35-
risc0-bigint2 = { git = "https://github.com/risc0/risc0", rev = "8fc8437633f08a66e0fbacce947f41d01b074774", default-features = false, features = ["num-bigint-dig"] }
35+
risc0-bigint2 = { version = "1.2.0", default-features = false, features = ["num-bigint-dig", "unstable"] }
3636

3737
[dev-dependencies]
3838
base64ct = { version = "1", features = ["alloc"] }

src/algorithms/rsa.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ use crate::traits::{PrivateKeyParts, PublicKeyParts};
2121
pub fn rsa_encrypt<K: PublicKeyParts>(key: &K, m: &BigUint) -> Result<BigUint> {
2222
#[cfg(target_os = "zkvm")]
2323
{
24+
use risc0_bigint2::ToBigInt2Buffer;
2425
// If we're in the RISC Zero zkVM, try to use an accelerated version.
2526
if *key.e() == BigUint::new(vec![65537]) {
26-
return Ok(risc0_bigint2::rsa::modpow_65537(m, key.n()));
27+
let m = m.to_u32_array();
28+
let n = key.n().to_u32_array();
29+
let mut result = [0u32; 128];
30+
risc0_bigint2::rsa::modpow_65537(&m, &n, &mut result);
31+
return Ok(BigUint::from_u32_array(result));
2732
}
2833
// Fall through when the exponent does not match the accelerator
2934
}

0 commit comments

Comments
 (0)