1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /******************************************************************************* 3 * Copyright 2017-2018, Fraunhofer SIT sponsored by Infineon Technologies AG 4 * All rights reserved. 5 *******************************************************************************/ 6 #ifndef TSS2_FAPI_H 7 #define TSS2_FAPI_H 8 9 #include "tss2_tcti.h" 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 /* Type definitions */ 16 17 typedef struct FAPI_CONTEXT FAPI_CONTEXT; 18 19 /* Context functions */ 20 21 TSS2_RC Fapi_Initialize( 22 FAPI_CONTEXT **context, 23 char const *uri); 24 25 TSS2_RC Fapi_Initialize_Async( 26 FAPI_CONTEXT **context, 27 char const *uri); 28 29 TSS2_RC Fapi_Initialize_Finish( 30 FAPI_CONTEXT **context); 31 32 void Fapi_Finalize( 33 FAPI_CONTEXT **context); 34 35 TSS2_RC Fapi_GetTcti( 36 FAPI_CONTEXT *context, 37 TSS2_TCTI_CONTEXT **tcti); 38 39 void Fapi_Free( 40 void *ptr); 41 42 #if defined(__linux__) || defined(__unix__) || defined(__APPLE__) || defined (__QNXNTO__) || defined (__VXWORKS__) 43 #if defined (__VXWORKS__) 44 #include <sys/poll.h> 45 #else 46 #include <poll.h> 47 #endif 48 typedef struct pollfd FAPI_POLL_HANDLE; 49 #elif defined(_WIN32) 50 #include <windows.h> 51 typedef HANDLE FAPI_POLL_HANDLE; 52 #else 53 typedef void FAPI_POLL_HANDLE; 54 #ifndef FAPI_SUPPRESS_POLL_WARNINGS 55 #pragma message "Info: Platform not supported for FAPI_POLL_HANDLES" 56 #endif 57 #endif 58 59 TSS2_RC Fapi_GetPollHandles( 60 FAPI_CONTEXT *context, 61 FAPI_POLL_HANDLE **handles, 62 size_t *num_handles); 63 64 TSS2_RC Fapi_GetInfo( 65 FAPI_CONTEXT *context, 66 char **info); 67 68 TSS2_RC Fapi_GetInfo_Async( 69 FAPI_CONTEXT *context); 70 71 TSS2_RC Fapi_GetInfo_Finish( 72 FAPI_CONTEXT *context, 73 char **info); 74 75 /* General functions */ 76 77 TSS2_RC Fapi_Provision( 78 FAPI_CONTEXT *context, 79 char const *authValueEh, 80 char const *authValueSh, 81 char const *authValueLockout); 82 83 TSS2_RC Fapi_Provision_Async( 84 FAPI_CONTEXT *context, 85 char const *authValueEh, 86 char const *authValueSh, 87 char const *authValueLockout); 88 89 TSS2_RC Fapi_Provision_Finish( 90 FAPI_CONTEXT *context); 91 92 TSS2_RC Fapi_GetPlatformCertificates( 93 FAPI_CONTEXT *context, 94 uint8_t **certificates, 95 size_t *certificatesSize); 96 97 TSS2_RC Fapi_GetPlatformCertificates_Async( 98 FAPI_CONTEXT *context); 99 100 TSS2_RC Fapi_GetPlatformCertificates_Finish( 101 FAPI_CONTEXT *context, 102 uint8_t **certificates, 103 size_t *certificatesSize); 104 105 TSS2_RC Fapi_GetRandom( 106 FAPI_CONTEXT *context, 107 size_t numBytes, 108 uint8_t **data); 109 110 TSS2_RC Fapi_GetRandom_Async( 111 FAPI_CONTEXT *context, 112 size_t numBytes); 113 114 TSS2_RC Fapi_GetRandom_Finish( 115 FAPI_CONTEXT *context, 116 uint8_t **data); 117 118 TSS2_RC Fapi_Import( 119 FAPI_CONTEXT *context, 120 char const *path, 121 char const *importData); 122 123 TSS2_RC Fapi_Import_Async( 124 FAPI_CONTEXT *context, 125 char const *path, 126 char const *importData); 127 128 TSS2_RC Fapi_Import_Finish( 129 FAPI_CONTEXT *context); 130 131 TSS2_RC Fapi_List( 132 FAPI_CONTEXT *context, 133 char const *searchPath, 134 char **pathList); 135 136 TSS2_RC Fapi_List_Async( 137 FAPI_CONTEXT *context, 138 char const *searchPath); 139 140 TSS2_RC Fapi_List_Finish( 141 FAPI_CONTEXT *context, 142 char **pathList); 143 144 TSS2_RC Fapi_Delete( 145 FAPI_CONTEXT *context, 146 char const *path); 147 148 TSS2_RC Fapi_Delete_Async( 149 FAPI_CONTEXT *context, 150 char const *path); 151 152 TSS2_RC Fapi_Delete_Finish( 153 FAPI_CONTEXT *context); 154 155 TSS2_RC Fapi_ChangeAuth( 156 FAPI_CONTEXT *context, 157 char const *entityPath, 158 char const *authValue); 159 160 TSS2_RC Fapi_ChangeAuth_Async( 161 FAPI_CONTEXT *context, 162 char const *entityPath, 163 char const *authValue); 164 165 TSS2_RC Fapi_ChangeAuth_Finish( 166 FAPI_CONTEXT *context); 167 168 TSS2_RC Fapi_SetDescription( 169 FAPI_CONTEXT *context, 170 char const *path, 171 char const *description); 172 173 TSS2_RC Fapi_SetDescription_Async( 174 FAPI_CONTEXT *context, 175 char const *path, 176 char const *description); 177 178 TSS2_RC Fapi_SetDescription_Finish( 179 FAPI_CONTEXT *context); 180 181 TSS2_RC Fapi_GetDescription( 182 FAPI_CONTEXT *context, 183 char const *path, 184 char **description); 185 186 TSS2_RC Fapi_GetDescription_Async( 187 FAPI_CONTEXT *context, 188 char const *path); 189 190 TSS2_RC Fapi_GetDescription_Finish( 191 FAPI_CONTEXT *context, 192 char **description); 193 194 TSS2_RC Fapi_SetAppData( 195 FAPI_CONTEXT *context, 196 char const *path, 197 uint8_t const *appData, 198 size_t appDataSize); 199 200 TSS2_RC Fapi_SetAppData_Async( 201 FAPI_CONTEXT *context, 202 char const *path, 203 uint8_t const *appData, 204 size_t appDataSize); 205 206 TSS2_RC Fapi_SetAppData_Finish( 207 FAPI_CONTEXT *context); 208 209 TSS2_RC Fapi_GetAppData( 210 FAPI_CONTEXT *context, 211 char const *path, 212 uint8_t **appData, 213 size_t *appDataSize); 214 215 TSS2_RC Fapi_GetAppData_Async( 216 FAPI_CONTEXT *context, 217 char const *path); 218 219 TSS2_RC Fapi_GetAppData_Finish( 220 FAPI_CONTEXT *context, 221 uint8_t **appData, 222 size_t *appDataSize); 223 224 TSS2_RC Fapi_GetTpmBlobs( 225 FAPI_CONTEXT *context, 226 char const *path, 227 uint8_t **tpm2bPublic, 228 size_t *tpm2bPublicSize, 229 uint8_t **tpm2bPrivate, 230 size_t *tpm2bPrivateSize, 231 char **policy); 232 233 TSS2_RC Fapi_GetTpmBlobs_Async( 234 FAPI_CONTEXT *context, 235 char const *path); 236 237 TSS2_RC Fapi_GetTpmBlobs_Finish( 238 FAPI_CONTEXT *context, 239 uint8_t **tpm2bPublic, 240 size_t *tpm2bPublicSize, 241 uint8_t **tpm2bPrivate, 242 size_t *tpm2bPrivateSize, 243 char **policy); 244 245 /* Key functions */ 246 247 TSS2_RC Fapi_CreateKey( 248 FAPI_CONTEXT *context, 249 char const *path, 250 char const *type, 251 char const *policyPath, 252 char const *authValue); 253 254 TSS2_RC Fapi_CreateKey_Async( 255 FAPI_CONTEXT *context, 256 char const *path, 257 char const *type, 258 char const *policyPath, 259 char const *authValue); 260 261 TSS2_RC Fapi_CreateKey_Finish( 262 FAPI_CONTEXT *context); 263 264 TSS2_RC Fapi_Sign( 265 FAPI_CONTEXT *context, 266 char const *keyPath, 267 char const *padding, 268 uint8_t const *digest, 269 size_t digestSize, 270 uint8_t **signature, 271 size_t *signatureSize, 272 char **publicKey, 273 char **certificate); 274 275 TSS2_RC Fapi_Sign_Async( 276 FAPI_CONTEXT *context, 277 char const *keyPath, 278 char const *padding, 279 uint8_t const *digest, 280 size_t digestSize); 281 282 TSS2_RC Fapi_Sign_Finish( 283 FAPI_CONTEXT *context, 284 uint8_t **signature, 285 size_t *signatureSize, 286 char **publicKey, 287 char **certificate); 288 289 TSS2_RC Fapi_VerifySignature( 290 FAPI_CONTEXT *context, 291 char const *keyPath, 292 uint8_t const *digest, 293 size_t digestSize, 294 uint8_t const *signature, 295 size_t signatureSize); 296 297 TSS2_RC Fapi_VerifySignature_Async( 298 FAPI_CONTEXT *context, 299 char const *keyPath, 300 uint8_t const *digest, 301 size_t digestSize, 302 uint8_t const *signature, 303 size_t signatureSize); 304 305 TSS2_RC Fapi_VerifySignature_Finish( 306 FAPI_CONTEXT *context); 307 308 TSS2_RC Fapi_Encrypt( 309 FAPI_CONTEXT *context, 310 char const *keyPath, 311 uint8_t const *plainText, 312 size_t plainTextSize, 313 uint8_t **cipherText, 314 size_t *cipherTextSize); 315 316 TSS2_RC Fapi_Encrypt_Async( 317 FAPI_CONTEXT *context, 318 char const *keyPath, 319 uint8_t const *plainText, 320 size_t plainTextSize); 321 322 TSS2_RC Fapi_Encrypt_Finish( 323 FAPI_CONTEXT *context, 324 uint8_t **cipherText, 325 size_t *cipherTextSize ); 326 327 TSS2_RC Fapi_Decrypt( 328 FAPI_CONTEXT *context, 329 char const *keyPath, 330 uint8_t const *cipherText, 331 size_t cipherTextSize, 332 uint8_t **plainText, 333 size_t *plainTextSize); 334 335 TSS2_RC Fapi_Decrypt_Async( 336 FAPI_CONTEXT *context, 337 char const *keyPath, 338 uint8_t const *cipherText, 339 size_t cipherTextSize); 340 341 TSS2_RC Fapi_Decrypt_Finish( 342 FAPI_CONTEXT *context, 343 uint8_t **plainText, 344 size_t *plainTextSize); 345 346 TSS2_RC Fapi_SetCertificate( 347 FAPI_CONTEXT *context, 348 char const *path, 349 char const *x509certData); 350 351 TSS2_RC Fapi_SetCertificate_Async( 352 FAPI_CONTEXT *context, 353 char const *path, 354 char const *x509certData); 355 356 TSS2_RC Fapi_SetCertificate_Finish( 357 FAPI_CONTEXT *context); 358 359 TSS2_RC Fapi_GetCertificate( 360 FAPI_CONTEXT *context, 361 char const *path, 362 char **x509certData); 363 364 TSS2_RC Fapi_GetCertificate_Async( 365 FAPI_CONTEXT *context, 366 char const *path); 367 368 TSS2_RC Fapi_GetCertificate_Finish( 369 FAPI_CONTEXT *context, 370 char **x509certData); 371 372 TSS2_RC Fapi_ExportKey( 373 FAPI_CONTEXT *context, 374 char const *pathOfKeyToDuplicate, 375 char const *pathToPublicKeyOfNewParent, 376 char **exportedData); 377 378 TSS2_RC Fapi_ExportKey_Async( 379 FAPI_CONTEXT *context, 380 char const *pathOfKeyToDuplicate, 381 char const *pathToPublicKeyOfNewParent); 382 383 TSS2_RC Fapi_ExportKey_Finish( 384 FAPI_CONTEXT *context, 385 char **exportedData); 386 387 /* Seal functions */ 388 389 TSS2_RC Fapi_CreateSeal( 390 FAPI_CONTEXT *context, 391 char const *path, 392 char const *type, 393 size_t size, 394 char const *policyPath, 395 char const *authValue, 396 uint8_t const *data); 397 398 TSS2_RC Fapi_CreateSeal_Async( 399 FAPI_CONTEXT *context, 400 char const *path, 401 char const *type, 402 size_t size, 403 char const *policyPath, 404 char const *authValue, 405 uint8_t const *data); 406 407 TSS2_RC Fapi_CreateSeal_Finish( 408 FAPI_CONTEXT *context); 409 410 TSS2_RC Fapi_Unseal( 411 FAPI_CONTEXT *context, 412 char const *path, 413 uint8_t **data, 414 size_t *size); 415 416 TSS2_RC Fapi_Unseal_Async( 417 FAPI_CONTEXT *context, 418 char const *path); 419 420 TSS2_RC Fapi_Unseal_Finish( 421 FAPI_CONTEXT *context, 422 uint8_t **data, 423 size_t *size); 424 425 /* Policy functions */ 426 427 TSS2_RC Fapi_ExportPolicy( 428 FAPI_CONTEXT *context, 429 char const *path, 430 char **jsonPolicy); 431 432 TSS2_RC Fapi_ExportPolicy_Async( 433 FAPI_CONTEXT *context, 434 char const *path); 435 436 TSS2_RC Fapi_ExportPolicy_Finish( 437 FAPI_CONTEXT *context, 438 char **jsonPolicy); 439 440 TSS2_RC Fapi_AuthorizePolicy( 441 FAPI_CONTEXT *context, 442 char const *policyPath, 443 char const *keyPath, 444 uint8_t const *policyRef, 445 size_t policyRefSize); 446 447 TSS2_RC Fapi_AuthorizePolicy_Async( 448 FAPI_CONTEXT *context, 449 char const *policyPath, 450 char const *keyPath, 451 uint8_t const *policyRef, 452 size_t policyRefSize); 453 454 TSS2_RC Fapi_AuthorizePolicy_Finish( 455 FAPI_CONTEXT *context); 456 457 TSS2_RC Fapi_WriteAuthorizeNv( 458 FAPI_CONTEXT *context, 459 char const *nvPath, 460 char const *policyPath); 461 462 TSS2_RC Fapi_WriteAuthorizeNv_Async( 463 FAPI_CONTEXT *context, 464 char const *nvPath, 465 char const *policyPath); 466 467 TSS2_RC Fapi_WriteAuthorizeNv_Finish( 468 FAPI_CONTEXT *context); 469 470 /* Attestation functions */ 471 472 TSS2_RC Fapi_PcrRead( 473 FAPI_CONTEXT *context, 474 uint32_t pcrIndex, 475 uint8_t **pcrValue, 476 size_t *pcrValueSize, 477 char **pcrLog); 478 479 TSS2_RC Fapi_PcrRead_Async( 480 FAPI_CONTEXT *context, 481 uint32_t pcrIndex); 482 483 TSS2_RC Fapi_PcrRead_Finish( 484 FAPI_CONTEXT *context, 485 uint8_t **pcrValue, 486 size_t *pcrValueSize, 487 char **pcrLog); 488 489 TSS2_RC Fapi_PcrExtend( 490 FAPI_CONTEXT *context, 491 uint32_t pcr, 492 uint8_t const *data, 493 size_t dataSize, 494 char const *logData); 495 496 TSS2_RC Fapi_PcrExtend_Async( 497 FAPI_CONTEXT *context, 498 uint32_t pcr, 499 uint8_t const *data, 500 size_t dataSize, 501 char const *logData); 502 503 TSS2_RC Fapi_PcrExtend_Finish( 504 FAPI_CONTEXT *context); 505 506 507 TSS2_RC Fapi_Quote( 508 FAPI_CONTEXT *context, 509 uint32_t *pcrList, 510 size_t pcrListSize, 511 char const *keyPath, 512 char const *quoteType, 513 uint8_t const *qualifyingData, 514 size_t qualifyingDataSize, 515 char **quoteInfo, 516 uint8_t **signature, 517 size_t *signatureSize, 518 char **pcrLog, 519 char **certificate); 520 521 TSS2_RC Fapi_Quote_Async( 522 FAPI_CONTEXT *context, 523 uint32_t *pcrList, 524 size_t pcrListSize, 525 char const *keyPath, 526 char const *quoteType, 527 uint8_t const *qualifyingData, 528 size_t qualifyingDataSize); 529 530 TSS2_RC Fapi_Quote_Finish( 531 FAPI_CONTEXT *context, 532 char **quoteInfo, 533 uint8_t **signature, 534 size_t *signatureSize, 535 char **pcrLog, 536 char **certificate); 537 538 TSS2_RC Fapi_VerifyQuote( 539 FAPI_CONTEXT *context, 540 char const *publicKeyPath, 541 uint8_t const *qualifyingData, 542 size_t qualifyingDataSize, 543 char const *quoteInfo, 544 uint8_t const *signature, 545 size_t signatureSize, 546 char const *pcrLog); 547 548 TSS2_RC Fapi_VerifyQuote_Async( 549 FAPI_CONTEXT *context, 550 char const *publicKeyPath, 551 uint8_t const *qualifyingData, 552 size_t qualifyingDataSize, 553 char const *quoteInfo, 554 uint8_t const *signature, 555 size_t signatureSize, 556 char const *pcrLog); 557 558 TSS2_RC Fapi_VerifyQuote_Finish( 559 FAPI_CONTEXT *context); 560 561 /* NV functions */ 562 563 TSS2_RC Fapi_CreateNv( 564 FAPI_CONTEXT *context, 565 char const *path, 566 char const *type, 567 size_t size, 568 char const *policyPath, 569 char const *authValue); 570 571 TSS2_RC Fapi_CreateNv_Async( 572 FAPI_CONTEXT *context, 573 char const *path, 574 char const *type, 575 size_t size, 576 char const *policyPath, 577 char const *authValue); 578 579 TSS2_RC Fapi_CreateNv_Finish( 580 FAPI_CONTEXT *context); 581 582 TSS2_RC Fapi_NvRead( 583 FAPI_CONTEXT *context, 584 char const *path, 585 uint8_t **data, 586 size_t *size, 587 char **logData); 588 589 TSS2_RC Fapi_NvRead_Async( 590 FAPI_CONTEXT *context, 591 char const *path); 592 593 TSS2_RC Fapi_NvRead_Finish( 594 FAPI_CONTEXT *context, 595 uint8_t **data, 596 size_t *size, 597 char **logData); 598 599 TSS2_RC Fapi_NvWrite( 600 FAPI_CONTEXT *context, 601 char const *path, 602 uint8_t const *data, 603 size_t size); 604 605 TSS2_RC Fapi_NvWrite_Async( 606 FAPI_CONTEXT *context, 607 char const *path, 608 uint8_t const *data, 609 size_t size); 610 611 TSS2_RC Fapi_NvWrite_Finish( 612 FAPI_CONTEXT *context); 613 614 TSS2_RC Fapi_NvExtend( 615 FAPI_CONTEXT *context, 616 char const *path, 617 uint8_t const *data, 618 size_t size, 619 char const *logData); 620 621 TSS2_RC Fapi_NvExtend_Async( 622 FAPI_CONTEXT *context, 623 char const *path, 624 uint8_t const *data, 625 size_t size, 626 char const *logData); 627 628 TSS2_RC Fapi_NvExtend_Finish( 629 FAPI_CONTEXT *context); 630 631 TSS2_RC Fapi_NvIncrement( 632 FAPI_CONTEXT *context, 633 char const *path); 634 635 TSS2_RC Fapi_NvIncrement_Async( 636 FAPI_CONTEXT *context, 637 char const *path); 638 639 TSS2_RC Fapi_NvIncrement_Finish( 640 FAPI_CONTEXT *context); 641 642 TSS2_RC Fapi_NvSetBits( 643 FAPI_CONTEXT *context, 644 char const *path, 645 uint64_t bitmap); 646 647 TSS2_RC Fapi_NvSetBits_Async( 648 FAPI_CONTEXT *context, 649 char const *path, 650 uint64_t bitmap); 651 652 TSS2_RC Fapi_NvSetBits_Finish( 653 FAPI_CONTEXT *context); 654 655 typedef TSS2_RC (*Fapi_CB_Auth)( 656 FAPI_CONTEXT *context, 657 char const *description, 658 char **auth, 659 void *userData); 660 661 TSS2_RC Fapi_SetAuthCB( 662 FAPI_CONTEXT *context, 663 Fapi_CB_Auth callback, 664 void *userData); 665 666 typedef TSS2_RC (*Fapi_CB_Branch)( 667 FAPI_CONTEXT *context, 668 char const *description, 669 char const **branchNames, 670 size_t numBranches, 671 size_t *selectedBranch, 672 void *userData); 673 674 TSS2_RC Fapi_SetBranchCB( 675 FAPI_CONTEXT *context, 676 Fapi_CB_Branch callback, 677 void *userData); 678 679 typedef TSS2_RC (*Fapi_CB_Sign)( 680 FAPI_CONTEXT *context, 681 char const *description, 682 char const *publicKey, 683 char const *publicKeyHint, 684 uint32_t hashAlg, 685 uint8_t const *dataToSign, 686 size_t dataToSignSize, 687 uint8_t **signature, 688 size_t *signatureSize, 689 void *userData); 690 691 TSS2_RC Fapi_SetSignCB( 692 FAPI_CONTEXT *context, 693 Fapi_CB_Sign callback, 694 void *userData); 695 696 typedef TSS2_RC (*Fapi_CB_PolicyAction)( 697 FAPI_CONTEXT *context, 698 char const *action, 699 void *userData); 700 701 TSS2_RC Fapi_SetPolicyActionCB( 702 FAPI_CONTEXT *context, 703 Fapi_CB_PolicyAction callback, 704 void *userData); 705 706 #ifdef __cplusplus 707 } 708 #endif 709 710 #endif /* TSS2_FAPI_H */ 711