views:

67

answers:

1

I'm writing an implementation of a diffie-hellman key exchange in ruby for a project for one of my university classes. I need to generate large (secure) prime numbers of at least 500 bits length. Any ideas? Should I use the OpenSSL library? If so, what functions would you recommend?

+2  A: 

Use the openssl gem

OpenSSL::BN::rand

You can specify the size you need - like so OpenSSL::BN::rand(212)

abdollar
Awesome, thanks! Where can I find the documentation on this? I've checked ruby-doc.org but all I can find is stuff on OpenSSL::HMAC and a few others.
Jarsen
Also, is there a function that makes sure it's prime?
Jarsen
Also try OpenSSL::BN::generate_prime(500)
abdollar
in terms of documention look at openssl documentation rather than the gem
abdollar
I cannot see BN_is_prime in the ruby openssl gem. You could file a bug to add that or add that to the gem yourself.
abdollar