Skip to content

Commit 78e014e

Browse files
tools: Fix wrong type usage of enums.
enums used as bitmask are now declared as <enum_type>_enum the bitmaks is now declared with typedef unsigned int <enum_type> Signed-off-by: Juergen Repp <juergen_repp@web.de>
1 parent 7b538d1 commit 78e014e

File tree

5 files changed

+43
-35
lines changed

5 files changed

+43
-35
lines changed

lib/tpm2_alg_util.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,26 @@
99

1010
#include "tool_rc.h"
1111

12-
typedef enum tpm2_alg_util_flags tpm2_alg_util_flags;
13-
enum tpm2_alg_util_flags {
14-
tpm2_alg_util_flags_none = 0,
15-
tpm2_alg_util_flags_hash = 1 << 0,
16-
tpm2_alg_util_flags_keyedhash = 1 << 1,
17-
tpm2_alg_util_flags_symmetric = 1 << 2,
18-
tpm2_alg_util_flags_asymmetric = 1 << 3,
19-
tpm2_alg_util_flags_kdf = 1 << 4,
20-
tpm2_alg_util_flags_mgf = 1 << 5,
21-
tpm2_alg_util_flags_sig = 1 << 6,
22-
tpm2_alg_util_flags_mode = 1 << 7,
23-
tpm2_alg_util_flags_base = 1 << 8,
24-
tpm2_alg_util_flags_misc = 1 << 9,
25-
tpm2_alg_util_flags_enc_scheme = 1 << 10,
26-
tpm2_alg_util_flags_rsa_scheme = 1 << 11,
27-
tpm2_alg_util_flags_any = ~0
12+
typedef enum tpm2_alg_util_flags_enum tpm2_alg_util_flags_enum;
13+
enum tpm2_alg_util_flags_enum {
14+
tpm2_alg_util_flags_none = 0,
15+
tpm2_alg_util_flags_hash = 1 << 0,
16+
tpm2_alg_util_flags_keyedhash = 1 << 1,
17+
tpm2_alg_util_flags_symmetric = 1 << 2,
18+
tpm2_alg_util_flags_asymmetric = 1 << 3,
19+
tpm2_alg_util_flags_kdf = 1 << 4,
20+
tpm2_alg_util_flags_mgf = 1 << 5,
21+
tpm2_alg_util_flags_sig = 1 << 6,
22+
tpm2_alg_util_flags_mode = 1 << 7,
23+
tpm2_alg_util_flags_base = 1 << 8,
24+
tpm2_alg_util_flags_misc = 1 << 9,
25+
tpm2_alg_util_flags_enc_scheme = 1 << 10,
26+
tpm2_alg_util_flags_rsa_scheme = 1 << 11,
27+
tpm2_alg_util_flags_any = ~0
2828
};
2929

30+
typedef unsigned int tpm2_alg_util_flags;
31+
3032
/**
3133
* Convert a "nice-name" string to an algorithm id.
3234
* @param name

lib/tpm2_openssl.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,15 @@ bool tpm2_openssl_hash_pcr_banks(TPMI_ALG_HASH hashAlg,
113113
bool tpm2_openssl_pcr_extend(TPMI_ALG_HASH halg, BYTE *pcr,
114114
const BYTE *data, UINT16 length);
115115

116-
typedef enum tpm2_openssl_load_rc tpm2_openssl_load_rc;
117-
enum tpm2_openssl_load_rc {
118-
lprc_error = 0, /* an error has occurred */
119-
lprc_private = 1 << 0, /* successfully loaded a private portion of object */
120-
lprc_public = 1 << 1, /* successfully loaded a public portion of object */
116+
typedef enum tpm2_openssl_load_rc_enum tpm2_openssl_load_rc_enum;
117+
enum tpm2_openssl_load_rc_eum {
118+
lprc_error = 0, /* an error has occurred */
119+
lprc_private = 1 << 0, /* successfully loaded a private portion of object */
120+
lprc_public = 1 << 1, /* successfully loaded a public portion of object */
121121
};
122122

123+
typedef unsigned int tpm2_openssl_load_rc;
124+
123125
/**
124126
* Helper routine for gathering if the loading status included a public
125127
* portion of an object.

lib/tpm2_util.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ char *tpm2_util_getenv(const char *name);
435435

436436
bool tpm2_util_env_yes(const char *name);
437437

438-
typedef enum tpm2_handle_flags tpm2_handle_flags;
439-
enum tpm2_handle_flags {
438+
typedef enum tpm2_handle_flags_enum tpm2_handle_flags_enum;
439+
enum tpm2_handle_flags_enum {
440440
TPM2_HANDLE_FLAGS_NONE = 0,
441441
TPM2_HANDLE_FLAGS_O = 1 << 0,
442442
TPM2_HANDLE_FLAGS_P = 1 << 1,
@@ -453,6 +453,8 @@ enum tpm2_handle_flags {
453453
TPM2_HANDLE_ALL_W_PCR = 0x17F,
454454
};
455455

456+
typedef unsigned int tpm2_handle_flags;
457+
456458
/**
457459
* Converts an option from the command line into a valid TPM handle, checking
458460
* for errors and if the tool supports it based on flags settings.

tools/misc/tpm2_certifyX509certutil.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static tool_rc generate_partial_X509() {
192192
BIO *cert_out = BIO_new_file(ctx.out_path, "wb");
193193
if (!cert_out) {
194194
LOG_ERR("Can not create file %s", ctx.out_path);
195-
return -1;
195+
return tool_rc_general_error;
196196
}
197197

198198
X509_EXTENSION *extv3 = NULL;

tools/tpm2_getekcertificate.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,21 @@ enum pubkey_enc_mode {
7272
*
7373
*/
7474

75-
typedef enum ek_nv_index ek_nv_index;
76-
enum ek_nv_index {
77-
RSA_EK_CERT_NV_INDEX = 0x01C00002,
78-
ECC_EK_CERT_NV_INDEX = 0x01C0000A,
79-
RSA_2048_EK_CERT_NV_INDEX = 0x01C00012,
80-
RSA_3072_EK_CERT_NV_INDEX = 0x01C0001C,
81-
RSA_4096_EK_CERT_NV_INDEX = 0x01C0001E,
82-
ECC_NIST_P256_EK_CERT_NV_INDEX = 0x01C00014,
83-
ECC_NIST_P384_EK_CERT_NV_INDEX = 0x01C00016,
84-
ECC_NIST_P521_EK_CERT_NV_INDEX = 0x01C00018,
85-
ECC_SM2_P256_EK_CERT_NV_INDEX = 0x01C0001A,
75+
typedef enum ek_nv_index_enum ek_nv_index_enum;
76+
enum ek_nv_index_enum {
77+
RSA_EK_CERT_NV_INDEX = 0x01C00002,
78+
ECC_EK_CERT_NV_INDEX = 0x01C0000A,
79+
RSA_2048_EK_CERT_NV_INDEX = 0x01C00012,
80+
RSA_3072_EK_CERT_NV_INDEX = 0x01C0001C,
81+
RSA_4096_EK_CERT_NV_INDEX = 0x01C0001E,
82+
ECC_NIST_P256_EK_CERT_NV_INDEX = 0x01C00014,
83+
ECC_NIST_P384_EK_CERT_NV_INDEX = 0x01C00016,
84+
ECC_NIST_P521_EK_CERT_NV_INDEX = 0x01C00018,
85+
ECC_SM2_P256_EK_CERT_NV_INDEX = 0x01C0001A,
8686
};
8787

88+
typedef unsigned int ek_nv_index;
89+
8890
#define EK_SERVER_INTEL "https://ekop.intel.com/ekcertservice/"
8991
#define EK_SERVER_AMD "https://ftpm.amd.com/pki/aia/"
9092

0 commit comments

Comments
 (0)