/usr/share/doc/libbobcat4-dev/man/bigint.3.html is in libbobcat-dev 4.08.02-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | <!DOCTYPE html><html><head>
<meta charset="UTF-8">
<title>FBB::BigInt(3bobcat)</title>
<style type="text/css">
figure {text-align: center;}
img {vertical-align: center;}
.XXfc {margin-left:auto;margin-right:auto;}
.XXtc {text-align: center;}
.XXtl {text-align: left;}
.XXtr {text-align: right;}
.XXvt {vertical-align: top;}
.XXvb {vertical-align: bottom;}
</style>
<link rev="made" href="mailto:Frank B. Brokken: f.b.brokken@rug.nl">
</head>
<body text="#27408B" bgcolor="#FFFAF0">
<hr/>
<h1 id="title">FBB::BigInt(3bobcat)</h1>
<h2 id="author">Big Integers<br/>(libbobcat-dev_4.08.02-x.tar.gz)</h2>
<h2 id="date">2005-2017</h2>
<p>
<h2 >NAME</h2>FBB::BigInt - Arithmetic on Integers of Unlimited Size
<p>
<h2 >SYNOPSIS</h2>
<strong >#include <bobcat/bigint></strong><br/>
Linking option: <em >-lbobcat -lcrypto</em>
<p>
<h2 >DESCRIPTION</h2>
<p>
This class is defined as a wrapper class around the <em >openSSL</em> <em >BN</em> 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 <em >BigInt</em> objects. Also, conversions
to characters and standard numerical value types are offered.
<p>
Below, the phrase <em >the object</em> 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.
<p>
Various constructors accept <em >BIGNUM</em> arguments. Type <em >BIGNUM</em> is the type
containing an integer of unlimited precision as defined by OpenSSL.
<p>
Signs of <em >BigInt</em> are handled in a special way. Whether a <em >BigInt</em> is
negative or positive is determined by its sign-flag, and not by a sign bit as
is the case with <em >int</em> typed values. Since <em >BigInt</em> values have unlimited
precision shifting values to the left won't change their signs.
<p>
Operators return either a reference to the current (modified) object or return
a <em >BigInt</em> object containing the computed value. The rule followed here was
to implement the operators analogously to the way the operators work on
<em >int</em> type values and variables. E.g., <em >operator+()</em> returns a <em >BigInt</em>
value whereas <em >operator+=()</em> returns a <em >BigInt &</em> reference.
<p>
All members modifying their objects return a reference to the current
(modified) object. All members not modifying the current object return a
<em >BigInt</em> object. If both members exists performing the same
functionality the name of the member returning a <em >BigInt</em> object ends
in a <em >c</em> (const) (e.g., <em >addMod</em> and <em >addModc</em>).
<p>
Almost all operators, members and constructors (except for the default
constructor) throw <em >Exception</em> exceptions on failure.
<p>
<h2 >INHERITS FROM</h2>
-
<p>
<h2 >TYPE</h2>
<p>
The class <strong >BigInt</strong> defines the type <em >Word</em>, which is equal to the type
<em >BN_ULONG</em> used by <em >OpenSSL</em> to store integral values of unlimited
precision. A <em >Word</em> is an <em >unsigned long</em>, which is, depending on the
architecture, usually 64 or 32 bits long.
<p>
<h2 >ENUMERATIONS</h2>
<strong >Msb</strong><br/>
This (most significant bit) enumeration is used when generating a
cryptographically strong random number. Its values are:
<ul>
<li> <strong >MSB_UNKNOWN</strong>:<br/>
The most significant bit may be 0 or 1.
<li> <strong >MSB_IS_ONE</strong>:<br/>
The most significant bit is guaranteed to be 1.
<li> <strong >TOP_TWO_BITS_ONE</strong>:<br/>
The two most significant bits are guaranteed to be 1, resulting in a
product of two values each containing <em >nBits</em> having <em >2 * nBits</em>
bits.
</ul>
<p>
<strong >Lsb</strong><br/>
This (least significant bit) enumeration is used when generating random
numbers, ensuring that the resulting value is either odd or even.
<ul>
<li> <strong >EVEN</strong>:<br/>
The random value will be an even value;
<li> <strong >ODD</strong>:<br/>
The random value will be an odd value.
</ul>
<p>
<h2 >CONSTRUCTORS</h2>
<p>
<ul>
<li> <strong >BigInt()</strong>:<br/>
The default constructor initializes a <em >BigInt</em> value to 0.
<li> <strong >explicit BigInt(BIGNUM const &value)</strong>:<br/>
This constructor initializes a <em >BigInt</em> from a <em >const BIGNUM</em>.
<li> <strong >explicit BigInt(BIGNUM const *value)</strong>:<br/>
This constructor initializes a <em >BigInt</em> from a pointer to a
<em >const BIGNUM</em>.
<li> <strong >explicit BigInt(BIGNUM *value)</strong>:<br/> This constructor initializes a
<em >BigInt</em> from a pointer to a <em >BIGNUM</em> (the <em >BIGNUM</em> value
pointed to by <em >value</em> is <em >not</em> mondified by the constructor.
This constructor is a mere wrapper around the previous constructor).
<li> <strong >BigInt(Type value)</strong>:<br/>
This constructor is defined as a member template. Any type that can be
converted using a static cast to an <em >unsigned long</em> can be used as argument
to this constructor. Promotion is allowed, so in many situations where
<em >BigInt</em>s are expected a plain numerical value can be used as well.
<li> <strong >BigInt(char const *bigEndian, size_t length, bool negative = false)</strong>:<br/>
This constructor initializes a <em >BigInt</em> from <em >length</em>
big-endian encoded bytes stored in <em >bigEndian</em>. This constructor interprets
the <em >char</em> values pointed at by <em >bigEndian</em> as unsigned values. Use this
constructor to reconstruct a <em >BigInt</em> object from the data made available by
the <em >bigEndian</em> member. If the number represents a negative value, then
provide a third argument <em >true</em>.
<li> <strong >explicit BigInt(std::string const &bigEndian, bool negative = false)</strong>:<br/>
This constructor initializes a <em >BigInt</em> from the bytes stored in
<em >bigEndian</em>, which must be big-endian encoded. This constructor interprets
the <em >char</em> values stored in <em >bigEndian</em> as unsigned values. If the number
that is stored in <em >bigEndian</em> represents a negative value, then provide a
second argument <em >true</em>.
</ul>
<p>
The standard copy constructor is available, the move constructor is not
available.
<p>
<h2 >MEMBER FUNCTIONS</h2>
<ul>
<li> <strong >BigInt &addMod(BigInt const &rhs, BigInt const &mod) </strong>:<br/>
<em >Rhs</em> is added (modulo <em >mod</em>) to the current object.
<p>
<li> <strong >BigInt addModc(BigInt const &rhs, BigInt const &mod) </strong>:<br/>
The sum (modulo <em >mod</em>) of the current object and <em >rhs</em> is returned.
<p>
<li> <strong >BigInt::Word at(size_t index) const</strong>:<br/>
Returns the <em >Word</em> at <em >index</em>. E.g., on a 32 bit architecture, if
the <strong >BigInt</strong> value equals 2<sup >33</sup>, then <em >at(0)</em> returns 0, and
<em >at(1)</em> returns 2. If <em >index</em> equals or exceeds the value returned
by <em >nWords</em> an <em >FBB::Exception</em> is thrown.
<p>
<li> <strong >BIGNUM const &bignum() const</strong>:<br/>
A reference to the <em >BIGNUM</em> value maintained by the current
<em >BigInt</em> object is returned.
<p>
<li> <strong >char *bigEndian() const</strong>:<br/> The value represented by the current object
is stored in a series of <em >char</em> typed values in big-endian order. If
a value consists of 5 <em >char</em>s the eight most significant bits will
be stored in the <em >char</em> having index value 0, the eight least
significant bits will be stored in the <em >char</em> having index value
4. When needed simply swap <em >char[i]</em> with <em >char[j]</em> (i = 0
.. nBytes/2, j = nBytes-1 .. nBytes/2) to convert to little-endian
order. The return value consists of a series of <em >sizeInBytes()</em> (see
below) dynamically allocated <em >char</em> values. The caller of
<em >bigEndian</em> owns the allocated memory and should eventually delete
it again using <em >delete[]</em>. Note that the current object's <em >sign</em>
cannot be inferred from the return value.
<p>
<li> <strong >BigInt &clearBit(size_t index)</strong>:<br/>
The current object's bit at index position <em >index</em> is cleared.
<p>
<li> <strong >BigInt clearBit(size_t index) const</strong>:<br/>
A copy of the current object having its bit at index position
<em >index</em> cleared.
<p>
<li> <strong >long long diophantus(long long *factor1, long long *factor2,
long long value1, long long value2)</strong>:<br/>
The integral solution of <em >factor1 * value1 + factor2 * value2 = gcd</em>
is computed. The function returns the greatest common divisor
(<em >gcd</em>) of <em >value1</em> and <em >value2</em>, and returns their
multiplication factors in, respectively, <em >*factor1</em> and
<em >*factor2</em>. The solution is not unique: another solution is obtained
by adding <em >k * value2</em> to <em >factor1</em> and subtracting <em >k * value1</em>
from <em >factor2</em>. For values exceeding <em >std::numeric_limits<long,
long>::max()</em> the next member can be used.
<p>
<li> <strong >BigInt diophantus(BigInt *factor1, BigInt *factor2,
BigInt const &value1, BigInt const &value2)</strong>:<br/>
The integral solution of <em >factor1 * value1 + factor2 * value2 = gcd</em>
is computed. The function returns the greatest common divisor
(<em >gcd</em>) of <em >value1</em> and <em >value2</em>, and returns their
multiplication factors in, respectively, <em >*factor1</em> and
<em >*factor2</em>. The solution is not unique: another solution is obtained
by adding <em >k * value2</em> to <em >factor1</em> and subtracting <em >k * value1</em>
from <em >factor2</em>.
<p>
<li> <strong >BigInt &div(BigInt *remainder, BigInt const &rhs)</strong>:<br/>
The current object is divided by <em >rhs</em>. The division's remainder
is returned in <em >*remainder</em>.
<p>
<li> <strong >BigInt divc(BigInt *remainder, BigInt const &rhs) const</strong>:<br/>
The quotient of the current object and <em >rhs</em> is returned. The
division's remainder is returned in <em >*remainder</em>.
<p>
<li> <strong >int compare(BigInt const &rsh) const</strong>:<br/>
Using signed values, if the current object is smaller than <em >rhs</em> -1
is returned; if they are equal 0 is returned; if the current object is
larger than <em >ths</em> 1 is returned (see also <em >uCompare</em>).
<p>
<li> <strong >BigInt &exp(BigInt const &exponent)</strong>:<br/>
The current object is raised to the power <em >exponent</em>.
<p>
<li> <strong >BigInt expc(BigInt const &exponent) const</strong>:<br/>
The current object raised to the power <em >exponent</em> is returned.
<p>
<li> <strong >BigInt &expMod(BigInt const &exponent, BigInt const &mod)</strong>:<br/>
The current object is raised to the power <em >exponent</em> modulo <em >mod</em>.
<p>
<li> <strong >BigInt expModc(BigInt const &exponent, BigInt const &mod) const</strong>:<br/>
The current object raised to the power <em >exponent</em> modulo <em >mod</em> is
returned.
<p>
<li> <strong >BigInt &gcd(BigInt const &rhs)</strong>:<br/>
The greatest common divisor (gcd) of the current object and <em >rhs</em> is
assigned to the current object. To compute the least common multiple
(lcm) the following relationship can be used:
<pre>
lcm(a, b) = a * b / a.gcd(b)
</pre>
<p>
<li> <strong >BigInt gcdc(BigInt const &rhs) const</strong>:<br/>
The greatest common divisor (gcd) of the current object and <em >rhs</em> is
returned. To compute the least common multiple (lcm) the following
relationship can be used:
<pre>
lcm(a, b) = a * b / a.gcd(b)
</pre>
<p>
<li> <strong >bool hasBit(size_t index)</strong>:<br/>
<em >True</em> is returned if the bit at index position <em >index</em> has been
set, <em >false</em> otherwise.
<p>
<li> <strong >BigInt &inverseMod(BigInt const &mod)</strong>:<br/>
The inverse of the current object modulo <em >mod</em> is assigned to the
current object. This is the value <em >ret</em> for which the following
expression holds true:
<pre>
(*this * ret) % mod = 1
</pre>
<p>
<li> <strong >BigInt inverseModc(BigInt const &mod) const</strong>:<br/>
This inverse of the current object modulo <em >mod</em> is returned.
<p>
<li> <strong >bool isNegative() const</strong>:<br/>
Returns <em >true</em> if the current object contains a negative value.
<p>
<li> <strong >bool isOdd() const</strong>:<br/>
Returns <em >true</em> if the current object is an odd value.
<p>
<li> <strong >bool isOne() const</strong>:<br/>
Returns <em >true</em> if the current object equals one (1).
<p>
<li> <strong >BigInt &isqrt()</strong>:<br/>
The current object's integer square root value is assigned to the
current object. The integer square root of a value <em >x</em> is the
biggest integral value whose square does not exceed <em >x</em>. E.g.,
<em >isqrt(17) == 4</em>. An <em >Exception</em> exception is thrown if the current
object's value is smaller than one.
<p>
<li> <strong >BigInt isqrtc() const</strong>:<br/>
The integer square root of the current object is returned. An
<em >Exception</em> exception is thrown if the current object's value is smaller
than one.
<p>
<li> <strong >bool isZero() const</strong>:<br/>
Returns <em >true</em> if the current object equals zero (0).
<p>
<li> <strong >BigInt &lshift()</strong>:<br/>
The current object's bits are shifted one bit to the left. The object's
sign remains unaltered.
<p>
<li> <strong >BigInt lshiftc()</strong>:<br/>
The current object's bits shifted one bit to the left are returned. The
object's sign will be equal to the current object's sign.
<p>
<li> <strong >BigInt &lshift(size_t nBits)</strong>:<br/>
The current object's bits are shifted <em >nBits</em> to the left. The
object's sign remains unaltered.
<p>
<li> <strong >BigInt lshiftc(size_t nBits) const</strong>:<br/>
The current object's bits shifted <em >nBits</em> bit to the left are
returned. The object's sign will be equal to the current object's
sign.
<p>
<li> <strong >BigInt &maskBits(size_t lowerNBits)</strong>:<br/>
The current object's <em >lowerNBits</em> lower bits are kept, its
higher order bits are cleared. The object's sign is not affected.
<p>
<li> <strong >BigInt maskBitsc(size_t lowerNBits) const</strong>:<br/>
A copy of the current object is returned having all but its
<em >lowerNBits</em> lower bits cleared. The sign of the returned object
will be equal to the current object's sign.
<p>
<li> <strong >size_t maxWordIndex() const</strong>:<br/>
Returns the maximum <em >Word</em>-index that can be used with the <em >at</em>
and <em >setWord</em> members for the current <strong >BigInt</strong> value.
<p>
<li> <strong >BigInt &mulMod(BigInt const &rhs, BigInt const &mod)</strong>:<br/>
The current object is multiplied (modulo <em >mod</em>) by <em >rhs</em>.
<p>
<li> <strong >BigInt mulModc(BigInt const &rhs, BigInt const &mod) const</strong>:<br/>
The current object multiplied (modulo <em >mod</em>) by <em >rhs</em> is returned.
<p>
<li> <strong >BigInt &negate()</strong>:<br/>
The current object's value is negated (i.e., the value changes its
sign).
<p>
<li> <strong >BigInt negatec() const</strong>:<br/>
The negated value of the current object is returned.
<p>
<li> <strong >size_t nWords() const</strong>:<br/>
The number of `words' required to store the <strong >BigInt</strong> value is
returned. Note that the returned value depends on the architecture's
number of bytes per word. For 32-bit architectures there are four
bytes per word, for 64-bit architectures eight bytes per word.
<p>
<li> <strong >BigInt &rshift()</strong>:<br/>
The current object's bits are shifted one bit to the right. The object's
sign remains unaltered.
<p>
<li> <strong >BigInt rshiftc()</strong>:<br/>
The current object's bits shifted one bit to the right are returned. The
object's sign will be equal to the current object's sign.
<p>
<li> <strong >BigInt &rshift(size_t nBits)</strong>:<br/>
The current object's bits are shifted <em >nBits</em> to the right. The
object's sign remains unaltered.
<p>
<li> <strong >BigInt rshiftc(size_t nBits) const</strong>:<br/>
The current object's bits shifted <em >nBits</em> bit to the right are
returned. The object's sign will be equal to the current object's
sign.
<p>
<li> <strong >BigInt &setBit(size_t index)</strong>:<br/>
The bit at index position <em >index</em> is set.
<p>
<li> <strong >BigInt setBitc(size_t index) const</strong>:<br/>
A copy of the current object is returned having its bit at index
position <em >index</em> set.
<p>
<li> <strong >BigInt &setBit(size_t index, bool value)</strong>:<br/>
The bit at index position <em >index</em> is set to <em >value</em>.
<p>
<li> <strong >BigInt setBitc(size_t index, bool value) const</strong>:<br/>
A copy of the current object is returned having its bit at index
position <em >index</em> set to <em >value</em>.
<p>
<li> <strong >BigInt &setNegative(bool negative)</strong>:<br/>
The current object's sign will be set to negative if the function's
argument is <em >true</em>, it will be set to positive if the function's
argument is <em >false</em>.
<p>
<li> <strong >BigInt setNegativec(bool negative) const</strong>:<br/>
A copy of the current object is return having a negative sign if the
function's argument is <em >true</em> and a positive sign if the function's
argument is <em >false</em>.
<p>
<li> <strong >void setWord(size_t index, BigInt::Word value)</strong>:<br/>
Assigns <em >value</em> to the <em >Word</em> at <em >index</em>. E.g., on a 32 bit
architecture, if the <strong >BigInt</strong> value equals 2<sup >33</sup>, then
after <em >setWord(1, 1)</em> the value has become 2<sup >32</sup>. If <em >index</em>
exceeds the value returned by <em >nWords</em> an <em >FBB::Exception</em> is
thrown.
<p>
<li> <strong >size_t size() const</strong>:<br/>
The number of significant <em >bits</em> required to store the current
<em >BIGNUM</em> value is returned.
<p>
<li> <strong >size_t sizeInBytes() const</strong>:<br/>
The number of bytes required to store the current <em >BIGNUM</em> value is
returned (returns the same value as the <em >size</em> memeber does).
<p>
<li> <strong >size_t constexpr sizeOfWord() const</strong>:<br/>
<strong >BigInt</strong> values are stored in units of `words', which are unsigned
long values. These values may consist of, e.g., 32 or 64 bits. The
number of bytes occupied by a `word' is returned: 4 for a 32 bit
value, 8 for a 64 bit value, and possibly other values, depending on
specific architecture peculiarities. The value returned by this
member, therefore, is architecture dependent.
<p>
<li> <strong >BigInt &sqr()</strong>:<br/>
The current object's value is squared.
<p>
<li> <strong >BigInt sqrc() const</strong>:<br/>
The square of the current object is returned.
<p>
<li> <strong >BigInt &sqrMod(BigInt const &mod) const</strong>:<br/>
The current object's value is squared modulo <em >mod</em>.
<p>
<li> <strong >BigInt sqrModc(BigInt const &mod) const</strong>:<br/>
The square (modulo <em >mod</em>) of the current object is returned.
<p>
<li> <strong >BigInt &subMod(BigInt const &rhs, BigInt const &mod)</strong>:<br/>
<em >Rhs</em> is subtracted modulo <em >mod</em> from the current object.
<p>
<li> <strong >BigInt subModc(BigInt const &rhs, BigInt const &mod) const</strong>:<br/>
The difference (modulo <em >mod</em>) of the current object and <em >rhs</em> is
returned.
<p>
<li> <strong >void swap(BigInt &other)</strong>:<br/>
The current object swaps its value with <em >other</em>.
<p>
<li> <strong >BigInt &tildeBits()</strong>:<br/>
All the bits in
the bytes of the current object and the sign of the current object
are toggled.
So, after
<pre>
Bigint b(5);
b.tildeBits();
</pre>
<em >b</em> contains the value -250. Also see the discussion with
<em >operator~()</em> below.
<p>
<li> <strong >BigInt tildeBitsc() const</strong>:<br/>
A copy of the current object whose bits are toggled is returned.
<p>
<li> <strong >BigInt &tildeInt()</strong>:<br/>
The `tilde' operation is performed on the current object using the
standard <em >int</em> semantics. E.g., ~5 results in -6. Also see the
discussion with <em >operator~()</em> below.
<p>
<li> <strong >BigInt tildeIntc() const</strong>:<br/>
A copy of the current object is returned to which the `tilde' operation
has been performed using the standard <em >int</em> semantics.
<p>
<li> <strong >unsigned long ulong() const</strong>:<br/>
The absolute value stored in the current object is returned as an
unsigned long. If it cannot be represented by an unsigned long it
returns <em >0xffffffffL</em>.
<p>
<li> <strong >int uCompare(BigInt const &rsh) const</strong>:<br/>
Using absolute values, if the current object is smaller than <em >rhs</em> -1
is returned; if they are equal 0 is returned; if the current object is
larger than <em >ths</em> 1 is returned (see also <em >uCompare</em>).
</ul>
<p>
<h2 >OVERLOADED OPERATORS</h2>
<p>
Except for some operators all operators perform their intuitive
operations. Where that isn't completely true an explanatory remark is
provided. E.g., <em >operator*()</em> multiplies two <em >BigInt</em>s, possibly promoting
one of the operands; <em >operator*=()</em> multiplies the lhs by the rhs
<em >BigInt</em>, possibly promoting the rhs operand.
<p>
Here are the available operators:
<p>
<strong >Unary operators:</strong>
<p>
<ul>
<li> <strong >bool operator bool() const</strong>:<br/>
Returns <em >true</em> if the <em >BigInt</em> value is unequal zero, otherwise
<em >false</em> is returned.
<p>
<li> <strong >BigInt &operator++()</strong>:<br/>
<li> <strong >BigInt operator++(int)</strong>:<br/>
<li> <strong >BigInt &operator--()</strong>:<br/>
<li> <strong >BigInt operator--(int)</strong>:<br/>
<li> <strong >BigInt operator-()</strong>:<br/>
<li> <strong >int operator[](size_t idx) const</strong>:<br/>
With <em >BigInt</em> objects it returns the bit-value of the object's
<em >idx</em>th bit as the value 0 or 1.
<p>
<li> <strong >BigInt::Bit operator[](size_t idx)</strong>:<br/>
With non-const <em >BigInt</em> objects it returns a reference to the
bit-value of the object's <em >idx</em>th bit. When used as <em >lvalue</em>
assigning a 0 or non-zero value to the operator's return value will
either clear or set the bit. Likewise, the following arithmetic
assignment operators may be used: binary or (<em >|=</em>), binary and
(<em >&=</em>) or binary xor (<em >^=</em>). When used as <em >rvalue</em> the value of
the object's <em >idx</em>th bit is returned as a <em >bool</em> value. When
inseerted into a <em >std::ostream</em> the bit's value is displayed as 0 or
1.
<p>
<li> <strong >BigInt operator~()</strong>:<br/>
This operator is <em >not</em> implemented as it cannot be implemented so
that it matches the actions of this operator when applied to <em >int</em>
type values.
<p>
When used on <em >int</em> values this operator toggles all the <em >int</em>'s
bits. E.g., ~5 represents -6, and ~-6 again equals five. The -6 is the
result of the sign bit of <em >int</em> values. The obvious implementation
of <em >BigInt::operator~()</em> is to toggle all the value's bits and to
toggle its sign bit. For 5 this would result in -250: 5, being 101
(binary), fits in one byte, so ~5 becomes 11111010 (binary), which is
250. Its sign must be reversed as well, so it becomes -250. This
clearly differs from the value represented by the <em >int</em> constant ~5:
when constructing <em >BigInt(~5)</em>, the value -6 is obtained.
<p>
It is possible to change the implementation. E.g., after
<pre>
Bigint b(5);
b = ~b;
</pre>
<em >~b</em> could be implemented so that it results in the value -6. But
this too leads to unexpected results. While <em >5 & ~5 == 0</em>, this
would no longer hold true for <em >BigInt</em> objects: Assuming <em >b</em>
contains 5 then <em >b & ~b</em> would expand to (binary) <em >101 &
(negative)110</em> which equals (binary) 100.
<p>
Since either implementation produces unexpected results
<em >BigInt::operator~()</em> was not implemented. Instead two members are
offered: <em >tildeBits()</em>, toggling all the bits of all the
<em >BigInt</em> bytes and toggling its sign (so
<pre>
Bigint b(5);
b.tildeBits();
</pre>
changes <em >b</em>'s value into -250), and <em >tildeInt()</em> changing the
object's value into the value that would have been obtained if a
<em >BigInt</em> was a mere <em >int</em> (so
<pre>
Bigint b(5);
b.tildeInt();
</pre>
changes <em >b</em>'s value into -6).
</ul>
<p>
<strong >Binary operators:</strong>
<p>
<ul>
<li> <strong >BigInt operator*(BigInt const &lhs, BigInt const &rhs)</strong>:<br/>
<li> <strong >BigInt operator/(BigInt const &lhs, BigInt const &rhs)</strong>:<br/>
This operator returns the quotient of the <em >lhs</em> object divided by the
<em >rhs</em> object. The remainder is lost (The member <em >div</em> performs the
division and makes the remainder available as well).
<li> <strong >BigInt operator%(BigInt const &lhs, BigInt const &rhs)</strong>:<br/>
<li> <strong >BigInt operator+(BigInt const &lhs, BigInt const &rhs)</strong>:<br/>
<li> <strong >BigInt operator-(BigInt const &lhs, BigInt const &rhs)</strong>:<br/>
<li> <strong >BigInt operator<<(BigInt const &lhs, size_t nBits)</strong>:<br/>
See also the <em >lshift</em> members. If <em >lhs</em> is positive,
<li> <strong >BigInt operator>>=(BigInt const &lhs, size_t nBits)</strong>:<br/>
See also the <em >rshift</em> members.
<li> <strong >BigInt operator&(BigInt const &lhs, BigInt const &rhs)</strong>:<br/>
This operator returns a <em >BigInt</em> value consisting of the
<em >bit_and</em>-ed bits and sign flags of lhs and rhs
operands. Consequently, if one operand is positive, the resulting
value will be positive.
<li> <strong >BigInt operator|(BigInt const &lhs, BigInt const &rhs)</strong>:<br/>
This operator returns a <em >BigInt</em> value consisting of the
<em >bit_or</em>-ed bits and sign flags of lhs and rhs
operands. Consequently, if either operand is negative, the result will
be negative.
<li> <strong >BigInt operator^(BigInt const &lhs, BigInt const &rhs)</strong>:<br/>
This operator returns a <em >BigInt</em> value consisting of the
<em >bit_xor</em>-ed bits and sign flags of lhs and rhs
operands. Consequently, if exactly one operand is negative, the result
will be negative.
</ul>
<p>
<strong >(Arithmetic) assignment operator(s):</strong>
<p>
<ul>
<li> <strong >BigInt &operator=(BigInt const &rhs)</strong>:<br/>
<li> <strong >BigInt &operator*=(BigInt const &rhs)</strong>:<br/>
<li> <strong >BigInt &operator/=(BigInt const &rhs)</strong>:<br/>
This operator assigns the result of the (integer) division of the current
<em >BigInt</em> object by <em >ths</em> to the current object. The remainder is
lost. The member <em >div</em> divides and makes the remainder available as
well.
<li> <strong >BigInt &operator%=(BigInt const &rhs)</strong>:<br/>
<li> <strong >BigInt &operator+=(BigInt const &rhs)</strong>:<br/>
<li> <strong >BigInt &operator-=(BigInt const &rhs)</strong>:<br/>
<li> <strong >BigInt &operator<<=(size_t nBits)</strong>:<br/>
See also the <em >lshift</em> members.
<li> <strong >BigInt &operator>>=(size_t nBits)</strong>:<br/>
See also the <em >rshift</em> members.
<li> <strong >BigInt &operator&=(BigInt const &rhs)</strong>:<br/>
This operator <em >bit_and</em>s the bits and sign flags of the current
object and the rhs operand.
<li> <strong >BigInt &operator|=(BigInt const &rhs)</strong>:<br/>
This operator <em >bit_or</em>s the bits and sign flags of the current
object and the rhs operand.
<li> <strong >BigInt &operator^=(BigInt const &rhs)</strong>:<br/>
This operator <em >bit_xor</em>s the bits and sign flags of the current
object and the rhs operand.
</ul>
<p>
Note that the move operator is not available
<p>
<h2 >STATIC MEMBERS</h2>
<p>
All members returning a <em >BigInt</em> computed from a set of arguments and
not requiring an existing <em >BigInt</em> object are defined as static members.
<p>
<ul>
<li> <strong >BigInt fromText(std::string text, int mode = 0)</strong>:<br/>
This member converts a textual representation of a number to a
<em >BigInt</em> value. Conversion continues until the end of <em >text</em> or
until a character outside of an expected range is encountered.
<p>
The expected range may be preset by specifying <em >mode</em> as <em >ios::dec,
ios::oct,</em> or <em >ios::hex</em> or (the default) the expected range is
determined by <em >fromText</em> itself by inspecting the characters in
<em >text</em>.
<p>
By default if <em >text</em> contains hexadecimal characters then
<em >fromText</em> assumes that the number is represented as a hexadecimal
value (e.g., <em >"abc"</em> is converted to the (decimal) value 2748); if
<em >text</em> starts with 0 and contains only characters in the range 0
until (including) 7 then <em >fromText</em> assumes the number is
represented as an octal value (e.g., <em >"01234"</em> is converted to the
(decimal) value 668). Otherwise a decimal value is assumed.
<p>
If the text does not represent a valid numerical value (of the
given extraction mode) then a <em >FBB::Exception</em> exception is thrown
(<em >fromText: text does not represent a BigInt value</em>).
<p>
<li> <strong >BigInt rand(size_t size, Msb msb = MSB_IS_ONE, Lsb lsb = ODD)</strong>:<br/>
This member returns a cryptographically strong pseudo-random number
of <em >size</em> bits. The most significant bit(s) can be controlled by
<em >msb</em> (by default <strong >MSB_IS_ONE</strong>), the least significant bit can be
controlled by <em >lsb</em> (by default <strong >ODD</strong>). Before calling this
member the random number generator must have been seeded.
<p>
From the <strong >RAND_add</strong>(3ssl) man-page:
<p>
OpenSSL makes sure that the PRNG state is unique for each thread. On
systems that provide <em >/dev/urandom</em>, the randomness device is used
to seed the PRNG transparently. However, on all other systems, the
application is responsible for seeding the PRNG by calling
<strong >RAND_add</strong>(3ssl), <strong >RAND_egd</strong>(3ssl), <strong >RAND_load_file</strong>(3ssl), or
<strong >RAND_seed</strong>(3ssl).
<p>
<li> <strong >BigInt randRange(BigInt const &max)</strong>:<br/>
This member returns a cryptographically strong pseudo-random
number in the range <em >0 <= number < max</em>. Before calling this
member the random number generator must have been seeded (see also
<strong >rand</strong>, described above).
<p>
<li> <strong >BigInt setBigEndian(std::string const &bytes)</strong>:<br/>
The <em >bytes.length()</em> bytes of <em >bytes</em> are used to compute a
<em >BigInt</em> object which is returned by this function. The characters
in <em >bytes</em> are interpreted as a series of bytes in big-endian
order. See also the member function <em >bigEndian()</em> above. The
returned <em >BigInt</em> has a positive value.
<p>
<li> <strong >BigInt prime(size_t nBits,
BigInt const *mod = 0, BigInt const *rem = 0,
PrimeType primeType = ANY)</strong>:<br/>
This member returns a prime number of <em >bBits</em> bits. If both <em >mod</em>
and <em >rem</em> are non-zero, the condition prime % mod == rem.
(E.g., use <em >prime % mod == 1</em> in order to suit a given
generator). The parameter <em >primeType</em> can be <em >ANY</em>, <em >(prime - 1)
/ 2</em> may or may not be a prime. If it is <em >SAFE</em> then <em >(prime - 1)
/ 2</em> will be a (so-called <em >safe</em>) prime.
<p>
<li> <strong >BigInt pseudoRand(size_t size, Msb msb = MSB_IS_ONE, Lsb lsb =
ODD)</strong>:<br/>
This member returns a potentially predictable pseudo-random number of
<em >size</em> bits. The most significant bit(s) can be controlled by
<em >msb</em> (by default <strong >MSB_IS_ONE</strong>), the least significant bit can be
controlled by <em >lsb</em> (by default <strong >ODD</strong>). It can be used for
non-cryptographic purposes and for certain purposes in cryptographic
protocols, but usually not for key generation.
<p>
<li> <strong >BigInt pseudoRandRange(BigInt const &max)</strong>:<br/>
This member returns a potentially predictable pseudo-random
number in the range <em >0 <= number < max</em>.
</ul>
<p>
<h2 >FREE FUNCTIONS IN THE FBB NAMESPACE</h2>
<p>
<ul>
<li> <strong >std::ostream &operator<<(ostream &out, BigInt const &value)</strong>:<br/>
Inserts <em >value</em> into the provided <em >ostream</em>. If the <em >hex</em>
manipulator has been inserted into the stream before inserting the <em >BigInt</em>
value the value will be displayed as a hexadecimal value (without a leading
<em >0x</em>); if the <em >oct</em> manipulator has been inserted the value will be
represented as an octal value (starting with a 0). The value will be
displayed as a decimal value if the <em >dec</em> manipulator is active. If the
<em >BigInt</em> value is negative its value will be preceded by a minus
character.
<li> <strong >std::istream &operator>>(istream &in, BigInt &value)</strong>:<br/>
Extracts <em >value</em> from the provided <em >istream</em>. Depending on the
currently set extraction mode (<em >dec, oct,</em> or <em >hex</em>) the matching
set of characters will be extracted from <em >in</em> and converted to a
number which is stored in <em >value</em>. Extraction stops at EOF or at the
first character outside of the range of characters matching the
extraction mode. if no numerical characters were extracted the
stream's <em >failbit</em> is set. The extracted value may be preceded
by a minus character, resulting in an extracted negative value.
</ul>
<p>
<h2 >EXAMPLE</h2>
<pre>
#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;
}
</pre>
<p>
<h2 >FILES</h2>
<em >bobcat/bigint</em> - defines the class interface
<p>
<h2 >SEE ALSO</h2>
<strong >bobcat</strong>(7), <strong >diffiehellman</strong>(3bobcat),
<strong >RAND_add</strong>(3ssl), <strong >RAND_egd</strong>(3ssl),
<strong >RAND_load_file</strong>(3ssl), <strong >RAND_seed</strong>(3).
<p>
<h2 >BUGS</h2>
<p>
Sep/Oct 2013: due to a change in library handling by the linker
(cf. <a href="http://fedoraproject.org/wiki/UnderstandingDSOLinkChange">http://fedoraproject.org/wiki/UnderstandingDSOLinkChange</a> and
<a href="https://wiki.debian.org/ToolChain/DSOLinking">https://wiki.debian.org/ToolChain/DSOLinking</a>) libraries that are
indirectly required are no longer automatically linked to your program. With
<strong >BigInt</strong> this is <em >libcrypto</em>, which requires programs to link to both
<em >bobcat</em> and <em >crypto</em>.
<p>
<h2 >DISTRIBUTION FILES</h2>
<ul>
<li> <em >bobcat_4.08.02-x.dsc</em>: detached signature;
<li> <em >bobcat_4.08.02-x.tar.gz</em>: source archive;
<li> <em >bobcat_4.08.02-x_i386.changes</em>: change log;
<li> <em >libbobcat1_4.08.02-x_*.deb</em>: debian package holding the
libraries;
<li> <em >libbobcat1-dev_4.08.02-x_*.deb</em>: debian package holding the
libraries, headers and manual pages;
<li> <em >http://sourceforge.net/projects/bobcat</em>: public archive location;
</ul>
<p>
<h2 >BOBCAT</h2>
Bobcat is an acronym of `Brokken's Own Base Classes And Templates'.
<p>
<h2 >COPYRIGHT</h2>
This is free software, distributed under the terms of the
GNU General Public License (GPL).
<p>
<h2 >AUTHOR</h2>
Frank B. Brokken (<strong >f.b.brokken@rug.nl</strong>).
<p>
</body>
</html>
|