KEYRING-IPINT(2) System Calls Manual KEYRING-IPINT(2)

keyring: IPint - `infinite' precision integer utility functions

include "keyring.m"
keyring:= load Keyring Keyring->PATH;
IPint: adt
{

iptob64: fn(i: self ref IPint): string;
b64toip: fn(str: string) : ref IPint;
iptobytes: fn(i: self ref IPint): array of byte;
bytestoip: fn(buf: array of byte): ref IPint;
iptobebytes: fn(i: self ref IPint): array of byte;
bebytestoip: fn(buf: array of byte): ref IPint;
inttoip: fn(i: int): ref IPint;
iptoint: fn(i: self ref IPint): int;
iptostr: fn(i: self ref IPint, base: int): string;
strtoip: fn(str: string, base: int): ref IPint;
random: fn(minbits, maxbits: int): ref IPint;
copy: fn(i: self ref IPint): ref IPint;
bits: fn(i: self ref IPint): int;
expmod: fn(base: self ref IPint, exp, mod: ref IPint):ref IPint;
add: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
sub: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
neg: fn(i: self ref IPint): ref IPint;
mul: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
div: fn(i1: self ref IPint, i2: ref IPint): (ref IPint, ref IPint);
eq: fn(i1: self ref IPint, i2: ref IPint): int;
cmp: fn(i1: self ref IPint, i2: ref IPint): int;
shl: fn(i: self ref IPint, n: int): ref IPint;
shr: fn(i: self ref IPint, n: int): ref IPint;
and: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
ori: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
not: fn(i: self ref IPint): ref IPint;
xor: fn(i1: self ref IPint, i2: ref IPint): ref IPint; };

IPint provides the following arbitrary-length integer manipulation functions required for cryptographic support in Limbo:

Returns a string that represents a large integer textually in base 64 for convenient transmission over a network connection.
Returns the IPint represented by the base-64 encoded str.
Returns an array of bytes representing a large integer. The representation includes both positive and negative numbers.
The inverse operation of iptobytes.
Returns an array of bytes in big-endian format representing the magnitude of a large integer; used for instance to pass a value to ssl (3). Only non-negative numbers are represented.
The inverse operation of iptobebytes.
Creates a new large integer from integer i.
Converts a large integer i to an int; returns 0 on error.
Converts a large integer to a string in base base; returns nil on error. Only the bases 10, 16, 32, and 64 are supported. Anything else defaults to 16.
Converts a string str representing a number in in base base to a large integer; returns nil on error. Only the bases 10, 16, 32, and 64 are supported.
Returns a large random number with length from minbits to maxbits. The largest number allowed in the current implementation is 2^8192-1 . The seed for the generator is obtained by duelling clocks.
Returns a reference to the same value as i.
Returns the number of bits of precision of i.
Returns (base**exp) mod mod.
Returns (i1+i2).
Returns (i1-i2).
Returns i1*i2.
Returns (i1/i2, i1modi2).
Returns 1 if i1 and i2 are equal; 0 otherwise.
Compares two large integers, returning 1 if i1 is larger, -1 if i2 is larger, and 0 if they are equal.
Returns i<<n
Returns i>>n
Returns i&n, bitwise AND
Returns i|n, bitwise inclusive-OR (it is ori because plain or is a Limbo keyword)
Returns ~i, bitwise ones-complement
Returns i^n, bitwise exclusive-OR