My Project
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
otz_tee_arith_api.h
Go to the documentation of this file.
1 /*
2  * OpenVirtualization:
3  * For additional details and support contact developer@sierraware.com.
4  * Additional documentation can be found at www.openvirtualization.org
5  *
6  * Copyright (C) 2010-2014 SierraWare
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  */
23 /*
24  * ARITHMETIC API implementation
25  *
26  */
27 #ifndef OTZ_TEE_ARITH_API_H
28 #define OTZ_TEE_ARITH_API_H
29 
30 #include <sw_types.h>
31 #include <sw_common_types.h>
32 #include <otz_tee_common.h>
33 #include <otz_tee_api.h>
34 
35 #define TEE_BigIntNumberOfBits 2048
36 #define TEE_BigIntSizeInU32(n) (((n+31)/32)+2)
37 #define ARITH_ARRAY_LEN 66
38 
39 
40 //#ifndef ARM_ARCH_ARMV7
41 //typedef enum __TEE_Result TEE_Result;
42 //#endif
43 
44 //typedef unsigned int u32;
45 //Arithmetic Data Types
46 typedef u32 TEE_BigInt;
47 typedef u32 TEE_BigIntFMM;
49 
50 //Memory allocations and sizeof() functions
51 
59 size_t TEE_BigIntFMMContextSizeInU32(size_t ModuleSizeInBits);
60 
69 TEE_Result TEE_BigIntInit(TEE_BigInt *bigInt, size_t len);
70 
81 
90 TEE_Result TEE_BigIntFMMInit(TEE_BigIntFMM* bigIntFMM, size_t len);
91 //Convertion Functions
92 
103 TEE_Result TEE_BigIntSetFromOctetString(TEE_BigInt *dest, u32 *buffer, size_t bufferLen, int sign);
104 
114 TEE_Result TEE_BigIntConvertToOctetString(void* buffer, size_t *bufferLen, TEE_BigInt* bigInt);
115 
122 void TEE_BigIntConvertFromS32(TEE_BigInt* dest, int shortVal);
123 
133 
142 int TEE_BigIntCmp(TEE_BigInt* op1, TEE_BigInt* op2);
143 
152 int TEE_BigIntCmpS32(TEE_BigInt* op1, int shortVal);
153 
161 void TEE_BigIntRightShift(TEE_BigInt* dest, TEE_BigInt* src, size_t bits);
162 
171 int TEE_BigIntGetBit(TEE_BigInt* src, u32 bitIndex);
172 
180 void TEE_BigIntAdd(TEE_BigInt* dest, TEE_BigInt* op1, TEE_BigInt* op2);
181 
189 void TEE_BigIntSub(TEE_BigInt* dest, TEE_BigInt* op1, TEE_BigInt* op2);
190 
197 void TEE_BigIntNeg(TEE_BigInt* dest, TEE_BigInt* src);
198 
206 void TEE_BigIntMult(TEE_BigInt* dest, TEE_BigInt* op1, TEE_BigInt* op2);
207 
214 void TEE_BigIntSquare(TEE_BigInt* dest, TEE_BigInt* src);
215 
224 void TEE_BigIntDivide(TEE_BigInt* dest_q, TEE_BigInt* dest_r, TEE_BigInt* op1, TEE_BigInt* op2);
225 
234 
243 void TEE_BigIntAddMod(TEE_BigInt* dest, TEE_BigInt* op1, TEE_BigInt* op2, TEE_BigInt* n);
244 
253 void TEE_BigIntSubMod(TEE_BigInt* dest, TEE_BigInt* op1, TEE_BigInt* op2, TEE_BigInt* n);
254 
263 void TEE_BigIntMultMod(TEE_BigInt* dest, TEE_BigInt* op1, TEE_BigInt* src, TEE_BigInt* n);
264 
273 
281 void TEE_BigIntInvMod(TEE_BigInt* dest, TEE_BigInt* op, TEE_BigInt* n);
282 
292 
303 
312 int TEE_BigIntIsProbablePrime(TEE_BigInt* op, u32 confidenceLevel);
313 
323 
333 
344 
352 size_t TEE_BigIntFMMSizeInU32(size_t moduleSizeInBits);
353 
361 void TEE_BigIntAddMult(TEE_BigInt* dest, TEE_BigInt* op1, TEE_BigInt* op2);
362 
370 u32 MaxBitPos(TEE_BigInt* src);
371 
379 void TEE_BigIntLeftShift(TEE_BigInt* dest, TEE_BigInt* src, size_t bits);
380 
386 void incrementBigInt(TEE_BigInt* dest);
387 
396 int XPowerY(int x, int y);
397 
398 #endif
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 a...
Definition: otz_tee_arith_api.c:492
u32 TEE_BigInt
Definition: otz_tee_arith_api.h:46
void TEE_BigIntLeftShift(TEE_BigInt *dest, TEE_BigInt *src, size_t bits)
Computes |dest| = |src| >> bits.
Definition: otz_tee_arith_api.c:427
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.
Definition: otz_tee_arith_api.c:117
int XPowerY(int x, int y)
Computes X raised to the power of Y.
Definition: otz_tee_arith_api.c:475
void TEE_BigIntFMM2BigInt(TEE_BigInt *dest, TEE_BigIntFMM *src, TEE_BigInt *n, TEE_BigIntFMMContext *context)
Definition: otz_tee_arith_api.c:686
void TEE_BigIntSub(TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2)
Computes dest = op1 - op2.
Definition: otz_tee_arith_api.c:303
void TEE_BigIntSquareMod(TEE_BigInt *dest, TEE_BigInt *src, TEE_BigInt *n)
Computes dest = src * src (mod n)
Definition: otz_tee_arith_api.c:586
int TEE_BigIntIsProbablePrime(TEE_BigInt *op, u32 confidenceLevel)
The TEE_BigIntIsProbablePrime function performs a probabilistic primality test on op...
Definition: otz_tee_arith_api.c:655
void TEE_BigIntAddMult(TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2)
Definition: otz_tee_arith_api.c:283
TEE_Result TEE_BigIntFMMInit(TEE_BigIntFMM *bigIntFMM, size_t len)
Initializes bigIntFMM and sets its represented value to zero. This function assumes that bigIntFMM po...
Definition: otz_tee_arith_api.c:101
void TEE_BigIntAdd(TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2)
Computes dest = op1 + op2.
Definition: otz_tee_arith_api.c:246
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...
Definition: otz_tee_arith_api.c:632
void TEE_BigIntFMMCompute(TEE_BigIntFMM *dest, TEE_BigIntFMM *op1, TEE_BigIntFMM *op2, TEE_BigInt *n, TEE_BigIntFMMContext *context)
Definition: otz_tee_arith_api.c:703
void TEE_BigIntAddMod(TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2, TEE_BigInt *n)
Computes dest = op1 + op2 (mod n)
Definition: otz_tee_arith_api.c:545
void TEE_BigIntReduceMod(TEE_BigInt *dest, TEE_BigInt *op, TEE_BigInt *n)
Definition: otz_tee_arith_api.c:532
void TEE_BigIntMultMod(TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *src, TEE_BigInt *n)
Computes dest = op1 * src (mod n)
Definition: otz_tee_arith_api.c:573
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 m...
Definition: otz_tee_arith_api.c:41
int TEE_BigIntCmpS32(TEE_BigInt *op1, int shortVal)
Checks whether op1>shortVal, op1==shortVal, or op1<shortVal.
Definition: otz_tee_arith_api.c:197
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...
Definition: otz_tee_arith_api.c:181
void TEE_BigIntConvertFromS32(TEE_BigInt *dest, int shortVal)
Sets *dest to the value shortVal.
Definition: otz_tee_arith_api.c:165
void incrementBigInt(TEE_BigInt *dest)
Definition: otz_tee_arith_api.c:454
TEE_Result TEE_BigIntFMMContextInit(TEE_BigIntFMMContext *context, size_t len, TEE_BigInt *modulus)
Definition: otz_tee_arith_api.c:84
int TEE_BigIntRelativePrime(TEE_BigInt *op1, TEE_BigInt *op2)
Determines whether gcd(op1, op2)==1.
Definition: otz_tee_arith_api.c:614
void TEE_BigIntSubMod(TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2, TEE_BigInt *n)
Computes dest = op1 - op2 (mod n)
Definition: otz_tee_arith_api.c:559
void TEE_BigIntMult(TEE_BigInt *dest, TEE_BigInt *op1, TEE_BigInt *op2)
Computes dest = op1 * op2.
Definition: otz_tee_arith_api.c:371
void TEE_BigIntNeg(TEE_BigInt *dest, TEE_BigInt *src)
Negates an operand: dest = -src.
Definition: otz_tee_arith_api.c:265
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 t...
Definition: otz_tee_arith_api.c:70
void TEE_BigIntSquare(TEE_BigInt *dest, TEE_BigInt *src)
Computes dest = src * src.
Definition: otz_tee_arith_api.c:393
void TEE_BigIntInvMod(TEE_BigInt *dest, TEE_BigInt *op, TEE_BigInt *n)
Computes dest such that dest * op = 1 (mod n)
Definition: otz_tee_arith_api.c:599
u32 TEE_BigIntFMM
Definition: otz_tee_arith_api.h:47
u32 MaxBitPos(TEE_BigInt *src)
Definition: otz_tee_arith_api.c:324
uint32_t TEE_Result
Definition: otz_tee_api.h:87
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.
Definition: otz_tee_arith_api.c:145
int TEE_BigIntGetBit(TEE_BigInt *src, u32 bitIndex)
Returns the bitIndexth bit of the natural binary representation of |src|. A true return value indicat...
Definition: otz_tee_arith_api.c:350
void TEE_BigInt2FMM(TEE_BigIntFMM *dest, TEE_BigInt *src, TEE_BigInt *n, TEE_BigIntFMMContext *context)
Definition: otz_tee_arith_api.c:670
u32 TEE_BigIntFMMContext
Definition: otz_tee_arith_api.h:48
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 g...
Definition: otz_tee_arith_api.c:55
int TEE_BigIntCmp(TEE_BigInt *op1, TEE_BigInt *op2)
Definition: otz_tee_arith_api.c:397
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.
Definition: otz_tee_arith_api.c:223