| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#ifndef VBOOT_REFERENCE_TLCL_INTERNAL_H_ |
| 7 |
#define VBOOT_REFERENCE_TLCL_INTERNAL_H_ |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#define kTpmRequestHeaderLength 10 |
| 14 |
#define kTpmResponseHeaderLength 10 |
| 15 |
#define kTpmReadInfoLength 12 |
| 16 |
#define kEncAuthLength 20 |
| 17 |
#define kPcrDigestLength 20 |
| 18 |
#define kTpmRequestAuthBlockLength \ |
| 19 |
(sizeof(uint32_t) + sizeof(TPM_NONCE) + 1 + TPM_AUTH_DATA_LEN) |
| 20 |
#define kTpmResponseAuthBlockLength (sizeof(TPM_NONCE) + 1 + TPM_AUTH_DATA_LEN) |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
__attribute__((unused)) |
| 30 |
static inline void ToTpmUint32(uint8_t *buffer, uint32_t x) { |
| 31 |
buffer[0] = (uint8_t)(x >> 24); |
| 32 |
buffer[1] = (uint8_t)((x >> 16) & 0xff); |
| 33 |
buffer[2] = (uint8_t)((x >> 8) & 0xff); |
| 34 |
buffer[3] = (uint8_t)(x & 0xff); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
__attribute__((unused)) |
| 41 |
static inline void FromTpmUint32(const uint8_t *buffer, uint32_t *x) { |
| 42 |
*x = (((uint32_t)buffer[0] << 24) | |
| 43 |
(buffer[1] << 16) | |
| 44 |
(buffer[2] << 8) | |
| 45 |
buffer[3]); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
__attribute__((unused)) |
| 52 |
static inline uint32_t ReadTpmUint32(const uint8_t **buffer) { |
| 53 |
uint32_t value; |
| 54 |
FromTpmUint32(*buffer, &value); |
| 55 |
*buffer += sizeof(value); |
| 56 |
return value; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
__attribute__((unused)) |
| 63 |
static inline void ToTpmUint16(uint8_t *buffer, uint16_t x) { |
| 64 |
buffer[0] = (uint8_t)(x >> 8); |
| 65 |
buffer[1] = (uint8_t)(x & 0xff); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
__attribute__((unused)) |
| 72 |
static inline void FromTpmUint16(const uint8_t *buffer, uint16_t *x) { |
| 73 |
*x = (buffer[0] << 8) | buffer[1]; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
__attribute__((unused)) |
| 80 |
static inline uint16_t ReadTpmUint16(const uint8_t **buffer) { |
| 81 |
uint16_t value; |
| 82 |
FromTpmUint16(*buffer, &value); |
| 83 |
*buffer += sizeof(value); |
| 84 |
return value; |
| 85 |
} |
| 86 |
|
| 87 |
#endif |