info > Crypt::OpenSSL::Bignum

πŸ“› NAME

Crypt::OpenSSL::Bignum β€” OpenSSL’s multiprecision integer arithmetic

πŸš€ Quick Reference

Use CaseCommandDescription
Create from decimal stringCrypt::OpenSSL::Bignum->new_from_decimal(β€œ1000”)πŸ†• New bignum from decimal
Create from hex stringCrypt::OpenSSL::Bignum->new_from_hex(β€œ3e8”)πŸ†• New bignum from hex (no 0x)
Create from wordCrypt::OpenSSL::Bignum->new_from_word(1000)πŸ†• New bignum from unsigned integer (0..2^32-1)
Create from binaryCrypt::OpenSSL::Bignum->new_from_bin($packed)πŸ†• New bignum from packed binary
Create random numberCrypt::OpenSSL::Bignum->rand($bits, $top, $bottom)🎲 Cryptographically strong random
Addition$a->add($b) or $a->add($b, $result)βž• Add two bignums
Subtraction$a->sub($b) or $a->sub($b, $result)βž– Subtract two bignums
Multiplication$a->mul($b, $ctx) or $a->mul($b, $ctx, $result)βœ–οΈ Multiply two bignums
Division$a->div($b, $ctx) or $a->div($b, $ctx, $q, $r)βž— Division with remainder
Modular exponentiation$a->mod_exp($exp, $mod, $ctx)πŸ”’ Compute $a^$exp mod $mod
Modular inverse$a->mod_inverse($n, $ctx)πŸ”„ Inverse modulo $n
GCD$a->gcd($b, $ctx)πŸ“ Greatest common divisor
Comparison$a->cmp($b)πŸ” Compare (returns -1, 0, 1)
Bit shift left$a->lshift($n)⬅️ Left shift by $n bits
Bit shift right$a->rshift($n)➑️ Right shift by $n bits

πŸ“– 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 Author: Che Dong Under GNU General Public License
2026-08-14 20:49 @2600:1f28:365:80b0:4d23:66fa:c2bb:7bae
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!