xref: /optee_os/lib/libutee/include/tee_internal_api.h (revision cd3a8cae93ab8e60a786bbabd60ecf14aaffdaae)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2014, STMicroelectronics International N.V.
4  */
5 
6 /* Based on GP TEE Internal API Specification Version 0.27 */
7 #ifndef TEE_INTERNAL_API_H
8 #define TEE_INTERNAL_API_H
9 
10 #ifdef __TEE_API_COMPAT_H
11 #error "<tee_api_compat.h> must not be included before <tee_internal_api.h>"
12 #endif
13 
14 #include <compiler.h>
15 #include <stddef.h>
16 #include <tee_api_defines.h>
17 #include <tee_api_types.h>
18 #include <trace.h>
19 
20 /* Property access functions */
21 
22 TEE_Result TEE_GetPropertyAsString(TEE_PropSetHandle propsetOrEnumerator,
23 				   const char *name, char *valueBuffer,
24 				   size_t *valueBufferLen);
25 TEE_Result __GP11_TEE_GetPropertyAsString(TEE_PropSetHandle propsetOrEnumerator,
26 					  const char *name, char *valueBuffer,
27 					  uint32_t *valueBufferLen);
28 
29 TEE_Result TEE_GetPropertyAsBool(TEE_PropSetHandle propsetOrEnumerator,
30 				 const char *name, bool *value);
31 
32 TEE_Result TEE_GetPropertyAsU32(TEE_PropSetHandle propsetOrEnumerator,
33 				const char *name, uint32_t *value);
34 
35 TEE_Result TEE_GetPropertyAsU64(TEE_PropSetHandle propsetOrEnumerator,
36 				const char *name, uint64_t *value);
37 
38 TEE_Result TEE_GetPropertyAsBinaryBlock(TEE_PropSetHandle propsetOrEnumerator,
39 					const char *name, void *valueBuffer,
40 					size_t *valueBufferLen);
41 TEE_Result
42 __GP11_TEE_GetPropertyAsBinaryBlock(TEE_PropSetHandle propsetOrEnumerator,
43 				    const char *name, void *valueBuffer,
44 				    uint32_t *valueBufferLen);
45 
46 TEE_Result TEE_GetPropertyAsUUID(TEE_PropSetHandle propsetOrEnumerator,
47 				 const char *name, TEE_UUID *value);
48 
49 TEE_Result TEE_GetPropertyAsIdentity(TEE_PropSetHandle propsetOrEnumerator,
50 				     const char *name, TEE_Identity *value);
51 
52 TEE_Result TEE_AllocatePropertyEnumerator(TEE_PropSetHandle *enumerator);
53 
54 void TEE_FreePropertyEnumerator(TEE_PropSetHandle enumerator);
55 
56 void TEE_StartPropertyEnumerator(TEE_PropSetHandle enumerator,
57 				 TEE_PropSetHandle propSet);
58 
59 void TEE_ResetPropertyEnumerator(TEE_PropSetHandle enumerator);
60 
61 TEE_Result TEE_GetPropertyName(TEE_PropSetHandle enumerator,
62 			       void *nameBuffer, size_t *nameBufferLen);
63 TEE_Result __GP11_TEE_GetPropertyName(TEE_PropSetHandle enumerator,
64 				      void *nameBuffer,
65 				      uint32_t *nameBufferLen);
66 
67 TEE_Result TEE_GetNextProperty(TEE_PropSetHandle enumerator);
68 
69 /* System API - Misc */
70 
71 void TEE_Panic(TEE_Result panicCode);
72 
73 /* System API - Internal Client API */
74 
75 TEE_Result TEE_OpenTASession(const TEE_UUID *destination,
76 			     uint32_t cancellationRequestTimeout,
77 			     uint32_t paramTypes,
78 			     TEE_Param params[TEE_NUM_PARAMS],
79 			     TEE_TASessionHandle *session,
80 			     uint32_t *returnOrigin);
81 TEE_Result __GP11_TEE_OpenTASession(const TEE_UUID *destination,
82 				    uint32_t cancellationRequestTimeout,
83 				    uint32_t paramTypes,
84 				    __GP11_TEE_Param params[TEE_NUM_PARAMS],
85 				    TEE_TASessionHandle *session,
86 				    uint32_t *returnOrigin);
87 
88 void TEE_CloseTASession(TEE_TASessionHandle session);
89 
90 TEE_Result TEE_InvokeTACommand(TEE_TASessionHandle session,
91 			       uint32_t cancellationRequestTimeout,
92 			       uint32_t commandID, uint32_t paramTypes,
93 			       TEE_Param params[TEE_NUM_PARAMS],
94 			       uint32_t *returnOrigin);
95 TEE_Result __GP11_TEE_InvokeTACommand(TEE_TASessionHandle session,
96 				      uint32_t cancellationRequestTimeout,
97 				      uint32_t commandID, uint32_t paramTypes,
98 				      __GP11_TEE_Param params[TEE_NUM_PARAMS],
99 				      uint32_t *returnOrigin);
100 
101 /* System API - Cancellations */
102 
103 bool TEE_GetCancellationFlag(void);
104 
105 bool TEE_UnmaskCancellation(void);
106 
107 bool TEE_MaskCancellation(void);
108 
109 /* System API - Memory Management */
110 
111 TEE_Result TEE_CheckMemoryAccessRights(uint32_t accessFlags, void *buffer,
112 				       size_t size);
113 TEE_Result __GP11_TEE_CheckMemoryAccessRights(uint32_t accessFlags,
114 					      void *buffer, uint32_t size);
115 
116 void TEE_SetInstanceData(const void *instanceData);
117 
118 const void *TEE_GetInstanceData(void);
119 
120 void *TEE_Malloc(uint32_t size, uint32_t hint);
121 
122 void *TEE_Realloc(void *buffer, uint32_t newSize);
123 
124 void TEE_Free(void *buffer);
125 
126 void *TEE_MemMove(void *dest, const void *src, uint32_t size);
127 
128 /*
129  * Note: TEE_MemCompare() has a constant-time implementation (execution time
130  * does not depend on buffer content but only on buffer size). It is the main
131  * difference with memcmp().
132  */
133 int32_t TEE_MemCompare(const void *buffer1, const void *buffer2, uint32_t size);
134 
135 void TEE_MemFill(void *buff, uint32_t x, uint32_t size);
136 
137 /* Data and Key Storage API  - Generic Object Functions */
138 
139 void TEE_GetObjectInfo(TEE_ObjectHandle object, TEE_ObjectInfo *objectInfo);
140 void __GP11_TEE_GetObjectInfo(TEE_ObjectHandle object,
141 			      __GP11_TEE_ObjectInfo *objectInfo);
142 
143 TEE_Result TEE_GetObjectInfo1(TEE_ObjectHandle object,
144 			      TEE_ObjectInfo *objectInfo);
145 TEE_Result __GP11_TEE_GetObjectInfo1(TEE_ObjectHandle object,
146 				     __GP11_TEE_ObjectInfo *objectInfo);
147 
148 void TEE_RestrictObjectUsage(TEE_ObjectHandle object, uint32_t objectUsage);
149 TEE_Result TEE_RestrictObjectUsage1(TEE_ObjectHandle object,
150 				    uint32_t objectUsage);
151 
152 TEE_Result TEE_GetObjectBufferAttribute(TEE_ObjectHandle object,
153 					uint32_t attributeID, void *buffer,
154 					uint32_t *size);
155 
156 TEE_Result TEE_GetObjectValueAttribute(TEE_ObjectHandle object,
157 				       uint32_t attributeID, uint32_t *a,
158 				       uint32_t *b);
159 
160 void TEE_CloseObject(TEE_ObjectHandle object);
161 
162 /* Data and Key Storage API  - Transient Object Functions */
163 
164 TEE_Result TEE_AllocateTransientObject(TEE_ObjectType objectType,
165 				       uint32_t maxKeySize,
166 				       TEE_ObjectHandle *object);
167 
168 void TEE_FreeTransientObject(TEE_ObjectHandle object);
169 
170 void TEE_ResetTransientObject(TEE_ObjectHandle object);
171 
172 TEE_Result TEE_PopulateTransientObject(TEE_ObjectHandle object,
173 				       const TEE_Attribute *attrs,
174 				       uint32_t attrCount);
175 TEE_Result __GP11_TEE_PopulateTransientObject(TEE_ObjectHandle object,
176 					      const __GP11_TEE_Attribute *attrs,
177 					      uint32_t attrCount);
178 
179 void TEE_InitRefAttribute(TEE_Attribute *attr, uint32_t attributeID,
180 			  const void *buffer, uint32_t length);
181 void __GP11_TEE_InitRefAttribute(__GP11_TEE_Attribute *attr,
182 				 uint32_t attributeID,
183 				 const void *buffer, uint32_t length);
184 
185 void TEE_InitValueAttribute(TEE_Attribute *attr, uint32_t attributeID,
186 			    uint32_t a, uint32_t b);
187 void __GP11_TEE_InitValueAttribute(__GP11_TEE_Attribute *attr,
188 				   uint32_t attributeID,
189 				   uint32_t a, uint32_t b);
190 
191 void TEE_CopyObjectAttributes(TEE_ObjectHandle destObject,
192 			      TEE_ObjectHandle srcObject);
193 
194 TEE_Result TEE_CopyObjectAttributes1(TEE_ObjectHandle destObject,
195 				     TEE_ObjectHandle srcObject);
196 
197 TEE_Result TEE_GenerateKey(TEE_ObjectHandle object, uint32_t keySize,
198 			   const TEE_Attribute *params, uint32_t paramCount);
199 TEE_Result __GP11_TEE_GenerateKey(TEE_ObjectHandle object, uint32_t keySize,
200 				  const __GP11_TEE_Attribute *params,
201 				  uint32_t paramCount);
202 
203 /* Data and Key Storage API  - Persistent Object Functions */
204 
205 TEE_Result TEE_OpenPersistentObject(uint32_t storageID, const void *objectID,
206 				    uint32_t objectIDLen, uint32_t flags,
207 				    TEE_ObjectHandle *object);
208 
209 TEE_Result TEE_CreatePersistentObject(uint32_t storageID, const void *objectID,
210 				      uint32_t objectIDLen, uint32_t flags,
211 				      TEE_ObjectHandle attributes,
212 				      const void *initialData,
213 				      uint32_t initialDataLen,
214 				      TEE_ObjectHandle *object);
215 
216 void TEE_CloseAndDeletePersistentObject(TEE_ObjectHandle object);
217 
218 TEE_Result TEE_CloseAndDeletePersistentObject1(TEE_ObjectHandle object);
219 
220 TEE_Result TEE_RenamePersistentObject(TEE_ObjectHandle object,
221 				      const void *newObjectID,
222 				      uint32_t newObjectIDLen);
223 
224 TEE_Result TEE_AllocatePersistentObjectEnumerator(TEE_ObjectEnumHandle *
225 						  objectEnumerator);
226 
227 void TEE_FreePersistentObjectEnumerator(TEE_ObjectEnumHandle objectEnumerator);
228 
229 void TEE_ResetPersistentObjectEnumerator(TEE_ObjectEnumHandle objectEnumerator);
230 
231 TEE_Result TEE_StartPersistentObjectEnumerator(TEE_ObjectEnumHandle
232 					       objectEnumerator,
233 					       uint32_t storageID);
234 
235 TEE_Result TEE_GetNextPersistentObject(TEE_ObjectEnumHandle objectEnumerator,
236 				       TEE_ObjectInfo *objectInfo,
237 				       void *objectID, uint32_t *objectIDLen);
238 TEE_Result
239 __GP11_TEE_GetNextPersistentObject(TEE_ObjectEnumHandle objectEnumerator,
240 				   __GP11_TEE_ObjectInfo *objectInfo,
241 				   void *objectID, uint32_t *objectIDLen);
242 
243 /* Data and Key Storage API  - Data Stream Access Functions */
244 
245 TEE_Result TEE_ReadObjectData(TEE_ObjectHandle object, void *buffer,
246 			      uint32_t size, uint32_t *count);
247 
248 TEE_Result TEE_WriteObjectData(TEE_ObjectHandle object, const void *buffer,
249 			       uint32_t size);
250 
251 TEE_Result TEE_TruncateObjectData(TEE_ObjectHandle object, uint32_t size);
252 
253 TEE_Result TEE_SeekObjectData(TEE_ObjectHandle object, int32_t offset,
254 			      TEE_Whence whence);
255 
256 /* Cryptographic Operations API - Generic Operation Functions */
257 
258 TEE_Result TEE_AllocateOperation(TEE_OperationHandle *operation,
259 				 uint32_t algorithm, uint32_t mode,
260 				 uint32_t maxKeySize);
261 
262 void TEE_FreeOperation(TEE_OperationHandle operation);
263 
264 void TEE_GetOperationInfo(TEE_OperationHandle operation,
265 			  TEE_OperationInfo *operationInfo);
266 
267 TEE_Result
268 TEE_GetOperationInfoMultiple(TEE_OperationHandle operation,
269 			     TEE_OperationInfoMultiple *operationInfoMultiple,
270 			     uint32_t *operationSize);
271 
272 void TEE_ResetOperation(TEE_OperationHandle operation);
273 
274 TEE_Result TEE_SetOperationKey(TEE_OperationHandle operation,
275 			       TEE_ObjectHandle key);
276 
277 TEE_Result TEE_SetOperationKey2(TEE_OperationHandle operation,
278 				TEE_ObjectHandle key1, TEE_ObjectHandle key2);
279 
280 void TEE_CopyOperation(TEE_OperationHandle dstOperation,
281 		       TEE_OperationHandle srcOperation);
282 
283 TEE_Result TEE_IsAlgorithmSupported(uint32_t algId, uint32_t element);
284 
285 /* Cryptographic Operations API - Message Digest Functions */
286 
287 void TEE_DigestUpdate(TEE_OperationHandle operation,
288 		      const void *chunk, uint32_t chunkSize);
289 
290 TEE_Result TEE_DigestDoFinal(TEE_OperationHandle operation, const void *chunk,
291 			     uint32_t chunkLen, void *hash, uint32_t *hashLen);
292 
293 /* Cryptographic Operations API - Symmetric Cipher Functions */
294 
295 void TEE_CipherInit(TEE_OperationHandle operation, const void *IV,
296 		    uint32_t IVLen);
297 
298 TEE_Result TEE_CipherUpdate(TEE_OperationHandle operation, const void *srcData,
299 			    uint32_t srcLen, void *destData, uint32_t *destLen);
300 
301 TEE_Result TEE_CipherDoFinal(TEE_OperationHandle operation,
302 			     const void *srcData, uint32_t srcLen,
303 			     void *destData, uint32_t *destLen);
304 
305 /* Cryptographic Operations API - MAC Functions */
306 
307 void TEE_MACInit(TEE_OperationHandle operation, const void *IV,
308 		 uint32_t IVLen);
309 
310 void TEE_MACUpdate(TEE_OperationHandle operation, const void *chunk,
311 		   uint32_t chunkSize);
312 
313 TEE_Result TEE_MACComputeFinal(TEE_OperationHandle operation,
314 			       const void *message, uint32_t messageLen,
315 			       void *mac, uint32_t *macLen);
316 
317 TEE_Result TEE_MACCompareFinal(TEE_OperationHandle operation,
318 			       const void *message, uint32_t messageLen,
319 			       const void *mac, uint32_t macLen);
320 
321 /* Cryptographic Operations API - Authenticated Encryption Functions */
322 
323 TEE_Result TEE_AEInit(TEE_OperationHandle operation, const void *nonce,
324 		      uint32_t nonceLen, uint32_t tagLen, uint32_t AADLen,
325 		      uint32_t payloadLen);
326 
327 void TEE_AEUpdateAAD(TEE_OperationHandle operation, const void *AADdata,
328 		     uint32_t AADdataLen);
329 
330 TEE_Result TEE_AEUpdate(TEE_OperationHandle operation, const void *srcData,
331 			uint32_t srcLen, void *destData, uint32_t *destLen);
332 
333 TEE_Result TEE_AEEncryptFinal(TEE_OperationHandle operation,
334 			      const void *srcData, uint32_t srcLen,
335 			      void *destData, uint32_t *destLen, void *tag,
336 			      uint32_t *tagLen);
337 
338 TEE_Result TEE_AEDecryptFinal(TEE_OperationHandle operation,
339 			      const void *srcData, uint32_t srcLen,
340 			      void *destData, uint32_t *destLen, void *tag,
341 			      uint32_t tagLen);
342 
343 /* Cryptographic Operations API - Asymmetric Functions */
344 
345 TEE_Result TEE_AsymmetricEncrypt(TEE_OperationHandle operation,
346 				 const TEE_Attribute *params,
347 				 uint32_t paramCount, const void *srcData,
348 				 uint32_t srcLen, void *destData,
349 				 uint32_t *destLen);
350 TEE_Result __GP11_TEE_AsymmetricEncrypt(TEE_OperationHandle operation,
351 					const __GP11_TEE_Attribute *params,
352 					uint32_t paramCount,
353 					const void *srcData, uint32_t srcLen,
354 					void *destData, uint32_t *destLen);
355 
356 TEE_Result TEE_AsymmetricDecrypt(TEE_OperationHandle operation,
357 				 const TEE_Attribute *params,
358 				 uint32_t paramCount, const void *srcData,
359 				 uint32_t srcLen, void *destData,
360 				 uint32_t *destLen);
361 TEE_Result __GP11_TEE_AsymmetricDecrypt(TEE_OperationHandle operation,
362 					const __GP11_TEE_Attribute *params,
363 					uint32_t paramCount,
364 					const void *srcData, uint32_t srcLen,
365 					void *destData, uint32_t *destLen);
366 
367 TEE_Result TEE_AsymmetricSignDigest(TEE_OperationHandle operation,
368 				    const TEE_Attribute *params,
369 				    uint32_t paramCount, const void *digest,
370 				    uint32_t digestLen, void *signature,
371 				    uint32_t *signatureLen);
372 TEE_Result __GP11_TEE_AsymmetricSignDigest(TEE_OperationHandle operation,
373 					   const __GP11_TEE_Attribute *params,
374 					   uint32_t paramCount,
375 					   const void *digest,
376 					   uint32_t digestLen, void *signature,
377 					   uint32_t *signatureLen);
378 
379 TEE_Result TEE_AsymmetricVerifyDigest(TEE_OperationHandle operation,
380 				      const TEE_Attribute *params,
381 				      uint32_t paramCount, const void *digest,
382 				      uint32_t digestLen, const void *signature,
383 				      uint32_t signatureLen);
384 TEE_Result __GP11_TEE_AsymmetricVerifyDigest(TEE_OperationHandle operation,
385 					     const __GP11_TEE_Attribute *params,
386 					     uint32_t paramCount,
387 					     const void *digest,
388 					     uint32_t digestLen,
389 					     const void *signature,
390 					     uint32_t signatureLen);
391 
392 /* Cryptographic Operations API - Key Derivation Functions */
393 
394 void TEE_DeriveKey(TEE_OperationHandle operation,
395 		   const TEE_Attribute *params, uint32_t paramCount,
396 		   TEE_ObjectHandle derivedKey);
397 void __GP11_TEE_DeriveKey(TEE_OperationHandle operation,
398 			  const __GP11_TEE_Attribute *params,
399 			  uint32_t paramCount, TEE_ObjectHandle derivedKey);
400 
401 /* Cryptographic Operations API - Random Number Generation Functions */
402 
403 void TEE_GenerateRandom(void *randomBuffer, uint32_t randomBufferLen);
404 
405 /* Date & Time API */
406 
407 void TEE_GetSystemTime(TEE_Time *time);
408 
409 TEE_Result TEE_Wait(uint32_t timeout);
410 
411 TEE_Result TEE_GetTAPersistentTime(TEE_Time *time);
412 
413 TEE_Result TEE_SetTAPersistentTime(const TEE_Time *time);
414 
415 void TEE_GetREETime(TEE_Time *time);
416 
417 /* TEE Arithmetical API - Memory allocation and size of objects */
418 
419 uint32_t TEE_BigIntFMMSizeInU32(uint32_t modulusSizeInBits);
420 
421 uint32_t TEE_BigIntFMMContextSizeInU32(uint32_t modulusSizeInBits);
422 
423 /* TEE Arithmetical API - Initialization functions */
424 
425 void TEE_BigIntInit(TEE_BigInt *bigInt, uint32_t len);
426 
427 void TEE_BigIntInitFMMContext(TEE_BigIntFMMContext *context, uint32_t len,
428 			      const TEE_BigInt *modulus);
429 
430 void TEE_BigIntInitFMM(TEE_BigIntFMM *bigIntFMM, uint32_t len);
431 
432 /* TEE Arithmetical API - Converter functions */
433 
434 TEE_Result TEE_BigIntConvertFromOctetString(TEE_BigInt *dest,
435 					    const uint8_t *buffer,
436 					    uint32_t bufferLen,
437 					    int32_t sign);
438 
439 TEE_Result TEE_BigIntConvertToOctetString(uint8_t *buffer, uint32_t *bufferLen,
440 					  const TEE_BigInt *bigInt);
441 
442 void TEE_BigIntConvertFromS32(TEE_BigInt *dest, int32_t shortVal);
443 
444 TEE_Result TEE_BigIntConvertToS32(int32_t *dest, const TEE_BigInt *src);
445 
446 /* TEE Arithmetical API - Logical operations */
447 
448 int32_t TEE_BigIntCmp(const TEE_BigInt *op1, const TEE_BigInt *op2);
449 
450 int32_t TEE_BigIntCmpS32(const TEE_BigInt *op, int32_t shortVal);
451 
452 void TEE_BigIntShiftRight(TEE_BigInt *dest, const TEE_BigInt *op,
453 			  size_t bits);
454 
455 bool TEE_BigIntGetBit(const TEE_BigInt *src, uint32_t bitIndex);
456 
457 uint32_t TEE_BigIntGetBitCount(const TEE_BigInt *src);
458 
459 void TEE_BigIntAdd(TEE_BigInt *dest, const TEE_BigInt *op1,
460 		   const TEE_BigInt *op2);
461 
462 void TEE_BigIntSub(TEE_BigInt *dest, const TEE_BigInt *op1,
463 		   const TEE_BigInt *op2);
464 
465 void TEE_BigIntNeg(TEE_BigInt *dest, const TEE_BigInt *op);
466 
467 void TEE_BigIntMul(TEE_BigInt *dest, const TEE_BigInt *op1,
468 		   const TEE_BigInt *op2);
469 
470 void TEE_BigIntSquare(TEE_BigInt *dest, const TEE_BigInt *op);
471 
472 void TEE_BigIntDiv(TEE_BigInt *dest_q, TEE_BigInt *dest_r,
473 		   const TEE_BigInt *op1, const TEE_BigInt *op2);
474 
475 /* TEE Arithmetical API - Modular arithmetic operations */
476 
477 void TEE_BigIntMod(TEE_BigInt *dest, const TEE_BigInt *op,
478 		   const TEE_BigInt *n);
479 
480 void TEE_BigIntAddMod(TEE_BigInt *dest, const TEE_BigInt *op1,
481 		      const TEE_BigInt *op2, const TEE_BigInt *n);
482 
483 void TEE_BigIntSubMod(TEE_BigInt *dest, const TEE_BigInt *op1,
484 		      const TEE_BigInt *op2, const TEE_BigInt *n);
485 
486 void TEE_BigIntMulMod(TEE_BigInt *dest, const  TEE_BigInt *op1,
487 		      const TEE_BigInt *op2, const TEE_BigInt *n);
488 
489 void TEE_BigIntSquareMod(TEE_BigInt *dest, const TEE_BigInt *op,
490 			 const TEE_BigInt *n);
491 
492 void TEE_BigIntInvMod(TEE_BigInt *dest, const TEE_BigInt *op,
493 		      const TEE_BigInt *n);
494 
495 /* TEE Arithmetical API - Other arithmetic operations */
496 
497 bool TEE_BigIntRelativePrime(const TEE_BigInt *op1, const TEE_BigInt *op2);
498 
499 void TEE_BigIntComputeExtendedGcd(TEE_BigInt *gcd, TEE_BigInt *u,
500 				  TEE_BigInt *v, const TEE_BigInt *op1,
501 				  const TEE_BigInt *op2);
502 
503 int32_t TEE_BigIntIsProbablePrime(const TEE_BigInt *op,
504 				  uint32_t confidenceLevel);
505 
506 /* TEE Arithmetical API - Fast modular multiplication operations */
507 
508 void TEE_BigIntConvertToFMM(TEE_BigIntFMM *dest, const TEE_BigInt *src,
509 			    const TEE_BigInt *n,
510 			    const TEE_BigIntFMMContext *context);
511 
512 void TEE_BigIntConvertFromFMM(TEE_BigInt *dest, const TEE_BigIntFMM *src,
513 			      const TEE_BigInt *n,
514 			      const TEE_BigIntFMMContext *context);
515 
516 void TEE_BigIntFMMConvertToBigInt(TEE_BigInt *dest, const TEE_BigIntFMM *src,
517 				  const TEE_BigInt *n,
518 				  const TEE_BigIntFMMContext *context);
519 
520 void TEE_BigIntComputeFMM(TEE_BigIntFMM *dest, const TEE_BigIntFMM *op1,
521 			  const TEE_BigIntFMM *op2, const TEE_BigInt *n,
522 			  const TEE_BigIntFMMContext *context);
523 
524 #define TA_EXPORT
525 
526 /*
527  * TA Interface
528  *
529  * Each Trusted Application must provide the Implementation with a number
530  * of functions, collectively called the “TA interface”. These functions
531  * are the entry points called by the Trusted Core Framework to create the
532  * instance, notify the instance that a new client is connecting, notify
533  * the instance when the client invokes a command, etc.
534  *
535  * Trusted Application Entry Points:
536  */
537 
538 /*
539  * The function TA_CreateEntryPoint is the Trusted Application's
540  * constructor, which the Framework calls when it creates a new instance of
541  * the Trusted Application. To register instance data, the implementation
542  * of this constructor can use either global variables or the function
543  * TEE_InstanceSetData.
544  *
545  * Return Value:
546  * - TEE_SUCCESS: if the instance is successfully created, the function
547  *   must return TEE_SUCCESS.
548  * - Any other value: if any other code is returned the instance is not
549  *   created, and no other entry points of this instance will be called.
550  *   The Framework MUST reclaim all resources and dereference all objects
551  *   related to the creation of the instance.
552  *
553  *   If this entry point was called as a result of a client opening a
554  *   session, the error code is returned to the client and the session is
555  *   not opened.
556  */
557 TEE_Result TA_EXPORT TA_CreateEntryPoint(void);
558 
559 /*
560  * The function TA_DestroyEntryPoint is the Trusted Application‟s
561  * destructor, which the Framework calls when the instance is being
562  * destroyed.
563  *
564  * When the function TA_DestroyEntryPoint is called, the Framework
565  * guarantees that no client session is currently open. Once the call to
566  * TA_DestroyEntryPoint has been completed, no other entry point of this
567  * instance will ever be called.
568  *
569  * Note that when this function is called, all resources opened by the
570  * instance are still available. It is only after the function returns that
571  * the Implementation MUST start automatically reclaiming resources left
572  * opened.
573  *
574  * Return Value:
575  * This function can return no success or error code. After this function
576  * returns the Implementation MUST consider the instance destroyed and
577  * reclaims all resources left open by the instance.
578  */
579 void TA_EXPORT TA_DestroyEntryPoint(void);
580 
581 /*
582  * The Framework calls the function TA_OpenSessionEntryPoint when a client
583  * requests to open a session with the Trusted Application. The open
584  * session request may result in a new Trusted Application instance being
585  * created as defined in section 4.5.
586  *
587  * The client can specify parameters in an open operation which are passed
588  * to the Trusted Application instance in the arguments paramTypes and
589  * params. These arguments can also be used by the Trusted Application
590  * instance to transfer response data back to the client. See section 4.3.6
591  * for a specification of how to handle the operation parameters.
592  *
593  * If this function returns TEE_SUCCESS, the client is connected to a
594  * Trusted Application instance and can invoke Trusted Application
595  * commands. When the client disconnects, the Framework will eventually
596  * call the TA_CloseSessionEntryPoint entry point.
597  *
598  * If the function returns any error, the Framework rejects the connection
599  * and returns the error code and the current content of the parameters the
600  * client. The return origin is then set to TEE_ORIGIN_TRUSTED_APP.
601  *
602  * The Trusted Application instance can register a session data pointer by
603  * setting *psessionContext. The value of this pointer is not interpreted
604  * by the Framework, and is simply passed back to other TA_ functions
605  * within this session. Note that *sessionContext may be set with a pointer
606  * to a memory allocated by the Trusted Application instance or with
607  * anything else, like an integer, a handle etc. The Framework will not
608  * automatically free *sessionContext when the session is closed; the
609  * Trusted Application instance is responsible for freeing memory if
610  * required.
611  *
612  * During the call to TA_OpenSessionEntryPoint the client may request to
613  * cancel the operation. See section 4.10 for more details on
614  * cancellations. If the call to TA_OpenSessionEntryPoint returns
615  * TEE_SUCCESS, the client must consider the session as successfully opened
616  * and explicitly close it if necessary.
617  *
618  * Parameters:
619  * - paramTypes: the types of the four parameters.
620  * - params: a pointer to an array of four parameters.
621  * - sessionContext: A pointer to a variable that can be filled by the
622  *   Trusted Application instance with an opaque void* data pointer
623  *
624  * Return Value:
625  * - TEE_SUCCESS if the session is successfully opened.
626  * - Any other value if the session could not be open.
627  *   o The error code may be one of the pre-defined codes, or may be a new
628  *     error code defined by the Trusted Application implementation itself.
629  */
630 TEE_Result TA_EXPORT TA_OpenSessionEntryPoint(uint32_t paramTypes,
631 					      TEE_Param params[TEE_NUM_PARAMS],
632 					      void **sessionContext);
633 TEE_Result TA_EXPORT
634 __GP11_TA_OpenSessionEntryPoint(uint32_t paramTypes,
635 				__GP11_TEE_Param params[TEE_NUM_PARAMS],
636 				void **sessionContext);
637 
638 /*
639  * The Framework calls this function to close a client session. During the
640  * call to this function the implementation can use any session functions.
641  *
642  * The Trusted Application implementation is responsible for freeing any
643  * resources consumed by the session being closed. Note that the Trusted
644  * Application cannot refuse to close a session, but can hold the closing
645  * until it returns from TA_CloseSessionEntryPoint. This is why this
646  * function cannot return an error code.
647  *
648  * Parameters:
649  * - sessionContext: The value of the void* opaque data pointer set by the
650  *   Trusted Application in the function TA_OpenSessionEntryPoint for this
651  *   session.
652  */
653 void TA_EXPORT TA_CloseSessionEntryPoint(void *sessionContext);
654 
655 /*
656  * The Framework calls this function when the client invokes a command
657  * within the given session.
658  *
659  * The Trusted Application can access the parameters sent by the client
660  * through the paramTypes and params arguments. It can also use these
661  * arguments to transfer response data back to the client.
662  *
663  * During the call to TA_InvokeCommandEntryPoint the client may request to
664  * cancel the operation.
665  *
666  * A command is always invoked within the context of a client session.
667  * Thus, any session function  can be called by the command implementation.
668  *
669  * Parameter:
670  * - sessionContext: The value of the void* opaque data pointer set by the
671  *   Trusted Application in the function TA_OpenSessionEntryPoint.
672  * - commandID: A Trusted Application-specific code that identifies the
673  *   command to be invoked.
674  * - paramTypes: the types of the four parameters.
675  * - params: a pointer to an array of four parameters.
676  *
677  * Return Value:
678  * - TEE_SUCCESS: if the command is successfully executed, the function
679  *   must return this value.
680  * - Any other value: if the invocation of the command fails for any
681  *   reason.
682  *   o The error code may be one of the pre-defined codes, or may be a new
683  *     error code defined by the Trusted Application implementation itself.
684  */
685 
686 TEE_Result TA_EXPORT
687 TA_InvokeCommandEntryPoint(void *sessionContext, uint32_t commandID,
688 			   uint32_t paramTypes,
689 			   TEE_Param params[TEE_NUM_PARAMS]);
690 TEE_Result TA_EXPORT
691 __GP11_TA_InvokeCommandEntryPoint(void *sessionContext, uint32_t commandID,
692 				  uint32_t paramTypes,
693 				  __GP11_TEE_Param params[TEE_NUM_PARAMS]);
694 
695 /*
696  * Matching Client Functions <--> TA Functions
697  *
698  * TEE_OpenSession or TEE_OpenTASession:
699  * If a new Trusted Application instance is needed to handle the session,
700  * TA_CreateEntryPoint is called.
701  * Then, TA_OpenSessionEntryPoint is called.
702  *
703  * TEE_InvokeCommand or TEE_InvokeTACommand:
704  * TA_InvokeCommandEntryPoint is called.
705  *
706  * TEE_CloseSession or TEE_CloseTASession:
707  * TA_CloseSessionEntryPoint is called.
708  * For a multi-instance TA or for a single-instance, non keep-alive TA, if
709  * the session closed was the last session on the instance, then
710  * TA_DestroyEntryPoint is called. Otherwise, the instance is kept until
711  * the TEE shuts down.
712  */
713 
714 #include <tee_api_compat.h>
715 
716 #endif /*TEE_INTERNAL_API_H*/
717