Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: bingos/aaaa-crypt-dh
base: master
...
head fork: wchristian/crypt-dh
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 10 commits
  • 14 files changed
  • 0 commit comments
  • 1 contributor
View
8 .gitignore
@@ -0,0 +1,8 @@
+inc
+MYMETA*
+Makefile
+MANIFEST.bak
+Crypt-DH-*
+blib
+pm_to_blib
+Makefile.old
View
41 Changes
@@ -1,10 +1,35 @@
-Changelog for AAAA::Crypt::DH
-=============================
+Revision history for Crypt::DH
-0.04 Tue Oct 5 10:23:57 BST 2010
- - version bump to include latest
- Devel::CheckLib which should
- detect libraries betterer.
+0.07 2012.06.06
+ - Made Math::BigInt::* dependency dynamic to avoid Math::BigInt falling
+ back to BigInt backends that are too slow for practical use.
-0.02 Mon Jan 18 16:11:34 GMT 2010
- - Initial CPAN release
+0.06 2005.06.10
+ - Fixed compute_key/compute_secret to accept a Math::Pari object, so that
+ it's backwards-compatible with e.g. Net::SSH::Perl.
+ - Added _any2bigint and tests for same.
+
+0.05 2005.06.06 (bradfitz)
+ - use makerandom_itv w/ proper range for priv_key (thanks to Paul
+ Crowley!)
+ - make _makerandom_itv wrapper around _makerandom to behave similarly
+ when Crypt::Random is not available
+
+0.04 2005.06.06 (bradfitz)
+ - Ported to Math::BigInt (which can use PARI,GMP,etc)
+ - Don't depend on Crypt::Random, just use it if already loaded
+ - renamed compute_key to compute_secret (kept old name)
+ - updated POD docs
+ - made test.pl sane and test everything realistically; moved into t/
+ - Updated Makefile.PL to use Module::Install
+
+0.03 2002.01.20
+ - Added patch from Kurt D. Starsinic to enable setting the
+ private key, rather than always having it generated.
+ - Removed unnecessary mp2bin function.
+
+0.02 2001.04.24
+ - Fixed broken test program (still need more tests).
+
+0.01 2001.03.22
+ - original version; created by h2xs 1.19
View
48 MANIFEST
@@ -1,23 +1,25 @@
-Changes
-inc/Devel/CheckLib.pm
-inc/Module/Install.pm
-inc/Module/Install/AutoLicense.pm
-inc/Module/Install/Base.pm
-inc/Module/Install/Can.pm
-inc/Module/Install/CheckLib.pm
-inc/Module/Install/Fetch.pm
-inc/Module/Install/GithubMeta.pm
-inc/Module/Install/Makefile.pm
-inc/Module/Install/Metadata.pm
-inc/Module/Install/ReadmeFromPod.pm
-inc/Module/Install/Win32.pm
-inc/Module/Install/WriteAll.pm
-lib/AAAA/Crypt/DH.pm
-LICENSE
-Makefile.PL
-MANIFEST This list of files
-META.yml
-README
-t/00_compile.t
-t/99_pod.t
-t/99_pod_coverage.t
+Changes
+inc/Devel/CheckLib.pm
+inc/Module/AutoInstall.pm
+inc/Module/Install.pm
+inc/Module/Install/AutoInstall.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/CheckLib.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/GithubMeta.pm
+inc/Module/Install/Include.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/ReadmeFromPod.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
+inc/Test/More.pm
+lib/Crypt/DH.pm
+Makefile.PL
+MANIFEST This list of files
+META.yml
+README
+t/00-compile.t
+t/01-dh.t
+ToDo
View
34 META.yml
@@ -0,0 +1,34 @@
+---
+abstract: 'Diffie-Hellman key exchange system'
+author:
+ - 'Benjamin Trott (cpan:BTROTT) <ben+cpan@stupidfool.org>'
+ - 'BinGOs - Chris Williams (cpan:BINGOS) <chris@bingosnet.co.uk>'
+ - 'Mithaldu - Christian Walde (cpan:MITHALDU) <walde.christian@googlemail.com>'
+build_requires:
+ ExtUtils::MakeMaker: 6.59
+configure_requires:
+ ExtUtils::MakeMaker: 6.59
+distribution_type: module
+dynamic_config: 1
+generated_by: 'Module::Install version 1.06'
+license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
+name: Crypt-DH
+no_index:
+ directory:
+ - inc
+ - t
+requires:
+ Math::BigInt: 1.60
+ Math::BigInt::GMP: 1.24
+ perl: 5.6.0
+resources:
+ homepage: https://github.com/wchristian/crypt-dh/tree
+ license: http://dev.perl.org/licenses/
+ repository:
+ type: git
+ url: git://github.com/wchristian/crypt-dh.git
+ web: https://github.com/wchristian/crypt-dh/tree
+version: 0.07
View
28 Makefile.PL
@@ -1,11 +1,18 @@
use strict;
use inc::Module::Install;
-name 'AAAA-Crypt-DH';
-author 'Chris Williams';
-version_from 'lib/AAAA/Crypt/DH.pm';
-abstract_from 'lib/AAAA/Crypt/DH.pm';
-readme_from 'lib/AAAA/Crypt/DH.pm';
+
+name 'Crypt-DH';
+abstract 'Diffie-Hellman key exchange system';
+author 'Benjamin Trott (cpan:BTROTT) <ben+cpan@stupidfool.org>';
+author 'BinGOs - Chris Williams (cpan:BINGOS) <chris@bingosnet.co.uk>';
+author 'Mithaldu - Christian Walde (cpan:MITHALDU) <walde.christian@googlemail.com>';
+version_from 'lib/Crypt/DH.pm';
+readme_from 'lib/Crypt/DH.pm';
license 'perl';
+no_index directory => 't';
+
+include 'ExtUtils::AutoInstall';
+
perl_version '5.006';
build_requires 'Test::More' => 0.47;
eval { assertlibs lib => 'gmp', header => 'gmp.h'; };
@@ -15,7 +22,12 @@ unless ($@) {
else {
requires 'Math::BigInt::Pari' => 1.13;
}
-auto_license;
+
+requires('Math::BigInt' => '1.60');
+
githubmeta;
-auto_provides;
-WriteAll();
+auto_include;
+auto_install;
+
+WriteAll;
+
View
167 README
@@ -1,42 +1,125 @@
-NAME
- AAAA::Crypt::DH - making Crypt::DH installable
-
-SYNOPSIS
- # in Makefile.PL
-
- requires 'AAAA::Crypt::DH';
-
-DESCRIPTION
- AAAA::Crypt::DH is a Task distribution that makes sure that either
- Math::BigInt::GMP or Math::BigInt::Pari are installed so that Crypt::DH
- works at a speed approaching reasonable.
-
- If you have a dependency on Crypt::DH add AAAA::Crypt::DH as an
- additional dependency and one of the above Math libs will be installed
- before Crypt::DH.
-
- Why the 'AAAA'? Well, CPAN and CPANPLUS install prereqs sorted
- alphabetically, the 'AAAA' ensures that this prereq is installed before
- Crypt::DH. Simples.
-
-AUTHOR
- Chris "BinGOs" Williams
-
-LICENSE
- Copyright � Chris Williams
-
- This module may be used, modified, and distributed under the same terms
- as Perl itself. Please see the license that came with your Perl
- distribution for details.
-
-SEE ALSO
- Crypt::DH::GMP
-
- Math::BigInt::GMP
-
- Math::BigInt::Pari
-
- <http://rt.cpan.org/Public/Dist/Display.html?Name=Crypt-DH>
-
- <http://cpanratings.perl.org/dist/Crypt-DH>
-
+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::DH* 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.
+
+THE ALGORITHM
+ The algorithm generally works as follows: Party A and Party B choose a
+ property *p* and a property *g*; these properties are shared by both
+ parties. Each party then computes a random private key integer
+ *priv_key*, where the length of *priv_key* is at most (number of bits in
+ *p*) - 1. Each party then computes a public key based on *g*,
+ *priv_key*, and *p*; 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 *p*. If the public key of Party B is denoted
+ *pub_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::DH* implements the core routines needed to use Diffie-Hellman
+ key exchange. To actually use the algorithm, you'll need to start with
+ values for *p* and *g*; *p* is a large prime, and *g* is a base which
+ must be larger than 0 and less than *p*.
+
+ *Crypt::DH* uses *Math::BigInt* internally for big-integer calculations.
+ All accessor methods (*p*, *g*, *priv_key*, and *pub_key*) thus return
+ *Math::BigInt* objects, as does the *compute_secret* method. 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 new *Crypt::DH* object and returns the object. *%param* may
+ include none, some, or all of the keys *p*, *g*, and *priv_key*.
+
+ $dh->p([ $p ])
+ Given an argument *$p*, sets the *p* parameter (large prime) for this
+ *Crypt::DH* object.
+
+ Returns the current value of *p*. (as a Math::BigInt object)
+
+ $dh->g([ $g ])
+ Given an argument *$g*, sets the *g* parameter (base) for this
+ *Crypt::DH* object.
+
+ Returns the current value of *g*.
+
+ $dh->generate_keys
+ Generates the public and private key portions of the *Crypt::DH* object,
+ assuming that you've already filled *p* and *g* 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.
+
+ $dh->compute_secret( $public_key )
+ Given the public key *$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 (*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 the
+ *priv_key* parameter for this *Crypt::DH* object.
+
+ $dh->pub_key
+ Returns 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.
+
View
3  ToDo
@@ -0,0 +1,3 @@
+Better test suite.
+
+Use Convert::PEM to read/write DH parameter files.
View
59 lib/AAAA/Crypt/DH.pm
@@ -1,59 +0,0 @@
-package AAAA::Crypt::DH;
-
-use strict;
-use warnings;
-use vars qw($VERSION);
-
-$VERSION = '0.04';
-
-qq[Making Crypt::DH installable];
-
-__END__
-
-=head1 NAME
-
-AAAA::Crypt::DH - making Crypt::DH installable
-
-=head1 SYNOPSIS
-
- # in Makefile.PL
-
- requires 'AAAA::Crypt::DH';
-
-=head1 DESCRIPTION
-
-AAAA::Crypt::DH is a L<Task> distribution that makes sure that either
-L<Math::BigInt::GMP> or L<Math::BigInt::Pari> are installed so that
-L<Crypt::DH> works at a speed approaching reasonable.
-
-If you have a dependency on L<Crypt::DH> add AAAA::Crypt::DH as an
-additional dependency and one of the above Math libs will be installed
-before L<Crypt::DH>.
-
-Why the C<'AAAA'>? Well, L<CPAN> and L<CPANPLUS> install prereqs sorted
-alphabetically, the C<'AAAA'> ensures that this prereq is installed before
-L<Crypt::DH>. Simples.
-
-=head1 AUTHOR
-
-Chris C<BinGOs> Williams
-
-=head1 LICENSE
-
-Copyright E<copy> Chris Williams
-
-This module may be used, modified, and distributed under the same terms as Perl itself. Please see the license that came with your Perl distribution for details.
-
-=head1 SEE ALSO
-
-L<Crypt::DH::GMP>
-
-L<Math::BigInt::GMP>
-
-L<Math::BigInt::Pari>
-
-L<http://rt.cpan.org/Public/Dist/Display.html?Name=Crypt-DH>
-
-L<http://cpanratings.perl.org/dist/Crypt-DH>
-
-=cut
View
259 lib/Crypt/DH.pm
@@ -0,0 +1,259 @@
+package Crypt::DH;
+use strict;
+
+use Math::BigInt lib => "GMP,Pari";
+our $VERSION = '0.07';
+
+sub new {
+ my $class = shift;
+ my $dh = bless {}, $class;
+
+ my %param = @_;
+ for my $w (qw( p g priv_key )) {
+ next unless exists $param{$w};
+ $dh->$w(delete $param{$w});
+ }
+ die "Unknown parameters to constructor: " . join(", ", keys %param) if %param;
+
+ $dh;
+}
+
+BEGIN {
+ no strict 'refs';
+ for my $meth (qw( p g pub_key priv_key )) {
+ *$meth = sub {
+ my $key = shift;
+ if (@_) {
+ $key->{$meth} = _any2bigint(shift);
+ }
+ my $ret = $key->{$meth} || "";
+ $ret;
+ };
+ }
+}
+
+sub _any2bigint {
+ my($value) = @_;
+ if (ref $value eq 'Math::BigInt') {
+ return $value;
+ }
+ elsif (ref $value eq 'Math::Pari') {
+ return Math::BigInt->new(Math::Pari::pari2pv($value));
+ }
+ elsif (defined $value && !(ref $value)) {
+ return Math::BigInt->new($value);
+ }
+ elsif (defined $value) {
+ die "Unknown parameter type: $value\n";
+ }
+}
+
+sub generate_keys {
+ my $dh = shift;
+
+ unless (defined $dh->{priv_key}) {
+ my $i = _bitsize($dh->{p}) - 1;
+ $dh->{priv_key} =
+ $Crypt::Random::VERSION ?
+ Crypt::Random::makerandom_itv(Strength => 0, Uniform => 1,
+ Lower => 1, Upper => $dh->{p} - 1) :
+ _makerandom_itv($i, 1, $dh->{p} - 1);
+ }
+
+ $dh->{pub_key} = $dh->{g}->copy->bmodpow($dh->{priv_key}, $dh->{p});
+}
+
+sub compute_key {
+ my $dh = shift;
+ my $pub_key = _any2bigint(shift);
+ $pub_key->copy->bmodpow($dh->{priv_key}, $dh->{p});
+}
+*compute_secret = \&compute_key;
+
+sub _bitsize {
+ return length($_[0]->as_bin) - 2;
+}
+
+sub _makerandom_itv {
+ my ($size, $min_inc, $max_exc) = @_;
+
+ while (1) {
+ my $r = _makerandom($size);
+ return $r if $r >= $min_inc && $r < $max_exc;
+ }
+}
+
+sub _makerandom {
+ my $size = shift;
+
+ my $bytes = int($size / 8) + ($size % 8 ? 1 : 0);
+
+ my $rand;
+ if (-e "/dev/urandom") {
+ my $fh;
+ open($fh, '/dev/urandom')
+ or die "Couldn't open /dev/urandom";
+ my $got = sysread $fh, $rand, $bytes;
+ die "Didn't read all bytes from urandom" unless $got == $bytes;
+ close $fh;
+ } else {
+ for (1..$bytes) {
+ $rand .= chr(int(rand(256)));
+ }
+ }
+
+ my $bits = unpack("b*", $rand);
+ die unless length($bits) >= $size;
+
+ Math::BigInt->new('0b' . substr($bits, 0, $size));
+}
+
+1;
+__END__
+
+=head1 NAME
+
+Crypt::DH - Diffie-Hellman key exchange system
+
+=head1 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 );
+
+=head1 DESCRIPTION
+
+I<Crypt::DH> 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<p> and a property I<g>; these properties are
+shared by both parties. Each party then computes a random private
+key integer I<priv_key>, where the length of I<priv_key> is at
+most (number of bits in I<p>) - 1. Each party then computes a
+public key based on I<g>, I<priv_key>, and I<p>; 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<p>. If the public key of Party B is
+denoted I<pub_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/
+
+=head1 USAGE
+
+I<Crypt::DH> 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<p> and I<g>; I<p> is a
+large prime, and I<g> is a base which must be larger than 0
+and less than I<p>.
+
+I<Crypt::DH> uses I<Math::BigInt> internally for big-integer
+calculations. All accessor methods (I<p>, I<g>, I<priv_key>, and
+I<pub_key>) thus return I<Math::BigInt> objects, as does the
+I<compute_secret> 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<Crypt::DH> object and returns the object.
+I<%param> may include none, some, or all of the keys I<p>, I<g>, and
+I<priv_key>.
+
+=head2 $dh->p([ $p ])
+
+Given an argument I<$p>, sets the I<p> parameter (large prime) for
+this I<Crypt::DH> object.
+
+Returns the current value of I<p>. (as a Math::BigInt object)
+
+=head2 $dh->g([ $g ])
+
+Given an argument I<$g>, sets the I<g> parameter (base) for
+this I<Crypt::DH> object.
+
+Returns the current value of I<g>.
+
+=head2 $dh->generate_keys
+
+Generates the public and private key portions of the I<Crypt::DH>
+object, assuming that you've already filled I<p> and I<g> 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<p>).
+
+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<priv_key> parameter for this I<Crypt::DH> object.
+
+=head2 $dh->pub_key
+
+Returns the public key.
+
+=head1 AUTHOR
+
+Benjamin Trott (cpan:BTROTT) <ben+cpan@stupidfool.org>
+
+Brad Fitzpatrick (cpan:BRADFITZ) <brad@danga.com>
+
+=head1 CONTRIBUTORS
+
+BinGOs - Chris Williams (cpan:BINGOS) <chris@bingosnet.co.uk>
+
+Mithaldu - Christian Walde (cpan:MITHALDU) <walde.christian@googlemail.com>
+
+=head1 COPYRIGHT
+
+Copyright (c) 2012 the Crypt::DH L</AUTHOR> and L</CONTRIBUTORS> as listed
+above.
+
+=head1 LICENSE
+
+This library is free software and may be distributed under the same terms
+as perl itself.
+
+=cut
View
6 t/00-compile.t
@@ -0,0 +1,6 @@
+# $Id: 00-compile.t 1852 2005-06-07 00:43:04Z btrott $
+
+use strict;
+use Test::More tests => 1;
+
+use_ok('Crypt::DH');
View
2  t/00_compile.t
@@ -1,2 +0,0 @@
-use Test::More 'no_plan';
-use_ok('AAAA::Crypt::DH');
View
60 t/01-dh.t
@@ -0,0 +1,60 @@
+# $Id: 01-dh.t 1860 2005-06-11 06:15:44Z btrott $
+
+use strict;
+
+use Test::More;
+use Crypt::DH;
+
+my $has_pari;
+BEGIN {
+ $has_pari = eval { require Math::Pari; 1 };
+}
+Test::More->import( tests => 18 + ($has_pari ? 3 : 0));
+
+my @pgs = (
+ {
+ p => "0xdcf93a0b883972ec0e19989ac5a2ce310e1d37717e8d9571bb7623731866e61ef75a2e27898b057f9891c2e27a639c3f29b60814581cd3b2ca3986d2683705577d45c2e7e52dc81c7a171876e5cea74b1448bfdfaf18828efd2519f14e45e3826634af1949e5b535cc829a483b8a76223e5d490a257f05bdff16f2fb22f5615b",
+ g => "2",
+ },
+ {
+ p => "0xdcf93a0b883972ec0e19989ac5a2ce310e1d37717e8d9571bb7623731866e61ef75a2e27898b057f9891c2e27a639c3f29b60814581cd3b2ca3986d2683705577d45c2e7e52dc81c7a171876e5cea74b1448bfdfaf18828efd2519f14e45e3826634af1949e5b535cc829a483b8a76223e5d490a257f05bdff16f2fb230138c3",
+ g => "2",
+ },
+ {
+ p => "0xdcf93a0b883972ec0e19989ac5a2ce310e1d37717e8d9571bb7623731866e61ef75a2e27898b057f9891c2e27a639c3f29b60814581cd3b2ca3986d2683705577d45c2e7e52dc81c7a171876e5cea74b1448bfdfaf18828efd2519f14e45e3826634af1949e5b535cc829a483b8a76223e5d490a257f05bdff16f2fb22f2d1b7",
+ g => "5",
+ },
+ {
+ p => "0xce96240b0b5684d9e281fda07d5b6c316e14c7ae83913f86d13cad2546f93b533d15629d4b3e2c76753c5abcc29a8fb610ca1c3eb1014b0fd8209c330fff6eb8a562474b7d387e3f8074fa29d0b58bad5e6967a0ad667c41d41e1241669431f865c57e9eeb00e69beb1d18c3b940810324b394fab8f75b27a9b4e7972f07b4916a6a3d50f0445024697155382bf1ad14f90f8bab7e9d3ccbae6cd84e488a98770a8c64943582c6d2bb529511945aba146115273eb6bd718b62febfcd503fb56e8d4262e17dc5ce1a9b1d3e8ffa5ce0b825498bc6254da9cc69ddf7ad9ba582ab8f812c4de3228c88c5640baef5f62b7c039588d6cd7f694f039507aa3aaf4fb368a3712230ffc05b66a14c7003e2ad6a938d544b8b9908c4536f945ac4bdb1ca623f2826a25ca16b39730c9fe940a8642eb35088ed341be768c10b152c8a65d32e4dbe68764e6b2abde6824088b6be258d7e3aea155cb919e1c500cdcee435515cf09575f75551c16fba0f3aede0aaba544e89a58e4c34e255eaafd8f65340daa55e3ed8ab903fe188416340ace15d36f9cede379cc3586e6d320f72aa310a1b0a781d06b7418a50525105fa749306ac59a788d6866b7ddd0f4c059ba6cee43fad5ad2a362b9de1c57324ade8b5b46c6b1ddabd82f0670f7a4da869f204efb27ea7e049bc7d6cfd2071682c894161922a99108eb3bb8922113ba9924018e41b7",
+ g => "5",
+ }
+ );
+
+my $num = '10000000000000000001';
+my @try = ($num, Math::BigInt->new($num));
+push @try, Math::Pari->new($num) if $has_pari;
+for my $try (@try) {
+ my $type = 'any2bigint(' . (ref($try) || 'scalar') . ')';
+ my $val = Crypt::DH::_any2bigint($try);
+ ok($val, $type . ' returns a defined value');
+ is(ref($val), 'Math::BigInt', $type . ' returns a Math::BigInt');
+ is($val->bstr, $num, $type . ' returns the correct value');
+}
+
+for my $pg (@pgs) {
+ my $dh1 = Crypt::DH->new(g => $pg->{g}, p => $pg->{p});
+ my $dh2 = Crypt::DH->new(g => $pg->{g}, p => $pg->{p});
+ $dh1->generate_keys;
+ $dh2->generate_keys;
+
+ is($dh1->g->bstr, $pg->{g}, 'Key generation did not modify g');
+ is($dh1->p->as_hex, $pg->{p}, 'Key generation did not modify p');
+
+ my $pub1 = $dh1->pub_key;
+ my $pub2 = $dh2->pub_key;
+
+ my $ss1 = $dh1->compute_key($pub2);
+ my $ss2 = $dh2->compute_key($pub1);
+
+ is($ss1, $ss2, 'Shared secrets match');
+}
View
4 t/99_pod.t
@@ -1,4 +0,0 @@
-use Test::More;
-eval "use Test::Pod 1.00";
-plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
-all_pod_files_ok();
View
4 t/99_pod_coverage.t
@@ -1,4 +0,0 @@
-use Test::More;
-eval "use Test::Pod::Coverage 1.00";
-plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@;
-all_pod_coverage_ok();

No commit comments for this range

Something went wrong with that request. Please try again.