bignum

Big number operations. More...

Typedefs

typedef struct BigNum BigNum
 Internal representation of large numbers.
 

Functions

EpidStatus NewBigNum (size_t data_size_bytes, BigNum **bignum)
 Constructs a new BigNum. More...
 
void DeleteBigNum (BigNum **bignum)
 Deletes a previously allocated BigNum. More...
 
EpidStatus ReadBigNum (ConstOctStr bn_str, size_t strlen, BigNum *bn)
 Deserializes a BigNum from a string. More...
 
EpidStatus WriteBigNum (BigNum const *bn, size_t strlen, OctStr bn_str)
 Serializes a BigNum to a string. More...
 
EpidStatus BigNumAdd (BigNum const *a, BigNum const *b, BigNum *r)
 Adds two BigNum values. More...
 
EpidStatus BigNumSub (BigNum const *a, BigNum const *b, BigNum *r)
 Subtracts two BigNum values. More...
 
EpidStatus BigNumMul (BigNum const *a, BigNum const *b, BigNum *r)
 Multiplies two BigNum values. More...
 
EpidStatus BigNumDiv (BigNum const *a, BigNum const *b, BigNum *q, BigNum *r)
 Divides two BigNum values. More...
 
EpidStatus BigNumMod (BigNum const *a, BigNum const *b, BigNum *r)
 Computes modular reduction for BigNum value by specified modulus. More...
 
EpidStatus BigNumIsEven (BigNum const *a, bool *is_even)
 Checks if a BigNum is even. More...
 
EpidStatus BigNumIsZero (BigNum const *a, bool *is_zero)
 Checks if a BigNum is zero. More...
 
EpidStatus BigNumPow2N (unsigned int n, BigNum *r)
 Raises 2 to the given power. More...
 

Detailed Description

Big number operations.

This module provides an API for working with large numbers. BigNums represent non-negative integers.

Each BigNum variable represents a number of a byte-size set when the variable was created. BigNum variables cannot be re-sized after they are created.

Function Documentation

◆ BigNumAdd()

EpidStatus BigNumAdd ( BigNum const *  a,
BigNum const *  b,
BigNum r 
)

Adds two BigNum values.

Parameters
[in]aThe first operand to be added.
[in]bThe second operand to be added.
[out]rThe result of adding a and b.
Returns
EpidStatus

◆ BigNumDiv()

EpidStatus BigNumDiv ( BigNum const *  a,
BigNum const *  b,
BigNum q,
BigNum r 
)

Divides two BigNum values.

Note
Only needed for Intel(R) EPID 1.1 verification.
Parameters
[in]aDividend parameter.
[in]bDivisor parameter.
[out]qQuotient of result.
[out]rRemainder of result.
Returns
EpidStatus

◆ BigNumIsEven()

EpidStatus BigNumIsEven ( BigNum const *  a,
bool is_even 
)

Checks if a BigNum is even.

Parameters
[in]aThe BigNum to check.
[out]is_evenThe result of the check.
Returns
EpidStatus

◆ BigNumIsZero()

EpidStatus BigNumIsZero ( BigNum const *  a,
bool is_zero 
)

Checks if a BigNum is zero.

Parameters
[in]aThe BigNum to check.
[out]is_zeroThe result of the check.
Returns
EpidStatus

◆ BigNumMod()

EpidStatus BigNumMod ( BigNum const *  a,
BigNum const *  b,
BigNum r 
)

Computes modular reduction for BigNum value by specified modulus.

Parameters
[in]aThe BigNum value.
[in]bThe modulus.
[out]rModular reduction result.
Returns
EpidStatus

◆ BigNumMul()

EpidStatus BigNumMul ( BigNum const *  a,
BigNum const *  b,
BigNum r 
)

Multiplies two BigNum values.

Parameters
[in]aThe first operand to be multiplied.
[in]bThe second operand to be multiplied.
[out]rThe result of multiplying a and b.
Returns
EpidStatus

◆ BigNumPow2N()

EpidStatus BigNumPow2N ( unsigned int  n,
BigNum r 
)

Raises 2 to the given power.

Parameters
[in]nThe power.
[out]rThe result of 2^n.
Returns
EpidStatus

◆ BigNumSub()

EpidStatus BigNumSub ( BigNum const *  a,
BigNum const *  b,
BigNum r 
)

Subtracts two BigNum values.

Parameters
[in]aThe first operand to use in subtraction.
[in]bThe second operand to use in subtraction.
[out]rThe result of subtracting a and b.
Returns
EpidStatus

◆ DeleteBigNum()

void DeleteBigNum ( BigNum **  bignum)

Deletes a previously allocated BigNum.

Frees memory pointed to by bignum. Nulls the pointer.

Parameters
[in]bignumThe BigNum. Can be NULL.
See also
NewBigNum

◆ NewBigNum()

EpidStatus NewBigNum ( size_t  data_size_bytes,
BigNum **  bignum 
)

Constructs a new BigNum.

Allocates memory and creates a new BigNum.

Use DeleteBigNum() to free memory.

Parameters
[in]data_size_bytesThe size in bytes of the new number.
[out]bignumThe BigNum.
Returns
EpidStatus
See also
DeleteBigNum

◆ ReadBigNum()

EpidStatus ReadBigNum ( ConstOctStr  bn_str,
size_t  strlen,
BigNum bn 
)

Deserializes a BigNum from a string.

Parameters
[in]bn_strThe serialized value.
[in]strlenThe size of bn_str in bytes.
[out]bnThe target BigNum.
Returns
EpidStatus

◆ WriteBigNum()

EpidStatus WriteBigNum ( BigNum const *  bn,
size_t  strlen,
OctStr  bn_str 
)

Serializes a BigNum to a string.

Parameters
[in]bnThe BigNum to be serialized.
[in]strlenThe size of bn_str in bytes.
[out]bn_strThe target string.
Returns
EpidStatus