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_CK_UNAVAILABLE_INFORMATION UINT32_C(0xFFFFFFFF) 22 #define PKCS11_UNDEFINED_ID UINT32_C(0xFFFFFFFF) 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 serialized arguments for the command. The output buffer store the 37 * 32bit TA return code for the command. As a consequence, param#0 shall 38 * always be an input/output memory reference of at least 32bit, more if 39 * the command expects more input arguments. 40 * 41 * When the TA returns with TEE_SUCCESS result, client shall always get the 42 * 32bit value stored in param#0 output buffer and use the value as TA 43 * return code for the invoked command. 44 * 45 * Param#1 can be used for input data arguments of the invoked command. 46 * It is unused or is an input memory reference, aka memref[1]. 47 * Evolution of the API may use memref[1] for output data as well. 48 * 49 * Param#2 is mostly used for output data arguments of the invoked command 50 * and for output handles generated from invoked commands. 51 * Few commands uses it for a secondary input data buffer argument. 52 * It is unused or is an input/output/in-out memory reference, aka memref[2]. 53 * 54 * Param#3 is currently unused and reserved for evolution of the API. 55 */ 56 57 enum pkcs11_ta_cmd { 58 /* 59 * PKCS11_CMD_PING Ack TA presence and return version info 60 * 61 * [in] memref[0] = 32bit, unused, must be 0 62 * [out] memref[0] = 32bit return code, enum pkcs11_rc 63 * [out] memref[2] = [ 64 * 32bit version major value, 65 * 32bit version minor value 66 * 32bit version patch value 67 * ] 68 */ 69 PKCS11_CMD_PING = 0, 70 71 /* 72 * PKCS11_CMD_SLOT_LIST - Get the table of the valid slot IDs 73 * 74 * [in] memref[0] = 32bit, unused, must be 0 75 * [out] memref[0] = 32bit return code, enum pkcs11_rc 76 * [out] memref[2] = 32bit array slot_ids[slot counts] 77 * 78 * The TA instance may represent several PKCS#11 slots and 79 * associated tokens. This commadn reports the IDs of embedded tokens. 80 * This command relates the PKCS#11 API function C_GetSlotList(). 81 */ 82 PKCS11_CMD_SLOT_LIST = 1, 83 84 /* 85 * PKCS11_CMD_SLOT_INFO - Get cryptoki structured slot information 86 * 87 * [in] memref[0] = 32bit slot ID 88 * [out] memref[0] = 32bit return code, enum pkcs11_rc 89 * [out] memref[2] = (struct pkcs11_slot_info)info 90 * 91 * The TA instance may represent several PKCS#11 slots/tokens. 92 * This command relates the PKCS#11 API function C_GetSlotInfo(). 93 */ 94 PKCS11_CMD_SLOT_INFO = 2, 95 96 /* 97 * PKCS11_CMD_TOKEN_INFO - Get cryptoki structured token information 98 * 99 * [in] memref[0] = 32bit slot ID 100 * [out] memref[0] = 32bit return code, enum pkcs11_rc 101 * [out] memref[2] = (struct pkcs11_token_info)info 102 * 103 * The TA instance may represent several PKCS#11 slots/tokens. 104 * This command relates the PKCS#11 API function C_GetTokenInfo(). 105 */ 106 PKCS11_CMD_TOKEN_INFO = 3, 107 108 /* 109 * PKCS11_CMD_MECHANISM_IDS - Get list of the supported mechanisms 110 * 111 * [in] memref[0] = 32bit slot ID 112 * [out] memref[0] = 32bit return code, enum pkcs11_rc 113 * [out] memref[2] = 32bit array mechanism IDs 114 * 115 * This command relates to the PKCS#11 API function 116 * C_GetMechanismList(). 117 */ 118 PKCS11_CMD_MECHANISM_IDS = 4, 119 120 /* 121 * PKCS11_CMD_MECHANISM_INFO - Get information on a specific mechanism 122 * 123 * [in] memref[0] = [ 124 * 32bit slot ID, 125 * 32bit mechanism ID (PKCS11_CKM_*) 126 * ] 127 * [out] memref[0] = 32bit return code, enum pkcs11_rc 128 * [out] memref[2] = (struct pkcs11_mechanism_info)info 129 * 130 * This command relates to the PKCS#11 API function 131 * C_GetMechanismInfo(). 132 */ 133 PKCS11_CMD_MECHANISM_INFO = 5, 134 135 /* 136 * PKCS11_CMD_OPEN_SESSION - Open a session 137 * 138 * [in] memref[0] = [ 139 * 32bit slot ID, 140 * 32bit session flags, 141 * ] 142 * [out] memref[0] = 32bit return code, enum pkcs11_rc 143 * [out] memref[2] = 32bit session handle 144 * 145 * This command relates to the PKCS#11 API function C_OpenSession(). 146 */ 147 PKCS11_CMD_OPEN_SESSION = 6, 148 149 /* 150 * PKCS11_CMD_CLOSE_SESSION - Close an opened session 151 * 152 * [in] memref[0] = 32bit session handle 153 * [out] memref[0] = 32bit return code, enum pkcs11_rc 154 * 155 * This command relates to the PKCS#11 API function C_CloseSession(). 156 */ 157 PKCS11_CMD_CLOSE_SESSION = 7, 158 159 /* 160 * PKCS11_CMD_CLOSE_ALL_SESSIONS - Close all client sessions on token 161 * 162 * [in] memref[0] = 32bit slot ID 163 * [out] memref[0] = 32bit return code, enum pkcs11_rc 164 * 165 * This command relates to the PKCS#11 API function 166 * C_CloseAllSessions(). 167 */ 168 PKCS11_CMD_CLOSE_ALL_SESSIONS = 8, 169 170 /* 171 * PKCS11_CMD_SESSION_INFO - Get Cryptoki information on a session 172 * 173 * [in] memref[0] = 32bit session handle 174 * [out] memref[0] = 32bit return code, enum pkcs11_rc 175 * [out] memref[2] = (struct pkcs11_session_info)info 176 * 177 * This command relates to the PKCS#11 API function C_GetSessionInfo(). 178 */ 179 PKCS11_CMD_SESSION_INFO = 9, 180 181 /* 182 * PKCS11_CMD_INIT_TOKEN - Initialize PKCS#11 token 183 * 184 * [in] memref[0] = [ 185 * 32bit slot ID, 186 * 32bit PIN length, 187 * byte array label[32] 188 * byte array PIN[PIN length], 189 * ] 190 * [out] memref[0] = 32bit return code, enum pkcs11_rc 191 * 192 * This command relates to the PKCS#11 API function C_InitToken(). 193 */ 194 PKCS11_CMD_INIT_TOKEN = 10, 195 196 /* 197 * PKCS11_CMD_INIT_PIN - Initialize user PIN 198 * 199 * [in] memref[0] = [ 200 * 32bit session handle, 201 * 32bit PIN byte size, 202 * byte array: PIN data 203 * ] 204 * [out] memref[0] = 32bit return code, enum pkcs11_rc 205 * 206 * This command relates to the PKCS#11 API function C_InitPIN(). 207 */ 208 PKCS11_CMD_INIT_PIN = 11, 209 210 /* 211 * PKCS11_CMD_SET_PIN - Change user PIN 212 * 213 * [in] memref[0] = [ 214 * 32bit session handle, 215 * 32bit old PIN byte size, 216 * 32bit new PIN byte size, 217 * byte array: PIN data, 218 * byte array: new PIN data, 219 * ] 220 * [out] memref[0] = 32bit return code, enum pkcs11_rc 221 * 222 * This command relates to the PKCS#11 API function C_SetPIN(). 223 */ 224 PKCS11_CMD_SET_PIN = 12, 225 226 /* 227 * PKCS11_CMD_LOGIN - Initialize user PIN 228 * 229 * [in] memref[0] = [ 230 * 32bit session handle, 231 * 32bit user identifier, enum pkcs11_user_type 232 * 32bit PIN byte size, 233 * byte array: PIN data 234 * ] 235 * [out] memref[0] = 32bit return code, enum pkcs11_rc 236 * 237 * This command relates to the PKCS#11 API function C_Login(). 238 */ 239 PKCS11_CMD_LOGIN = 13, 240 241 /* 242 * PKCS11_CMD_LOGOUT - Log out from token 243 * 244 * [in] memref[0] = [ 245 * 32bit session handle, 246 * ] 247 * [out] memref[0] = 32bit return code, enum pkcs11_rc 248 * 249 * This command relates to the PKCS#11 API function C_Logout(). 250 */ 251 PKCS11_CMD_LOGOUT = 14, 252 253 /* 254 * PKCS11_CMD_CREATE_OBJECT - Create a raw client assembled object in 255 * the session or token 256 * 257 * 258 * [in] memref[0] = [ 259 * 32bit session handle, 260 * (struct pkcs11_object_head)attribs + attributes data 261 * ] 262 * [out] memref[0] = 32bit return code, enum pkcs11_rc 263 * [out] memref[2] = 32bit object handle 264 * 265 * This command relates to the PKCS#11 API function C_CreateObject(). 266 */ 267 PKCS11_CMD_CREATE_OBJECT = 15, 268 269 /* 270 * PKCS11_CMD_DESTROY_OBJECT - Destroy an object 271 * 272 * [in] memref[0] = [ 273 * 32bit session handle, 274 * 32bit object handle 275 * ] 276 * [out] memref[0] = 32bit return code, enum pkcs11_rc 277 * 278 * This command relates to the PKCS#11 API function C_DestroyObject(). 279 */ 280 PKCS11_CMD_DESTROY_OBJECT = 16, 281 282 /* 283 * PKCS11_CMD_ENCRYPT_INIT - Initialize encryption processing 284 * PKCS11_CMD_DECRYPT_INIT - Initialize decryption processing 285 * 286 * [in] memref[0] = [ 287 * 32bit session handle, 288 * 32bit object handle of the key, 289 * (struct pkcs11_attribute_head)mechanism + mecha params 290 * ] 291 * [out] memref[0] = 32bit return code, enum pkcs11_rc 292 * 293 * These commands relate to the PKCS#11 API functions 294 * C_EncryptInit() and C_DecryptInit(). 295 */ 296 PKCS11_CMD_ENCRYPT_INIT = 17, 297 PKCS11_CMD_DECRYPT_INIT = 18, 298 299 /* 300 * PKCS11_CMD_ENCRYPT_UPDATE - Update encryption processing 301 * PKCS11_CMD_DECRYPT_UPDATE - Update decryption processing 302 * 303 * [in] memref[0] = 32bit session handle 304 * [out] memref[0] = 32bit return code, enum pkcs11_rc 305 * [in] memref[1] = input data to be processed 306 * [out] memref[2] = output processed data 307 * 308 * These commands relate to the PKCS#11 API functions 309 * C_EncryptUpdate() and C_DecryptUpdate(). 310 */ 311 PKCS11_CMD_ENCRYPT_UPDATE = 19, 312 PKCS11_CMD_DECRYPT_UPDATE = 20, 313 314 /* 315 * PKCS11_CMD_ENCRYPT_FINAL - Finalize encryption processing 316 * PKCS11_CMD_DECRYPT_FINAL - Finalize decryption processing 317 * 318 * [in] memref[0] = 32bit session handle 319 * [out] memref[0] = 32bit return code, enum pkcs11_rc 320 * [out] memref[2] = output processed data 321 * 322 * These commands relate to the PKCS#11 API functions 323 * C_EncryptFinal() and C_DecryptFinal(). 324 */ 325 PKCS11_CMD_ENCRYPT_FINAL = 21, 326 PKCS11_CMD_DECRYPT_FINAL = 22, 327 328 /* 329 * PKCS11_CMD_ENCRYPT_ONESHOT - Update and finalize encryption 330 * processing 331 * PKCS11_CMD_DECRYPT_ONESHOT - Update and finalize decryption 332 * processing 333 * 334 * [in] memref[0] = 32bit session handle 335 * [out] memref[0] = 32bit return code, enum pkcs11_rc 336 * [in] memref[1] = input data to be processed 337 * [out] memref[2] = output processed data 338 * 339 * These commands relate to the PKCS#11 API functions C_Encrypt and 340 * C_Decrypt. 341 */ 342 PKCS11_CMD_ENCRYPT_ONESHOT = 23, 343 PKCS11_CMD_DECRYPT_ONESHOT = 24, 344 }; 345 346 /* 347 * Command return codes 348 * PKCS11_<x> relates CryptoKi client API CKR_<x> 349 */ 350 enum pkcs11_rc { 351 PKCS11_CKR_OK = 0, 352 PKCS11_CKR_CANCEL = 0x0001, 353 PKCS11_CKR_SLOT_ID_INVALID = 0x0003, 354 PKCS11_CKR_GENERAL_ERROR = 0x0005, 355 PKCS11_CKR_FUNCTION_FAILED = 0x0006, 356 PKCS11_CKR_ARGUMENTS_BAD = 0x0007, 357 PKCS11_CKR_ATTRIBUTE_READ_ONLY = 0x0010, 358 PKCS11_CKR_ATTRIBUTE_SENSITIVE = 0x0011, 359 PKCS11_CKR_ATTRIBUTE_TYPE_INVALID = 0x0012, 360 PKCS11_CKR_ATTRIBUTE_VALUE_INVALID = 0x0013, 361 PKCS11_CKR_ACTION_PROHIBITED = 0x001b, 362 PKCS11_CKR_DATA_INVALID = 0x0020, 363 PKCS11_CKR_DATA_LEN_RANGE = 0x0021, 364 PKCS11_CKR_DEVICE_ERROR = 0x0030, 365 PKCS11_CKR_DEVICE_MEMORY = 0x0031, 366 PKCS11_CKR_DEVICE_REMOVED = 0x0032, 367 PKCS11_CKR_ENCRYPTED_DATA_INVALID = 0x0040, 368 PKCS11_CKR_ENCRYPTED_DATA_LEN_RANGE = 0x0041, 369 PKCS11_CKR_KEY_HANDLE_INVALID = 0x0060, 370 PKCS11_CKR_KEY_SIZE_RANGE = 0x0062, 371 PKCS11_CKR_KEY_TYPE_INCONSISTENT = 0x0063, 372 PKCS11_CKR_KEY_FUNCTION_NOT_PERMITTED = 0x0068, 373 PKCS11_CKR_KEY_NOT_WRAPPABLE = 0x0069, 374 PKCS11_CKR_KEY_UNEXTRACTABLE = 0x006a, 375 PKCS11_CKR_MECHANISM_INVALID = 0x0070, 376 PKCS11_CKR_MECHANISM_PARAM_INVALID = 0x0071, 377 PKCS11_CKR_OBJECT_HANDLE_INVALID = 0x0082, 378 PKCS11_CKR_OPERATION_ACTIVE = 0x0090, 379 PKCS11_CKR_OPERATION_NOT_INITIALIZED = 0x0091, 380 PKCS11_CKR_PIN_INCORRECT = 0x00a0, 381 PKCS11_CKR_PIN_INVALID = 0x00a1, 382 PKCS11_CKR_PIN_LEN_RANGE = 0x00a2, 383 PKCS11_CKR_PIN_EXPIRED = 0x00a3, 384 PKCS11_CKR_PIN_LOCKED = 0x00a4, 385 PKCS11_CKR_SESSION_CLOSED = 0x00b0, 386 PKCS11_CKR_SESSION_COUNT = 0x00b1, 387 PKCS11_CKR_SESSION_HANDLE_INVALID = 0x00b3, 388 PKCS11_CKR_SESSION_READ_ONLY = 0x00b5, 389 PKCS11_CKR_SESSION_EXISTS = 0x00b6, 390 PKCS11_CKR_SESSION_READ_ONLY_EXISTS = 0x00b7, 391 PKCS11_CKR_SESSION_READ_WRITE_SO_EXISTS = 0x00b8, 392 PKCS11_CKR_SIGNATURE_INVALID = 0x00c0, 393 PKCS11_CKR_SIGNATURE_LEN_RANGE = 0x00c1, 394 PKCS11_CKR_TEMPLATE_INCOMPLETE = 0x00d0, 395 PKCS11_CKR_TEMPLATE_INCONSISTENT = 0x00d1, 396 PKCS11_CKR_TOKEN_NOT_PRESENT = 0x00e0, 397 PKCS11_CKR_TOKEN_NOT_RECOGNIZED = 0x00e1, 398 PKCS11_CKR_TOKEN_WRITE_PROTECTED = 0x00e2, 399 PKCS11_CKR_USER_ALREADY_LOGGED_IN = 0x0100, 400 PKCS11_CKR_USER_NOT_LOGGED_IN = 0x0101, 401 PKCS11_CKR_USER_PIN_NOT_INITIALIZED = 0x0102, 402 PKCS11_CKR_USER_TYPE_INVALID = 0x0103, 403 PKCS11_CKR_USER_ANOTHER_ALREADY_LOGGED_IN = 0x0104, 404 PKCS11_CKR_USER_TOO_MANY_TYPES = 0x0105, 405 PKCS11_CKR_DOMAIN_PARAMS_INVALID = 0x0130, 406 PKCS11_CKR_CURVE_NOT_SUPPORTED = 0x0140, 407 PKCS11_CKR_BUFFER_TOO_SMALL = 0x0150, 408 PKCS11_CKR_SAVED_STATE_INVALID = 0x0160, 409 PKCS11_CKR_INFORMATION_SENSITIVE = 0x0170, 410 PKCS11_CKR_STATE_UNSAVEABLE = 0x0180, 411 PKCS11_CKR_PIN_TOO_WEAK = 0x01b8, 412 PKCS11_CKR_PUBLIC_KEY_INVALID = 0x01b9, 413 PKCS11_CKR_FUNCTION_REJECTED = 0x0200, 414 /* Vendor specific IDs not returned to client */ 415 PKCS11_RV_NOT_FOUND = 0x80000000, 416 PKCS11_RV_NOT_IMPLEMENTED = 0x80000001, 417 }; 418 419 /* 420 * Arguments for PKCS11_CMD_SLOT_INFO 421 */ 422 #define PKCS11_SLOT_DESC_SIZE 64 423 #define PKCS11_SLOT_MANUFACTURER_SIZE 32 424 #define PKCS11_SLOT_VERSION_SIZE 2 425 426 struct pkcs11_slot_info { 427 uint8_t slot_description[PKCS11_SLOT_DESC_SIZE]; 428 uint8_t manufacturer_id[PKCS11_SLOT_MANUFACTURER_SIZE]; 429 uint32_t flags; 430 uint8_t hardware_version[PKCS11_SLOT_VERSION_SIZE]; 431 uint8_t firmware_version[PKCS11_SLOT_VERSION_SIZE]; 432 }; 433 434 /* 435 * Values for pkcs11_slot_info::flags. 436 * PKCS11_CKFS_<x> reflects CryptoKi client API slot flags CKF_<x>. 437 */ 438 #define PKCS11_CKFS_TOKEN_PRESENT (1U << 0) 439 #define PKCS11_CKFS_REMOVABLE_DEVICE (1U << 1) 440 #define PKCS11_CKFS_HW_SLOT (1U << 2) 441 442 /* 443 * Arguments for PKCS11_CMD_TOKEN_INFO 444 */ 445 #define PKCS11_TOKEN_LABEL_SIZE 32 446 #define PKCS11_TOKEN_MANUFACTURER_SIZE 32 447 #define PKCS11_TOKEN_MODEL_SIZE 16 448 #define PKCS11_TOKEN_SERIALNUM_SIZE 16 449 450 struct pkcs11_token_info { 451 uint8_t label[PKCS11_TOKEN_LABEL_SIZE]; 452 uint8_t manufacturer_id[PKCS11_TOKEN_MANUFACTURER_SIZE]; 453 uint8_t model[PKCS11_TOKEN_MODEL_SIZE]; 454 uint8_t serial_number[PKCS11_TOKEN_SERIALNUM_SIZE]; 455 uint32_t flags; 456 uint32_t max_session_count; 457 uint32_t session_count; 458 uint32_t max_rw_session_count; 459 uint32_t rw_session_count; 460 uint32_t max_pin_len; 461 uint32_t min_pin_len; 462 uint32_t total_public_memory; 463 uint32_t free_public_memory; 464 uint32_t total_private_memory; 465 uint32_t free_private_memory; 466 uint8_t hardware_version[2]; 467 uint8_t firmware_version[2]; 468 uint8_t utc_time[16]; 469 }; 470 471 /* 472 * Values for pkcs11_token_info::flags. 473 * PKCS11_CKFT_<x> reflects CryptoKi client API token flags CKF_<x>. 474 */ 475 #define PKCS11_CKFT_RNG (1U << 0) 476 #define PKCS11_CKFT_WRITE_PROTECTED (1U << 1) 477 #define PKCS11_CKFT_LOGIN_REQUIRED (1U << 2) 478 #define PKCS11_CKFT_USER_PIN_INITIALIZED (1U << 3) 479 #define PKCS11_CKFT_RESTORE_KEY_NOT_NEEDED (1U << 5) 480 #define PKCS11_CKFT_CLOCK_ON_TOKEN (1U << 6) 481 #define PKCS11_CKFT_PROTECTED_AUTHENTICATION_PATH (1U << 8) 482 #define PKCS11_CKFT_DUAL_CRYPTO_OPERATIONS (1U << 9) 483 #define PKCS11_CKFT_TOKEN_INITIALIZED (1U << 10) 484 #define PKCS11_CKFT_SECONDARY_AUTHENTICATION (1U << 11) 485 #define PKCS11_CKFT_USER_PIN_COUNT_LOW (1U << 16) 486 #define PKCS11_CKFT_USER_PIN_FINAL_TRY (1U << 17) 487 #define PKCS11_CKFT_USER_PIN_LOCKED (1U << 18) 488 #define PKCS11_CKFT_USER_PIN_TO_BE_CHANGED (1U << 19) 489 #define PKCS11_CKFT_SO_PIN_COUNT_LOW (1U << 20) 490 #define PKCS11_CKFT_SO_PIN_FINAL_TRY (1U << 21) 491 #define PKCS11_CKFT_SO_PIN_LOCKED (1U << 22) 492 #define PKCS11_CKFT_SO_PIN_TO_BE_CHANGED (1U << 23) 493 #define PKCS11_CKFT_ERROR_STATE (1U << 24) 494 495 /* Values for user identity */ 496 enum pkcs11_user_type { 497 PKCS11_CKU_SO = 0x000, 498 PKCS11_CKU_USER = 0x001, 499 PKCS11_CKU_CONTEXT_SPECIFIC = 0x002, 500 }; 501 502 /* 503 * Values for 32bit session flags argument to PKCS11_CMD_OPEN_SESSION 504 * and pkcs11_session_info::flags. 505 * PKCS11_CKFSS_<x> reflects CryptoKi client API session flags CKF_<x>. 506 */ 507 #define PKCS11_CKFSS_RW_SESSION (1U << 1) 508 #define PKCS11_CKFSS_SERIAL_SESSION (1U << 2) 509 510 /* 511 * Arguments for PKCS11_CMD_SESSION_INFO 512 */ 513 514 struct pkcs11_session_info { 515 uint32_t slot_id; 516 uint32_t state; 517 uint32_t flags; 518 uint32_t device_error; 519 }; 520 521 /* Valid values for pkcs11_session_info::state */ 522 enum pkcs11_session_state { 523 PKCS11_CKS_RO_PUBLIC_SESSION = 0, 524 PKCS11_CKS_RO_USER_FUNCTIONS = 1, 525 PKCS11_CKS_RW_PUBLIC_SESSION = 2, 526 PKCS11_CKS_RW_USER_FUNCTIONS = 3, 527 PKCS11_CKS_RW_SO_FUNCTIONS = 4, 528 }; 529 530 /* 531 * Arguments for PKCS11_CMD_MECHANISM_INFO 532 */ 533 534 struct pkcs11_mechanism_info { 535 uint32_t min_key_size; 536 uint32_t max_key_size; 537 uint32_t flags; 538 }; 539 540 /* 541 * Values for pkcs11_mechanism_info::flags. 542 * PKCS11_CKFM_<x> reflects CryptoKi client API mechanism flags CKF_<x>. 543 */ 544 #define PKCS11_CKFM_HW (1U << 0) 545 #define PKCS11_CKFM_ENCRYPT (1U << 8) 546 #define PKCS11_CKFM_DECRYPT (1U << 9) 547 #define PKCS11_CKFM_DIGEST (1U << 10) 548 #define PKCS11_CKFM_SIGN (1U << 11) 549 #define PKCS11_CKFM_SIGN_RECOVER (1U << 12) 550 #define PKCS11_CKFM_VERIFY (1U << 13) 551 #define PKCS11_CKFM_VERIFY_RECOVER (1U << 14) 552 #define PKCS11_CKFM_GENERATE (1U << 15) 553 #define PKCS11_CKFM_GENERATE_KEY_PAIR (1U << 16) 554 #define PKCS11_CKFM_WRAP (1U << 17) 555 #define PKCS11_CKFM_UNWRAP (1U << 18) 556 #define PKCS11_CKFM_DERIVE (1U << 19) 557 #define PKCS11_CKFM_EC_F_P (1U << 20) 558 #define PKCS11_CKFM_EC_F_2M (1U << 21) 559 #define PKCS11_CKFM_EC_ECPARAMETERS (1U << 22) 560 #define PKCS11_CKFM_EC_NAMEDCURVE (1U << 23) 561 #define PKCS11_CKFM_EC_UNCOMPRESS (1U << 24) 562 #define PKCS11_CKFM_EC_COMPRESS (1U << 25) 563 564 /* 565 * pkcs11_object_head - Header of object whose data are serialized in memory 566 * 567 * An object is made of several attributes. Attributes are stored one next to 568 * the other with byte alignment as a serialized byte array. The byte array 569 * of serialized attributes is prepended with the size of the attrs[] array 570 * in bytes and the number of attributes in the array, yielding the struct 571 * pkcs11_object_head. 572 * 573 * @attrs_size - byte size of whole byte array attrs[] 574 * @attrs_count - number of attribute items stored in attrs[] 575 * @attrs - then starts the attributes data 576 */ 577 struct pkcs11_object_head { 578 uint32_t attrs_size; 579 uint32_t attrs_count; 580 uint8_t attrs[]; 581 }; 582 583 /* 584 * Attribute reference in the TA ABI. Each attribute starts with a header 585 * structure followed by the attribute value. The attribute byte size is 586 * defined in the attribute header. 587 * 588 * @id - the 32bit identifier of the attribute, see PKCS11_CKA_<x> 589 * @size - the 32bit value attribute byte size 590 * @data - then starts the attribute value 591 */ 592 struct pkcs11_attribute_head { 593 uint32_t id; 594 uint32_t size; 595 uint8_t data[]; 596 }; 597 598 /* 599 * Attribute identification IDs as of v2.40 excluding deprecated IDs. 600 * Valid values for struct pkcs11_attribute_head::id 601 * PKCS11_CKA_<x> reflects CryptoKi client API attribute IDs CKA_<x>. 602 */ 603 enum pkcs11_attr_id { 604 PKCS11_CKA_CLASS = 0x0000, 605 PKCS11_CKA_TOKEN = 0x0001, 606 PKCS11_CKA_PRIVATE = 0x0002, 607 PKCS11_CKA_LABEL = 0x0003, 608 PKCS11_CKA_APPLICATION = 0x0010, 609 PKCS11_CKA_VALUE = 0x0011, 610 PKCS11_CKA_OBJECT_ID = 0x0012, 611 PKCS11_CKA_CERTIFICATE_TYPE = 0x0080, 612 PKCS11_CKA_ISSUER = 0x0081, 613 PKCS11_CKA_SERIAL_NUMBER = 0x0082, 614 PKCS11_CKA_AC_ISSUER = 0x0083, 615 PKCS11_CKA_OWNER = 0x0084, 616 PKCS11_CKA_ATTR_TYPES = 0x0085, 617 PKCS11_CKA_TRUSTED = 0x0086, 618 PKCS11_CKA_CERTIFICATE_CATEGORY = 0x0087, 619 PKCS11_CKA_JAVA_MIDP_SECURITY_DOMAIN = 0x0088, 620 PKCS11_CKA_URL = 0x0089, 621 PKCS11_CKA_HASH_OF_SUBJECT_PUBLIC_KEY = 0x008a, 622 PKCS11_CKA_HASH_OF_ISSUER_PUBLIC_KEY = 0x008b, 623 PKCS11_CKA_NAME_HASH_ALGORITHM = 0x008c, 624 PKCS11_CKA_CHECK_VALUE = 0x0090, 625 PKCS11_CKA_KEY_TYPE = 0x0100, 626 PKCS11_CKA_SUBJECT = 0x0101, 627 PKCS11_CKA_ID = 0x0102, 628 PKCS11_CKA_SENSITIVE = 0x0103, 629 PKCS11_CKA_ENCRYPT = 0x0104, 630 PKCS11_CKA_DECRYPT = 0x0105, 631 PKCS11_CKA_WRAP = 0x0106, 632 PKCS11_CKA_UNWRAP = 0x0107, 633 PKCS11_CKA_SIGN = 0x0108, 634 PKCS11_CKA_SIGN_RECOVER = 0x0109, 635 PKCS11_CKA_VERIFY = 0x010a, 636 PKCS11_CKA_VERIFY_RECOVER = 0x010b, 637 PKCS11_CKA_DERIVE = 0x010c, 638 PKCS11_CKA_START_DATE = 0x0110, 639 PKCS11_CKA_END_DATE = 0x0111, 640 PKCS11_CKA_MODULUS = 0x0120, 641 PKCS11_CKA_MODULUS_BITS = 0x0121, 642 PKCS11_CKA_PUBLIC_EXPONENT = 0x0122, 643 PKCS11_CKA_PRIVATE_EXPONENT = 0x0123, 644 PKCS11_CKA_PRIME_1 = 0x0124, 645 PKCS11_CKA_PRIME_2 = 0x0125, 646 PKCS11_CKA_EXPONENT_1 = 0x0126, 647 PKCS11_CKA_EXPONENT_2 = 0x0127, 648 PKCS11_CKA_COEFFICIENT = 0x0128, 649 PKCS11_CKA_PUBLIC_KEY_INFO = 0x0129, 650 PKCS11_CKA_PRIME = 0x0130, 651 PKCS11_CKA_SUBPRIME = 0x0131, 652 PKCS11_CKA_BASE = 0x0132, 653 PKCS11_CKA_PRIME_BITS = 0x0133, 654 PKCS11_CKA_SUBPRIME_BITS = 0x0134, 655 PKCS11_CKA_VALUE_BITS = 0x0160, 656 PKCS11_CKA_VALUE_LEN = 0x0161, 657 PKCS11_CKA_EXTRACTABLE = 0x0162, 658 PKCS11_CKA_LOCAL = 0x0163, 659 PKCS11_CKA_NEVER_EXTRACTABLE = 0x0164, 660 PKCS11_CKA_ALWAYS_SENSITIVE = 0x0165, 661 PKCS11_CKA_KEY_GEN_MECHANISM = 0x0166, 662 PKCS11_CKA_MODIFIABLE = 0x0170, 663 PKCS11_CKA_COPYABLE = 0x0171, 664 PKCS11_CKA_DESTROYABLE = 0x0172, 665 PKCS11_CKA_EC_PARAMS = 0x0180, 666 PKCS11_CKA_EC_POINT = 0x0181, 667 PKCS11_CKA_ALWAYS_AUTHENTICATE = 0x0202, 668 PKCS11_CKA_WRAP_WITH_TRUSTED = 0x0210, 669 /* 670 * The leading 4 comes from the PKCS#11 spec or:ing with 671 * CKF_ARRAY_ATTRIBUTE = 0x40000000. 672 */ 673 PKCS11_CKA_WRAP_TEMPLATE = 0x40000211, 674 PKCS11_CKA_UNWRAP_TEMPLATE = 0x40000212, 675 PKCS11_CKA_DERIVE_TEMPLATE = 0x40000213, 676 PKCS11_CKA_OTP_FORMAT = 0x0220, 677 PKCS11_CKA_OTP_LENGTH = 0x0221, 678 PKCS11_CKA_OTP_TIME_INTERVAL = 0x0222, 679 PKCS11_CKA_OTP_USER_FRIENDLY_MODE = 0x0223, 680 PKCS11_CKA_OTP_CHALLENGE_REQUIREMENT = 0x0224, 681 PKCS11_CKA_OTP_TIME_REQUIREMENT = 0x0225, 682 PKCS11_CKA_OTP_COUNTER_REQUIREMENT = 0x0226, 683 PKCS11_CKA_OTP_PIN_REQUIREMENT = 0x0227, 684 PKCS11_CKA_OTP_COUNTER = 0x022e, 685 PKCS11_CKA_OTP_TIME = 0x022f, 686 PKCS11_CKA_OTP_USER_IDENTIFIER = 0x022a, 687 PKCS11_CKA_OTP_SERVICE_IDENTIFIER = 0x022b, 688 PKCS11_CKA_OTP_SERVICE_LOGO = 0x022c, 689 PKCS11_CKA_OTP_SERVICE_LOGO_TYPE = 0x022d, 690 PKCS11_CKA_GOSTR3410_PARAMS = 0x0250, 691 PKCS11_CKA_GOSTR3411_PARAMS = 0x0251, 692 PKCS11_CKA_GOST28147_PARAMS = 0x0252, 693 PKCS11_CKA_HW_FEATURE_TYPE = 0x0300, 694 PKCS11_CKA_RESET_ON_INIT = 0x0301, 695 PKCS11_CKA_HAS_RESET = 0x0302, 696 PKCS11_CKA_PIXEL_X = 0x0400, 697 PKCS11_CKA_PIXEL_Y = 0x0401, 698 PKCS11_CKA_RESOLUTION = 0x0402, 699 PKCS11_CKA_CHAR_ROWS = 0x0403, 700 PKCS11_CKA_CHAR_COLUMNS = 0x0404, 701 PKCS11_CKA_COLOR = 0x0405, 702 PKCS11_CKA_BITS_PER_PIXEL = 0x0406, 703 PKCS11_CKA_CHAR_SETS = 0x0480, 704 PKCS11_CKA_ENCODING_METHODS = 0x0481, 705 PKCS11_CKA_MIME_TYPES = 0x0482, 706 PKCS11_CKA_MECHANISM_TYPE = 0x0500, 707 PKCS11_CKA_REQUIRED_CMS_ATTRIBUTES = 0x0501, 708 PKCS11_CKA_DEFAULT_CMS_ATTRIBUTES = 0x0502, 709 PKCS11_CKA_SUPPORTED_CMS_ATTRIBUTES = 0x0503, 710 /* 711 * The leading 4 comes from the PKCS#11 spec or:ing with 712 * CKF_ARRAY_ATTRIBUTE = 0x40000000. 713 */ 714 PKCS11_CKA_ALLOWED_MECHANISMS = 0x40000600, 715 /* Vendor extension: reserved for undefined ID (~0U) */ 716 PKCS11_CKA_UNDEFINED_ID = PKCS11_UNDEFINED_ID, 717 }; 718 719 /* 720 * Valid values for attribute PKCS11_CKA_CLASS 721 * PKCS11_CKO_<x> reflects CryptoKi client API object class IDs CKO_<x>. 722 */ 723 enum pkcs11_class_id { 724 PKCS11_CKO_DATA = 0x000, 725 PKCS11_CKO_CERTIFICATE = 0x001, 726 PKCS11_CKO_PUBLIC_KEY = 0x002, 727 PKCS11_CKO_PRIVATE_KEY = 0x003, 728 PKCS11_CKO_SECRET_KEY = 0x004, 729 PKCS11_CKO_HW_FEATURE = 0x005, 730 PKCS11_CKO_DOMAIN_PARAMETERS = 0x006, 731 PKCS11_CKO_MECHANISM = 0x007, 732 PKCS11_CKO_OTP_KEY = 0x008, 733 /* Vendor extension: reserved for undefined ID (~0U) */ 734 PKCS11_CKO_UNDEFINED_ID = PKCS11_UNDEFINED_ID, 735 }; 736 737 /* 738 * Valid values for attribute PKCS11_CKA_KEY_TYPE 739 * PKCS11_CKK_<x> reflects CryptoKi client API key type IDs CKK_<x>. 740 * Note that this is only a subset of the PKCS#11 specification. 741 */ 742 enum pkcs11_key_type { 743 PKCS11_CKK_RSA = 0x000, 744 PKCS11_CKK_DSA = 0x001, 745 PKCS11_CKK_DH = 0x002, 746 PKCS11_CKK_EC = 0x003, 747 PKCS11_CKK_GENERIC_SECRET = 0x010, 748 PKCS11_CKK_AES = 0x01f, 749 PKCS11_CKK_MD5_HMAC = 0x027, 750 PKCS11_CKK_SHA_1_HMAC = 0x028, 751 PKCS11_CKK_SHA256_HMAC = 0x02b, 752 PKCS11_CKK_SHA384_HMAC = 0x02c, 753 PKCS11_CKK_SHA512_HMAC = 0x02d, 754 PKCS11_CKK_SHA224_HMAC = 0x02e, 755 /* Vendor extension: reserved for undefined ID (~0U) */ 756 PKCS11_CKK_UNDEFINED_ID = PKCS11_UNDEFINED_ID, 757 }; 758 759 /* 760 * Valid values for mechanism IDs 761 * PKCS11_CKM_<x> reflects CryptoKi client API mechanism IDs CKM_<x>. 762 * Note that this will be extended as needed. 763 */ 764 enum pkcs11_mechanism_id { 765 PKCS11_CKM_AES_KEY_GEN = 0x01080, 766 PKCS11_CKM_AES_ECB = 0x01081, 767 PKCS11_CKM_AES_CBC = 0x01082, 768 PKCS11_CKM_AES_CBC_PAD = 0x01085, 769 PKCS11_CKM_AES_CTR = 0x01086, 770 PKCS11_CKM_AES_CTS = 0x01089, 771 PKCS11_CKM_AES_ECB_ENCRYPT_DATA = 0x01104, 772 PKCS11_CKM_AES_CBC_ENCRYPT_DATA = 0x01105, 773 /* 774 * Vendor extensions below. 775 * PKCS11 added IDs for operation not related to a CK mechanism ID 776 */ 777 PKCS11_PROCESSING_IMPORT = 0x80000000, 778 PKCS11_CKM_UNDEFINED_ID = PKCS11_UNDEFINED_ID, 779 }; 780 #endif /*PKCS11_TA_H*/ 781