num Struct Reference

#include <pk.h>

Collaboration diagram for num:

Collaboration graph

Detailed Description

Implementation of the arithmetic in various groups, rings, and fields.


Public Member Functions

Constructors and Destructors
 num ()
 Constructor.
 num (const num &x)
 Constructor used to duplicate a given num object.
 num (const num &x, const str &y)
 Constructor used to convert a str into a num object with specified parameters.
 num (int x)
 Constructor used to instantiate a new num object based on an integer.
 num (const FParms *p1)
 Constructor used to create new num with specified parameters.
 num (const str &x)
 Constructor used to convert a str into a num object.
 num (int type1, int len)
 Constructor used to created a new num object of specified type and size.
 ~num ()
 Destructor. Calls clear1().
Initializers and Manipulators
void setlen (int n)
 Set the length of this object in nwords.
void add (int n, const char *x)
 Load octet string into this object.
void mod2to (int n)
  Reduce this object modulo 2^n.
Assignment and Arithmetic Operators
void operator= (const FParms *p1)
 Assign parameters to this object.
void operator= (const num &x)
 Assignment operator for num objects.
num operator & (const FParms *p1) const
 Change this object's parameters, but not its value.
numoperator= (nword x)
 Assignment operator for nword.
numoperator= (int x)
 Assignment operator for int.
numoperator-= (int x)
 Decrement this object by a specified integer.
num operator- () const
 Negate this object.
num operator- (int x)
 Subtract an integer from this object.
num operator+ (const num &y) const
 Add a num object to this one.
num operator- (const num &y) const
 Subtract a num object from this one.
num operator * (int y) const
 Multiply this object by an integer.
num operator * (const num &y) const
 Multiply this num by another one.
num operator/ (int y) const
 Divide this num by an integer.
num operator/ (const num &x) const
 Divide this num by another num.
numoperator+= (const num &x)
 Increment this object by a specified value.
numoperator-= (const num &x)
 Decrement this object by a specified value.
int operator% (int k) const
 Compute this num's residue modulo a specified integer.
num operator^ (int n) const
 Raise this object's value to an integer exponent.
numoperator *= (int n)
 Multiply this num by an integer.
numoperator/= (int n)
 Divide this object by an integer.
Arithmetic Predicates
bool isNeg () const
 Predicate used to determine if this object is negative.
bool isNat () const
 Predicate used to determine if this object represents a natural number.
bool isMod () const
 Predicate used to determine if this object is a ring or field element.
bool isChar2 () const
 Predicate used to determine if this object is an element of a field of char 2.
bool isEven () const
 Predicate used to determine if this object is even.
bool isZero () const
 Predicate used to determine if this object is the zero element.
bool isPrime (int rounds=8) const
 Predicate used to test primality.
bool isIrred () const
 Predicate used to test irreducibility.
bool isMontg () const
 Predicate used to determine if this object is in its Montgomery representation.
int isSquare () const
 Predicate to test quadratic residuosity.
Operator Predicates
bool operator| (const num &y) const
 Predicate used to test whether a given num divides this one.
bool operator== (const num &y) const
 Predicate to test equality of two nums.
bool operator!= (const num &y) const
 Predicate to test inequality of two nums.
bool operator== (int n) const
 Predicate to test equality of this oject with an int.
bool operator!= (int n) const
 Predicate to test inequality of this oject with an int.
bool operator< (const num &y) const
 Predicate to test "less than" relation between two nums.
bool operator<= (const num &y) const
 Predicate to test "less than or equal to" relation between two nums.
bool operator> (const num &y) const
 Predicate to test "greater than" relation between two nums.
bool operator>= (const num &y) const
 Predicate to test "greater than or equal to" relation between two nums.
bool operator> (int n) const
 Predicate to test "greater than" relation with an int.
bool operator< (int n) const
 Predicate to test "less than" relation with an int.
bool operator<= (int n) const
 Predicate to test "less than or equal to" relation with an int.
bool operator>= (int n) const
 Predicate to test "greater than or equal to" relation with an int.
Arithmetic Functions
num abs () const
 Absolute value of this object.
num sqrt () const
 Calculate square root.
void mmult (const num &x, const num &y)
 Assign the product of two num objects to this one.
void divide (const num &y, num &quot, num &rem) const
 Divide this num by another.
num mod1 (const num &y, int deg=0) const
 Modular reduction.
num mod (const num &y, int deg=0) const
 Modular reduction. Alias for mod1().
num mod2 (const num &y) const
 Modular reduction.
num inverse () const
 Compute the inverse of this object (uses Euclidean Algorithm).
void power (const num &x, const num &y)
 Assign x^y to this object.
num reciprocal () const
 Invert this object.
void square ()
 Square this object.
void square (int k)
 Square this object a specified number of times.
void square (const num &x)
 Assign the square of another num to this object.
void mpower (const num &x, const num &y)
 Exponentiation: assign x^y to this object.
Inspectors
int bytes () const
 Get the length of this object's value in bytes.
int l () const
 Get the length of this object in nwords.
int bits () const
 Get the number of bits in this object's representation.
int bit (int k) const
 Get the kth bit of this object's value.
int byte (int k) const
 Get the kth element in the array of bytes representing this object's value.
nwordwd (int k)
 Get reference to kth nword in the representation of this object as an array of nwords.
nword w (int k) const
 Get kth nword in the representation of this object as an array of nwords.
const nwordwords () const
 Get a pointer to the array of nwords representing this object.
int degree () const
 Get object's degree.
int degf () const
 Get the degree of the underlying field extension in characteristic 2.
num modulus () const
 Get the characteristic of the underlying field.
num modulus2 () const
 Get the degree of the field extension in char 2.
const FParmsparms () const
 Get the parameters of the underlying group, ring, or field.
int checkModulus () const
 Test object's parameters.
Conversions
num toint () const
 Map this object to a natural number.
template<class T>
to (int n=0) const
 Convert this object to type T.
cdk::str tostr (int n=0) const
 Get a str representation of this object.


Constructor & Destructor Documentation

num ( const num x  )  [inline]

Constructor used to duplicate a given num object.

Parameters:
x num to duplicate in this object

num ( const num x,
const str y 
) [inline]

Constructor used to convert a str into a num object with specified parameters.

Parameters:
x num whose parameters are to be copied
y str to convert into this num object

num ( int  x  )  [inline]

Constructor used to instantiate a new num object based on an integer.

Parameters:
x int to be assigned to this new num object.

num ( const FParms p1  )  [inline]

Constructor used to create new num with specified parameters.

Parameters:
p1 parameters to use for this new num object.

num ( const str x  )  [explicit]

Constructor used to convert a str into a num object.

Parameters:
x str to be converted into this num.

num ( int  type1,
int  len 
) [inline]

Constructor used to created a new num object of specified type and size.

Parameters:
type1 one of FParms::Types
len size of num object to be created

~num (  )  [inline]

Destructor. Calls clear1().

Remarks:
Modifies: v (zeroized as v may have held a key), p


Member Function Documentation

num abs (  )  const

Absolute value of this object.

Returns:
a positive representation of this num with the same absolute value

void add ( int  n,
const char *  x 
) [inline]

Load octet string into this object.

Parameters:
n length of input array in nwords
x pointer to an octet string (base 256) to assign to this object.

int bit ( int  k  )  const [inline]

Get the kth bit of this object's value.

Parameters:
k the index of the bit to be returned
Returns:
the kth bit of this object's value

int bits (  )  const [inline]

Get the number of bits in this object's representation.

Returns:
1 plus the object's degree

int byte ( int  k  )  const [inline]

Get the kth element in the array of bytes representing this object's value.

Parameters:
k index of byte to return
Returns:
the kth byte of the num

int bytes (  )  const [inline]

Get the length of this object's value in bytes.

Returns:
the size of the num in bytes

int checkModulus (  )  const

Test object's parameters.

Returns:
0, if the object's parameters are prime/irreducible
non-zero, otherwise

int degf (  )  const [inline]

Get the degree of the underlying field extension in characteristic 2.

Returns:
the degree of the field extension containing this object

int degree (  )  const [inline]

Get object's degree.

Returns:
the degree of this object

void divide ( const num y,
num quot,
num rem 
) const

Divide this num by another.

Parameters:
y num by which to divide this object
quot buffer which is to receive quotient
rem buffer which is to receive remainder

num inverse (  )  const

Compute the inverse of this object (uses Euclidean Algorithm).

Returns:
a num containing the inverse of this object

bool isChar2 (  )  const [inline]

Predicate used to determine if this object is an element of a field of char 2.

Returns:
true, if type is Char2
false, otherwise

bool isEven (  )  const [inline]

Predicate used to determine if this object is even.

Returns:
true, if object is even
false, otherwise

bool isIrred (  )  const

Predicate used to test irreducibility.

Returns:
true, if this object is irreducible
false, otherwise

bool isMod (  )  const [inline]

Predicate used to determine if this object is a ring or field element.

Returns:
true, if type is Modular
false, otherwise

bool isMontg (  )  const [inline]

Predicate used to determine if this object is in its Montgomery representation.

Returns:
true, if this object is in its Montgomery representation
false, otherwise

bool isNat (  )  const [inline]

Predicate used to determine if this object represents a natural number.

Returns:
true, if type is Natural
false, otherwise

bool isNeg (  )  const [inline]

Predicate used to determine if this object is negative.

Returns:
true, if type is Negative
false, otherwise

bool isPrime ( int  rounds = 8  )  const

Predicate used to test primality.

Parameters:
rounds number of Miller-Rabin rounds to run
Returns:
true, if this object passes the test (i.e., is a probable prime)
false, if this object is composite

int isSquare (  )  const

Predicate to test quadratic residuosity.

Returns:
+1 if this is a square mod p

bool isZero (  )  const [inline]

Predicate used to determine if this object is the zero element.

Returns:
true, if object is the additive identity
false otherwise

int l (  )  const [inline]

Get the length of this object in nwords.

Returns:
the length of this object in nwords

void mmult ( const num x,
const num y 
)

Assign the product of two num objects to this one.

Parameters:
x multiplicand
y multiplier
Remarks:
This object receives the value x * y.

num mod ( const num y,
int  deg = 0 
) const [inline]

Modular reduction. Alias for mod1().

Parameters:
y modulus
deg 0 for char p; degree of the field extension in char 2
Returns:
this object reduced modulo y

num mod1 ( const num y,
int  deg = 0 
) const

Modular reduction.

Parameters:
y modulus
deg 0 for char p; degree of the field extension in char 2
Returns:
this reduced mod y

num mod2 ( const num y  )  const [inline]

Modular reduction.

Parameters:
y modulus
Returns:
this object reduced modulo y

void mod2to ( int  n  ) 

Assign a power of 2 to this object.

Parameters:
n exponent to which 2 is to be raised before storing in this object.

num modulus (  )  const

Get the characteristic of the underlying field.

Returns:
the characteristic of the underlying field (a large prime)

num modulus2 (  )  const

Get the degree of the field extension in char 2.

Returns:
the degree of the field extension in char 2

void mpower ( const num x,
const num y 
)

Exponentiation: assign x^y to this object.

Parameters:
x base
y exponent

num operator & ( const FParms p1  )  const

Change this object's parameters, but not its value.

Parameters:
p1 pointer to new parameters to use this num object.

num operator * ( const num y  )  const

Multiply this num by another one.

Parameters:
y num by which to multiply this num
Returns:
a num representing this object's value * y's value

num operator * ( int  y  )  const

Multiply this object by an integer.

Parameters:
y int by which this object is to be multiplied
Returns:
a num representing this object's value times y

num& operator *= ( int  n  ) 

Multiply this num by an integer.

Parameters:
n integer multiplier
Returns:
a reference to this object

bool operator!= ( int  n  )  const [inline]

Predicate to test inequality of this oject with an int.

Parameters:
n int to which this object is to be compared
Returns:
true, if this object is not equal to n
false, otherwise

bool operator!= ( const num y  )  const [inline]

Predicate to test inequality of two nums.

Parameters:
y num to which this object is to be compared
Returns:
true, if this object is not equal to y
false, otherwise

int operator% ( int  k  )  const

Compute this num's residue modulo a specified integer.

Parameters:
k modulus
Returns:
remainder obtained by dividing this object by k

num operator+ ( const num y  )  const

Add a num object to this one.

Parameters:
y the num to added to this object.
Returns:
a num representing this object's value plus y's value

num& operator+= ( const num x  ) 

Increment this object by a specified value.

Parameters:
x num to add to this one
Returns:
a reference to this object

num operator- ( const num y  )  const

Subtract a num object from this one.

Parameters:
y the num to subtracted from this object.
Returns:
a num representing this object's value minus y's value

num operator- ( int  x  )  [inline]

Subtract an integer from this object.

Parameters:
x int to be subtracted from this object.
Returns:
a num representing this object's value minus x

num operator- (  )  const

Negate this object.

Returns:
a negated copy of this object
Remarks:
If this object represents A, then a num representing -A is returned.

num& operator-= ( const num x  ) 

Decrement this object by a specified value.

Parameters:
x num to subtract from this one
Returns:
a reference to this object

num& operator-= ( int  x  )  [inline]

Decrement this object by a specified integer.

Parameters:
x int to be subtracted from this object.
Returns:
a reference to this object

num operator/ ( const num x  )  const [inline]

Divide this num by another num.

Parameters:
x divisor
Returns:
a num representing this object's value divided by x's value

num operator/ ( int  y  )  const

Divide this num by an integer.

Parameters:
y the integer divisor
Returns:
a num representing this object's value divided by y

num& operator/= ( int  n  ) 

Divide this object by an integer.

Parameters:
n int divisor
Returns:
a reference to this object

bool operator< ( int  n  )  const [inline]

Predicate to test "less than" relation with an int.

Parameters:
n int to which this object is to be compared
Returns:
true, if this object is less than n
false, otherwise

bool operator< ( const num y  )  const

Predicate to test "less than" relation between two nums.

Parameters:
y num to which this object is to be compared
Returns:
true, if this object is less than y
false, otherwise

bool operator<= ( int  n  )  const [inline]

Predicate to test "less than or equal to" relation with an int.

Parameters:
n int to which this object is to be compared
Returns:
true, if this object is less than or equal to n
false, otherwise

bool operator<= ( const num y  )  const

Predicate to test "less than or equal to" relation between two nums.

Parameters:
y num to which this object is to be compared
Returns:
true, if this object is less than or equal to y
false, otherwise

num& operator= ( int  x  ) 

Assignment operator for int.

Parameters:
x int to be assigned to this object.
Returns:
a reference to this object

num& operator= ( nword  x  ) 

Assignment operator for nword.

Parameters:
x nword to to be assigned to this object.
Returns:
a reference to this object

void operator= ( const num x  )  [inline]

Assignment operator for num objects.

Parameters:
x num to copy into this num object.

void operator= ( const FParms p1  )  [inline]

Assign parameters to this object.

Parameters:
p1 new parameters to use for this object.

bool operator== ( int  n  )  const

Predicate to test equality of this oject with an int.

Parameters:
n int to which this object is to be compared
Returns:
true, if this object is equal to n
false, otherwise

bool operator== ( const num y  )  const

Predicate to test equality of two nums.

Parameters:
y num to which this object is to be compared
Returns:
true, if this object is equal to y
false, otherwise

bool operator> ( int  n  )  const [inline]

Predicate to test "greater than" relation with an int.

Parameters:
n int to which this object is to be compared
Returns:
true, if this object is greater than n
false, otherwise

bool operator> ( const num y  )  const [inline]

Predicate to test "greater than" relation between two nums.

Parameters:
y num to which this object is to be compared
Returns:
true, if this object is greater than y
false, otherwise

bool operator>= ( int  n  )  const

Predicate to test "greater than or equal to" relation with an int.

Parameters:
n int to which this object is to be compared
Returns:
true, if this object is greater than or equal to n
false, otherwise

bool operator>= ( const num y  )  const [inline]

Predicate to test "greater than or equal to" relation between two nums.

Parameters:
y num to which this object is to be compared
Returns:
true, if this object is greater than or equal to y
false, otherwise

num operator^ ( int  n  )  const

Raise this object's value to an integer exponent.

Parameters:
n exponent
Returns:
a num = this ^ n if n < 1000 (if n >= 1000 an assertion occurs)

bool operator| ( const num y  )  const [inline]

Predicate used to test whether a given num divides this one.

Parameters:
y divisor
Returns:
true, if y divides this object
false, otherwise

const FParms* parms (  )  const [inline]

Get the parameters of the underlying group, ring, or field.

Returns:
a pointer to this object's parameters

void power ( const num x,
const num y 
)

Assign x^y to this object.

Parameters:
x the base
y the exponent

num reciprocal (  )  const

Invert this object.

Returns:
a num containing the reciprocal of this object

void setlen ( int  n  )  [inline]

Set the length of this object in nwords.

Parameters:
n the number of nwords to use for this num.
Remarks:
WARNING: This call is dangerous!

num sqrt (  )  const

Calculate square root.

Returns:
the square root of this object

void square ( const num x  )  [inline]

Assign the square of another num to this object.

Parameters:
x the num to be squared

void square ( int  k  ) 

Square this object a specified number of times.

Parameters:
k number of times to square this object

T to ( int  n = 0  )  const

Convert this object to type T.

Parameters:
n minimum size of output in bytes
Returns:
a type T represenation of this object (typically a str representation with leading 0's removed)

num toint (  )  const

Map this object to a natural number.

Returns:
a num containing this object's value but without parameter information

cdk::str tostr ( int  n = 0  )  const

Get a str representation of this object.

Parameters:
n the minimum length of the str to be created
Returns:
a (binary) str representation of the value of this num

nword w ( int  k  )  const [inline]

Get kth nword in the representation of this object as an array of nwords.

Parameters:
k index of nword to return
Returns:
the kth nword

nword& wd ( int  k  )  [inline]

Get reference to kth nword in the representation of this object as an array of nwords.

Parameters:
k index of nword to return
Returns:
a reference to the kth nword

const nword* words (  )  const [inline]

Get a pointer to the array of nwords representing this object.

Returns:
a reference to the array of nwords stored in this Nat object


The documentation for this struct was generated from the following file:
ISC Cryptographic Development Kit - User's Guide
ISC website
Questions? E-mail ISC technical support
Copyright© 2002-2006 Information Security Corp. All rights reserved.