[Top] [Prev] [Next] [Bottom]
IPint adt - 'infinite' precision integer utility functions
include "keyring.m"
keyring:= load Keyring Keyring->PATH;
#infinite precision integers
IPint: adt
{
x: int;
#conversions
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;
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;
# create a random large integer
# using the accelerated generator
random: fn(minbits, maxbits: int): ref IPint;
#operations
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;
};
Description
The IPint adt provides the following integer manipulation functions required for cryptographic support in Limbo:
iptob64(i)
iptob64: fn(i: self ref IPint): string;
## returns base 64 string; nil on error.
The iptob64 function converts a large integer to a base 64 string for convenient transmission over a network connection.
b64toip(str)
b64toip: fn(str: string): ref IPint;
## returns nil on error.
The b64toip function performs the inverse operation of iptob64.
iptobytes(i)
iptobytes: fn(i: self ref IPint): array of byte;
## returns nil on error.
The iptobytes function converts a large integer to an array of bytes for faster communication to the kernel ssl device.
bytestoip
bytestoip: fn(buf: array of byte): ref IPint;
## returns nil on error.
The bytestoip function performs the inverse operation of iptobytes.
inttoip
inttoip: fn(i: int): ref IPint;
## returns nil on error.
The inttoip function creates a new large integer from an int.
iptoint
iptoint: fn(i: self ref IPint): int;
## returns converted integer; 0 on error.
The iptoint function converts a large integer to an int.
iptostr
iptostr: fn(i: self ref IPint, base: int): string;
## returns nil on error.
The iptostr function converts a large integer to a string in base base.
strtoip
strtoip: fn(str: string, base: int): ref IPint;
## returns nil on error.
The strtoip function converts a string in base base to a large integer.
random (minbits, maxbits)
random: fn(minbits, maxbits: int): ref IPint;
## returns nil on error.
The random function generates large random numbers with a range of minbits to maxbits. The maximum number allowed in the current implementation is 228192-1. The seed for the generator is obtained by dueling clocks. IPint types are manipulated during security protocols.
bits (i)
bits: fn(i: self ref IPint): int
The bits function returns the number of bits of precision in IPint.
expmod (base, exp, mod)
expmod: fn(base: self ref IPint, exp, mod: ref IPint):
ref IPint;
## returns nil on error.
The expmod function returns baseexp mod mod.
add
add: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
## returns nil on error.
The add function returns the sum of i1 and i2.
sub
sub: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
## returns nil on error.
The sub function returns the difference of i1 and i2.
mul
mul: fn(i1: self ref IPint, i2: ref IPint): ref IPint;
## returns nil on error.
The mul function returns the product of i1 and i2.
div
div: fn(i1: self ref IPint, i2: ref IPint):
(ref IPint, ref IPint);
## returns (nil, nil) on error.
The div function returns a tuple that represents the (quotient, remainder) of i1 divided by i2.
eq (i1, i2)
eq: fn(i1: self ref IPint, i2: ref IPint): int;
## returns 1 for equality; 0 otherwise.
The eq function is a simple comparison of two IPints, which returns 1 if the two are equal, 0 otherwise.
cmp
cmp: fn(i1: self ref IPint, i2: ref IPint): int;
The cmp function compares two large integers, returning 1 if i1 is larger and -1 if i2 is larger.
[Top] [Prev] [Next] [Bottom]
infernosupport@lucent.com
Copyright © 1997, Lucent Technologies, Inc.. All rights
reserved.