My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Macros | Typedefs | Functions
otz_tee_arith_api.h File Reference
#include <sw_types.h>
#include <sw_common_types.h>
#include <otz_tee_common.h>
#include <otz_tee_api.h>

Go to the source code of this file.

Macros

#define TEE_BigIntNumberOfBits   2048
 
#define TEE_BigIntSizeInU32(n)   (((n+31)/32)+2)
 
#define ARITH_ARRAY_LEN   66
 

Typedefs

typedef u32 TEE_BigInt
 
typedef u32 TEE_BigIntFMM
 
typedef u32 TEE_BigIntFMMContext
 

Functions

size_t TEE_BigIntFMMContextSizeInU32 (size_t ModuleSizeInBits)
 Returns the size of the array of uint32_t values needed to represent a fast modular context using a given modulus size. More...
 
TEE_Result TEE_BigIntInit (TEE_BigInt *bigInt, size_t len)
 Initializes bigInt and sets its represented value to zero. This function assumes that bigInt points to a memory area of len uint32_t. More...
 
TEE_Result TEE_BigIntFMMContextInit (TEE_BigIntFMMContext *context, size_t len, TEE_BigInt *modulus)
 
TEE_Result TEE_BigIntFMMInit (TEE_BigIntFMM *bigIntFMM, size_t len)
 Initializes bigIntFMM and sets its represented value to zero. This function assumes that bigIntFMM points to a memory area of len uint32_t. More...
 
TEE_Result TEE_BigIntSetFromOctetString (TEE_BigInt *dest, u32 *buffer, size_t bufferLen, int sign)
 Converts a bufferLen byte octet string buffer into a TEE_BigInt format. More...
 
TEE_Result TEE_BigIntConvertToOctetString (void *buffer, size_t *bufferLen, TEE_BigInt *bigInt)
 Converts the absolute value of an integer in TEE_BigInt format into an octet string. The octet string is written in a most significant byte first representation. More...
 
void TEE_BigIntConvertFromS32 (TEE_BigInt *dest, int shortVal)
 Sets *dest to the value shortVal. More...
 
TEE_Result TEE_BigIntConvertToS32 (int *dest, TEE_BigInt *src)
 Sets *dest to the value of src, including the sign of src. If src does not fit within an int32_t, the value of *dest is undefined. More...
 
int TEE_BigIntCmp (TEE_BigInt *op1, TEE_BigInt *op2)
 
int TEE_BigIntCmpS32 (TEE_BigInt *op1, int shortVal)
 Checks whether op1>shortVal, op1==shortVal, or op1<shortVal. More...
 
void TEE_BigIntRightShift (TEE_BigInt *dest, TEE_BigInt *src, size_t bits)
 Computes |dest| = |src| >> bits and dest will have the same sign as op. More...
 
int TEE_BigIntGetBit (TEE_BigInt *src, u32 bitIndex)
 Returns the bitIndexth bit of the natural binary representation of |src|. A true return value indicates a “1” and a false return value indicates a “0” in the bitIndexth position. More...
 
void TEE_BigIntAdd (TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2)
 Computes dest = op1 + op2. More...
 
void TEE_BigIntSub (TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2)
 Computes dest = op1 - op2. More...
 
void TEE_BigIntNeg (TEE_BigInt *dest, TEE_BigInt *src)
 Negates an operand: dest = -src. More...
 
void TEE_BigIntMult (TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2)
 Computes dest = op1 * op2. More...
 
void TEE_BigIntSquare (TEE_BigInt *dest, TEE_BigInt *src)
 Computes dest = src * src. More...
 
void TEE_BigIntDivide (TEE_BigInt *dest_q, TEE_BigInt *dest_r, TEE_BigInt *op1, TEE_BigInt *op2)
 Computes dest_r and dest_q such that op1 = dest_q * op2 + dest_r. It will round dest_q towards zero and dest_r will have the same sign as op1. More...
 
void TEE_BigIntReduceMod (TEE_BigInt *dest, TEE_BigInt *op, TEE_BigInt *n)
 
void TEE_BigIntAddMod (TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2, TEE_BigInt *n)
 Computes dest = op1 + op2 (mod n) More...
 
void TEE_BigIntSubMod (TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2, TEE_BigInt *n)
 Computes dest = op1 - op2 (mod n) More...
 
void TEE_BigIntMultMod (TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *src, TEE_BigInt *n)
 Computes dest = op1 * src (mod n) More...
 
void TEE_BigIntSquareMod (TEE_BigInt *dest, TEE_BigInt *src, TEE_BigInt *n)
 Computes dest = src * src (mod n) More...
 
void TEE_BigIntInvMod (TEE_BigInt *dest, TEE_BigInt *op, TEE_BigInt *n)
 Computes dest such that dest * op = 1 (mod n) More...
 
int TEE_BigIntRelativePrime (TEE_BigInt *op1, TEE_BigInt *op2)
 Determines whether gcd(op1, op2)==1. More...
 
void TEE_BigIntExtendedGcd (TEE_BigInt *gcd, TEE_BigInt *u, TEE_BigInt *v, TEE_BigInt *op1, TEE_BigInt *op2)
 Computes the greatest common divisor of the input parameters op1 and op2. Furthermore it computes the coefficients u and v such that u*op1+v*op2==gcd. More...
 
int TEE_BigIntIsProbablePrime (TEE_BigInt *op, u32 confidenceLevel)
 The TEE_BigIntIsProbablePrime function performs a probabilistic primality test on op. The parameter confidenceLevel is used to specify the probability of a non-conclusive answer. If the function cannot guarantee that op is prime or composite, it MUST iterate the test until the probability that op is composite is less than 2^(-confidenceLevel). Values smaller than 80 for confidenceLevel will not be recognized and will default to 80. The maximum honored value of confidenceLevel is implementation specific, but MUST be at least 80. More...
 
void TEE_BigInt2FMM (TEE_BigIntFMM *dest, TEE_BigInt *src, TEE_BigInt *n, TEE_BigIntFMMContext *context)
 
void TEE_BigIntFMM2BigInt (TEE_BigInt *dest, TEE_BigIntFMM *src, TEE_BigInt *n, TEE_BigIntFMMContext *context)
 
void TEE_BigIntFMMCompute (TEE_BigIntFMM *dest, TEE_BigIntFMM *op1, TEE_BigIntFMM *op2, TEE_BigInt *n, TEE_BigIntFMMContext *context)
 
size_t TEE_BigIntFMMSizeInU32 (size_t moduleSizeInBits)
 returns the size of the array of uint32_t values needed to represent an integer in the fast modular multiplication representation given the size of the modulus in bits More...
 
void TEE_BigIntAddMult (TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2)
 
u32 MaxBitPos (TEE_BigInt *src)
 
void TEE_BigIntLeftShift (TEE_BigInt *dest, TEE_BigInt *src, size_t bits)
 Computes |dest| = |src| >> bits. More...
 
void incrementBigInt (TEE_BigInt *dest)
 
int XPowerY (int x, int y)
 Computes X raised to the power of Y. More...
 

Macro Definition Documentation

#define ARITH_ARRAY_LEN   66
#define TEE_BigIntNumberOfBits   2048
#define TEE_BigIntSizeInU32 (   n)    (((n+31)/32)+2)

Typedef Documentation

typedef u32 TEE_BigInt
typedef u32 TEE_BigIntFMM
typedef u32 TEE_BigIntFMMContext

Function Documentation

void incrementBigInt ( TEE_BigInt dest)
Parameters
dest
u32 MaxBitPos ( TEE_BigInt src)
Parameters
src
Returns
void TEE_BigInt2FMM ( TEE_BigIntFMM dest,
TEE_BigInt src,
TEE_BigInt n,
TEE_BigIntFMMContext context 
)
Parameters
dest
src
n
context
void TEE_BigIntAdd ( TEE_BigInt dest,
TEE_BigInt op1,
TEE_BigInt op2 
)

Computes dest = op1 + op2.

Parameters
dest
op1
op2
void TEE_BigIntAddMod ( TEE_BigInt dest,
TEE_BigInt op1,
TEE_BigInt op2,
TEE_BigInt n 
)

Computes dest = op1 + op2 (mod n)

Parameters
dest
op1
op2
n
void TEE_BigIntAddMult ( TEE_BigInt dest,
TEE_BigInt op1,
TEE_BigInt op2 
)
Parameters
dest
op1
op2
int TEE_BigIntCmp ( TEE_BigInt op1,
TEE_BigInt op2 
)
Parameters
op1
op2
Returns
int TEE_BigIntCmpS32 ( TEE_BigInt op1,
int  shortVal 
)

Checks whether op1>shortVal, op1==shortVal, or op1<shortVal.

Parameters
op1
shortVal
Returns
void TEE_BigIntConvertFromS32 ( TEE_BigInt dest,
int  shortVal 
)

Sets *dest to the value shortVal.

Parameters
dest
shortVal
TEE_Result TEE_BigIntConvertToOctetString ( void *  buffer,
size_t bufferLen,
TEE_BigInt bigInt 
)

Converts the absolute value of an integer in TEE_BigInt format into an octet string. The octet string is written in a most significant byte first representation.

Parameters
buffer
bufferLen
bigInt
Returns
TEE_Result TEE_BigIntConvertToS32 ( int *  dest,
TEE_BigInt src 
)

Sets *dest to the value of src, including the sign of src. If src does not fit within an int32_t, the value of *dest is undefined.

Parameters
dest
src
Returns
void TEE_BigIntDivide ( TEE_BigInt dest_q,
TEE_BigInt dest_r,
TEE_BigInt op1,
TEE_BigInt op2 
)

Computes dest_r and dest_q such that op1 = dest_q * op2 + dest_r. It will round dest_q towards zero and dest_r will have the same sign as op1.

Parameters
dest_q
dest_r
op1
op2
void TEE_BigIntExtendedGcd ( TEE_BigInt gcd,
TEE_BigInt u,
TEE_BigInt v,
TEE_BigInt op1,
TEE_BigInt op2 
)

Computes the greatest common divisor of the input parameters op1 and op2. Furthermore it computes the coefficients u and v such that u*op1+v*op2==gcd.

Parameters
gcd
u
v
op1
op2
void TEE_BigIntFMM2BigInt ( TEE_BigInt dest,
TEE_BigIntFMM src,
TEE_BigInt n,
TEE_BigIntFMMContext context 
)
Parameters
dest
src
n
context
void TEE_BigIntFMMCompute ( TEE_BigIntFMM dest,
TEE_BigIntFMM op1,
TEE_BigIntFMM op2,
TEE_BigInt n,
TEE_BigIntFMMContext context 
)
Parameters
dest
op1
op2
n
context
TEE_Result TEE_BigIntFMMContextInit ( TEE_BigIntFMMContext context,
size_t  len,
TEE_BigInt modulus 
)
Parameters
context
len
modulus
Returns
size_t TEE_BigIntFMMContextSizeInU32 ( size_t  ModuleSizeInBits)

Returns the size of the array of uint32_t values needed to represent a fast modular context using a given modulus size.

Parameters
ModuleSizeInBits
Returns
TEE_Result TEE_BigIntFMMInit ( TEE_BigIntFMM bigIntFMM,
size_t  len 
)

Initializes bigIntFMM and sets its represented value to zero. This function assumes that bigIntFMM points to a memory area of len uint32_t.

Parameters
bigIntFMM
len
Returns
size_t TEE_BigIntFMMSizeInU32 ( size_t  moduleSizeInBits)

returns the size of the array of uint32_t values needed to represent an integer in the fast modular multiplication representation given the size of the modulus in bits

Parameters
moduleSizeInBits
Returns
int TEE_BigIntGetBit ( TEE_BigInt src,
u32  bitIndex 
)

Returns the bitIndexth bit of the natural binary representation of |src|. A true return value indicates a “1” and a false return value indicates a “0” in the bitIndexth position.

Parameters
src
bitIndex
Returns
TEE_Result TEE_BigIntInit ( TEE_BigInt bigInt,
size_t  len 
)

Initializes bigInt and sets its represented value to zero. This function assumes that bigInt points to a memory area of len uint32_t.

Parameters
bigInt
len
Returns
void TEE_BigIntInvMod ( TEE_BigInt dest,
TEE_BigInt op,
TEE_BigInt n 
)

Computes dest such that dest * op = 1 (mod n)

Parameters
dest
op
n
int TEE_BigIntIsProbablePrime ( TEE_BigInt op,
u32  confidenceLevel 
)

The TEE_BigIntIsProbablePrime function performs a probabilistic primality test on op. The parameter confidenceLevel is used to specify the probability of a non-conclusive answer. If the function cannot guarantee that op is prime or composite, it MUST iterate the test until the probability that op is composite is less than 2^(-confidenceLevel). Values smaller than 80 for confidenceLevel will not be recognized and will default to 80. The maximum honored value of confidenceLevel is implementation specific, but MUST be at least 80.

Parameters
op
confidenceLevel
Returns
void TEE_BigIntLeftShift ( TEE_BigInt dest,
TEE_BigInt src,
size_t  bits 
)

Computes |dest| = |src| >> bits.

Parameters
dest
src
bits
void TEE_BigIntMult ( TEE_BigInt dest,
TEE_BigInt op1,
TEE_BigInt op2 
)

Computes dest = op1 * op2.

Parameters
dest
op1
op2
destresult
op1operand 1
op2operand 2
void TEE_BigIntMultMod ( TEE_BigInt dest,
TEE_BigInt op1,
TEE_BigInt src,
TEE_BigInt n 
)

Computes dest = op1 * src (mod n)

Parameters
dest
op1
src
n
void TEE_BigIntNeg ( TEE_BigInt dest,
TEE_BigInt src 
)

Negates an operand: dest = -src.

Parameters
dest
src
void TEE_BigIntReduceMod ( TEE_BigInt dest,
TEE_BigInt op,
TEE_BigInt n 
)
Parameters
dest
op
n
int TEE_BigIntRelativePrime ( TEE_BigInt op1,
TEE_BigInt op2 
)

Determines whether gcd(op1, op2)==1.

Parameters
op1
op2
Returns
void TEE_BigIntRightShift ( TEE_BigInt dest,
TEE_BigInt src,
size_t  bits 
)

Computes |dest| = |src| >> bits and dest will have the same sign as op.

Parameters
dest
src
bits
TEE_Result TEE_BigIntSetFromOctetString ( TEE_BigInt dest,
u32 *  buffer,
size_t  bufferLen,
int  sign 
)

Converts a bufferLen byte octet string buffer into a TEE_BigInt format.

Parameters
dest
buffer
bufferLen
sign
Returns
void TEE_BigIntSquare ( TEE_BigInt dest,
TEE_BigInt src 
)

Computes dest = src * src.

Parameters
dest
src
void TEE_BigIntSquareMod ( TEE_BigInt dest,
TEE_BigInt src,
TEE_BigInt n 
)

Computes dest = src * src (mod n)

Parameters
dest
src
n
void TEE_BigIntSub ( TEE_BigInt dest,
TEE_BigInt op1,
TEE_BigInt op2 
)

Computes dest = op1 - op2.

Parameters
dest
op1
op2
void TEE_BigIntSubMod ( TEE_BigInt dest,
TEE_BigInt op1,
TEE_BigInt op2,
TEE_BigInt n 
)

Computes dest = op1 - op2 (mod n)

Parameters
dest
op1
op2
n
int XPowerY ( int  x,
int  y 
)

Computes X raised to the power of Y.

Parameters
x
y
Returns