1Bignum(3)             User Contributed Perl Documentation            Bignum(3)
2
3
4

NAME

6       Crypt::OpenSSL::Bignum - OpenSSL's multiprecision integer arithmetic
7

SYNOPSIS

9         use Crypt::OpenSSL::Bignum;
10
11         my $bn = Crypt::OpenSSL::Bignum->new_from_decimal( "1000" );
12         # or
13         my $bn = Crypt::OpenSSL::Bignum->new_from_word( 1000 );
14         # or
15         my $bn = Crypt::OpenSSL::Bignum->new_from_hex("0x3e8");
16         # or
17         my $bn = Crypt::OpenSSL::Bignum->new_from_bin(pack( "C*", 3, 232 ))
18
19         use Crypt::OpenSSL::Bignum::CTX;
20
21         sub print_factorial
22         {
23           my( $n ) = @_;
24           my $fac = Crypt::OpenSSL::Bignum->one();
25           my $ctx = Crypt::OpenSSL::Bignum::CTX->new();
26           foreach my $i (1 .. $n)
27           {
28             $fac->mul( Crypt::OpenSSL::Bignum->new_from_word( $i ), $ctx, $fac );
29           }
30           print "$n factorial is ", $fac->to_decimal(), "\n";
31         }
32

DESCRIPTION

34       Crypt::OpenSSL::Bignum provides access to OpenSSL multiprecision
35       integer arithmetic libraries.  Presently, many though not all of the
36       arithmetic operations that OpenSSL provides are exposed to perl.  In
37       addition, this module can be used to provide access to bignum values
38       produced by other OpenSSL modules, such as key parameters from
39       Crypt::OpenSSL::RSA.
40
41       NOTE: Many of the methods in this package can croak, so use eval, or
42       Error.pm's try/catch mechanism to capture errors.
43

Class Methods

45       new_from_word
46           Create a new Crypt::OpenSSL::Bignum object whose value will be the
47           word given.  Note that numbers represneted by objects created using
48           this method are necessarily between 0 and 2^32 - 1.
49
50       new_from_decimal
51           Create a new Crypt::OpenSSL::Bignum object whose value is specified
52           by the given decimal representation.
53
54       new_from_hex
55           Create a new Crypt::OpenSSL::Bignum object whose value is specified
56           by the given hexidecimal representation.
57
58       new_from_bin
59           Create a new Crypt::OpenSSL::Bignum object whose value is specified
60           by the given packed binary string.  Note that objects created using
61           this method are necessarily nonnegative.
62
63       zero
64           Returns a new Crypt::OpenSSL::Bignum object representing 0
65
66       one Returns a new Crypt::OpenSSL::Bignum object representing 1
67
68       bless_pointer
69           Given a pointer to a OpenSSL BIGNUM object in memory, construct and
70           return Crypt::OpenSSL::Bignum object around this.  Note that the
71           underlying BIGNUM object will be destroyed (via
72           BN_clear_free(3ssl)) when the returned Crypt::OpenSSL::Bignum
73           object is no longer referenced, so the pointer passed to this
74           method should only be referenced via the returned perl object after
75           calling bless_pointer.
76
77           This method is intended only for use by XSUB writers writing code
78           that interfaces with OpenSSL library methods, and who wish to be
79           able to return a BIGNUM structure to perl as a
80           Crypt::OpenSSL::Bignum object.
81

Instance Methods

83       to_decimal
84           Return a decimal string representation of this object.
85
86       to_hex
87           Return a hexidecimal string representation of this object.
88
89       to_bin
90           Return a packed binary string representation of this object.  Note
91           that sign is ignored, so that to bin called on a
92           Crypt::OpenSSL::Bignum object representing a negative number
93           returns the same value as it would called on an object representing
94           that number's absolute value.
95
96       get_word
97           Return a scalar integer representation of this object, if it can be
98           represented as an unsigned long.
99
100       is_zero
101           Returns true of this object represents 0.
102
103       is_one
104           Returns true of this object represents 1.
105
106       is_odd
107           Returns true of this object represents an odd number.
108
109       copy
110           Returns a copy of this object.
111
112       add This method returns the sum of this object and the first argument.
113           If only one argument is passed, a new Crypt::OpenSSL::Bignum object
114           is created for the return value; otherwise, the value of second
115           argument is set to the result and returned.
116
117       sub This method returns the difference of this object and the first
118           argument.  If only one argument is passed, a new
119           Crypt::OpenSSL::Bignum object is created for the return value;
120           otherwise, the value of second argument is set to the result and
121           returned.
122
123       mul This method returns the product of this object and the first
124           argument, using the second argument, a Crypt::OpenSSL::Bignum::CTX
125           object, as a scratchpad.  If only two arguments are passed, a new
126           Crypt::OpenSSL::Bignum object is created for the return value;
127           otherwise, the value of third argument is set to the result and
128           returned.
129
130       div This method returns a list consisting of quotient and the remainder
131           obtained by dividing this object by the first argument, using the
132           second argument, a Crypt::OpenSSL::Bignum::CTX object, as a
133           scratchpad.  If only two arguments are passed, new
134           Crypt::OpenSSL::Bignum objects is created for both return values.
135           If a third argument is passed, otherwise, the value of third
136           argument is set to the quotient.  If a fourth argument is passed,
137           the value of the fourth argument is set to the remainder.
138
139       exp This method returns the product of this object exponeniated by the
140           first argument, using the second argument, a
141           Crypt::OpenSSL::Bignum::CTX object, as a scratchpad.
142
143       mod_exp
144           This method returns the product of this object exponeniated by the
145           first argument, modulo the second argument, using the third
146           argument, a Crypt::OpenSSL::Bignum::CTX object, as a scratchpad.
147
148       pointer_copy
149           This method is intended only for use by XSUB writers wanting to
150           have access to the underlying BIGNUM structure referenced by a
151           Crypt::OpenSSL::Bignum perl object so that they can pass them to
152           other routines in the OpenSSL library.  It returns a perl scalar
153           whose IV can be cast to a BIGNUM* value.  This can then be passed
154           to an XSUB which can work with the BIGNUM directly.  Note that the
155           BIGNUM object pointed to will be a copy of the BIGNUM object
156           wrapped by the instance; it is thus the responsiblity of the client
157           to free space allocated by this BIGNUM object if and when it is
158           done with it. See also bless_pointer.
159

AUTHOR

161       Ian Robertson, iroberts@cpan.org
162

SEE ALSO

164       perl, bn(3ssl)
165
166
167
168perl v5.12.0                      2007-05-20                         Bignum(3)
Impressum