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 (void const *bn_str, size_t strlen, BigNum *bn)
 Deserializes a BigNum from a string. More...
 
EpidStatus WriteBigNum (BigNum const *bn, size_t strlen, void const *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 BigNumMod (BigNum const *a, BigNum const *b, BigNum *r)
 Computes modular reduction for BigNum value by specified modulus. 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

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

Adds two BigNum values.

Parameters
[in]aThe left hand parameter.
[in]bThe right hand parameter.
[out]rThe result of adding a and b.
Returns
EpidStatus
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
EpidStatus BigNumMul ( BigNum const *  a,
BigNum const *  b,
BigNum r 
)

Multiplies two BigNum values.

Parameters
[in]aThe left hand parameter.
[in]bThe right hand parameter.
[out]rThe result of multiplying a and b.
Returns
EpidStatus
EpidStatus BigNumSub ( BigNum const *  a,
BigNum const *  b,
BigNum r 
)

Subtracts two BigNum values.

Parameters
[in]aThe left hand parameter.
[in]bThe right hand parameter.
[out]rThe result of subtracting a and b.
Returns
EpidStatus
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
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
EpidStatus ReadBigNum ( void const *  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
EpidStatus WriteBigNum ( BigNum const *  bn,
size_t  strlen,
void const *  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