xref: /optee_os/ta/pkcs11/include/pkcs11_ta.h (revision d34f326650ce6bd37cceead87c677035faad26f5)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2018-2020, Linaro Limited
4  */
5 
6 #ifndef PKCS11_TA_H
7 #define PKCS11_TA_H
8 
9 #include <stdbool.h>
10 #include <stdint.h>
11 
12 #define PKCS11_TA_UUID { 0xfd02c9da, 0x306c, 0x48c7, \
13 			 { 0xa4, 0x9c, 0xbb, 0xd8, 0x27, 0xae, 0x86, 0xee } }
14 
15 /* PKCS11 trusted application version information */
16 #define PKCS11_TA_VERSION_MAJOR			0
17 #define PKCS11_TA_VERSION_MINOR			1
18 #define PKCS11_TA_VERSION_PATCH			0
19 
20 /* Attribute specific values */
21 #define PKCS11_UNAVAILABLE_INFORMATION		UINT32_C(0xFFFFFFFF)
22 #define PKCS11_UNDEFINED_ID			PKCS11_UNAVAILABLE_INFORMATION
23 #define PKCS11_FALSE				false
24 #define PKCS11_TRUE				true
25 
26 /*
27  * Note on PKCS#11 TA commands ABI
28  *
29  * For evolution of the TA API and to not mess with the GPD TEE 4 parameters
30  * constraint, all the PKCS11 TA invocation commands use a subset of available
31  * the GPD TEE invocation parameter types.
32  *
33  * Param#0 is used for the so-called control arguments of the invoked command
34  * and for providing a PKCS#11 compliant status code for the request command.
35  * Param#0 is an in/out memory reference (aka memref[0]). The input buffer
36  * stores the command arguments serialized inside. The output buffer will
37  * store the 32bit TA return code for the command. Client shall get this
38  * return code and override the GPD TEE Client API legacy TEE_Result value.
39  *
40  * Param#1 is used for input data arguments of the invoked command.
41  * It is unused or is a input memory reference, aka memref[1].
42  * Evolution of the API may use memref[1] for output data as well.
43  *
44  * Param#2 is mostly used for output data arguments of the invoked command
45  * and for output handles generated from invoked commands.
46  * Few commands uses it for a secondary input data buffer argument.
47  * It is unused or is a input/output/in-out memory reference, aka memref[2].
48  *
49  * Param#3 is currently unused and reserved for evolution of the API.
50  */
51 
52 /*
53  * PKCS11_CMD_PING		Acknowledge TA presence and return version info
54  *
55  * Optinal invocation parameter (if none, command simply returns with success)
56  * [out]        memref[2] = [
57  *                      32bit version major value,
58  *                      32bit version minor value
59  *                      32bit version patch value
60  *              ]
61  */
62 #define PKCS11_CMD_PING				0
63 
64 /*
65  * Command return codes
66  * PKCS11_<x> relates CryptoKi client API CKR_<x>
67  */
68 enum pkcs11_rc {
69 	PKCS11_CKR_OK				= 0,
70 	PKCS11_CKR_CANCEL			= 0x0001,
71 	PKCS11_CKR_SLOT_ID_INVALID		= 0x0003,
72 	PKCS11_CKR_GENERAL_ERROR		= 0x0005,
73 	PKCS11_CKR_FUNCTION_FAILED		= 0x0006,
74 	PKCS11_CKR_ARGUMENTS_BAD		= 0x0007,
75 	PKCS11_CKR_ATTRIBUTE_READ_ONLY		= 0x0010,
76 	PKCS11_CKR_ATTRIBUTE_SENSITIVE		= 0x0011,
77 	PKCS11_CKR_ATTRIBUTE_TYPE_INVALID	= 0x0012,
78 	PKCS11_CKR_ATTRIBUTE_VALUE_INVALID	= 0x0013,
79 	PKCS11_CKR_ACTION_PROHIBITED		= 0x001b,
80 	PKCS11_CKR_DATA_INVALID			= 0x0020,
81 	PKCS11_CKR_DATA_LEN_RANGE		= 0x0021,
82 	PKCS11_CKR_DEVICE_ERROR			= 0x0030,
83 	PKCS11_CKR_DEVICE_MEMORY		= 0x0031,
84 	PKCS11_CKR_DEVICE_REMOVED		= 0x0032,
85 	PKCS11_CKR_ENCRYPTED_DATA_INVALID	= 0x0040,
86 	PKCS11_CKR_ENCRYPTED_DATA_LEN_RANGE	= 0x0041,
87 	PKCS11_CKR_KEY_HANDLE_INVALID		= 0x0060,
88 	PKCS11_CKR_KEY_SIZE_RANGE		= 0x0062,
89 	PKCS11_CKR_KEY_TYPE_INCONSISTENT	= 0x0063,
90 	PKCS11_CKR_KEY_FUNCTION_NOT_PERMITTED	= 0x0068,
91 	PKCS11_CKR_KEY_NOT_WRAPPABLE		= 0x0069,
92 	PKCS11_CKR_KEY_UNEXTRACTABLE		= 0x006a,
93 	PKCS11_CKR_MECHANISM_INVALID		= 0x0070,
94 	PKCS11_CKR_MECHANISM_PARAM_INVALID	= 0x0071,
95 	PKCS11_CKR_OBJECT_HANDLE_INVALID	= 0x0082,
96 	PKCS11_CKR_OPERATION_ACTIVE		= 0x0090,
97 	PKCS11_CKR_OPERATION_NOT_INITIALIZED	= 0x0091,
98 	PKCS11_CKR_PIN_INCORRECT		= 0x00a0,
99 	PKCS11_CKR_PIN_INVALID			= 0x00a1,
100 	PKCS11_CKR_PIN_LEN_RANGE		= 0x00a2,
101 	PKCS11_CKR_PIN_EXPIRED			= 0x00a3,
102 	PKCS11_CKR_PIN_LOCKED			= 0x00a4,
103 	PKCS11_CKR_SESSION_CLOSED		= 0x00b0,
104 	PKCS11_CKR_SESSION_COUNT		= 0x00b1,
105 	PKCS11_CKR_SESSION_HANDLE_INVALID	= 0x00b3,
106 	PKCS11_CKR_SESSION_READ_ONLY		= 0x00b5,
107 	PKCS11_CKR_SESSION_EXISTS		= 0x00b6,
108 	PKCS11_CKR_SESSION_READ_ONLY_EXISTS	= 0x00b7,
109 	PKCS11_CKR_SESSION_READ_WRITE_SO_EXISTS	= 0x00b8,
110 	PKCS11_CKR_SIGNATURE_INVALID		= 0x00c0,
111 	PKCS11_CKR_SIGNATURE_LEN_RANGE		= 0x00c1,
112 	PKCS11_CKR_TEMPLATE_INCOMPLETE		= 0x00d0,
113 	PKCS11_CKR_TEMPLATE_INCONSISTENT	= 0x00d1,
114 	PKCS11_CKR_TOKEN_NOT_PRESENT		= 0x00e0,
115 	PKCS11_CKR_TOKEN_NOT_RECOGNIZED		= 0x00e1,
116 	PKCS11_CKR_TOKEN_WRITE_PROTECTED	= 0x00e2,
117 	PKCS11_CKR_USER_ALREADY_LOGGED_IN	= 0x0100,
118 	PKCS11_CKR_USER_NOT_LOGGED_IN		= 0x0101,
119 	PKCS11_CKR_USER_PIN_NOT_INITIALIZED	= 0x0102,
120 	PKCS11_CKR_USER_TYPE_INVALID		= 0x0103,
121 	PKCS11_CKR_USER_ANOTHER_ALREADY_LOGGED_IN = 0x0104,
122 	PKCS11_CKR_USER_TOO_MANY_TYPES		= 0x0105,
123 	PKCS11_CKR_DOMAIN_PARAMS_INVALID	= 0x0130,
124 	PKCS11_CKR_CURVE_NOT_SUPPORTED		= 0x0140,
125 	PKCS11_CKR_BUFFER_TOO_SMALL		= 0x0150,
126 	PKCS11_CKR_SAVED_STATE_INVALID		= 0x0160,
127 	PKCS11_CKR_INFORMATION_SENSITIVE	= 0x0170,
128 	PKCS11_CKR_STATE_UNSAVEABLE		= 0x0180,
129 	PKCS11_CKR_PIN_TOO_WEAK			= 0x01b8,
130 	PKCS11_CKR_PUBLIC_KEY_INVALID		= 0x01b9,
131 	PKCS11_CKR_FUNCTION_REJECTED		= 0x0200,
132 	/* Vendor specific IDs not returned to client */
133 	PKCS11_RV_NOT_FOUND			= 0x80000000,
134 	PKCS11_RV_NOT_IMPLEMENTED		= 0x80000001,
135 };
136 #endif /*PKCS11_TA_H*/
137