1Crypt::DH::GMP(3)     User Contributed Perl Documentation    Crypt::DH::GMP(3)
2
3
4

NAME

6       Crypt::DH::GMP - Crypt::DH Using GMP Directly
7

SYNOPSIS

9         use Crypt::DH::GMP;
10
11         my $dh = Crypt::DH::GMP->new(p => $p, g => $g);
12         my $val = $dh->compute_secret();
13
14         # If you want compatibility with Crypt::DH (it uses Math::BigInt)
15         # then use this flag
16         # You /think/ you're using Crypt::DH, but...
17         use Crypt::DH::GMP qw(-compat);
18
19         my $dh = Crypt::DH->new(p => $p, g => $g);
20         my $val = $dh->compute_secret();
21

DESCRIPTION

23       Crypt::DH::GMP is a (somewhat) portable replacement to Crypt::DH,
24       implemented mostly in C.
25

RATIONALE

27       In the beginning, there was "Crypt::DH". However, "Crypt::DH" suffers
28       from a couple of problems:
29
30       GMP/Pari libraries are almost always required
31           "Crypt::DH" works with a plain "Math::BigInt", but if you want to
32           use it in production, you almost always need to install
33           "Math::BigInt::GMP" or "Math::BigInt::Pari" because without them,
34           the computation that is required by "Crypt::DH" makes the module
35           pretty much unusable.
36
37           Because of this, "Crypt::DH" might as well make "Math::BigInt::GMP"
38           a hard requirement.
39
40       Crypt::DH suffers from having Math::BigInt in between GMP
41           With or without "Math::BigInt::GMP" or "Math::BigInt::Pari",
42           "Crypt::DH" makes several round trip conversions between Perl
43           scalars, Math::BigInt objects, and finally its C representation (if
44           GMP/Pari are installed).
45
46           Instantiating an object comes with a relatively high cost, and if
47           you make many computations in one go, your program will suffer
48           dramatically because of this.
49
50       These problems quickly become apparent when you use modules such as
51       "Net::OpenID::Consumer", which requires to make a few calls to
52       "Crypt::DH".
53
54       "Crypt::DH::GMP" attempts to alleviate these problems by providing a
55       "Crypt::DH"-compatible layer, which, instead of doing calculations via
56       Math::BigInt, directly works with libgmp in C.
57
58       This means that we've essentially eliminated 2 call stacks worth of
59       expensive Perl method calls and we also only load 1 (Crypt::DH::GMP)
60       module instead of 3 (Crypt::DH + Math::BigInt + Math::BigInt::GMP).
61
62       These add up to a fairly significant increase in performance.
63

COMPATIBILITY WITH Crypt::DH

65       Crypt::DH::GMP absolutely refuses to consider using anything other than
66       strings as its parameters and/or return values therefore if you would
67       like to use Math::BigInt objects as your return values, you can not use
68       Crypt::DH::GMP directly. Instead, you need to be explicit about it:
69
70         use Crypt::DH;
71         use Crypt::DH::GMP qw(-compat); # must be loaded AFTER Crypt::DH
72
73       Specifying -compat invokes a very nasty hack that overwrites
74       Crypt::DH's symbol table -- this then forces Crypt::DH users to use
75       Crypt::DH::GMP instead, even if you are writing
76
77         my $dh = Crypt::DH->new(...);
78         $dh->compute_key();
79

BENCHMARK

81       By NO MEANS is this an exhaustive benchmark, but here's what I get on
82       my MacBook (OS X 10.5.8, 2.4 GHz Core 2 Duo, 4GB RAM)
83
84         Benchmarking instatiation cost...
85                Rate   pp  gmp
86         pp   9488/s   -- -79%
87         gmp 45455/s 379%   --
88
89         Benchmarking key generation cost...
90               Rate gmp  pp
91         gmp 6.46/s  -- -0%
92         pp  6.46/s  0%  --
93
94         Benchmarking compute_key cost...
95                 Rate    pp   gmp
96         pp   12925/s    --  -96%
97         gmp 365854/s 2730%    --
98

METHODS

100   new
101   p
102   g
103   compute_key
104   compute_secret
105   generate_keys
106   pub_key
107   priv_key
108   compute_key_twoc
109       Computes the key, and returns a string that is byte-padded two's
110       compliment in binary form.
111
112   pub_key_twoc
113       Returns the pub_key as a string that is byte-padded two's compliment in
114       binary form.
115
116   clone

AUTHOR

118       Daisuke Maki "<daisuke@endeworks.jp>"
119

LICENSE

121       This program is free software; you can redistribute it and/or modify it
122       under the same terms as Perl itself.
123
124       See http://www.perl.com/perl/misc/Artistic.html
125
126
127
128perl v5.32.1                      2021-01-27                 Crypt::DH::GMP(3)
Impressum