[34] | 1 | // =================================================================== |
---|
| 2 | // |
---|
| 3 | // Copyright (c) 2005, Intel Corp. |
---|
| 4 | // All rights reserved. |
---|
| 5 | // |
---|
| 6 | // Redistribution and use in source and binary forms, with or without |
---|
| 7 | // modification, are permitted provided that the following conditions |
---|
| 8 | // are met: |
---|
| 9 | // |
---|
| 10 | // * Redistributions of source code must retain the above copyright |
---|
| 11 | // notice, this list of conditions and the following disclaimer. |
---|
| 12 | // * Redistributions in binary form must reproduce the above |
---|
| 13 | // copyright notice, this list of conditions and the following |
---|
| 14 | // disclaimer in the documentation and/or other materials provided |
---|
| 15 | // with the distribution. |
---|
| 16 | // * Neither the name of Intel Corporation nor the names of its |
---|
| 17 | // contributors may be used to endorse or promote products derived |
---|
| 18 | // from this software without specific prior written permission. |
---|
| 19 | // |
---|
| 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
---|
| 23 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
---|
| 24 | // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
---|
| 25 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
| 26 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
---|
| 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
| 28 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
---|
| 29 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
---|
| 31 | // OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | // =================================================================== |
---|
| 33 | // |
---|
| 34 | // bsg.h |
---|
| 35 | // |
---|
| 36 | // This file contains API's for the TPM Byte Stream functions |
---|
| 37 | // |
---|
| 38 | // ================================================================== |
---|
| 39 | |
---|
| 40 | #ifndef __BSG_H__ |
---|
| 41 | #define __BSG_H__ |
---|
| 42 | |
---|
| 43 | #include <stdarg.h> |
---|
| 44 | #include "buffer.h" |
---|
| 45 | |
---|
| 46 | typedef unsigned int BSG_UINT32; |
---|
| 47 | typedef unsigned char BSG_BYTE; |
---|
| 48 | |
---|
| 49 | // forward decl |
---|
| 50 | struct pack_const_tuple_t; |
---|
| 51 | |
---|
| 52 | struct pack_tuple_t; |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | * Byte stream generator |
---|
| 57 | */ |
---|
| 58 | // this has to be manually kept in sync with the |
---|
| 59 | // s_fmt array!! |
---|
| 60 | // but now we have a self-check function which can make sure things are well |
---|
| 61 | // (if used!) |
---|
| 62 | typedef enum BSG_Type |
---|
| 63 | { |
---|
| 64 | BSG_TYPE_FIRST = 1, |
---|
| 65 | BSG_TYPE_UINT32 = 1, // start at 1 so that Type 0 only serves as an |
---|
| 66 | // unused/special value |
---|
| 67 | BSG_TYPE_UINT16, |
---|
| 68 | BSG_TYPE_BYTE, |
---|
| 69 | BSG_TYPE_BOOL, |
---|
| 70 | BSG_TPM_SIZE32_DATA, // a 32 bit unsigned size, followed by |
---|
| 71 | // a pointer to that much data. can pass a |
---|
| 72 | // struct pack_buf_t as the param |
---|
| 73 | BSG_TPM_TAG, |
---|
| 74 | BSG_TPM_HANDLE, |
---|
| 75 | BSG_TPM_RESULT, |
---|
| 76 | BSG_TPM_RESOURCE_TYPE, |
---|
| 77 | BSG_TPM_COMMAND_CODE, |
---|
| 78 | BSG_TPM_AUTH_DATA_USAGE, |
---|
| 79 | BSG_TPM_ALGORITHM_ID, |
---|
| 80 | BSG_TPM_PROTOCOL_ID, |
---|
| 81 | BSG_TPM_KEY_USAGE, |
---|
| 82 | BSG_TPM_ENC_SCHEME, |
---|
| 83 | BSG_TPM_SIG_SCHEME, |
---|
| 84 | BSG_TPM_MIGRATE_SCHEME, |
---|
| 85 | BSG_TPM_KEY_FLAGS, |
---|
| 86 | BSG_TPM_AUTHDATA, |
---|
| 87 | BSG_TPM_SECRET, |
---|
| 88 | BSG_TPM_ENCAUTH, |
---|
| 89 | BSG_TPM_PAYLOAD_TYPE, |
---|
| 90 | |
---|
| 91 | BSG_TPM_VERSION, |
---|
| 92 | BSG_TPM_DIGEST, |
---|
| 93 | BSG_TPM_COMPOSITE_HASH, |
---|
| 94 | BSG_TPM_CHOSENID_HASH, |
---|
| 95 | BSG_TPM_NONCE, |
---|
| 96 | BSG_TPM_KEY_HANDLE, |
---|
| 97 | BSG_TPM_KEY_HANDLE_LIST, |
---|
| 98 | BSG_TPM_KEY_PARMS, |
---|
| 99 | BSG_TPM_RSA_KEY_PARMS, |
---|
| 100 | BSG_TPM_STORE_PUBKEY, |
---|
| 101 | BSG_TPM_PUBKEY, |
---|
| 102 | BSG_TPM_KEY, |
---|
| 103 | |
---|
| 104 | BSG_TPM_MIGRATIONKEYAUTH, |
---|
| 105 | BSG_TCPA_AUDIT_EVENT, |
---|
| 106 | BSG_TCPA_EVENT_CERT, |
---|
| 107 | BSG_TPM_PCR_SELECTION, |
---|
| 108 | BSG_TPM_PCR_COMPOSITE, |
---|
| 109 | BSG_TPM_PCR_INFO, |
---|
| 110 | BSG_TPM_STORED_DATA, |
---|
| 111 | BSG_TPM_SYMMETRIC_KEY, |
---|
| 112 | BSG_TPM_STORE_PRIVKEY, |
---|
| 113 | BSG_TPM_STORE_ASYMKEY, |
---|
| 114 | BSG_TPM_MIGRATE_ASYMKEY, |
---|
| 115 | BSG_TPM_QUOTE_INFO, |
---|
| 116 | BSG_TPM_IDENTITY_CONTENTS, |
---|
| 117 | BSG_TPM_PCRVALUE, |
---|
| 118 | BSG_TCPA_PCR_FLAGS, |
---|
| 119 | BSG_TCS_AUTH, |
---|
| 120 | |
---|
| 121 | // this is the BSG_TPM_KEY struct without the encData field |
---|
| 122 | BSG_TPM_KEY_NONSENSITIVE, |
---|
| 123 | |
---|
| 124 | BSG_PACKED, |
---|
| 125 | |
---|
| 126 | BSG_TYPE_MAX |
---|
| 127 | } BSG_Type; |
---|
| 128 | |
---|
| 129 | struct pack_const_tuple_t { |
---|
| 130 | BSG_Type type; |
---|
| 131 | const void * addr; |
---|
| 132 | }; |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | typedef struct pack_tuple_t { |
---|
| 136 | BSG_Type type; |
---|
| 137 | void * addr; |
---|
| 138 | } pack_tuple_t; |
---|
| 139 | |
---|
| 140 | int BSG_Pack(BSG_Type type, const void* src, BSG_BYTE* dst); |
---|
| 141 | int BSG_Unpack(BSG_Type type, const BSG_BYTE* src, void* dst); |
---|
| 142 | void BSG_Destroy(BSG_Type type, void* src); |
---|
| 143 | |
---|
| 144 | // wrappers of Pack and PackList which malloc the ouput buffer. to be freed |
---|
| 145 | // by the caller later. returns size of allocated buffer, or -1 in case |
---|
| 146 | // allocation failed |
---|
| 147 | int BSG_PackMalloc (BSG_Type type, const void* src, BSG_BYTE** o_dst); |
---|
| 148 | int BSG_PackListMalloc (BSG_BYTE** outBuffer, int ParamCount, ... ); |
---|
| 149 | |
---|
| 150 | // a va_list version of PackList |
---|
| 151 | int BSG_PackList(BSG_BYTE* outBuffer, int ParamCount, ... ); |
---|
| 152 | int BSG_UnpackList(const BSG_BYTE* inBuffer, int ParamCount, ... ); |
---|
| 153 | void BSG_DestroyList(int ParamCount, ... ); |
---|
| 154 | |
---|
| 155 | // wrapper of PackList which uses a buffer_t |
---|
| 156 | TPM_RESULT BSG_PackListBuf (buffer_t * o_buf, int ParamCount, ...); |
---|
| 157 | |
---|
| 158 | // and a tuple version |
---|
| 159 | TPM_RESULT BSG_DestroyTuple (int numParams, pack_tuple_t params[]); |
---|
| 160 | |
---|
| 161 | void BSG_PackConst(BSG_UINT32 val, int size, BSG_BYTE* dst); |
---|
| 162 | BSG_UINT32 BSG_UnpackConst(const BSG_BYTE* src, int size); |
---|
| 163 | |
---|
| 164 | BOOL BSG_static_selfcheck (); |
---|
| 165 | |
---|
| 166 | #endif |
---|