FBB::BigInt(3bobcat)

Big Integers
(libbobcat-dev_6.02.02)

2005-2022

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. BIGNUM's definition is


    typedef struct bignum_st BIGNUM;

    struct bignum_st
    {
        BN_ULONG *d;    // Pointer to an array of 'BN_BITS2' bit chunks.
        int top;        // Index of last used d +1.
        // The next are internal book keeping for bn_expand.
        int dmax;       // Size of the d array.
        int neg;        // one if the number is negative
        int flags;
    };
        

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

Copy and move constructors (and assignment operators) are 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):

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. The first diophantus member, returning a long long value, also is a static member.

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 << '\n';
}

// shows:
// (1258586273445895786081124957771 * 828997573545038) %
//                                                  1007205247048889 = 1

FILES

bobcat/bigint - defines the class interface

SEE ALSO

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

For BIGNUM:
https://www.openssl.org/docs/man1.0.2/man3/bn_sub_words.html

BUGS

None Reported.

BOBCAT PROJECT 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).