# Is there any crates that support generate prime and pow method for bigint?

**URL:** <https://users.rust-lang.org/t/is-there-any-crates-that-support-generate-prime-and-pow-method-for-bigint/69089>\
**Category:** help\
**Created:** [December 20, 2021, 7:29pm UTC](https://users.rust-lang.org/t/is-there-any-crates-that-support-generate-prime-and-pow-method-for-bigint/69089 "2021-12-20T19:29:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HaidaLu](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/haidalu/32/23784_2.png) [@HaidaLu](https://users.rust-lang.org/u/HaidaLu)\
**Post date:** [December 20, 2021, 7:29pm UTC](https://users.rust-lang.org/t/is-there-any-crates-that-support-generate-prime-and-pow-method-for-bigint/69089/1 "2021-12-20T19:29:04Z")

</div>

Hello, I am new to Rust and want to use Rust to write some kind of a digital signature scheme.

Now first I want to generate a prime big int number like the crates provide [num-primes](https://docs.rs/num-primes/0.3.0/num_primes/)

```rust
pub struct Generator;
let prime = Generator::new_prime(512);

```

But seems like the BigUint type this crate provides only has modpow method, (a ^ b) mod c.  
My algorithm needs only pow method a ^ b,  
for example in golang, you can just set the last to nil.

```rust
e := new(big.Int).Exp(big.NewInt(2), big.NewInt(100), nil)

```

In rust, this crate [num-bigint](https://docs.rs/num-bigint/latest/num_bigint/) provides both pow and modpow method.

But seem like their biguint type are incompatible, is any way to handle this?? Or there is any other crates I can use?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![HaidaLu](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/haidalu/32/23784_2.png) [@HaidaLu](https://users.rust-lang.org/u/HaidaLu)\
**Post date:** [December 20, 2021, 7:38pm UTC](https://users.rust-lang.org/t/is-there-any-crates-that-support-generate-prime-and-pow-method-for-bigint/69089/2 "2021-12-20T19:38:20Z")

</div>

```rust
let c = Generator::new_prime(506); // use num-primes crate
        let d = c.clone().to_bytes_be();
        let f = BigUint::from_bytes_be(&d); // use num-bigint crate

```

maybe it will work? Not sure if there will cause any problem 🤣

---

<div class="post-metadata">

**Author:** ![quinedot](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/quinedot/32/17693_2.png) [@quinedot](https://users.rust-lang.org/u/quinedot)\
**Post date:** [December 20, 2021, 10:33pm UTC](https://users.rust-lang.org/t/is-there-any-crates-that-support-generate-prime-and-pow-method-for-bigint/69089/3 "2021-12-20T22:33:20Z")

</div>

It looks to just be a [re-export of `num_bigint::BigUint`,](https://github.com/AtropineTears/num-primes/blob/a5cc125f194a189288ff55c00452c3e447b1733e/src/lib.rs#L6-L12) so it should work (check crate versions I guess).

That said, given [this statement,](https://crates.io/crates/num-primes) you may want a different crate anyway.

> Please note there is a critical bug in this program that I cannot seem to fix where it marks some prime numbers as not prime. It is in the miller-rabin implementation and I cannot seem to fix it. If anyone is up to it, feel free to look through the issues tab for information about the bug and submit a PR if you find a fix.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [March 20, 2022, 10:34pm UTC](https://users.rust-lang.org/t/is-there-any-crates-that-support-generate-prime-and-pow-method-for-bigint/69089/4 "2022-03-20T22:34:12Z")

</div>

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
