Skip to content

Commit

Permalink
Update bigint2 impl with 4096 bit support (#4)
Browse files Browse the repository at this point in the history
* update acceleration to use latest version of bigint2 (with 4096 bit support)

* bump version

* bump to 1.2
  • Loading branch information
austinabell authored Dec 10, 2024
1 parent fa372e9 commit cb42fd2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
16 changes: 14 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
7 changes: 6 additions & 1 deletion src/algorithms/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ use crate::traits::{PrivateKeyParts, PublicKeyParts};
pub fn rsa_encrypt<K: PublicKeyParts>(key: &K, m: &BigUint) -> Result<BigUint> {
#[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
}
Expand Down

0 comments on commit cb42fd2

Please sign in to comment.