| 1 |
/* |
| 2 |
* Copyright (c) 2010-2012 United States Government, as represented by |
| 3 |
* the Secretary of Defense. All rights reserved. |
| 4 |
* |
| 5 |
* based off of the original tools/vtpm_manager code base which is: |
| 6 |
* Copyright (c) 2005, Intel Corp. |
| 7 |
* All rights reserved. |
| 8 |
* |
| 9 |
* Redistribution and use in source and binary forms, with or without |
| 10 |
* modification, are permitted provided that the following conditions |
| 11 |
* are met: |
| 12 |
* |
| 13 |
* * Redistributions of source code must retain the above copyright |
| 14 |
* notice, this list of conditions and the following disclaimer. |
| 15 |
* * Redistributions in binary form must reproduce the above |
| 16 |
* copyright notice, this list of conditions and the following |
| 17 |
* disclaimer in the documentation and/or other materials provided |
| 18 |
* with the distribution. |
| 19 |
* * Neither the name of Intel Corporation nor the names of its |
| 20 |
* contributors may be used to endorse or promote products derived |
| 21 |
* from this software without specific prior written permission. |
| 22 |
* |
| 23 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 24 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 25 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 26 |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 27 |
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 28 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 29 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 30 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 31 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 32 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 33 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 34 |
* OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 |
*/ |
| 36 |
|
| 37 |
#ifndef MARSHAL_H |
| 38 |
#define MARSHAL_H |
| 39 |
|
| 40 |
#include <stdlib.h> |
| 41 |
#include <mini-os/byteorder.h> |
| 42 |
#include <mini-os/endian.h> |
| 43 |
#include "tcg.h" |
| 44 |
|
| 45 |
typedef enum UnpackPtr { |
| 46 |
UNPACK_ALIAS, |
| 47 |
UNPACK_ALLOC |
| 48 |
} UnpackPtr; |
| 49 |
|
| 50 |
static |
| 51 |
inline BYTE* pack_BYTE(BYTE* ptr, BYTE t) { |
| 52 |
ptr[0] = t; |
| 53 |
return ++ptr; |
| 54 |
} |
| 55 |
|
| 56 |
static |
| 57 |
inline BYTE* unpack_BYTE(BYTE* ptr, BYTE* t) { |
| 58 |
t[0] = ptr[0]; |
| 59 |
return ++ptr; |
| 60 |
} |
| 61 |
|
| 62 |
static |
| 63 |
inline int unpack3_BYTE(BYTE* ptr, UINT32* pos, UINT32 max, BYTE *t) |
| 64 |
{ |
| 65 |
if (*pos + 1 > max) |
| 66 |
return TPM_SIZE; |
| 67 |
unpack_BYTE(ptr + *pos, t); |
| 68 |
*pos += 1; |
| 69 |
return 0; |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
#define pack_BOOL(p, t) pack_BYTE(p, t) |
| 74 |
#define unpack_BOOL(p, t) unpack_BYTE(p, t) |
| 75 |
#define unpack3_BOOL(p, x, m, t) unpack3_BYTE(p, x, m, t) |
| 76 |
#define sizeof_BOOL(t) 1 |
| 77 |
|
| 78 |
static |
| 79 |
inline BYTE* pack_UINT16(void* ptr, UINT16 t) { |
| 80 |
UINT16* p = ptr; |
| 81 |
*p = cpu_to_be16(t); |
| 82 |
return ptr + sizeof(UINT16); |
| 83 |
} |
| 84 |
|
| 85 |
static |
| 86 |
inline BYTE* unpack_UINT16(void* ptr, UINT16* t) { |
| 87 |
UINT16* p = ptr; |
| 88 |
*t = be16_to_cpu(*p); |
| 89 |
return ptr + sizeof(UINT16); |
| 90 |
} |
| 91 |
|
| 92 |
static |
| 93 |
inline int unpack3_UINT16(BYTE* ptr, UINT32* pos, UINT32 max, UINT16 *t) |
| 94 |
{ |
| 95 |
if (*pos + 2 > max) |
| 96 |
return TPM_SIZE; |
| 97 |
unpack_UINT16(ptr + *pos, t); |
| 98 |
*pos += 2; |
| 99 |
return 0; |
| 100 |
} |
| 101 |
|
| 102 |
static |
| 103 |
inline BYTE* pack_UINT32(void* ptr, UINT32 t) { |
| 104 |
UINT32* p = ptr; |
| 105 |
*p = cpu_to_be32(t); |
| 106 |
return ptr + sizeof(UINT32); |
| 107 |
} |
| 108 |
|
| 109 |
static |
| 110 |
inline BYTE* unpack_UINT32(void* ptr, UINT32* t) { |
| 111 |
UINT32* p = ptr; |
| 112 |
*t = be32_to_cpu(*p); |
| 113 |
return ptr + sizeof(UINT32); |
| 114 |
} |
| 115 |
|
| 116 |
static |
| 117 |
inline int unpack3_UINT32(BYTE* ptr, UINT32* pos, UINT32 max, UINT32 *t) |
| 118 |
{ |
| 119 |
if (*pos + 4 > max) |
| 120 |
return TPM_SIZE; |
| 121 |
unpack_UINT32(ptr + *pos, t); |
| 122 |
*pos += 4; |
| 123 |
return 0; |
| 124 |
} |
| 125 |
|
| 126 |
#define sizeof_BYTE(x) 1 |
| 127 |
#define sizeof_UINT16(x) 2 |
| 128 |
#define sizeof_UINT32(x) 4 |
| 129 |
|
| 130 |
#define pack_TPM_RESULT(p, t) pack_UINT32(p, t) |
| 131 |
#define pack_TPM_PCRINDEX(p, t) pack_UINT32(p, t) |
| 132 |
#define pack_TPM_DIRINDEX(p, t) pack_UINT32(p, t) |
| 133 |
#define pack_TPM_HANDLE(p, t) pack_UINT32(p, t) |
| 134 |
#define pack_TPM_AUTHHANDLE(p, t) pack_TPM_HANDLE(p, t) |
| 135 |
#define pack_TCPA_HASHHANDLE(p, t) pack_TPM_HANDLE(p, t) |
| 136 |
#define pack_TCPA_HMACHANDLE(p, t) pack_TPM_HANDLE(p, t) |
| 137 |
#define pack_TCPA_ENCHANDLE(p, t) pack_TPM_HANDLE(p, t) |
| 138 |
#define pack_TPM_KEY_HANDLE(p, t) pack_TPM_HANDLE(p, t) |
| 139 |
#define pack_TCPA_ENTITYHANDLE(p, t) pack_TPM_HANDLE(p, t) |
| 140 |
#define pack_TPM_RESOURCE_TYPE(p, t) pack_UINT32(p, t) |
| 141 |
#define pack_TPM_COMMAND_CODE(p, t) pack_UINT32(p, t) |
| 142 |
#define pack_TPM_PROTOCOL_ID(p, t) pack_UINT16(p, t) |
| 143 |
#define pack_TPM_AUTH_DATA_USAGE(p, t) pack_BYTE(p, t) |
| 144 |
#define pack_TPM_ENTITY_TYPE(p, t) pack_UINT16(p, t) |
| 145 |
#define pack_TPM_ALGORITHM_ID(p, t) pack_UINT32(p, t) |
| 146 |
#define pack_TPM_KEY_USAGE(p, t) pack_UINT16(p, t) |
| 147 |
#define pack_TPM_STARTUP_TYPE(p, t) pack_UINT16(p, t) |
| 148 |
#define pack_TPM_CAPABILITY_AREA(p, t) pack_UINT32(p, t) |
| 149 |
#define pack_TPM_ENC_SCHEME(p, t) pack_UINT16(p, t) |
| 150 |
#define pack_TPM_SIG_SCHEME(p, t) pack_UINT16(p, t) |
| 151 |
#define pack_TPM_MIGRATE_SCHEME(p, t) pack_UINT16(p, t) |
| 152 |
#define pack_TPM_PHYSICAL_PRESENCE(p, t) pack_UINT16(p, t) |
| 153 |
#define pack_TPM_KEY_FLAGS(p, t) pack_UINT32(p, t) |
| 154 |
#define pack_TPM_LOCALITY_SELECTION(p, t) pack_BYTE(p, t) |
| 155 |
|
| 156 |
#define unpack_TPM_RESULT(p, t) unpack_UINT32(p, t) |
| 157 |
#define unpack_TPM_PCRINDEX(p, t) unpack_UINT32(p, t) |
| 158 |
#define unpack_TPM_DIRINDEX(p, t) unpack_UINT32(p, t) |
| 159 |
#define unpack_TPM_HANDLE(p, t) unpack_UINT32(p, t) |
| 160 |
#define unpack_TPM_AUTHHANDLE(p, t) unpack_TPM_HANDLE(p, t) |
| 161 |
#define unpack_TCPA_HASHHANDLE(p, t) unpack_TPM_HANDLE(p, t) |
| 162 |
#define unpack_TCPA_HMACHANDLE(p, t) unpack_TPM_HANDLE(p, t) |
| 163 |
#define unpack_TCPA_ENCHANDLE(p, t) unpack_TPM_HANDLE(p, t) |
| 164 |
#define unpack_TPM_KEY_HANDLE(p, t) unpack_TPM_HANDLE(p, t) |
| 165 |
#define unpack_TCPA_ENTITYHANDLE(p, t) unpack_TPM_HANDLE(p, t) |
| 166 |
#define unpack_TPM_RESOURCE_TYPE(p, t) unpack_UINT32(p, t) |
| 167 |
#define unpack_TPM_COMMAND_CODE(p, t) unpack_UINT32(p, t) |
| 168 |
#define unpack_TPM_PROTOCOL_ID(p, t) unpack_UINT16(p, t) |
| 169 |
#define unpack_TPM_AUTH_DATA_USAGE(p, t) unpack_BYTE(p, t) |
| 170 |
#define unpack_TPM_ENTITY_TYPE(p, t) unpack_UINT16(p, t) |
| 171 |
#define unpack_TPM_ALGORITHM_ID(p, t) unpack_UINT32(p, t) |
| 172 |
#define unpack_TPM_KEY_USAGE(p, t) unpack_UINT16(p, t) |
| 173 |
#define unpack_TPM_STARTUP_TYPE(p, t) unpack_UINT16(p, t) |
| 174 |
#define unpack_TPM_CAPABILITY_AREA(p, t) unpack_UINT32(p, t) |
| 175 |
#define unpack_TPM_ENC_SCHEME(p, t) unpack_UINT16(p, t) |
| 176 |
#define unpack_TPM_SIG_SCHEME(p, t) unpack_UINT16(p, t) |
| 177 |
#define unpack_TPM_MIGRATE_SCHEME(p, t) unpack_UINT16(p, t) |
| 178 |
#define unpack_TPM_PHYSICAL_PRESENCE(p, t) unpack_UINT16(p, t) |
| 179 |
#define unpack_TPM_KEY_FLAGS(p, t) unpack_UINT32(p, t) |
| 180 |
#define unpack_TPM_LOCALITY_SELECTION(p, t) unpack_BYTE(p, t) |
| 181 |
|
| 182 |
#define unpack3_TPM_RESULT(p, l, m, t) unpack3_UINT32(p, l, m, t) |
| 183 |
#define unpack3_TPM_PCRINDEX(p, l, m, t) unpack3_UINT32(p, l, m, t) |
| 184 |
#define unpack3_TPM_DIRINDEX(p, l, m, t) unpack3_UINT32(p, l, m, t) |
| 185 |
#define unpack3_TPM_HANDLE(p, l, m, t) unpack3_UINT32(p, l, m, t) |
| 186 |
#define unpack3_TPM_AUTHHANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t) |
| 187 |
#define unpack3_TCPA_HASHHANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t) |
| 188 |
#define unpack3_TCPA_HMACHANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t) |
| 189 |
#define unpack3_TCPA_ENCHANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t) |
| 190 |
#define unpack3_TPM_KEY_HANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t) |
| 191 |
#define unpack3_TCPA_ENTITYHANDLE(p, l, m, t) unpack3_TPM_HANDLE(p, l, m, t) |
| 192 |
#define unpack3_TPM_RESOURCE_TYPE(p, l, m, t) unpack3_UINT32(p, l, m, t) |
| 193 |
#define unpack3_TPM_COMMAND_CODE(p, l, m, t) unpack3_UINT32(p, l, m, t) |
| 194 |
#define unpack3_TPM_PROTOCOL_ID(p, l, m, t) unpack3_UINT16(p, l, m, t) |
| 195 |
#define unpack3_TPM_AUTH_DATA_USAGE(p, l, m, t) unpack3_BYTE(p, l, m, t) |
| 196 |
#define unpack3_TPM_ENTITY_TYPE(p, l, m, t) unpack3_UINT16(p, l, m, t) |
| 197 |
#define unpack3_TPM_ALGORITHM_ID(p, l, m, t) unpack3_UINT32(p, l, m, t) |
| 198 |
#define unpack3_TPM_KEY_USAGE(p, l, m, t) unpack3_UINT16(p, l, m, t) |
| 199 |
#define unpack3_TPM_STARTUP_TYPE(p, l, m, t) unpack3_UINT16(p, l, m, t) |
| 200 |
#define unpack3_TPM_CAPABILITY_AREA(p, l, m, t) unpack3_UINT32(p, l, m, t) |
| 201 |
#define unpack3_TPM_ENC_SCHEME(p, l, m, t) unpack3_UINT16(p, l, m, t) |
| 202 |
#define unpack3_TPM_SIG_SCHEME(p, l, m, t) unpack3_UINT16(p, l, m, t) |
| 203 |
#define unpack3_TPM_MIGRATE_SCHEME(p, l, m, t) unpack3_UINT16(p, l, m, t) |
| 204 |
#define unpack3_TPM_PHYSICAL_PRESENCE(p, l, m, t) unpack3_UINT16(p, l, m, t) |
| 205 |
#define unpack3_TPM_KEY_FLAGS(p, l, m, t) unpack3_UINT32(p, l, m, t) |
| 206 |
#define unpack3_TPM_LOCALITY_SELECTION(p, l, m, t) unpack3_BYTE(p, l, m, t) |
| 207 |
#define unpack3_TPM_DEEP_QUOTE_INFO(p, l, m, t) unpack3_UINT32(p, l, m, t) |
| 208 |
|
| 209 |
#define sizeof_TPM_RESULT(t) sizeof_UINT32(t) |
| 210 |
#define sizeof_TPM_PCRINDEX(t) sizeof_UINT32(t) |
| 211 |
#define sizeof_TPM_DIRINDEX(t) sizeof_UINT32(t) |
| 212 |
#define sizeof_TPM_HANDLE(t) sizeof_UINT32(t) |
| 213 |
#define sizeof_TPM_AUTHHANDLE(t) sizeof_TPM_HANDLE(t) |
| 214 |
#define sizeof_TCPA_HASHHANDLE(t) sizeof_TPM_HANDLE(t) |
| 215 |
#define sizeof_TCPA_HMACHANDLE(t) sizeof_TPM_HANDLE(t) |
| 216 |
#define sizeof_TCPA_ENCHANDLE(t) sizeof_TPM_HANDLE(t) |
| 217 |
#define sizeof_TPM_KEY_HANDLE(t) sizeof_TPM_HANDLE(t) |
| 218 |
#define sizeof_TCPA_ENTITYHANDLE(t) sizeof_TPM_HANDLE(t) |
| 219 |
#define sizeof_TPM_RESOURCE_TYPE(t) sizeof_UINT32(t) |
| 220 |
#define sizeof_TPM_COMMAND_CODE(t) sizeof_UINT32(t) |
| 221 |
#define sizeof_TPM_PROTOCOL_ID(t) sizeof_UINT16(t) |
| 222 |
#define sizeof_TPM_AUTH_DATA_USAGE(t) sizeof_BYTE(t) |
| 223 |
#define sizeof_TPM_ENTITY_TYPE(t) sizeof_UINT16(t) |
| 224 |
#define sizeof_TPM_ALGORITHM_ID(t) sizeof_UINT32(t) |
| 225 |
#define sizeof_TPM_KEY_USAGE(t) sizeof_UINT16(t) |
| 226 |
#define sizeof_TPM_STARTUP_TYPE(t) sizeof_UINT16(t) |
| 227 |
#define sizeof_TPM_CAPABILITY_AREA(t) sizeof_UINT32(t) |
| 228 |
#define sizeof_TPM_ENC_SCHEME(t) sizeof_UINT16(t) |
| 229 |
#define sizeof_TPM_SIG_SCHEME(t) sizeof_UINT16(t) |
| 230 |
#define sizeof_TPM_MIGRATE_SCHEME(t) sizeof_UINT16(t) |
| 231 |
#define sizeof_TPM_PHYSICAL_PRESENCE(t) sizeof_UINT16(t) |
| 232 |
#define sizeof_TPM_KEY_FLAGS(t) sizeof_UINT32(t) |
| 233 |
#define sizeof_TPM_LOCALITY_SELECTION(t) sizeof_BYTE(t) |
| 234 |
|
| 235 |
#define pack_TPM_AUTH_HANDLE(p, t) pack_UINT32(p, t) |
| 236 |
#define pack_TCS_CONTEXT_HANDLE(p, t) pack_UINT32(p, t) |
| 237 |
#define pack_TCS_KEY_HANDLE(p, t) pack_UINT32(p, t) |
| 238 |
|
| 239 |
#define unpack_TPM_AUTH_HANDLE(p, t) unpack_UINT32(p, t) |
| 240 |
#define unpack_TCS_CONTEXT_HANDLE(p, t) unpack_UINT32(p, t) |
| 241 |
#define unpack_TCS_KEY_HANDLE(p, t) unpack_UINT32(p, t) |
| 242 |
|
| 243 |
#define sizeof_TPM_AUTH_HANDLE(t) sizeof_UINT32(t) |
| 244 |
#define sizeof_TCS_CONTEXT_HANDLE(t) sizeof_UINT32(t) |
| 245 |
#define sizeof_TCS_KEY_HANDLE(t) sizeof_UINT32(t) |
| 246 |
|
| 247 |
|
| 248 |
static |
| 249 |
inline BYTE* pack_BUFFER(BYTE* ptr, const BYTE* buf, UINT32 size) { |
| 250 |
memcpy(ptr, buf, size); |
| 251 |
return ptr + size; |
| 252 |
} |
| 253 |
|
| 254 |
static |
| 255 |
inline BYTE* unpack_BUFFER(BYTE* ptr, BYTE* buf, UINT32 size) { |
| 256 |
memcpy(buf, ptr, size); |
| 257 |
return ptr + size; |
| 258 |
} |
| 259 |
|
| 260 |
static |
| 261 |
inline int unpack3_BUFFER(BYTE* ptr, UINT32* pos, UINT32 max, BYTE* buf, UINT32 size) { |
| 262 |
if (*pos + size > max) |
| 263 |
return TPM_SIZE; |
| 264 |
memcpy(buf, ptr + *pos, size); |
| 265 |
*pos += size; |
| 266 |
return 0; |
| 267 |
} |
| 268 |
|
| 269 |
#define sizeof_BUFFER(b, s) s |
| 270 |
|
| 271 |
static |
| 272 |
inline BYTE* unpack_ALIAS(BYTE* ptr, BYTE** buf, UINT32 size) { |
| 273 |
*buf = ptr; |
| 274 |
return ptr + size; |
| 275 |
} |
| 276 |
|
| 277 |
static |
| 278 |
inline BYTE* unpack_ALLOC(BYTE* ptr, BYTE** buf, UINT32 size) { |
| 279 |
if(size) { |
| 280 |
*buf = malloc(size); |
| 281 |
memcpy(*buf, ptr, size); |
| 282 |
} else { |
| 283 |
*buf = NULL; |
| 284 |
} |
| 285 |
return ptr + size; |
| 286 |
} |
| 287 |
|
| 288 |
static |
| 289 |
inline BYTE* unpack_PTR(BYTE* ptr, BYTE** buf, UINT32 size, UnpackPtr alloc) { |
| 290 |
if(alloc == UNPACK_ALLOC) { |
| 291 |
return unpack_ALLOC(ptr, buf, size); |
| 292 |
} else { |
| 293 |
return unpack_ALIAS(ptr, buf, size); |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
static |
| 298 |
inline int unpack3_PTR(BYTE* ptr, UINT32* pos, UINT32 max, BYTE** buf, UINT32 size, UnpackPtr alloc) { |
| 299 |
if (size > max || *pos + size > max) |
| 300 |
return TPM_SIZE; |
| 301 |
if (alloc == UNPACK_ALLOC) { |
| 302 |
unpack_ALLOC(ptr + *pos, buf, size); |
| 303 |
} else { |
| 304 |
unpack_ALIAS(ptr + *pos, buf, size); |
| 305 |
} |
| 306 |
*pos += size; |
| 307 |
return 0; |
| 308 |
} |
| 309 |
#define unpack3_VPTR(ptr, pos, max, buf, size, alloc) unpack3_PTR(ptr, pos, max, (void*)(buf), size, alloc) |
| 310 |
|
| 311 |
static |
| 312 |
inline BYTE* pack_TPM_AUTHDATA(BYTE* ptr, const TPM_AUTHDATA* d) { |
| 313 |
return pack_BUFFER(ptr, *d, TPM_DIGEST_SIZE); |
| 314 |
} |
| 315 |
|
| 316 |
static |
| 317 |
inline BYTE* unpack_TPM_AUTHDATA(BYTE* ptr, TPM_AUTHDATA* d) { |
| 318 |
return unpack_BUFFER(ptr, *d, TPM_DIGEST_SIZE); |
| 319 |
} |
| 320 |
|
| 321 |
static |
| 322 |
inline int unpack3_TPM_AUTHDATA(BYTE* ptr, UINT32* pos, UINT32 len, TPM_AUTHDATA* d) { |
| 323 |
return unpack3_BUFFER(ptr, pos, len, *d, TPM_DIGEST_SIZE); |
| 324 |
} |
| 325 |
|
| 326 |
#define sizeof_TPM_AUTHDATA(d) TPM_DIGEST_SIZE |
| 327 |
|
| 328 |
#define pack_TPM_SECRET(p, t) pack_TPM_AUTHDATA(p, t) |
| 329 |
#define pack_TPM_ENCAUTH(p, t) pack_TPM_AUTHDATA(p, t) |
| 330 |
#define pack_TPM_PAYLOAD_TYPE(p, t) pack_BYTE(p, t) |
| 331 |
#define pack_TPM_TAG(p, t) pack_UINT16(p, t) |
| 332 |
#define pack_TPM_STRUCTURE_TAG(p, t) pack_UINT16(p, t) |
| 333 |
|
| 334 |
#define unpack_TPM_SECRET(p, t) unpack_TPM_AUTHDATA(p, t) |
| 335 |
#define unpack_TPM_ENCAUTH(p, t) unpack_TPM_AUTHDATA(p, t) |
| 336 |
#define unpack_TPM_PAYLOAD_TYPE(p, t) unpack_BYTE(p, t) |
| 337 |
#define unpack_TPM_TAG(p, t) unpack_UINT16(p, t) |
| 338 |
#define unpack_TPM_STRUCTURE_TAG(p, t) unpack_UINT16(p, t) |
| 339 |
#define unpack3_TPM_STRUCTURE_TAG(p, l, m, t) unpack3_UINT16(p, l, m, t) |
| 340 |
|
| 341 |
#define sizeof_TPM_SECRET(t) sizeof_TPM_AUTHDATA(t) |
| 342 |
#define sizeof_TPM_ENCAUTH(t) sizeof_TPM_AUTHDATA(t) |
| 343 |
#define sizeof_TPM_PAYLOAD_TYPE(t) sizeof_BYTE(t) |
| 344 |
#define sizeof_TPM_TAG(t) sizeof_UINT16(t) |
| 345 |
#define sizeof_TPM_STRUCTURE_TAG(t) sizeof_UINT16(t) |
| 346 |
|
| 347 |
static |
| 348 |
inline BYTE* pack_TPM_VERSION(BYTE* ptr, const TPM_VERSION* t) { |
| 349 |
ptr[0] = t->major; |
| 350 |
ptr[1] = t->minor; |
| 351 |
ptr[2] = t->revMajor; |
| 352 |
ptr[3] = t->revMinor; |
| 353 |
return ptr + 4; |
| 354 |
} |
| 355 |
|
| 356 |
static |
| 357 |
inline BYTE* unpack_TPM_VERSION(BYTE* ptr, TPM_VERSION* t) { |
| 358 |
t->major = ptr[0]; |
| 359 |
t->minor = ptr[1]; |
| 360 |
t->revMajor = ptr[2]; |
| 361 |
t->revMinor = ptr[3]; |
| 362 |
return ptr + 4; |
| 363 |
} |
| 364 |
|
| 365 |
static |
| 366 |
inline int unpack3_TPM_VERSION(BYTE* ptr, UINT32 *pos, UINT32 max, TPM_VERSION* t) { |
| 367 |
if (*pos + 4 > max) |
| 368 |
return TPM_SIZE; |
| 369 |
ptr += *pos; |
| 370 |
t->major = ptr[0]; |
| 371 |
t->minor = ptr[1]; |
| 372 |
t->revMajor = ptr[2]; |
| 373 |
t->revMinor = ptr[3]; |
| 374 |
*pos += 4; |
| 375 |
return 0; |
| 376 |
} |
| 377 |
|
| 378 |
#define sizeof_TPM_VERSION(x) 4 |
| 379 |
|
| 380 |
static |
| 381 |
inline BYTE* pack_TPM_CAP_VERSION_INFO(BYTE* ptr, const TPM_CAP_VERSION_INFO* v) { |
| 382 |
ptr = pack_TPM_STRUCTURE_TAG(ptr, v->tag); |
| 383 |
ptr = pack_TPM_VERSION(ptr, &v->version); |
| 384 |
ptr = pack_UINT16(ptr, v->specLevel); |
| 385 |
ptr = pack_BYTE(ptr, v->errataRev); |
| 386 |
ptr = pack_BUFFER(ptr, v->tpmVendorID, sizeof(v->tpmVendorID)); |
| 387 |
ptr = pack_UINT16(ptr, v->vendorSpecificSize); |
| 388 |
ptr = pack_BUFFER(ptr, v->vendorSpecific, v->vendorSpecificSize); |
| 389 |
return ptr; |
| 390 |
} |
| 391 |
|
| 392 |
static |
| 393 |
inline BYTE* unpack_TPM_CAP_VERSION_INFO(BYTE* ptr, TPM_CAP_VERSION_INFO* v, UnpackPtr alloc) { |
| 394 |
ptr = unpack_TPM_STRUCTURE_TAG(ptr, &v->tag); |
| 395 |
ptr = unpack_TPM_VERSION(ptr, &v->version); |
| 396 |
ptr = unpack_UINT16(ptr, &v->specLevel); |
| 397 |
ptr = unpack_BYTE(ptr, &v->errataRev); |
| 398 |
ptr = unpack_BUFFER(ptr, v->tpmVendorID, sizeof(v->tpmVendorID)); |
| 399 |
ptr = unpack_UINT16(ptr, &v->vendorSpecificSize); |
| 400 |
ptr = unpack_PTR(ptr, &v->vendorSpecific, v->vendorSpecificSize, alloc); |
| 401 |
return ptr; |
| 402 |
} |
| 403 |
|
| 404 |
static |
| 405 |
inline BYTE* pack_TPM_DIGEST(BYTE* ptr, const TPM_DIGEST* d) { |
| 406 |
return pack_BUFFER(ptr, d->digest, TPM_DIGEST_SIZE); |
| 407 |
} |
| 408 |
|
| 409 |
static |
| 410 |
inline BYTE* unpack_TPM_DIGEST(BYTE* ptr, TPM_DIGEST* d) { |
| 411 |
return unpack_BUFFER(ptr, d->digest, TPM_DIGEST_SIZE); |
| 412 |
} |
| 413 |
|
| 414 |
static |
| 415 |
inline int unpack3_TPM_DIGEST(BYTE* ptr, UINT32* pos, UINT32 max, TPM_DIGEST* d) { |
| 416 |
return unpack3_BUFFER(ptr, pos, max, d->digest, TPM_DIGEST_SIZE); |
| 417 |
} |
| 418 |
|
| 419 |
#define sizeof_TPM_DIGEST(d) TPM_DIGEST_SIZE |
| 420 |
|
| 421 |
#define pack_TPM_PCRVALUE(ptr, d) pack_TPM_DIGEST(ptr, d) |
| 422 |
#define unpack_TPM_PCRVALUE(ptr, d) unpack_TPM_DIGEST(ptr, d) |
| 423 |
#define unpack3_TPM_PCRVALUE(p...) unpack3_TPM_DIGEST(p) |
| 424 |
|
| 425 |
#define pack_TPM_COMPOSITE_HASH(ptr, d) pack_TPM_DIGEST(ptr, d) |
| 426 |
#define unpack_TPM_COMPOSITE_HASH(ptr, d) unpack_TPM_DIGEST(ptr, d) |
| 427 |
#define unpack3_TPM_COMPOSITE_HASH(ptr, p, m, d) unpack3_TPM_DIGEST(ptr, p, m, d) |
| 428 |
#define sizeof_TPM_COMPOSITE_HASH(d) TPM_DIGEST_SIZE |
| 429 |
|
| 430 |
#define pack_TPM_DIRVALUE(ptr, d) pack_TPM_DIGEST(ptr, d) |
| 431 |
#define unpack_TPM_DIRVALUE(ptr, d) unpack_TPM_DIGEST(ptr, d) |
| 432 |
|
| 433 |
#define pack_TPM_HMAC(ptr, d) pack_TPM_DIGEST(ptr, d) |
| 434 |
#define unpack_TPM_HMAC(ptr, d) unpack_TPM_DIGEST(ptr, d) |
| 435 |
|
| 436 |
#define pack_TPM_CHOSENID_HASH(ptr, d) pack_TPM_DIGEST(ptr, d) |
| 437 |
#define unpack_TPM_CHOSENID_HASH(ptr, d) unpack_TPM_DIGEST(ptr, d) |
| 438 |
|
| 439 |
static |
| 440 |
inline BYTE* pack_TPM_NONCE(BYTE* ptr, const TPM_NONCE* n) { |
| 441 |
return pack_BUFFER(ptr, n->nonce, TPM_DIGEST_SIZE); |
| 442 |
} |
| 443 |
|
| 444 |
static |
| 445 |
inline BYTE* unpack_TPM_NONCE(BYTE* ptr, TPM_NONCE* n) { |
| 446 |
return unpack_BUFFER(ptr, n->nonce, TPM_DIGEST_SIZE); |
| 447 |
} |
| 448 |
|
| 449 |
#define sizeof_TPM_NONCE(x) TPM_DIGEST_SIZE |
| 450 |
|
| 451 |
static |
| 452 |
inline int unpack3_TPM_NONCE(BYTE* ptr, UINT32* pos, UINT32 max, TPM_NONCE* n) { |
| 453 |
return unpack3_BUFFER(ptr, pos, max, n->nonce, TPM_DIGEST_SIZE); |
| 454 |
} |
| 455 |
|
| 456 |
static |
| 457 |
inline BYTE* pack_TPM_SYMMETRIC_KEY_PARMS(BYTE* ptr, const TPM_SYMMETRIC_KEY_PARMS* k) { |
| 458 |
ptr = pack_UINT32(ptr, k->keyLength); |
| 459 |
ptr = pack_UINT32(ptr, k->blockSize); |
| 460 |
ptr = pack_UINT32(ptr, k->ivSize); |
| 461 |
return pack_BUFFER(ptr, k->IV, k->ivSize); |
| 462 |
} |
| 463 |
|
| 464 |
static |
| 465 |
inline BYTE* pack_TPM_SYMMETRIC_KEY(BYTE* ptr, const TPM_SYMMETRIC_KEY* k) { |
| 466 |
ptr = pack_UINT32(ptr, k->algId); |
| 467 |
ptr = pack_UINT16(ptr, k->encScheme); |
| 468 |
ptr = pack_UINT16(ptr, k->size); |
| 469 |
return pack_BUFFER(ptr, k->data, k->size); |
| 470 |
} |
| 471 |
|
| 472 |
static |
| 473 |
inline int unpack3_TPM_SYMMETRIC_KEY_PARMS(BYTE* ptr, UINT32* pos, UINT32 max, TPM_SYMMETRIC_KEY_PARMS* k, UnpackPtr alloc) { |
| 474 |
return unpack3_UINT32(ptr, pos, max, &k->keyLength) || |
| 475 |
unpack3_UINT32(ptr, pos, max, &k->blockSize) || |
| 476 |
unpack3_UINT32(ptr, pos, max, &k->ivSize) || |
| 477 |
unpack3_PTR(ptr, pos, max, &k->IV, k->ivSize, alloc); |
| 478 |
} |
| 479 |
|
| 480 |
static |
| 481 |
inline int sizeof_TPM_SYMMETRIC_KEY_PARMS(const TPM_SYMMETRIC_KEY_PARMS* k) { |
| 482 |
return 12 + k->ivSize; |
| 483 |
} |
| 484 |
|
| 485 |
static |
| 486 |
inline int unpack3_TPM_SYMMETRIC_KEY(BYTE* ptr, UINT32* pos, UINT32 max, TPM_SYMMETRIC_KEY* k, UnpackPtr alloc) { |
| 487 |
return unpack3_UINT32(ptr, pos, max, &k->algId) || |
| 488 |
unpack3_UINT16(ptr, pos, max, &k->encScheme) || |
| 489 |
unpack3_UINT16(ptr, pos, max, &k->size) || |
| 490 |
unpack3_PTR(ptr, pos, max, &k->data, k->size, alloc); |
| 491 |
} |
| 492 |
|
| 493 |
static |
| 494 |
inline BYTE* pack_TPM_RSA_KEY_PARMS(BYTE* ptr, const TPM_RSA_KEY_PARMS* k) { |
| 495 |
ptr = pack_UINT32(ptr, k->keyLength); |
| 496 |
ptr = pack_UINT32(ptr, k->numPrimes); |
| 497 |
ptr = pack_UINT32(ptr, k->exponentSize); |
| 498 |
return pack_BUFFER(ptr, k->exponent, k->exponentSize); |
| 499 |
} |
| 500 |
|
| 501 |
static |
| 502 |
inline int unpack3_TPM_RSA_KEY_PARMS(BYTE* ptr, UINT32* pos, UINT32 max, TPM_RSA_KEY_PARMS* k, UnpackPtr alloc) { |
| 503 |
return unpack3_UINT32(ptr, pos, max, &k->keyLength) || |
| 504 |
unpack3_UINT32(ptr, pos, max, &k->numPrimes) || |
| 505 |
unpack3_UINT32(ptr, pos, max, &k->exponentSize) || |
| 506 |
unpack3_PTR(ptr, pos, max, &k->exponent, k->exponentSize, alloc); |
| 507 |
} |
| 508 |
|
| 509 |
static |
| 510 |
inline int sizeof_TPM_RSA_KEY_PARMS(const TPM_RSA_KEY_PARMS* k) { |
| 511 |
return 12 + k->exponentSize; |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
static |
| 516 |
inline BYTE* pack_TPM_KEY_PARMS(BYTE* ptr, const TPM_KEY_PARMS* k) { |
| 517 |
ptr = pack_TPM_ALGORITHM_ID(ptr, k->algorithmID); |
| 518 |
ptr = pack_TPM_ENC_SCHEME(ptr, k->encScheme); |
| 519 |
ptr = pack_TPM_SIG_SCHEME(ptr, k->sigScheme); |
| 520 |
ptr = pack_UINT32(ptr, k->parmSize); |
| 521 |
|
| 522 |
if(k->parmSize) { |
| 523 |
switch(k->algorithmID) { |
| 524 |
case TPM_ALG_RSA: |
| 525 |
return pack_TPM_RSA_KEY_PARMS(ptr, &k->parms.rsa); |
| 526 |
case TPM_ALG_AES128: |
| 527 |
case TPM_ALG_AES192: |
| 528 |
case TPM_ALG_AES256: |
| 529 |
return pack_TPM_SYMMETRIC_KEY_PARMS(ptr, &k->parms.sym); |
| 530 |
} |
| 531 |
} |
| 532 |
return ptr; |
| 533 |
} |
| 534 |
|
| 535 |
static |
| 536 |
inline int unpack3_TPM_KEY_PARMS(BYTE* ptr, UINT32* pos, UINT32 len, TPM_KEY_PARMS* k, UnpackPtr alloc) { |
| 537 |
int rc = unpack3_TPM_ALGORITHM_ID(ptr, pos, len, &k->algorithmID) || |
| 538 |
unpack3_TPM_ENC_SCHEME(ptr, pos, len, &k->encScheme) || |
| 539 |
unpack3_TPM_SIG_SCHEME(ptr, pos, len, &k->sigScheme) || |
| 540 |
unpack3_UINT32(ptr, pos, len, &k->parmSize); |
| 541 |
if (rc || k->parmSize == 0) |
| 542 |
return rc; |
| 543 |
switch(k->algorithmID) { |
| 544 |
case TPM_ALG_RSA: |
| 545 |
return unpack3_TPM_RSA_KEY_PARMS(ptr, pos, len, &k->parms.rsa, alloc); |
| 546 |
case TPM_ALG_AES128: |
| 547 |
case TPM_ALG_AES192: |
| 548 |
case TPM_ALG_AES256: |
| 549 |
return unpack3_TPM_SYMMETRIC_KEY_PARMS(ptr, pos, len, &k->parms.sym, alloc); |
| 550 |
} |
| 551 |
return TPM_FAIL; |
| 552 |
} |
| 553 |
|
| 554 |
static |
| 555 |
inline int sizeof_TPM_KEY_PARMS(const TPM_KEY_PARMS* k) { |
| 556 |
int rc = 0; |
| 557 |
rc += sizeof_TPM_ALGORITHM_ID(&k->algorithmID); |
| 558 |
rc += sizeof_TPM_ENC_SCHEME(&k->encScheme); |
| 559 |
rc += sizeof_TPM_SIG_SCHEME(&k->sigScheme); |
| 560 |
rc += sizeof_UINT32(&k->parmSize); |
| 561 |
if (!k->parmSize) |
| 562 |
return rc; |
| 563 |
switch(k->algorithmID) { |
| 564 |
case TPM_ALG_RSA: |
| 565 |
rc += sizeof_TPM_RSA_KEY_PARMS(&k->parms.rsa); |
| 566 |
break; |
| 567 |
case TPM_ALG_AES128: |
| 568 |
case TPM_ALG_AES192: |
| 569 |
case TPM_ALG_AES256: |
| 570 |
rc += sizeof_TPM_SYMMETRIC_KEY_PARMS(&k->parms.sym); |
| 571 |
break; |
| 572 |
} |
| 573 |
return rc; |
| 574 |
} |
| 575 |
|
| 576 |
static |
| 577 |
inline BYTE* pack_TPM_STORE_PUBKEY(BYTE* ptr, const TPM_STORE_PUBKEY* k) { |
| 578 |
ptr = pack_UINT32(ptr, k->keyLength); |
| 579 |
ptr = pack_BUFFER(ptr, k->key, k->keyLength); |
| 580 |
return ptr; |
| 581 |
} |
| 582 |
|
| 583 |
static |
| 584 |
inline int unpack3_TPM_STORE_PUBKEY(BYTE* ptr, UINT32* pos, UINT32 max, TPM_STORE_PUBKEY* k, UnpackPtr alloc) { |
| 585 |
return unpack3_UINT32(ptr, pos, max, &k->keyLength) || |
| 586 |
unpack3_PTR(ptr, pos, max, &k->key, k->keyLength, alloc); |
| 587 |
} |
| 588 |
|
| 589 |
static |
| 590 |
inline int sizeof_TPM_STORE_PUBKEY(const TPM_STORE_PUBKEY* k) { |
| 591 |
return 4 + k->keyLength; |
| 592 |
} |
| 593 |
|
| 594 |
static |
| 595 |
inline BYTE* pack_TPM_PUBKEY(BYTE* ptr, const TPM_PUBKEY* k) { |
| 596 |
ptr = pack_TPM_KEY_PARMS(ptr, &k->algorithmParms); |
| 597 |
return pack_TPM_STORE_PUBKEY(ptr, &k->pubKey); |
| 598 |
} |
| 599 |
|
| 600 |
static |
| 601 |
inline int unpack3_TPM_PUBKEY(BYTE* ptr, UINT32* pos, UINT32 len, TPM_PUBKEY* k, UnpackPtr alloc) { |
| 602 |
return unpack3_TPM_KEY_PARMS(ptr, pos, len, &k->algorithmParms, alloc) || |
| 603 |
unpack3_TPM_STORE_PUBKEY(ptr, pos, len, &k->pubKey, alloc); |
| 604 |
} |
| 605 |
|
| 606 |
static |
| 607 |
inline BYTE* pack_TPM_PCR_SELECTION(BYTE* ptr, const TPM_PCR_SELECTION* p) { |
| 608 |
ptr = pack_UINT16(ptr, p->sizeOfSelect); |
| 609 |
ptr = pack_BUFFER(ptr, p->pcrSelect, p->sizeOfSelect); |
| 610 |
return ptr; |
| 611 |
} |
| 612 |
|
| 613 |
static |
| 614 |
inline BYTE* unpack_TPM_PCR_SELECTION(BYTE* ptr, TPM_PCR_SELECTION* p, UnpackPtr alloc) { |
| 615 |
ptr = unpack_UINT16(ptr, &p->sizeOfSelect); |
| 616 |
ptr = unpack_PTR(ptr, &p->pcrSelect, p->sizeOfSelect, alloc); |
| 617 |
return ptr; |
| 618 |
} |
| 619 |
|
| 620 |
static |
| 621 |
inline int unpack3_TPM_PCR_SELECTION(BYTE* ptr, UINT32* pos, UINT32 max, TPM_PCR_SELECTION* p, UnpackPtr alloc) { |
| 622 |
return unpack3_UINT16(ptr, pos, max, &p->sizeOfSelect) || |
| 623 |
unpack3_PTR(ptr, pos, max, &p->pcrSelect, p->sizeOfSelect, alloc); |
| 624 |
} |
| 625 |
|
| 626 |
static |
| 627 |
inline int sizeof_TPM_PCR_SELECTION(const TPM_PCR_SELECTION* p) { |
| 628 |
return 2 + p->sizeOfSelect; |
| 629 |
} |
| 630 |
|
| 631 |
static |
| 632 |
inline BYTE* pack_TPM_PCR_INFO(BYTE* ptr, const TPM_PCR_INFO* p) { |
| 633 |
ptr = pack_TPM_PCR_SELECTION(ptr, &p->pcrSelection); |
| 634 |
ptr = pack_TPM_COMPOSITE_HASH(ptr, &p->digestAtRelease); |
| 635 |
ptr = pack_TPM_COMPOSITE_HASH(ptr, &p->digestAtCreation); |
| 636 |
return ptr; |
| 637 |
} |
| 638 |
|
| 639 |
static |
| 640 |
inline int unpack3_TPM_PCR_INFO(BYTE* ptr, UINT32* pos, UINT32 max, TPM_PCR_INFO* p, UnpackPtr alloc) { |
| 641 |
return unpack3_TPM_PCR_SELECTION(ptr, pos, max, &p->pcrSelection, alloc) || |
| 642 |
unpack3_TPM_COMPOSITE_HASH(ptr, pos, max, &p->digestAtRelease) || |
| 643 |
unpack3_TPM_COMPOSITE_HASH(ptr, pos, max, &p->digestAtCreation); |
| 644 |
} |
| 645 |
|
| 646 |
static |
| 647 |
inline int sizeof_TPM_PCR_INFO(const TPM_PCR_INFO* p) { |
| 648 |
int rc = 0; |
| 649 |
rc += sizeof_TPM_PCR_SELECTION(&p->pcrSelection); |
| 650 |
rc += sizeof_TPM_COMPOSITE_HASH(&p->digestAtRelease); |
| 651 |
rc += sizeof_TPM_COMPOSITE_HASH(&p->digestAtCreation); |
| 652 |
return rc; |
| 653 |
} |
| 654 |
|
| 655 |
static |
| 656 |
inline BYTE* pack_TPM_PCR_INFO_LONG(BYTE* ptr, const TPM_PCR_INFO_LONG* p) { |
| 657 |
ptr = pack_TPM_STRUCTURE_TAG(ptr, p->tag); |
| 658 |
ptr = pack_TPM_LOCALITY_SELECTION(ptr, p->localityAtCreation); |
| 659 |
ptr = pack_TPM_LOCALITY_SELECTION(ptr, p->localityAtRelease); |
| 660 |
ptr = pack_TPM_PCR_SELECTION(ptr, &p->creationPCRSelection); |
| 661 |
ptr = pack_TPM_PCR_SELECTION(ptr, &p->releasePCRSelection); |
| 662 |
ptr = pack_TPM_COMPOSITE_HASH(ptr, &p->digestAtCreation); |
| 663 |
ptr = pack_TPM_COMPOSITE_HASH(ptr, &p->digestAtRelease); |
| 664 |
return ptr; |
| 665 |
} |
| 666 |
|
| 667 |
static |
| 668 |
inline int sizeof_TPM_PCR_INFO_LONG(const TPM_PCR_INFO_LONG* p) { |
| 669 |
int rc = 0; |
| 670 |
rc += sizeof_TPM_STRUCTURE_TAG(p->tag); |
| 671 |
rc += sizeof_TPM_LOCALITY_SELECTION(p->localityAtCreation); |
| 672 |
rc += sizeof_TPM_LOCALITY_SELECTION(p->localityAtRelease); |
| 673 |
rc += sizeof_TPM_PCR_SELECTION(&p->creationPCRSelection); |
| 674 |
rc += sizeof_TPM_PCR_SELECTION(&p->releasePCRSelection); |
| 675 |
rc += sizeof_TPM_COMPOSITE_HASH(&p->digestAtCreation); |
| 676 |
rc += sizeof_TPM_COMPOSITE_HASH(&p->digestAtRelease); |
| 677 |
return rc; |
| 678 |
} |
| 679 |
|
| 680 |
static |
| 681 |
inline int unpack3_TPM_PCR_INFO_LONG(BYTE* ptr, UINT32* pos, UINT32 max, TPM_PCR_INFO_LONG* p, UnpackPtr alloc) { |
| 682 |
return unpack3_TPM_STRUCTURE_TAG(ptr, pos, max, &p->tag) || |
| 683 |
unpack3_TPM_LOCALITY_SELECTION(ptr, pos, max, |
| 684 |
&p->localityAtCreation) || |
| 685 |
unpack3_TPM_LOCALITY_SELECTION(ptr, pos, max, |
| 686 |
&p->localityAtRelease) || |
| 687 |
unpack3_TPM_PCR_SELECTION(ptr, pos, max, |
| 688 |
&p->creationPCRSelection, alloc) || |
| 689 |
unpack3_TPM_PCR_SELECTION(ptr, pos, max, |
| 690 |
&p->releasePCRSelection, alloc) || |
| 691 |
unpack3_TPM_COMPOSITE_HASH(ptr, pos, max, |
| 692 |
&p->digestAtCreation) || |
| 693 |
unpack3_TPM_COMPOSITE_HASH(ptr, pos, max, &p->digestAtRelease); |
| 694 |
} |
| 695 |
|
| 696 |
static |
| 697 |
inline BYTE* pack_TPM_PCR_COMPOSITE(BYTE* ptr, const TPM_PCR_COMPOSITE* p) { |
| 698 |
ptr = pack_TPM_PCR_SELECTION(ptr, &p->select); |
| 699 |
ptr = pack_UINT32(ptr, p->valueSize); |
| 700 |
ptr = pack_BUFFER(ptr, (const BYTE*)p->pcrValue, p->valueSize); |
| 701 |
return ptr; |
| 702 |
} |
| 703 |
|
| 704 |
static |
| 705 |
inline int unpack3_TPM_PCR_COMPOSITE(BYTE* ptr, UINT32* pos, UINT32 max, TPM_PCR_COMPOSITE* p, UnpackPtr alloc) { |
| 706 |
return unpack3_TPM_PCR_SELECTION(ptr, pos, max, &p->select, alloc) || |
| 707 |
unpack3_UINT32(ptr, pos, max, &p->valueSize) || |
| 708 |
unpack3_PTR(ptr, pos, max, (BYTE**)&p->pcrValue, p->valueSize, alloc); |
| 709 |
} |
| 710 |
|
| 711 |
static |
| 712 |
inline BYTE* pack_TPM_KEY(BYTE* ptr, const TPM_KEY* k) { |
| 713 |
ptr = pack_TPM_VERSION(ptr, &k->ver); |
| 714 |
ptr = pack_TPM_KEY_USAGE(ptr, k->keyUsage); |
| 715 |
ptr = pack_TPM_KEY_FLAGS(ptr, k->keyFlags); |
| 716 |
ptr = pack_TPM_AUTH_DATA_USAGE(ptr, k->authDataUsage); |
| 717 |
ptr = pack_TPM_KEY_PARMS(ptr, &k->algorithmParms); |
| 718 |
ptr = pack_UINT32(ptr, k->PCRInfoSize); |
| 719 |
if(k->PCRInfoSize) { |
| 720 |
ptr = pack_TPM_PCR_INFO(ptr, &k->PCRInfo); |
| 721 |
} |
| 722 |
ptr = pack_TPM_STORE_PUBKEY(ptr, &k->pubKey); |
| 723 |
ptr = pack_UINT32(ptr, k->encDataSize); |
| 724 |
return pack_BUFFER(ptr, k->encData, k->encDataSize); |
| 725 |
} |
| 726 |
|
| 727 |
static |
| 728 |
inline int unpack3_TPM_KEY(BYTE* ptr, UINT32* pos, UINT32 max, TPM_KEY* k, UnpackPtr alloc) { |
| 729 |
int rc = unpack3_TPM_VERSION(ptr, pos, max, &k->ver) || |
| 730 |
unpack3_TPM_KEY_USAGE(ptr, pos, max, &k->keyUsage) || |
| 731 |
unpack3_TPM_KEY_FLAGS(ptr, pos, max, &k->keyFlags) || |
| 732 |
unpack3_TPM_AUTH_DATA_USAGE(ptr, pos, max, &k->authDataUsage) || |
| 733 |
unpack3_TPM_KEY_PARMS(ptr, pos, max, &k->algorithmParms, alloc) || |
| 734 |
unpack3_UINT32(ptr, pos, max, &k->PCRInfoSize); |
| 735 |
if (rc) return rc; |
| 736 |
if(k->PCRInfoSize) { |
| 737 |
rc = unpack3_TPM_PCR_INFO(ptr, pos, max, &k->PCRInfo, alloc); |
| 738 |
} |
| 739 |
if (rc) return rc; |
| 740 |
return unpack3_TPM_STORE_PUBKEY(ptr, pos, max, &k->pubKey, alloc) || |
| 741 |
unpack3_UINT32(ptr, pos, max, &k->encDataSize) || |
| 742 |
unpack3_PTR(ptr, pos, max, &k->encData, k->encDataSize, alloc); |
| 743 |
} |
| 744 |
|
| 745 |
static |
| 746 |
inline int sizeof_TPM_KEY(const TPM_KEY* k) { |
| 747 |
int rc = 0; |
| 748 |
rc += sizeof_TPM_VERSION(&k->ver); |
| 749 |
rc += sizeof_TPM_KEY_USAGE(k->keyUsage); |
| 750 |
rc += sizeof_TPM_KEY_FLAGS(k->keyFlags); |
| 751 |
rc += sizeof_TPM_AUTH_DATA_USAGE(k->authDataUsage); |
| 752 |
rc += sizeof_TPM_KEY_PARMS(&k->algorithmParms); |
| 753 |
rc += sizeof_UINT32(k->PCRInfoSize); |
| 754 |
if(k->PCRInfoSize) { |
| 755 |
rc += sizeof_TPM_PCR_INFO(&k->PCRInfo); |
| 756 |
} |
| 757 |
rc += sizeof_TPM_STORE_PUBKEY(&k->pubKey); |
| 758 |
rc += sizeof_UINT32(k->encDataSize); |
| 759 |
rc += k->encDataSize; |
| 760 |
return rc; |
| 761 |
} |
| 762 |
|
| 763 |
static |
| 764 |
inline BYTE* pack_TPM_BOUND_DATA(BYTE* ptr, const TPM_BOUND_DATA* b, UINT32 payloadSize) { |
| 765 |
ptr = pack_TPM_VERSION(ptr, &b->ver); |
| 766 |
ptr = pack_TPM_PAYLOAD_TYPE(ptr, b->payload); |
| 767 |
return pack_BUFFER(ptr, b->payloadData, payloadSize); |
| 768 |
} |
| 769 |
|
| 770 |
static |
| 771 |
inline BYTE* unpack_TPM_BOUND_DATA(BYTE* ptr, TPM_BOUND_DATA* b, UINT32 payloadSize, UnpackPtr alloc) { |
| 772 |
ptr = unpack_TPM_VERSION(ptr, &b->ver); |
| 773 |
ptr = unpack_TPM_PAYLOAD_TYPE(ptr, &b->payload); |
| 774 |
return unpack_PTR(ptr, &b->payloadData, payloadSize, alloc); |
| 775 |
} |
| 776 |
|
| 777 |
static |
| 778 |
inline BYTE* pack_TPM_STORED_DATA(BYTE* ptr, const TPM_STORED_DATA* d) { |
| 779 |
ptr = pack_TPM_VERSION(ptr, &d->ver); |
| 780 |
ptr = pack_UINT32(ptr, d->sealInfoSize); |
| 781 |
if(d->sealInfoSize) { |
| 782 |
ptr = pack_TPM_PCR_INFO(ptr, &d->sealInfo); |
| 783 |
} |
| 784 |
ptr = pack_UINT32(ptr, d->encDataSize); |
| 785 |
ptr = pack_BUFFER(ptr, d->encData, d->encDataSize); |
| 786 |
return ptr; |
| 787 |
} |
| 788 |
|
| 789 |
static |
| 790 |
inline int sizeof_TPM_STORED_DATA(const TPM_STORED_DATA* d) { |
| 791 |
int rv = sizeof_TPM_VERSION(&d->ver) + sizeof_UINT32(d->sealInfoSize); |
| 792 |
if (d->sealInfoSize) { |
| 793 |
rv += sizeof_TPM_PCR_INFO(&d->sealInfo); |
| 794 |
} |
| 795 |
rv += sizeof_UINT32(d->encDataSize); |
| 796 |
rv += sizeof_BUFFER(d->encData, d->encDataSize); |
| 797 |
return rv; |
| 798 |
} |
| 799 |
|
| 800 |
static |
| 801 |
inline int unpack3_TPM_STORED_DATA(BYTE* ptr, UINT32* pos, UINT32 len, TPM_STORED_DATA* d, UnpackPtr alloc) { |
| 802 |
int rc = unpack3_TPM_VERSION(ptr, pos, len, &d->ver) || |
| 803 |
unpack3_UINT32(ptr, pos, len, &d->sealInfoSize); |
| 804 |
if (rc) |
| 805 |
return rc; |
| 806 |
if (d->sealInfoSize) |
| 807 |
rc = unpack3_TPM_PCR_INFO(ptr, pos, len, &d->sealInfo, alloc); |
| 808 |
if (rc) |
| 809 |
return rc; |
| 810 |
rc = unpack3_UINT32(ptr, pos, len, &d->encDataSize) || |
| 811 |
unpack3_PTR(ptr, pos, len, &d->encData, d->encDataSize, alloc); |
| 812 |
return rc; |
| 813 |
} |
| 814 |
|
| 815 |
static |
| 816 |
inline BYTE* pack_TPM_STORED_DATA12(BYTE* ptr, const TPM_STORED_DATA12* d) { |
| 817 |
ptr = pack_TPM_STRUCTURE_TAG(ptr, d->tag); |
| 818 |
ptr = pack_TPM_ENTITY_TYPE(ptr, d->et); |
| 819 |
ptr = pack_UINT32(ptr, d->sealInfoLongSize); |
| 820 |
if(d->sealInfoLongSize) { |
| 821 |
ptr = pack_TPM_PCR_INFO_LONG(ptr, &d->sealInfoLong); |
| 822 |
} |
| 823 |
ptr = pack_UINT32(ptr, d->encDataSize); |
| 824 |
ptr = pack_BUFFER(ptr, d->encData, d->encDataSize); |
| 825 |
return ptr; |
| 826 |
} |
| 827 |
|
| 828 |
static |
| 829 |
inline int sizeof_TPM_STORED_DATA12(const TPM_STORED_DATA12* d) { |
| 830 |
int rv = sizeof_TPM_STRUCTURE_TAG(&d->ver) + |
| 831 |
sizeof_TPM_ENTITY_TYPE(&d->et) + |
| 832 |
sizeof_UINT32(d->sealInfoLongSize); |
| 833 |
if (d->sealInfoLongSize) { |
| 834 |
rv += sizeof_TPM_PCR_INFO_LONG(&d->sealInfoLong); |
| 835 |
} |
| 836 |
rv += sizeof_UINT32(d->encDataSize); |
| 837 |
rv += sizeof_BUFFER(d->encData, d->encDataSize); |
| 838 |
return rv; |
| 839 |
} |
| 840 |
|
| 841 |
static |
| 842 |
inline int unpack3_TPM_STORED_DATA12(BYTE* ptr, UINT32* pos, UINT32 len, TPM_STORED_DATA12* d, UnpackPtr alloc) { |
| 843 |
int rc = unpack3_TPM_STRUCTURE_TAG(ptr, pos, len, &d->tag) || |
| 844 |
unpack3_TPM_ENTITY_TYPE(ptr, pos, len, &d->et) || |
| 845 |
unpack3_UINT32(ptr, pos, len, &d->sealInfoLongSize); |
| 846 |
if (rc) |
| 847 |
return rc; |
| 848 |
if (d->sealInfoLongSize) |
| 849 |
rc = unpack3_TPM_PCR_INFO_LONG(ptr, pos, len, &d->sealInfoLong, |
| 850 |
alloc); |
| 851 |
if (rc) |
| 852 |
return rc; |
| 853 |
rc = unpack3_UINT32(ptr, pos, len, &d->encDataSize) || |
| 854 |
unpack3_PTR(ptr, pos, len, &d->encData, d->encDataSize, alloc); |
| 855 |
return rc; |
| 856 |
} |
| 857 |
|
| 858 |
static |
| 859 |
inline BYTE* pack_TPM_AUTH_SESSION(BYTE* ptr, const TPM_AUTH_SESSION* auth) { |
| 860 |
ptr = pack_TPM_AUTH_HANDLE(ptr, auth->AuthHandle); |
| 861 |
ptr = pack_TPM_NONCE(ptr, &auth->NonceOdd); |
| 862 |
ptr = pack_BOOL(ptr, auth->fContinueAuthSession); |
| 863 |
ptr = pack_TPM_AUTHDATA(ptr, &auth->HMAC); |
| 864 |
return ptr; |
| 865 |
} |
| 866 |
|
| 867 |
static |
| 868 |
inline BYTE* unpack_TPM_AUTH_SESSION(BYTE* ptr, TPM_AUTH_SESSION* auth) { |
| 869 |
ptr = unpack_TPM_NONCE(ptr, &auth->NonceEven); |
| 870 |
ptr = unpack_BOOL(ptr, &auth->fContinueAuthSession); |
| 871 |
ptr = unpack_TPM_AUTHDATA(ptr, &auth->HMAC); |
| 872 |
return ptr; |
| 873 |
} |
| 874 |
|
| 875 |
static |
| 876 |
inline int unpack3_TPM_AUTH_SESSION(BYTE* ptr, UINT32* pos, UINT32 len, TPM_AUTH_SESSION* auth) { |
| 877 |
return unpack3_TPM_NONCE(ptr, pos, len, &auth->NonceEven) || |
| 878 |
unpack3_BOOL(ptr, pos, len, &auth->fContinueAuthSession) || |
| 879 |
unpack3_TPM_AUTHDATA(ptr, pos, len, &auth->HMAC); |
| 880 |
} |
| 881 |
|
| 882 |
|
| 883 |
static |
| 884 |
inline int sizeof_TPM_AUTH_SESSION(const TPM_AUTH_SESSION* auth) { |
| 885 |
int rv = 0; |
| 886 |
rv += sizeof_TPM_AUTH_HANDLE(auth->AuthHandle); |
| 887 |
rv += sizeof_TPM_NONCE(&auth->NonceOdd); |
| 888 |
rv += sizeof_BOOL(auth->fContinueAuthSession); |
| 889 |
rv += sizeof_TPM_AUTHDATA(&auth->HMAC); |
| 890 |
return rv; |
| 891 |
} |
| 892 |
|
| 893 |
static |
| 894 |
inline int sizeof_TPM_RQU_HEADER(BYTE* ptr) { |
| 895 |
int rv = 0; |
| 896 |
rv += sizeof_UINT16(ptr); |
| 897 |
rv += sizeof_UINT32(ptr); |
| 898 |
rv += sizeof_UINT32(ptr); |
| 899 |
return rv; |
| 900 |
} |
| 901 |
|
| 902 |
static |
| 903 |
inline BYTE* pack_TPM_RQU_HEADER(BYTE* ptr, |
| 904 |
TPM_TAG tag, |
| 905 |
UINT32 size, |
| 906 |
TPM_COMMAND_CODE ord) { |
| 907 |
ptr = pack_UINT16(ptr, tag); |
| 908 |
ptr = pack_UINT32(ptr, size); |
| 909 |
return pack_UINT32(ptr, ord); |
| 910 |
} |
| 911 |
|
| 912 |
static |
| 913 |
inline BYTE* unpack_TPM_RQU_HEADER(BYTE* ptr, |
| 914 |
TPM_TAG* tag, |
| 915 |
UINT32* size, |
| 916 |
TPM_COMMAND_CODE* ord) { |
| 917 |
ptr = unpack_UINT16(ptr, tag); |
| 918 |
ptr = unpack_UINT32(ptr, size); |
| 919 |
ptr = unpack_UINT32(ptr, ord); |
| 920 |
return ptr; |
| 921 |
} |
| 922 |
|
| 923 |
static |
| 924 |
inline int unpack3_TPM_RQU_HEADER(BYTE* ptr, UINT32* pos, UINT32 max, |
| 925 |
TPM_TAG* tag, UINT32* size, TPM_COMMAND_CODE* ord) { |
| 926 |
return |
| 927 |
unpack3_UINT16(ptr, pos, max, tag) || |
| 928 |
unpack3_UINT32(ptr, pos, max, size) || |
| 929 |
unpack3_UINT32(ptr, pos, max, ord); |
| 930 |
} |
| 931 |
|
| 932 |
static |
| 933 |
inline int sizeof_TPM_RQU_GetRandom(BYTE* ptr) { |
| 934 |
return sizeof_TPM_RQU_HEADER(ptr) + sizeof_UINT32(ptr); |
| 935 |
} |
| 936 |
|
| 937 |
#define pack_TPM_RSP_HEADER(p, t, s, r) pack_TPM_RQU_HEADER(p, t, s, r) |
| 938 |
#define unpack_TPM_RSP_HEADER(p, t, s, r) unpack_TPM_RQU_HEADER(p, t, s, r) |
| 939 |
#define unpack3_TPM_RSP_HEADER(p, l, m, t, s, r) unpack3_TPM_RQU_HEADER(p, l, m, t, s, r) |
| 940 |
#define sizeof_TPM_RSP_HEADER(p) sizeof_TPM_RQU_HEADER(p) |
| 941 |
|
| 942 |
#endif |