is a Perl implementation of the Diffie-Hellman key
exchange system. Diffie-Hellman is an algorithm by which two
parties can agree on a shared secret key, known only to them.
The secret is negotiated over an insecure network without the
two parties ever passing the actual shared secret, or their
private keys, between them.
=head1 THE ALGORITHM
The algorithm generally works as follows: Party A and Party B
choose a property I and a property I; these properties are
shared by both parties. Each party then computes a random private
key integer I, where the length of I is at
most (number of bits in I

) - 1. Each party then computes a
public key based on I, I, and I

; the exact value
is
g ^ priv_key mod p
The parties exchange these public keys.
The shared secret key is generated based on the exchanged public
key, the private key, and I

. If the public key of Party B is
denoted I, then the shared secret is equal to
pub_key_B ^ priv_key mod p
The mathematical principles involved insure that both parties will
generate the same shared secret key.
More information can be found in PKCS #3 (Diffie-Hellman Key
Agreement Standard):
http://www.rsasecurity.com/rsalabs/pkcs/pkcs-3/
=head1 USAGE
I implements the core routines needed to use
Diffie-Hellman key exchange. To actually use the algorithm,
you'll need to start with values for I

and I; I

is a
large prime, and I is a base which must be larger than 0
and less than I

.
I uses I internally for big-integer
calculations. All accessor methods (I

, I, I, and
I) thus return I objects, as does the
I method. The accessors, however, allow setting with a
scalar decimal string, hex string (^0x), Math::BigInt object, or
Math::Pari object (for backwards compatibility).
=head2 $dh = Crypt::DH->new([ %param ]).
Constructs a new I object and returns the object.
I<%param> may include none, some, or all of the keys I

, I, and
I.
=head2 $dh->p([ $p ])
Given an argument I<$p>, sets the I

parameter (large prime) for
this I object.
Returns the current value of I

. (as a Math::BigInt object)
=head2 $dh->g([ $g ])
Given an argument I<$g>, sets the I parameter (base) for
this I object.
Returns the current value of I.
=head2 $dh->generate_keys
Generates the public and private key portions of the I
object, assuming that you've already filled I

and I with
appropriate values.
If you've provided a priv_key, it's used, otherwise a random priv_key
is created using either Crypt::Random (if already loaded), or
/dev/urandom, or Perl's rand, in that order.
=head2 $dh->compute_secret( $public_key )
Given the public key I<$public_key> of Party B (the party with which
you're performing key negotiation and exchange), computes the shared
secret key, based on that public key, your own private key, and your
own large prime value (I

).
The historical method name "compute_key" is aliased to this for
compatibility.
=head2 $dh->priv_key([ $priv_key ])
Returns the private key. Given an argument I<$priv_key>, sets the
I parameter for this I object.
=head2 $dh->pub_key
Returns the public key.
=head1 AUTHOR & COPYRIGHT
Benjamin Trott, ben@rhumba.pair.com
Brad Fitzpatrick, brad@danga.com
Except where otherwise noted, Crypt::DH is Copyright 2001
Benjamin Trott. All rights reserved. Crypt::DH is free
software; you may redistribute it and/or modify it under
the same terms as Perl itself.
=cut