Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primes generation and checking with num-bigint #31

Open
vimmerru opened this issue Mar 2, 2018 · 9 comments
Open

Primes generation and checking with num-bigint #31

vimmerru opened this issue Mar 2, 2018 · 9 comments
Labels

Comments

@vimmerru
Copy link

vimmerru commented Mar 2, 2018

Hi,

Is there any solution for generation of primes, safe primes and prime checking with num-bigint?

@cuviper
Copy link
Member

cuviper commented Mar 2, 2018

Nothing in the crate, and I'm not aware of anything published elsewhere. I do have a generic Miller-Rabin implementation that I use for Project Euler problems, but I'm not sure it's good enough to share. :)

@vimmerru
Copy link
Author

vimmerru commented Mar 2, 2018

Does it look fast enough for RSA-like crypto needs? For now i use OpenSSL, but consider switching to some rust-native solution to simplify cross-platforms builds and deployment.

@cuviper
Copy link
Member

cuviper commented Mar 2, 2018

I'm not confident enough to answer that... Tell you what, I'll see if I can clean that up as an example program, at least, and we can go from there.

@vimmerru
Copy link
Author

vimmerru commented Mar 2, 2018

If you interested in we can benchmark it over OpenSSL together. My BN wrapper over OpenSSL is placed here https://github.com/hyperledger/indy-crypto/blob/master/libindy-crypto/src/bn/openssl.rs

I am interesting in performance of calls:

 pub fn generate_prime(size: usize) -> Result<BigNumber, IndyCryptoError> {
        let mut bn = BigNumber::new()?;
        BigNumRef::generate_prime(&mut bn.openssl_bn, size as i32, false, None, None)?;
        Ok(bn)
    }

    pub fn generate_safe_prime(size: usize) -> Result<BigNumber, IndyCryptoError> {
        let mut bn = BigNumber::new()?;
        BigNumRef::generate_prime(&mut bn.openssl_bn, (size + 1) as i32, true, None, None)?;
        Ok(bn)
}

@cuviper
Copy link
Member

cuviper commented Mar 3, 2018

See #33 -- but I'll save you some suspense, it's definitely not as fast as OpenSSL. Make sure you at least run it with optimization though, e.g. cargo run --release --features rand --example primes.

@vimmerru
Copy link
Author

vimmerru commented Mar 5, 2018

Thanks for this work. I will check on my side this week.

@vks
Copy link
Contributor

vks commented Apr 10, 2018

If you are ok with using non-Rust code, you could try rug or rust-gmp.

@dignifiedquire
Copy link
Contributor

I have done some work on this, you can find more details about it here: #33 (comment)

@cmpute
Copy link

cmpute commented Jan 25, 2022

Although it's an old question, but I'm building a crate (num-prime) to support various algorithms for prime generation, primality checks and integer factorization with big integer implementation (right now num-bigint, in future maybe also support rug). Just list it here in case anyone is interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants