FBB::BigInt(3bobcat)

Big Integers
(libbobcat-dev_4.08.03-x.tar.gz)

2005-2018

NAME

FBB::BigInt - Arithmetic on Integers of Unlimited Size

SYNOPSIS

#include <bobcat/bigint>
Linking option: -lbobcat -lcrypto

DESCRIPTION

This class is defined as a wrapper class around the openSSL BN series of functions, offering members to perform arithmetic on integral values of unlimited sizes. Members are offered to generate primes and to perform all kinds of common arithmetic operations on BigInt objects. Also, conversions to characters and standard numerical value types are offered.

Below, the phrase the object may also refer to the object's value. The context in which this occurs will make clear that the object's value rather than the object as-is is referred to.

Various constructors accept BIGNUM arguments. Type BIGNUM is the type containing an integer of unlimited precision as defined by OpenSSL.

Signs of BigInt are handled in a special way. Whether a BigInt is negative or positive is determined by its sign-flag, and not by a sign bit as is the case with int typed values. Since BigInt values have unlimited precision shifting values to the left won't change their signs.

Operators return either a reference to the current (modified) object or return a BigInt object containing the computed value. The rule followed here was to implement the operators analogously to the way the operators work on int type values and variables. E.g., operator+() returns a BigInt value whereas operator+=() returns a BigInt & reference.

All members modifying their objects return a reference to the current (modified) object. All members not modifying the current object return a BigInt object. If both members exists performing the same functionality the name of the member returning a BigInt object ends in a c (const) (e.g., addMod and addModc).

Almost all operators, members and constructors (except for the default constructor) throw Exception exceptions on failure.

INHERITS FROM

-

TYPE

The class BigInt defines the type Word, which is equal to the type BN_ULONG used by OpenSSL to store integral values of unlimited precision. A Word is an unsigned long, which is, depending on the architecture, usually 64 or 32 bits long.

ENUMERATIONS

Msb
This (most significant bit) enumeration is used when generating a cryptographically strong random number. Its values are:

Lsb
This (least significant bit) enumeration is used when generating random numbers, ensuring that the resulting value is either odd or even.

CONSTRUCTORS

The standard copy constructor is available, the move constructor is not available.

MEMBER FUNCTIONS

OVERLOADED OPERATORS

Except for some operators all operators perform their intuitive operations. Where that isn't completely true an explanatory remark is provided. E.g., operator*() multiplies two BigInts, possibly promoting one of the operands; operator*=() multiplies the lhs by the rhs BigInt, possibly promoting the rhs operand.

Here are the available operators:

Unary operators:

Binary operators:

(Arithmetic) assignment operator(s):

Note that the move operator is not available

STATIC MEMBERS

All members returning a BigInt computed from a set of arguments and not requiring an existing BigInt object are defined as static members.

FREE FUNCTIONS IN THE FBB NAMESPACE

EXAMPLE


#include <iostream>
#include <bobcat/bigint>

using namespace std;
using namespace FBB;

int main()
{
    BigInt value(BigInt::prime(100));
    BigInt mod(BigInt::rand(50));
    BigInt inverse(value.inverseModc(mod));

    cout << '(' << value << " * " << inverse << ") % " << mod << " = " <<
             (    value       *      inverse     ) %      mod << endl;
}
        

FILES

bobcat/bigint - defines the class interface

SEE ALSO

bobcat(7), diffiehellman(3bobcat), RAND_add(3ssl), RAND_egd(3ssl), RAND_load_file(3ssl), RAND_seed(3).

BUGS

Sep/Oct 2013: due to a change in library handling by the linker (cf. http://fedoraproject.org/wiki/UnderstandingDSOLinkChange and https://wiki.debian.org/ToolChain/DSOLinking) libraries that are indirectly required are no longer automatically linked to your program. With BigInt this is libcrypto, which requires programs to link to both bobcat and crypto.

DISTRIBUTION FILES

BOBCAT

Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.

COPYRIGHT

This is free software, distributed under the terms of the GNU General Public License (GPL).

AUTHOR

Frank B. Brokken (f.b.brokken@rug.nl).