NingSun | 535535b | 2018-02-28 18:24:31 -0800 | [diff] [blame] | 1 | //**********************************************************************; |
| 2 | // Copyright (c) 2017, Intel Corporation |
| 3 | // All rights reserved. |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are met: |
| 7 | // |
| 8 | // 1. Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // |
| 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | // this list of conditions and the following disclaimer in the documentation |
| 13 | // and/or other materials provided with the distribution. |
| 14 | // |
| 15 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 18 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 19 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 25 | // THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | //**********************************************************************; |
| 27 | |
| 28 | #ifndef __TPM_API_H__ |
| 29 | #define __TPM_API_H__ |
| 30 | |
| 31 | #include <stdlib.h> |
| 32 | #include <stdio.h> |
| 33 | #include <string.h> |
| 34 | #include <limits.h> |
| 35 | #include <ctype.h> |
| 36 | #include <getopt.h> |
| 37 | |
NingSun | 8a5b33a | 2018-03-27 10:42:51 -0700 | [diff] [blame^] | 38 | #include <tss2/tss2_sys.h> |
NingSun | 535535b | 2018-02-28 18:24:31 -0800 | [diff] [blame] | 39 | |
| 40 | #include "plugin_register.h" |
| 41 | |
| 42 | #ifdef __cplusplus |
| 43 | extern "C" { |
| 44 | #endif |
| 45 | |
| 46 | #define TPM_SKM_SRK_HANDLE 0x81000011 |
| 47 | |
| 48 | #define TPM_SKM_AC0_HANDLE 0x90000000 |
| 49 | #define TPM_SKM_AC1_HANDLE 0x90000001 |
| 50 | #define TPM_SKM_AC2_HANDLE 0x90000002 |
| 51 | |
| 52 | #define TPM_SKM_APP_HANDLE 0x91100001 |
| 53 | |
| 54 | #define INIT_SIMPLE_TPM2B_SIZE( type ) (type).t.size = sizeof( type ) - 2; |
| 55 | |
| 56 | #define APP_RC_OFFSET 0x100 |
| 57 | |
| 58 | #define TSS2_APP_RC_PASSED (APP_RC_PASSED + APP_RC_OFFSET + TSS2_APP_ERROR_LEVEL) |
| 59 | #define TSS2_APP_RC_GET_NAME_FAILED (APP_RC_GET_NAME_FAILED + APP_RC_OFFSET + TSS2_APP_ERROR_LEVEL) |
| 60 | #define TSS2_APP_RC_CREATE_SESSION_KEY_FAILED (APP_RC_CREATE_SESSION_KEY_FAILED + APP_RC_OFFSET + TSS2_APP_ERROR_LEVEL) |
| 61 | #define TSS2_APP_RC_SESSION_SLOT_NOT_FOUND (APP_RC_SESSION_SLOT_NOT_FOUND + APP_RC_OFFSET + TSS2_APP_ERROR_LEVEL) |
| 62 | #define TSS2_APP_RC_BAD_ALGORITHM (APP_RC_BAD_ALGORITHM + APP_RC_OFFSET + TSS2_APP_ERROR_LEVEL) |
| 63 | #define TSS2_APP_RC_SYS_CONTEXT_CREATE_FAILED (APP_RC_SYS_CONTEXT_CREATE_FAILED + APP_RC_OFFSET + TSS2_APP_ERROR_LEVEL) |
| 64 | #define TSS2_APP_RC_GET_SESSION_STRUCT_FAILED (APP_RC_GET_SESSION_STRUCT_FAILED + APP_RC_OFFSET + TSS2_APP_ERROR_LEVEL) |
| 65 | #define TSS2_APP_RC_GET_SESSION_ALG_ID_FAILED (APP_RC_GET_SESSION_ALG_ID_FAILED + APP_RC_OFFSET + TSS2_APP_ERROR_LEVEL) |
| 66 | #define TSS2_APP_RC_INIT_SYS_CONTEXT_FAILED (APP_RC_INIT_SYS_CONTEXT_FAILED + APP_RC_OFFSET + TSS2_APP_ERROR_LEVEL) |
| 67 | #define TSS2_APP_RC_TEARDOWN_SYS_CONTEXT_FAILED (APP_RC_TEARDOWN_SYS_CONTEXT_FAILED + APP_RC_OFFSET + TSS2_APP_ERROR_LEVEL) |
| 68 | #define TSS2_APP_RC_BAD_LOCALITY (APP_RC_BAD_LOCALITY + APP_RC_OFFSET + TSS2_APP_ERROR_LEVEL) |
| 69 | |
| 70 | enum TSS2_APP_RC_CODE |
| 71 | { |
| 72 | APP_RC_PASSED, |
| 73 | APP_RC_GET_NAME_FAILED, |
| 74 | APP_RC_CREATE_SESSION_KEY_FAILED, |
| 75 | APP_RC_SESSION_SLOT_NOT_FOUND, |
| 76 | APP_RC_BAD_ALGORITHM, |
| 77 | APP_RC_SYS_CONTEXT_CREATE_FAILED, |
| 78 | APP_RC_GET_SESSION_STRUCT_FAILED, |
| 79 | APP_RC_GET_SESSION_ALG_ID_FAILED, |
| 80 | APP_RC_INIT_SYS_CONTEXT_FAILED, |
| 81 | APP_RC_TEARDOWN_SYS_CONTEXT_FAILED, |
| 82 | APP_RC_BAD_LOCALITY |
| 83 | }; |
| 84 | |
| 85 | TSS2_SYS_CONTEXT *InitSysContext (UINT16 maxCommandSize, |
| 86 | TSS2_TCTI_CONTEXT *tctiContext, |
| 87 | TSS2_ABI_VERSION *abiVersion ); |
| 88 | |
| 89 | void TeardownSysContext( TSS2_SYS_CONTEXT **sysContext ); |
| 90 | |
| 91 | TSS2_RC TeardownTctiResMgrContext( TSS2_TCTI_CONTEXT *tctiContext ); |
| 92 | |
NingSun | 8a5b33a | 2018-03-27 10:42:51 -0700 | [diff] [blame^] | 93 | int tpm2_plugin_init(); |
| 94 | int tpm2_plugin_uninit(); |
| 95 | int tpm2_plugin_activate(SSHSM_HW_PLUGIN_ACTIVATE_IN_INFO_t *activate_in_info); |
| 96 | int tpm2_plugin_load_key( |
| 97 | SSHSM_HW_PLUGIN_LOAD_KEY_IN_INFO_t *loadkey_in_info, |
| 98 | void **keyHandle |
| 99 | ); |
| 100 | |
NingSun | 535535b | 2018-02-28 18:24:31 -0800 | [diff] [blame] | 101 | int tpm2_rsa_create_object( |
| 102 | unsigned long appHandle, |
| 103 | //DhsmWPKRSAFormat* wpk, |
| 104 | void *wpk, |
| 105 | unsigned char* swk, |
| 106 | int swk_len, |
| 107 | unsigned char* iv, |
| 108 | int iv_len, |
| 109 | int tag_len, |
| 110 | void **cb_object); |
| 111 | |
| 112 | int tpm2_rsa_delete_object( |
| 113 | void *cb_object); |
| 114 | |
NingSun | 8a5b33a | 2018-03-27 10:42:51 -0700 | [diff] [blame^] | 115 | int tpm2_plugin_rsa_sign_init( |
NingSun | 535535b | 2018-02-28 18:24:31 -0800 | [diff] [blame] | 116 | unsigned long mechanish, |
| 117 | void *param, |
| 118 | size_t len, |
| 119 | void *ctx); |
| 120 | |
NingSun | 8a5b33a | 2018-03-27 10:42:51 -0700 | [diff] [blame^] | 121 | int tpm2_plugin_rsa_sign( |
NingSun | 535535b | 2018-02-28 18:24:31 -0800 | [diff] [blame] | 122 | void *ctx, |
| 123 | unsigned char *msg, |
| 124 | int msg_len, |
| 125 | unsigned char *sig, |
| 126 | int *sig_len); |
| 127 | |
| 128 | |
| 129 | int tpm2_import_object( |
NingSun | 8a5b33a | 2018-03-27 10:42:51 -0700 | [diff] [blame^] | 130 | unsigned long appHandle, |
| 131 | unsigned char* tlvbuffer, |
| 132 | int buflen, |
| 133 | unsigned char* iv, |
| 134 | int iv_len, |
| 135 | unsigned char* tpm_pwd, |
NingSun | 535535b | 2018-02-28 18:24:31 -0800 | [diff] [blame] | 136 | int tpm_pwd_len); |
| 137 | |
| 138 | |
| 139 | #ifdef __cplusplus |
| 140 | } |
| 141 | #endif |
| 142 | |
| 143 | |
| 144 | #endif |