primitive roots using libgmp

Haig Didizian haig@didizian.com
17 Dec 2002 22:03:37 -0500


Hi -

I'm trying to write a C library that implements Diffie-Hellman key
exchange, and I'm having trouble finding an efficient way to find a
primitive root of a large (256b) number. I had used OpenSSL for DH
before, but its manpage is a bit cryptic (har har) regarding the way
that it checks generators. From the "bugs" section of 
DH_generate_parameters(3): "If generator is not 2 or 5, dh->g=generator
is not a usable generator." I'm not really sure why. 

Anyway, is there a nice way to:
  a) check to see if an integer is a primitive root of large number
  b) implement it easily using libgmp?

Thanks very much for your time -

Haig