Provided by: libcrypt-dh-perl_0.07-2_all

**NAME**

Crypt::DH - Diffie-Hellman key exchange system

**SYNOPSIS**

use Crypt::DH; my $dh = Crypt::DH->new; $dh->g($g); $dh->p($p); ## Generate public and private keys. $dh->generate_keys; $my_pub_key = $dh->pub_key; ## Send $my_pub_key to "other" party, and receive "other" ## public key in return. ## Now compute shared secret from "other" public key. my $shared_secret = $dh->compute_secret( $other_pub_key );

**DESCRIPTION**

Crypt::DHis 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.

**THE** **ALGORITHM**

The algorithm generally works as follows: Party A and Party B choose a propertypand a propertyg; these properties are shared by both parties. Each party then computes a random private key integerpriv_key, where the length ofpriv_keyis at most (number of bits inp) - 1. Each party then computes a public key based ong,priv_key, andp; 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, andp. If the public key of Party B is denotedpub_key_B, 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/

**USAGE**

Crypt::DHimplements the core routines needed to use Diffie-Hellman key exchange. To actually use the algorithm, you'll need to start with values forpandg;pis a large prime, andgis a base which must be larger than 0 and less thanp.Crypt::DHusesMath::BigIntinternally for big-integer calculations. All accessor methods (p,g,priv_key, andpub_key) thus returnMath::BigIntobjects, as does thecompute_secretmethod. The accessors, however, allow setting with a scalar decimal string, hex string (^0x), Math::BigInt object, or Math::Pari object (for backwards compatibility).$dh=Crypt::DH->new([%param]).Constructs a newCrypt::DHobject and returns the object.%parammay include none, some, or all of the keysp,g, andpriv_key.$dh->p([$p])Given an argument$p, sets thepparameter (large prime) for thisCrypt::DHobject. Returns the current value ofp. (as a Math::BigInt object)$dh->g([$g])Given an argument$g, sets thegparameter (base) for thisCrypt::DHobject. Returns the current value ofg.$dh->generate_keysGenerates the public and private key portions of theCrypt::DHobject, assuming that you've already filledpandgwith 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.$dh->compute_secret($public_key)Given the public key$public_keyof 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 (p). The historical method name "compute_key" is aliased to this for compatibility.$dh->priv_key([$priv_key])Returns the private key. Given an argument$priv_key, sets thepriv_keyparameter for thisCrypt::DHobject.$dh->pub_keyReturns the public key.

**AUTHOR**

Benjamin Trott (cpan:BTROTT) <ben+cpan@stupidfool.org> Brad Fitzpatrick (cpan:BRADFITZ) <brad@danga.com>

**CONTRIBUTORS**

BinGOs - Chris Williams (cpan:BINGOS) <chris@bingosnet.co.uk> Mithaldu - Christian Walde (cpan:MITHALDU) <walde.christian@googlemail.com>

**COPYRIGHT**

Copyright (c) 2012 the Crypt::DH "AUTHOR" and "CONTRIBUTORS" as listed above.

**LICENSE**

This library is free software and may be distributed under the same terms as perl itself.