.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Bignum 3pm" .TH Bignum 3pm "2007-05-20" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Crypt::OpenSSL::Bignum \- OpenSSL's multiprecision integer arithmetic .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Crypt::OpenSSL::Bignum; \& \& my $bn = Crypt::OpenSSL::Bignum\->new_from_decimal( "1000" ); \& # or \& my $bn = Crypt::OpenSSL::Bignum\->new_from_word( 1000 ); \& # or \& my $bn = Crypt::OpenSSL::Bignum\->new_from_hex("0x3e8"); \& # or \& my $bn = Crypt::OpenSSL::Bignum\->new_from_bin(pack( "C*", 3, 232 )) \& \& use Crypt::OpenSSL::Bignum::CTX; \& \& sub print_factorial \& { \& my( $n ) = @_; \& my $fac = Crypt::OpenSSL::Bignum\->one(); \& my $ctx = Crypt::OpenSSL::Bignum::CTX\->new(); \& foreach my $i (1 .. $n) \& { \& $fac\->mul( Crypt::OpenSSL::Bignum\->new_from_word( $i ), $ctx, $fac ); \& } \& print "$n factorial is ", $fac\->to_decimal(), "\en"; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Crypt::OpenSSL::Bignum provides access to OpenSSL multiprecision integer arithmetic libraries. Presently, many though not all of the arithmetic operations that OpenSSL provides are exposed to perl. In addition, this module can be used to provide access to bignum values produced by other OpenSSL modules, such as key parameters from Crypt::OpenSSL::RSA. .PP \&\fI\s-1NOTE\s0\fR: Many of the methods in this package can croak, so use eval, or Error.pm's try/catch mechanism to capture errors. .SH "Class Methods" .IX Header "Class Methods" .IP "new_from_word" 4 .IX Item "new_from_word" Create a new Crypt::OpenSSL::Bignum object whose value will be the word given. Note that numbers represneted by objects created using this method are necessarily between 0 and 2^32 \- 1. .IP "new_from_decimal" 4 .IX Item "new_from_decimal" Create a new Crypt::OpenSSL::Bignum object whose value is specified by the given decimal representation. .IP "new_from_hex" 4 .IX Item "new_from_hex" Create a new Crypt::OpenSSL::Bignum object whose value is specified by the given hexidecimal representation. .IP "new_from_bin" 4 .IX Item "new_from_bin" Create a new Crypt::OpenSSL::Bignum object whose value is specified by the given packed binary string. Note that objects created using this method are necessarily nonnegative. .IP "zero" 4 .IX Item "zero" Returns a new Crypt::OpenSSL::Bignum object representing 0 .IP "one" 4 .IX Item "one" Returns a new Crypt::OpenSSL::Bignum object representing 1 .IP "bless_pointer" 4 .IX Item "bless_pointer" Given a pointer to a OpenSSL \s-1BIGNUM\s0 object in memory, construct and return Crypt::OpenSSL::Bignum object around this. Note that the underlying \s-1BIGNUM\s0 object will be destroyed (via \fIBN_clear_free\fR\|(3ssl)) when the returned Crypt::OpenSSL::Bignum object is no longer referenced, so the pointer passed to this method should only be referenced via the returned perl object after calling bless_pointer. .Sp This method is intended only for use by \s-1XSUB\s0 writers writing code that interfaces with OpenSSL library methods, and who wish to be able to return a \s-1BIGNUM\s0 structure to perl as a Crypt::OpenSSL::Bignum object. .SH "Instance Methods" .IX Header "Instance Methods" .IP "to_decimal" 4 .IX Item "to_decimal" Return a decimal string representation of this object. .IP "to_hex" 4 .IX Item "to_hex" Return a hexidecimal string representation of this object. .IP "to_bin" 4 .IX Item "to_bin" Return a packed binary string representation of this object. Note that sign is ignored, so that to bin called on a Crypt::OpenSSL::Bignum object representing a negative number returns the same value as it would called on an object representing that number's absolute value. .IP "get_word" 4 .IX Item "get_word" Return a scalar integer representation of this object, if it can be represented as an unsigned long. .IP "is_zero" 4 .IX Item "is_zero" Returns true of this object represents 0. .IP "is_one" 4 .IX Item "is_one" Returns true of this object represents 1. .IP "is_odd" 4 .IX Item "is_odd" Returns true of this object represents an odd number. .IP "copy" 4 .IX Item "copy" Returns a copy of this object. .IP "add" 4 .IX Item "add" This method returns the sum of this object and the first argument. If only one argument is passed, a new Crypt::OpenSSL::Bignum object is created for the return value; otherwise, the value of second argument is set to the result and returned. .IP "sub" 4 .IX Item "sub" This method returns the difference of this object and the first argument. If only one argument is passed, a new Crypt::OpenSSL::Bignum object is created for the return value; otherwise, the value of second argument is set to the result and returned. .IP "mul" 4 .IX Item "mul" This method returns the product of this object and the first argument, using the second argument, a Crypt::OpenSSL::Bignum::CTX object, as a scratchpad. If only two arguments are passed, a new Crypt::OpenSSL::Bignum object is created for the return value; otherwise, the value of third argument is set to the result and returned. .IP "div" 4 .IX Item "div" This method returns a list consisting of quotient and the remainder obtained by dividing this object by the first argument, using the second argument, a Crypt::OpenSSL::Bignum::CTX object, as a scratchpad. If only two arguments are passed, new Crypt::OpenSSL::Bignum objects is created for both return values. If a third argument is passed, otherwise, the value of third argument is set to the quotient. If a fourth argument is passed, the value of the fourth argument is set to the remainder. .IP "exp" 4 .IX Item "exp" This method returns the product of this object exponeniated by the first argument, using the second argument, a Crypt::OpenSSL::Bignum::CTX object, as a scratchpad. .IP "mod_exp" 4 .IX Item "mod_exp" This method returns the product of this object exponeniated by the first argument, modulo the second argument, using the third argument, a Crypt::OpenSSL::Bignum::CTX object, as a scratchpad. .IP "pointer_copy" 4 .IX Item "pointer_copy" This method is intended only for use by \s-1XSUB\s0 writers wanting to have access to the underlying \s-1BIGNUM\s0 structure referenced by a Crypt::OpenSSL::Bignum perl object so that they can pass them to other routines in the OpenSSL library. It returns a perl scalar whose \s-1IV\s0 can be cast to a BIGNUM* value. This can then be passed to an \s-1XSUB\s0 which can work with the \s-1BIGNUM\s0 directly. Note that the \s-1BIGNUM\s0 object pointed to will be a copy of the \s-1BIGNUM\s0 object wrapped by the instance; it is thus the responsiblity of the client to free space allocated by this \s-1BIGNUM\s0 object if and when it is done with it. See also bless_pointer. .SH "AUTHOR" .IX Header "AUTHOR" Ian Robertson, iroberts@cpan.org .SH "SEE ALSO" .IX Header "SEE ALSO" perl, \fIbn\fR\|(3ssl)