Skip to content

Commit

Permalink
lib: rename TPM2B_INIT() macro to TPM2B_INIT_SIZE()
Browse files Browse the repository at this point in the history
A TPM2B_INIT() macro is already defined in tpm2-tss 1.x SAPI headers, so
lets rename it to TPM2B_INIT_SIZE() to prevent the following build error
when building the tpm2-tools against that tpm2-tss version:

In file included from lib/tcti/tpm2_tools_tcti_abrmd.c:39:0:
./lib/tpm2_util.h:49:0: error: "TPM2B_INIT" redefined [-Werror]
 #define TPM2B_INIT(xsize) { .t = { .size = xsize, }, }

In file included from /usr/include/sapi/tpm20.h:42:0,
                 from /usr/local/include/tcti/tcti-tabrmd.h:34,
                 from lib/tcti/tpm2_tools_tcti_abrmd.c:33:
/usr/include/sapi/tpmb.h:75:0: note: this is the location of the previous definition
 #define TPM2B_INIT(TYPE, name)     \

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
  • Loading branch information
martinezjavier authored and William Roberts committed Nov 13, 2017
1 parent ada5df3 commit 60f235d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/tpm2_util.h
Expand Up @@ -46,8 +46,8 @@
#define BUFFER_SIZE(type, field) (sizeof((((type *)NULL)->t.field)))

#define TPM2B_TYPE_INIT(type, field) { .t = { .size = BUFFER_SIZE(type, field), }, }
#define TPM2B_INIT(xsize) { .t = { .size = xsize, }, }
#define TPM2B_EMPTY_INIT TPM2B_INIT(0)
#define TPM2B_INIT_SIZE(xsize) { .t = { .size = xsize, }, }
#define TPM2B_EMPTY_INIT TPM2B_INIT_SIZE(0)
#define TPM2B_SENSITIVE_CREATE_EMPTY_INIT { \
.t.sensitive = { \
.data.t.size = 0, \
Expand Down
6 changes: 3 additions & 3 deletions tools/tpm2_import.c
Expand Up @@ -91,7 +91,7 @@ struct tpm_import_ctx {
static tpm_import_ctx ctx = {
.input_key_file = NULL,
.parent_key_handle = 0,
.parent_public_key = TPM2B_INIT(MAX_RSA_KEY_BYTES),
.parent_public_key = TPM2B_INIT_SIZE(MAX_RSA_KEY_BYTES),
.import_key_public = TPM2B_TYPE_INIT(TPM2B_PUBLIC, publicArea),
.import_key_public_name = TPM2B_TYPE_INIT(TPM2B_NAME, name),
.import_key_private = TPM2B_EMPTY_INIT,
Expand Down Expand Up @@ -348,7 +348,7 @@ static void create_import_key_sensitive_data(void) {
static bool calc_outer_integrity_hmac_key_and_dupsensitive_enc_key(void) {

TPM2B null_2b = { .size = 0 };
TPM2B_DIGEST to_TPM2B_seed = TPM2B_INIT(SHA256_DIGEST_SIZE);
TPM2B_DIGEST to_TPM2B_seed = TPM2B_INIT_SIZE(SHA256_DIGEST_SIZE);
memcpy(to_TPM2B_seed.t.buffer, ctx.protection_seed_data,
SHA256_DIGEST_SIZE); //max digest size
TPM2B_MAX_BUFFER result_key;
Expand Down Expand Up @@ -474,7 +474,7 @@ static bool import_external_key_and_save_public_private_data(TSS2_SYS_CONTEXT *s
};

TPM2B_PRIVATE importPrivate = TPM2B_TYPE_INIT(TPM2B_PRIVATE, buffer);
TPM2B_ENCRYPTED_SECRET enc_inp_seed = TPM2B_INIT(MAX_RSA_KEY_BYTES);
TPM2B_ENCRYPTED_SECRET enc_inp_seed = TPM2B_INIT_SIZE(MAX_RSA_KEY_BYTES);

memcpy(enc_inp_seed.t.secret, ctx.encrypted_protection_seed_data,
MAX_RSA_KEY_BYTES);
Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_pcrevent.c
Expand Up @@ -100,7 +100,7 @@ static TPM_RC tpm_pcrevent_file(TSS2_SYS_CONTEXT *sapi_context,
/* If we can get the file size and its less than 1024, just do it in one hash invocation */
if (res && file_size <= BUFFER_SIZE(TPM2B_EVENT, buffer)) {

TPM2B_EVENT buffer = TPM2B_INIT(file_size);
TPM2B_EVENT buffer = TPM2B_INIT_SIZE(file_size);

res = files_read_bytes(ctx.input, buffer.t.buffer, buffer.t.size);
if (!res) {
Expand Down

0 comments on commit 60f235d

Please sign in to comment.