perldoc > Crypt::OpenSSL::Bignum

📛 NAME

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

🚀 Quick Reference

Use CaseCommandDescription
🔢 Create from decimalCrypt::OpenSSL::Bignum->new_from_decimal($decimal_string)Bignum from decimal string
🔢 Create from hexCrypt::OpenSSL::Bignum->new_from_hex($hex_string)Bignum from hex string (no leading 0x)
🔢 Create from binaryCrypt::OpenSSL::Bignum->new_from_bin($bin_buffer)Bignum from packed binary
➕ Addition$bn->add($bn_b)Sum of two bignums
➖ Subtraction$bn->sub($bn_b)Difference of two bignums
✖️ Multiplication$bn->mul($bn_b, $ctx)Product (requires CTX)
➗ Division$bn->div($bn_b, $ctx)Returns quotient and remainder
🔢 Modular exponentiation$bn->mod_exp($exp, $mod, $ctx)($self ** $exp) % $mod
🔢 Modular inverse$bn->mod_inverse($n, $ctx)Inverse modulo $n
⚖️ Comparison$bn->cmp($bn_b)Returns -1, 0, or 1
🔀 Random numberCrypt::OpenSSL::Bignum->rand($bits, $top, $bottom)Cryptographically strong random
🔀 Pseudo-randomCrypt::OpenSSL::Bignum->pseudo_rand($bits, $top, $bottom)Non-cryptographic random

📝 SYNOPSIS

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("3e8"); # no leading 0x
# 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(), "\n";
}

📖 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.

⚠️ Note: Many of the methods in this package can croak, so use eval, or Error.pm's try/catch mechanism to capture errors.

🏗️ Constructors

🔧 Instance Methods

✍️ AUTHOR

Ian Robertson, iroberts AT cpan.org

🔗 SEE ALSO

https://www.openssl.org/docs/crypto/bn.html

Crypt::OpenSSL::Bignum
📛 NAME 🚀 Quick Reference 📝 SYNOPSIS 📖 DESCRIPTION
🏗️ Constructors 🔧 Instance Methods
✍️ AUTHOR 🔗 SEE ALSO

Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-22 05:45 @216.73.216.206
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^