Debian Codegraph @

src/security/tpm/tss/tcg-1.2/tss_internal.h

raw symbols SCIP
1 /* SPDX-License-Identifier: BSD-3-Clause */
2
3 #ifndef TCG_TSS_INTERNAL_H_
4 #define TCG_TSS_INTERNAL_H_
5
6 #include <stdint.h>
7
8 /*
9 * These numbers derive from adding the sizes of command fields as shown in the
10 * TPM commands manual.
11 */
12 #define kTpmRequestHeaderLength 10
13 #define kTpmResponseHeaderLength 10
14 #define kTpmReadInfoLength 12
15 #define kEncAuthLength 20
16 #define kPcrDigestLength 20
17
18 /*
19 * Conversion functions. to_tpm_TYPE puts a value of type TYPE into a TPM
20 * command buffer. from_tpm_TYPE gets a value of type TYPE from a TPM command
21 * buffer into a variable.
22 */
23 __attribute__((unused))
24 static inline void to_tpm_uint32(uint8_t *buffer, uint32_t x)
25 {
26 buffer[0] = (uint8_t)(x >> 24);
27 buffer[1] = (uint8_t)((x >> 16) & 0xff);
28 buffer[2] = (uint8_t)((x >> 8) & 0xff);
29 buffer[3] = (uint8_t)(x & 0xff);
30 }
31
32 /*
33 * See comment for above function.
34 */
35 __attribute__((unused))
36 static inline void from_tpm_uint32(const uint8_t *buffer, uint32_t *x)
37 {
38 *x = ((buffer[0] << 24) |
39 (buffer[1] << 16) |
40 (buffer[2] << 8) |
41 buffer[3]);
42 }
43
44 /*
45 * See comment for above function.
46 */
47 __attribute__((unused))
48 static inline void to_tpm_uint16(uint8_t *buffer, uint16_t x)
49 {
50 buffer[0] = (uint8_t)(x >> 8);
51 buffer[1] = (uint8_t)(x & 0xff);
52 }
53
54 /*
55 * See comment for above function.
56 */
57 __attribute__((unused))
58 static inline void from_tpm_uint16(const uint8_t *buffer, uint16_t *x)
59 {
60 *x = (buffer[0] << 8) | buffer[1];
61 }
62
63 #endif /* TCG_TSS_INTERNAL_H_ */