xref: /optee_os/lib/libutee/include/tee_internal_api.h (revision 24ea76132a1203c2c46113512f7e5afa4c689f7d)
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(size_t size, uint32_t hint);
121 void *__GP11_TEE_Malloc(uint32_t size, uint32_t hint);
122 
123 void *TEE_Realloc(void *buffer, size_t newSize);
124 void *__GP11_TEE_Realloc(void *buffer, uint32_t newSize);
125 
126 void TEE_Free(void *buffer);
127 
128 void *TEE_MemMove(void *dest, const void *src, size_t size);
129 void *__GP11_TEE_MemMove(void *dest, const void *src, uint32_t size);
130 
131 /*
132  * Note: TEE_MemCompare() has a constant-time implementation (execution time
133  * does not depend on buffer content but only on buffer size). It is the main
134  * difference with memcmp().
135  */
136 int32_t TEE_MemCompare(const void *buffer1, const void *buffer2, size_t size);
137 int32_t __GP11_TEE_MemCompare(const void *buffer1, const void *buffer2,
138 			      uint32_t size);
139 
140 void TEE_MemFill(void *buff, uint32_t x, size_t size);
141 void __GP11_TEE_MemFill(void *buff, uint32_t x, uint32_t size);
142 
143 /* Data and Key Storage API  - Generic Object Functions */
144 
145 void TEE_GetObjectInfo(TEE_ObjectHandle object, TEE_ObjectInfo *objectInfo);
146 void __GP11_TEE_GetObjectInfo(TEE_ObjectHandle object,
147 			      __GP11_TEE_ObjectInfo *objectInfo);
148 
149 TEE_Result TEE_GetObjectInfo1(TEE_ObjectHandle object,
150 			      TEE_ObjectInfo *objectInfo);
151 TEE_Result __GP11_TEE_GetObjectInfo1(TEE_ObjectHandle object,
152 				     __GP11_TEE_ObjectInfo *objectInfo);
153 
154 void TEE_RestrictObjectUsage(TEE_ObjectHandle object, uint32_t objectUsage);
155 TEE_Result TEE_RestrictObjectUsage1(TEE_ObjectHandle object,
156 				    uint32_t objectUsage);
157 
158 TEE_Result TEE_GetObjectBufferAttribute(TEE_ObjectHandle object,
159 					uint32_t attributeID, void *buffer,
160 					size_t *size);
161 TEE_Result __GP11_TEE_GetObjectBufferAttribute(TEE_ObjectHandle object,
162 					       uint32_t attributeID,
163 					       void *buffer, uint32_t *size);
164 
165 TEE_Result TEE_GetObjectValueAttribute(TEE_ObjectHandle object,
166 				       uint32_t attributeID, uint32_t *a,
167 				       uint32_t *b);
168 
169 void TEE_CloseObject(TEE_ObjectHandle object);
170 
171 /* Data and Key Storage API  - Transient Object Functions */
172 
173 TEE_Result TEE_AllocateTransientObject(TEE_ObjectType objectType,
174 				       uint32_t maxObjectSize,
175 				       TEE_ObjectHandle *object);
176 TEE_Result __GP11_TEE_AllocateTransientObject(TEE_ObjectType objectType,
177 					      uint32_t maxKeySize,
178 					      TEE_ObjectHandle *object);
179 
180 void TEE_FreeTransientObject(TEE_ObjectHandle object);
181 
182 void TEE_ResetTransientObject(TEE_ObjectHandle object);
183 
184 TEE_Result TEE_PopulateTransientObject(TEE_ObjectHandle object,
185 				       const TEE_Attribute *attrs,
186 				       uint32_t attrCount);
187 TEE_Result __GP11_TEE_PopulateTransientObject(TEE_ObjectHandle object,
188 					      const __GP11_TEE_Attribute *attrs,
189 					      uint32_t attrCount);
190 
191 void TEE_InitRefAttribute(TEE_Attribute *attr, uint32_t attributeID,
192 			  const void *buffer, size_t length);
193 void __GP11_TEE_InitRefAttribute(__GP11_TEE_Attribute *attr,
194 				 uint32_t attributeID,
195 				 const void *buffer, uint32_t length);
196 
197 void TEE_InitValueAttribute(TEE_Attribute *attr, uint32_t attributeID,
198 			    uint32_t a, uint32_t b);
199 void __GP11_TEE_InitValueAttribute(__GP11_TEE_Attribute *attr,
200 				   uint32_t attributeID,
201 				   uint32_t a, uint32_t b);
202 
203 void TEE_CopyObjectAttributes(TEE_ObjectHandle destObject,
204 			      TEE_ObjectHandle srcObject);
205 
206 TEE_Result TEE_CopyObjectAttributes1(TEE_ObjectHandle destObject,
207 				     TEE_ObjectHandle srcObject);
208 
209 TEE_Result TEE_GenerateKey(TEE_ObjectHandle object, uint32_t keySize,
210 			   const TEE_Attribute *params, uint32_t paramCount);
211 TEE_Result __GP11_TEE_GenerateKey(TEE_ObjectHandle object, uint32_t keySize,
212 				  const __GP11_TEE_Attribute *params,
213 				  uint32_t paramCount);
214 
215 /* Data and Key Storage API  - Persistent Object Functions */
216 
217 TEE_Result TEE_OpenPersistentObject(uint32_t storageID, const void *objectID,
218 				    size_t objectIDLen, uint32_t flags,
219 				    TEE_ObjectHandle *object);
220 TEE_Result __GP11_TEE_OpenPersistentObject(uint32_t storageID,
221 					   const void *objectID,
222 					   uint32_t objectIDLen, uint32_t flags,
223 					   TEE_ObjectHandle *object);
224 
225 TEE_Result TEE_CreatePersistentObject(uint32_t storageID, const void *objectID,
226 				      size_t objectIDLen, uint32_t flags,
227 				      TEE_ObjectHandle attributes,
228 				      const void *initialData,
229 				      size_t initialDataLen,
230 				      TEE_ObjectHandle *object);
231 TEE_Result __GP11_TEE_CreatePersistentObject(uint32_t storageID,
232 					     const void *objectID,
233 					     uint32_t objectIDLen,
234 					     uint32_t flags,
235 					     TEE_ObjectHandle attributes,
236 					     const void *initialData,
237 					     uint32_t initialDataLen,
238 					     TEE_ObjectHandle *object);
239 
240 void TEE_CloseAndDeletePersistentObject(TEE_ObjectHandle object);
241 
242 TEE_Result TEE_CloseAndDeletePersistentObject1(TEE_ObjectHandle object);
243 
244 TEE_Result TEE_RenamePersistentObject(TEE_ObjectHandle object,
245 				      const void *newObjectID,
246 				      size_t newObjectIDLen);
247 TEE_Result __GP11_TEE_RenamePersistentObject(TEE_ObjectHandle object,
248 					     const void *newObjectID,
249 					     uint32_t newObjectIDLen);
250 
251 TEE_Result TEE_AllocatePersistentObjectEnumerator(TEE_ObjectEnumHandle *
252 						  objectEnumerator);
253 
254 void TEE_FreePersistentObjectEnumerator(TEE_ObjectEnumHandle objectEnumerator);
255 
256 void TEE_ResetPersistentObjectEnumerator(TEE_ObjectEnumHandle objectEnumerator);
257 
258 TEE_Result TEE_StartPersistentObjectEnumerator(TEE_ObjectEnumHandle
259 					       objectEnumerator,
260 					       uint32_t storageID);
261 
262 TEE_Result TEE_GetNextPersistentObject(TEE_ObjectEnumHandle objectEnumerator,
263 				       TEE_ObjectInfo *objectInfo,
264 				       void *objectID, size_t *objectIDLen);
265 TEE_Result
266 __GP11_TEE_GetNextPersistentObject(TEE_ObjectEnumHandle objectEnumerator,
267 				   __GP11_TEE_ObjectInfo *objectInfo,
268 				   void *objectID, uint32_t *objectIDLen);
269 
270 /* Data and Key Storage API  - Data Stream Access Functions */
271 
272 TEE_Result TEE_ReadObjectData(TEE_ObjectHandle object, void *buffer,
273 			      size_t size, size_t *count);
274 TEE_Result __GP11_TEE_ReadObjectData(TEE_ObjectHandle object, void *buffer,
275 				     uint32_t size, uint32_t *count);
276 
277 TEE_Result TEE_WriteObjectData(TEE_ObjectHandle object, const void *buffer,
278 			       size_t size);
279 TEE_Result __GP11_TEE_WriteObjectData(TEE_ObjectHandle object,
280 				      const void *buffer, uint32_t size);
281 
282 TEE_Result TEE_TruncateObjectData(TEE_ObjectHandle object, size_t size);
283 TEE_Result __GP11_TEE_TruncateObjectData(TEE_ObjectHandle object,
284 					 uint32_t size);
285 
286 TEE_Result TEE_SeekObjectData(TEE_ObjectHandle object, intmax_t offset,
287 			      TEE_Whence whence);
288 TEE_Result __GP11_TEE_SeekObjectData(TEE_ObjectHandle object, int32_t offset,
289 				     TEE_Whence whence);
290 
291 /* Cryptographic Operations API - Generic Operation Functions */
292 
293 TEE_Result TEE_AllocateOperation(TEE_OperationHandle *operation,
294 				 uint32_t algorithm, uint32_t mode,
295 				 uint32_t maxKeySize);
296 
297 void TEE_FreeOperation(TEE_OperationHandle operation);
298 void __GP11_TEE_FreeOperation(TEE_OperationHandle operation);
299 
300 void TEE_GetOperationInfo(TEE_OperationHandle operation,
301 			  TEE_OperationInfo *operationInfo);
302 
303 TEE_Result
304 TEE_GetOperationInfoMultiple(TEE_OperationHandle operation,
305 			     TEE_OperationInfoMultiple *operationInfoMultiple,
306 			     size_t *operationSize);
307 TEE_Result
308 __GP11_TEE_GetOperationInfoMultiple(TEE_OperationHandle operation,
309 				    TEE_OperationInfoMultiple *info,
310 				    uint32_t *operationSize);
311 
312 void TEE_ResetOperation(TEE_OperationHandle operation);
313 
314 TEE_Result TEE_SetOperationKey(TEE_OperationHandle operation,
315 			       TEE_ObjectHandle key);
316 
317 TEE_Result TEE_SetOperationKey2(TEE_OperationHandle operation,
318 				TEE_ObjectHandle key1, TEE_ObjectHandle key2);
319 
320 void TEE_CopyOperation(TEE_OperationHandle dstOperation,
321 		       TEE_OperationHandle srcOperation);
322 
323 TEE_Result TEE_IsAlgorithmSupported(uint32_t algId, uint32_t element);
324 
325 /* Cryptographic Operations API - Message Digest Functions */
326 
327 void TEE_DigestUpdate(TEE_OperationHandle operation,
328 		      const void *chunk, size_t chunkSize);
329 void __GP11_TEE_DigestUpdate(TEE_OperationHandle operation,
330 			     const void *chunk, uint32_t chunkSize);
331 
332 TEE_Result TEE_DigestDoFinal(TEE_OperationHandle operation, const void *chunk,
333 			     size_t chunkLen, void *hash, size_t *hashLen);
334 TEE_Result __GP11_TEE_DigestDoFinal(TEE_OperationHandle operation,
335 				    const void *chunk, uint32_t chunkLen,
336 				    void *hash, uint32_t *hashLen);
337 
338 TEE_Result TEE_DigestExtract(TEE_OperationHandle operation, void *hash,
339 			     size_t *hashLen);
340 
341 /* Cryptographic Operations API - Symmetric Cipher Functions */
342 
343 void TEE_CipherInit(TEE_OperationHandle operation, const void *IV,
344 		    size_t IVLen);
345 void __GP11_TEE_CipherInit(TEE_OperationHandle operation, const void *IV,
346 			   uint32_t IVLen);
347 
348 TEE_Result TEE_CipherUpdate(TEE_OperationHandle operation, const void *srcData,
349 			    size_t srcLen, void *destData, size_t *destLen);
350 TEE_Result __GP11_TEE_CipherUpdate(TEE_OperationHandle operation,
351 				   const void *srcData, uint32_t srcLen,
352 				   void *destData, uint32_t *destLen);
353 
354 TEE_Result TEE_CipherDoFinal(TEE_OperationHandle operation,
355 			     const void *srcData, size_t srcLen,
356 			     void *destData, size_t *destLen);
357 TEE_Result __GP11_TEE_CipherDoFinal(TEE_OperationHandle operation,
358 				    const void *srcData, uint32_t srcLen,
359 				    void *destData, uint32_t *destLen);
360 
361 /* Cryptographic Operations API - MAC Functions */
362 
363 void TEE_MACInit(TEE_OperationHandle operation, const void *IV,
364 		 size_t IVLen);
365 void __GP11_TEE_MACInit(TEE_OperationHandle operation, const void *IV,
366 			uint32_t IVLen);
367 
368 void TEE_MACUpdate(TEE_OperationHandle operation, const void *chunk,
369 		   size_t chunkSize);
370 void __GP11_TEE_MACUpdate(TEE_OperationHandle operation, const void *chunk,
371 			  uint32_t chunkSize);
372 
373 TEE_Result TEE_MACComputeFinal(TEE_OperationHandle operation,
374 			       const void *message, size_t messageLen,
375 			       void *mac, size_t *macLen);
376 TEE_Result __GP11_TEE_MACComputeFinal(TEE_OperationHandle operation,
377 				      const void *message, uint32_t messageLen,
378 				      void *mac, uint32_t *macLen);
379 
380 TEE_Result TEE_MACCompareFinal(TEE_OperationHandle operation,
381 			       const void *message, size_t messageLen,
382 			       const void *mac, size_t macLen);
383 TEE_Result __GP11_TEE_MACCompareFinal(TEE_OperationHandle operation,
384 				      const void *message, uint32_t messageLen,
385 				      const void *mac, uint32_t macLen);
386 
387 /* Cryptographic Operations API - Authenticated Encryption Functions */
388 
389 TEE_Result TEE_AEInit(TEE_OperationHandle operation, const void *nonce,
390 		      size_t nonceLen, uint32_t tagLen, size_t AADLen,
391 		      size_t payloadLen);
392 TEE_Result __GP11_TEE_AEInit(TEE_OperationHandle operation, const void *nonce,
393 			     uint32_t nonceLen, uint32_t tagLen,
394 			     uint32_t AADLen, uint32_t payloadLen);
395 
396 void TEE_AEUpdateAAD(TEE_OperationHandle operation, const void *AADdata,
397 		     size_t AADdataLen);
398 void __GP11_TEE_AEUpdateAAD(TEE_OperationHandle operation, const void *AADdata,
399 			    uint32_t AADdataLen);
400 
401 TEE_Result TEE_AEUpdate(TEE_OperationHandle operation, const void *srcData,
402 			size_t srcLen, void *destData, size_t *destLen);
403 TEE_Result __GP11_TEE_AEUpdate(TEE_OperationHandle operation,
404 			       const void *srcData, uint32_t srcLen,
405 			       void *destData, uint32_t *destLen);
406 
407 TEE_Result TEE_AEEncryptFinal(TEE_OperationHandle operation,
408 			      const void *srcData, size_t srcLen,
409 			      void *destData, size_t *destLen, void *tag,
410 			      size_t *tagLen);
411 TEE_Result __GP11_TEE_AEEncryptFinal(TEE_OperationHandle operation,
412 				     const void *srcData, uint32_t srcLen,
413 				     void *destData, uint32_t *destLen,
414 				     void *tag, uint32_t *tagLen);
415 
416 TEE_Result TEE_AEDecryptFinal(TEE_OperationHandle operation,
417 			      const void *srcData, size_t srcLen,
418 			      void *destData, size_t *destLen, void *tag,
419 			      size_t tagLen);
420 TEE_Result __GP11_TEE_AEDecryptFinal(TEE_OperationHandle operation,
421 				     const void *srcData, uint32_t srcLen,
422 				     void *destData, uint32_t *destLen,
423 				     void *tag, uint32_t tagLen);
424 
425 /* Cryptographic Operations API - Asymmetric Functions */
426 
427 TEE_Result TEE_AsymmetricEncrypt(TEE_OperationHandle operation,
428 				 const TEE_Attribute *params,
429 				 uint32_t paramCount, const void *srcData,
430 				 size_t srcLen, void *destData,
431 				 size_t *destLen);
432 TEE_Result __GP11_TEE_AsymmetricEncrypt(TEE_OperationHandle operation,
433 					const __GP11_TEE_Attribute *params,
434 					uint32_t paramCount,
435 					const void *srcData, uint32_t srcLen,
436 					void *destData, uint32_t *destLen);
437 
438 TEE_Result TEE_AsymmetricDecrypt(TEE_OperationHandle operation,
439 				 const TEE_Attribute *params,
440 				 uint32_t paramCount, const void *srcData,
441 				 size_t srcLen, void *destData,
442 				 size_t *destLen);
443 TEE_Result __GP11_TEE_AsymmetricDecrypt(TEE_OperationHandle operation,
444 					const __GP11_TEE_Attribute *params,
445 					uint32_t paramCount,
446 					const void *srcData, uint32_t srcLen,
447 					void *destData, uint32_t *destLen);
448 
449 TEE_Result TEE_AsymmetricSignDigest(TEE_OperationHandle operation,
450 				    const TEE_Attribute *params,
451 				    uint32_t paramCount, const void *digest,
452 				    size_t digestLen, void *signature,
453 				    size_t *signatureLen);
454 TEE_Result __GP11_TEE_AsymmetricSignDigest(TEE_OperationHandle operation,
455 					   const __GP11_TEE_Attribute *params,
456 					   uint32_t paramCount,
457 					   const void *digest,
458 					   uint32_t digestLen, void *signature,
459 					   uint32_t *signatureLen);
460 
461 TEE_Result TEE_AsymmetricVerifyDigest(TEE_OperationHandle operation,
462 				      const TEE_Attribute *params,
463 				      uint32_t paramCount, const void *digest,
464 				      size_t digestLen, const void *signature,
465 				      size_t signatureLen);
466 TEE_Result __GP11_TEE_AsymmetricVerifyDigest(TEE_OperationHandle operation,
467 					     const __GP11_TEE_Attribute *params,
468 					     uint32_t paramCount,
469 					     const void *digest,
470 					     uint32_t digestLen,
471 					     const void *signature,
472 					     uint32_t signatureLen);
473 
474 /* Cryptographic Operations API - Key Derivation Functions */
475 
476 void TEE_DeriveKey(TEE_OperationHandle operation,
477 		   const TEE_Attribute *params, uint32_t paramCount,
478 		   TEE_ObjectHandle derivedKey);
479 void __GP11_TEE_DeriveKey(TEE_OperationHandle operation,
480 			  const __GP11_TEE_Attribute *params,
481 			  uint32_t paramCount, TEE_ObjectHandle derivedKey);
482 
483 /* Cryptographic Operations API - Random Number Generation Functions */
484 
485 void TEE_GenerateRandom(void *randomBuffer, size_t randomBufferLen);
486 void __GP11_TEE_GenerateRandom(void *randomBuffer, uint32_t randomBufferLen);
487 
488 /* Date & Time API */
489 
490 void TEE_GetSystemTime(TEE_Time *time);
491 
492 TEE_Result TEE_Wait(uint32_t timeout);
493 
494 TEE_Result TEE_GetTAPersistentTime(TEE_Time *time);
495 
496 TEE_Result TEE_SetTAPersistentTime(const TEE_Time *time);
497 
498 void TEE_GetREETime(TEE_Time *time);
499 
500 /* TEE Arithmetical API - Memory allocation and size of objects */
501 
502 size_t TEE_BigIntFMMSizeInU32(size_t modulusSizeInBits);
503 uint32_t __GP11_TEE_BigIntFMMSizeInU32(uint32_t modulusSizeInBits);
504 
505 size_t TEE_BigIntFMMContextSizeInU32(size_t modulusSizeInBits);
506 uint32_t __GP11_TEE_BigIntFMMContextSizeInU32(uint32_t modulusSizeInBits);
507 
508 /* TEE Arithmetical API - Initialization functions */
509 
510 void TEE_BigIntInit(TEE_BigInt *bigInt, size_t len);
511 void __GP11_TEE_BigIntInit(TEE_BigInt *bigInt, uint32_t len);
512 
513 void TEE_BigIntInitFMMContext(TEE_BigIntFMMContext *context, size_t len,
514 			      const TEE_BigInt *modulus);
515 void __GP11_TEE_BigIntInitFMMContext(TEE_BigIntFMMContext *context,
516 				     uint32_t len, const TEE_BigInt *modulus);
517 
518 TEE_Result TEE_BigIntInitFMMContext1(TEE_BigIntFMMContext *context,
519 				     size_t len, const TEE_BigInt *modulus);
520 
521 void TEE_BigIntInitFMM(TEE_BigIntFMM *bigIntFMM, size_t len);
522 void __GP11_TEE_BigIntInitFMM(TEE_BigIntFMM *bigIntFMM, uint32_t len);
523 
524 /* TEE Arithmetical API - Converter functions */
525 
526 TEE_Result TEE_BigIntConvertFromOctetString(TEE_BigInt *dest,
527 					    const uint8_t *buffer,
528 					    size_t bufferLen,
529 					    int32_t sign);
530 TEE_Result __GP11_TEE_BigIntConvertFromOctetString(TEE_BigInt *dest,
531 						   const uint8_t *buffer,
532 						   uint32_t bufferLen,
533 						   int32_t sign);
534 
535 TEE_Result TEE_BigIntConvertToOctetString(uint8_t *buffer, size_t *bufferLen,
536 					  const TEE_BigInt *bigInt);
537 TEE_Result __GP11_TEE_BigIntConvertToOctetString(uint8_t *buffer,
538 						 uint32_t *bufferLen,
539 						 const TEE_BigInt *bigInt);
540 
541 void TEE_BigIntConvertFromS32(TEE_BigInt *dest, int32_t shortVal);
542 
543 TEE_Result TEE_BigIntConvertToS32(int32_t *dest, const TEE_BigInt *src);
544 
545 /* TEE Arithmetical API - Logical operations */
546 
547 int32_t TEE_BigIntCmp(const TEE_BigInt *op1, const TEE_BigInt *op2);
548 
549 int32_t TEE_BigIntCmpS32(const TEE_BigInt *op, int32_t shortVal);
550 
551 void TEE_BigIntShiftRight(TEE_BigInt *dest, const TEE_BigInt *op,
552 			  size_t bits);
553 void __GP11_TEE_BigIntShiftRight(TEE_BigInt *dest, const TEE_BigInt *op,
554 				 uint32_t bits);
555 
556 bool TEE_BigIntGetBit(const TEE_BigInt *src, uint32_t bitIndex);
557 
558 uint32_t TEE_BigIntGetBitCount(const TEE_BigInt *src);
559 
560 void TEE_BigIntAdd(TEE_BigInt *dest, const TEE_BigInt *op1,
561 		   const TEE_BigInt *op2);
562 
563 void TEE_BigIntSub(TEE_BigInt *dest, const TEE_BigInt *op1,
564 		   const TEE_BigInt *op2);
565 
566 void TEE_BigIntNeg(TEE_BigInt *dest, const TEE_BigInt *op);
567 
568 void TEE_BigIntMul(TEE_BigInt *dest, const TEE_BigInt *op1,
569 		   const TEE_BigInt *op2);
570 
571 void TEE_BigIntSquare(TEE_BigInt *dest, const TEE_BigInt *op);
572 
573 void TEE_BigIntDiv(TEE_BigInt *dest_q, TEE_BigInt *dest_r,
574 		   const TEE_BigInt *op1, const TEE_BigInt *op2);
575 
576 /* TEE Arithmetical API - Modular arithmetic operations */
577 
578 void TEE_BigIntMod(TEE_BigInt *dest, const TEE_BigInt *op,
579 		   const TEE_BigInt *n);
580 
581 void TEE_BigIntAddMod(TEE_BigInt *dest, const TEE_BigInt *op1,
582 		      const TEE_BigInt *op2, const TEE_BigInt *n);
583 
584 void TEE_BigIntSubMod(TEE_BigInt *dest, const TEE_BigInt *op1,
585 		      const TEE_BigInt *op2, const TEE_BigInt *n);
586 
587 void TEE_BigIntMulMod(TEE_BigInt *dest, const  TEE_BigInt *op1,
588 		      const TEE_BigInt *op2, const TEE_BigInt *n);
589 
590 void TEE_BigIntSquareMod(TEE_BigInt *dest, const TEE_BigInt *op,
591 			 const TEE_BigInt *n);
592 
593 void TEE_BigIntInvMod(TEE_BigInt *dest, const TEE_BigInt *op,
594 		      const TEE_BigInt *n);
595 
596 /* TEE Arithmetical API - Other arithmetic operations */
597 
598 bool TEE_BigIntRelativePrime(const TEE_BigInt *op1, const TEE_BigInt *op2);
599 
600 void TEE_BigIntComputeExtendedGcd(TEE_BigInt *gcd, TEE_BigInt *u,
601 				  TEE_BigInt *v, const TEE_BigInt *op1,
602 				  const TEE_BigInt *op2);
603 
604 int32_t TEE_BigIntIsProbablePrime(const TEE_BigInt *op,
605 				  uint32_t confidenceLevel);
606 
607 /* TEE Arithmetical API - Fast modular multiplication operations */
608 
609 void TEE_BigIntConvertToFMM(TEE_BigIntFMM *dest, const TEE_BigInt *src,
610 			    const TEE_BigInt *n,
611 			    const TEE_BigIntFMMContext *context);
612 
613 void TEE_BigIntConvertFromFMM(TEE_BigInt *dest, const TEE_BigIntFMM *src,
614 			      const TEE_BigInt *n,
615 			      const TEE_BigIntFMMContext *context);
616 
617 void TEE_BigIntFMMConvertToBigInt(TEE_BigInt *dest, const TEE_BigIntFMM *src,
618 				  const TEE_BigInt *n,
619 				  const TEE_BigIntFMMContext *context);
620 
621 void TEE_BigIntComputeFMM(TEE_BigIntFMM *dest, const TEE_BigIntFMM *op1,
622 			  const TEE_BigIntFMM *op2, const TEE_BigInt *n,
623 			  const TEE_BigIntFMMContext *context);
624 
625 #define TA_EXPORT
626 
627 /*
628  * TA Interface
629  *
630  * Each Trusted Application must provide the Implementation with a number
631  * of functions, collectively called the “TA interface”. These functions
632  * are the entry points called by the Trusted Core Framework to create the
633  * instance, notify the instance that a new client is connecting, notify
634  * the instance when the client invokes a command, etc.
635  *
636  * Trusted Application Entry Points:
637  */
638 
639 /*
640  * The function TA_CreateEntryPoint is the Trusted Application's
641  * constructor, which the Framework calls when it creates a new instance of
642  * the Trusted Application. To register instance data, the implementation
643  * of this constructor can use either global variables or the function
644  * TEE_InstanceSetData.
645  *
646  * Return Value:
647  * - TEE_SUCCESS: if the instance is successfully created, the function
648  *   must return TEE_SUCCESS.
649  * - Any other value: if any other code is returned the instance is not
650  *   created, and no other entry points of this instance will be called.
651  *   The Framework MUST reclaim all resources and dereference all objects
652  *   related to the creation of the instance.
653  *
654  *   If this entry point was called as a result of a client opening a
655  *   session, the error code is returned to the client and the session is
656  *   not opened.
657  */
658 TEE_Result TA_EXPORT TA_CreateEntryPoint(void);
659 
660 /*
661  * The function TA_DestroyEntryPoint is the Trusted Application‟s
662  * destructor, which the Framework calls when the instance is being
663  * destroyed.
664  *
665  * When the function TA_DestroyEntryPoint is called, the Framework
666  * guarantees that no client session is currently open. Once the call to
667  * TA_DestroyEntryPoint has been completed, no other entry point of this
668  * instance will ever be called.
669  *
670  * Note that when this function is called, all resources opened by the
671  * instance are still available. It is only after the function returns that
672  * the Implementation MUST start automatically reclaiming resources left
673  * opened.
674  *
675  * Return Value:
676  * This function can return no success or error code. After this function
677  * returns the Implementation MUST consider the instance destroyed and
678  * reclaims all resources left open by the instance.
679  */
680 void TA_EXPORT TA_DestroyEntryPoint(void);
681 
682 /*
683  * The Framework calls the function TA_OpenSessionEntryPoint when a client
684  * requests to open a session with the Trusted Application. The open
685  * session request may result in a new Trusted Application instance being
686  * created as defined in section 4.5.
687  *
688  * The client can specify parameters in an open operation which are passed
689  * to the Trusted Application instance in the arguments paramTypes and
690  * params. These arguments can also be used by the Trusted Application
691  * instance to transfer response data back to the client. See section 4.3.6
692  * for a specification of how to handle the operation parameters.
693  *
694  * If this function returns TEE_SUCCESS, the client is connected to a
695  * Trusted Application instance and can invoke Trusted Application
696  * commands. When the client disconnects, the Framework will eventually
697  * call the TA_CloseSessionEntryPoint entry point.
698  *
699  * If the function returns any error, the Framework rejects the connection
700  * and returns the error code and the current content of the parameters the
701  * client. The return origin is then set to TEE_ORIGIN_TRUSTED_APP.
702  *
703  * The Trusted Application instance can register a session data pointer by
704  * setting *psessionContext. The value of this pointer is not interpreted
705  * by the Framework, and is simply passed back to other TA_ functions
706  * within this session. Note that *sessionContext may be set with a pointer
707  * to a memory allocated by the Trusted Application instance or with
708  * anything else, like an integer, a handle etc. The Framework will not
709  * automatically free *sessionContext when the session is closed; the
710  * Trusted Application instance is responsible for freeing memory if
711  * required.
712  *
713  * During the call to TA_OpenSessionEntryPoint the client may request to
714  * cancel the operation. See section 4.10 for more details on
715  * cancellations. If the call to TA_OpenSessionEntryPoint returns
716  * TEE_SUCCESS, the client must consider the session as successfully opened
717  * and explicitly close it if necessary.
718  *
719  * Parameters:
720  * - paramTypes: the types of the four parameters.
721  * - params: a pointer to an array of four parameters.
722  * - sessionContext: A pointer to a variable that can be filled by the
723  *   Trusted Application instance with an opaque void* data pointer
724  *
725  * Return Value:
726  * - TEE_SUCCESS if the session is successfully opened.
727  * - Any other value if the session could not be open.
728  *   o The error code may be one of the pre-defined codes, or may be a new
729  *     error code defined by the Trusted Application implementation itself.
730  */
731 TEE_Result TA_EXPORT TA_OpenSessionEntryPoint(uint32_t paramTypes,
732 					      TEE_Param params[TEE_NUM_PARAMS],
733 					      void **sessionContext);
734 TEE_Result TA_EXPORT
735 __GP11_TA_OpenSessionEntryPoint(uint32_t paramTypes,
736 				__GP11_TEE_Param params[TEE_NUM_PARAMS],
737 				void **sessionContext);
738 
739 /*
740  * The Framework calls this function to close a client session. During the
741  * call to this function the implementation can use any session functions.
742  *
743  * The Trusted Application implementation is responsible for freeing any
744  * resources consumed by the session being closed. Note that the Trusted
745  * Application cannot refuse to close a session, but can hold the closing
746  * until it returns from TA_CloseSessionEntryPoint. This is why this
747  * function cannot return an error code.
748  *
749  * Parameters:
750  * - sessionContext: The value of the void* opaque data pointer set by the
751  *   Trusted Application in the function TA_OpenSessionEntryPoint for this
752  *   session.
753  */
754 void TA_EXPORT TA_CloseSessionEntryPoint(void *sessionContext);
755 
756 /*
757  * The Framework calls this function when the client invokes a command
758  * within the given session.
759  *
760  * The Trusted Application can access the parameters sent by the client
761  * through the paramTypes and params arguments. It can also use these
762  * arguments to transfer response data back to the client.
763  *
764  * During the call to TA_InvokeCommandEntryPoint the client may request to
765  * cancel the operation.
766  *
767  * A command is always invoked within the context of a client session.
768  * Thus, any session function  can be called by the command implementation.
769  *
770  * Parameter:
771  * - sessionContext: The value of the void* opaque data pointer set by the
772  *   Trusted Application in the function TA_OpenSessionEntryPoint.
773  * - commandID: A Trusted Application-specific code that identifies the
774  *   command to be invoked.
775  * - paramTypes: the types of the four parameters.
776  * - params: a pointer to an array of four parameters.
777  *
778  * Return Value:
779  * - TEE_SUCCESS: if the command is successfully executed, the function
780  *   must return this value.
781  * - Any other value: if the invocation of the command fails for any
782  *   reason.
783  *   o The error code may be one of the pre-defined codes, or may be a new
784  *     error code defined by the Trusted Application implementation itself.
785  */
786 
787 TEE_Result TA_EXPORT
788 TA_InvokeCommandEntryPoint(void *sessionContext, uint32_t commandID,
789 			   uint32_t paramTypes,
790 			   TEE_Param params[TEE_NUM_PARAMS]);
791 TEE_Result TA_EXPORT
792 __GP11_TA_InvokeCommandEntryPoint(void *sessionContext, uint32_t commandID,
793 				  uint32_t paramTypes,
794 				  __GP11_TEE_Param params[TEE_NUM_PARAMS]);
795 
796 /*
797  * Matching Client Functions <--> TA Functions
798  *
799  * TEE_OpenSession or TEE_OpenTASession:
800  * If a new Trusted Application instance is needed to handle the session,
801  * TA_CreateEntryPoint is called.
802  * Then, TA_OpenSessionEntryPoint is called.
803  *
804  * TEE_InvokeCommand or TEE_InvokeTACommand:
805  * TA_InvokeCommandEntryPoint is called.
806  *
807  * TEE_CloseSession or TEE_CloseTASession:
808  * TA_CloseSessionEntryPoint is called.
809  * For a multi-instance TA or for a single-instance, non keep-alive TA, if
810  * the session closed was the last session on the instance, then
811  * TA_DestroyEntryPoint is called. Otherwise, the instance is kept until
812  * the TEE shuts down.
813  */
814 
815 #include <tee_api_compat.h>
816 
817 #endif /*TEE_INTERNAL_API_H*/
818