Skip to content

Commit

Permalink
working load
Browse files Browse the repository at this point in the history
Signed-off-by: Bill Roberts <[email protected]>
  • Loading branch information
williamcroberts committed Dec 7, 2023
1 parent 0f4e279 commit df6a67a
Show file tree
Hide file tree
Showing 105 changed files with 153 additions and 113 deletions.
10 changes: 6 additions & 4 deletions lib/tpm2_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ union tpm2_option_flags {
uint8_t quiet :1;
uint8_t enable_errata :1;
uint8_t tcti_none :1;
uint8_t no_output :1;
//uint8_t no_output :1;
};
uint8_t all;
};
Expand Down Expand Up @@ -66,9 +66,11 @@ typedef bool (*tpm2_arg_handler)(int argc, char **argv);
* TPM2_OPTIONS_NO_SAPI:
* Skip SAPI initialization. Removes the "-T" common option.
*/
#define TPM2_OPTIONS_NO_SAPI 0x1
#define TPM2_OPTIONS_OPTIONAL_SAPI 0x2
#define TPM2_OPTIONS_OPTIONAL_SAPI_AND_FAKE_TCTI 0x4
#define TPM2_OPTIONS_NO_SAPI (1 << 0)
#define TPM2_OPTIONS_OPTIONAL_SAPI (1 << 1)
#define TPM2_OPTIONS_NO_OUTPUT (1 << 2)

#define TPM2_OPTIONS_OPTIONAL_SAPI_AND_FAKE_TCTI (TPM2_OPTIONS_NO_SAPI | TPM2_OPTIONS_OPTIONAL_SAPI)

struct tpm2_options {
struct {
Expand Down
14 changes: 14 additions & 0 deletions lib/tpm2_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,20 @@ void tpm2_util_hexdump2(FILE *f, const BYTE *data, size_t len) {
}
}

char *tpm2_util_bin2hex(const BYTE *data, size_t len) {

char *c = calloc(1, len * 2 + 1);
if (!c) {
return NULL;
}
size_t i, j;
for (i = 0, j = 0; i < len && j < len * 2 + 1; i++, j+=2) {
sprintf(&c[j], "%02x", data[i]);
}

return c;
}

void tpm2_util_hexdump(const BYTE *data, size_t len) {

if (!output_enabled) {
Expand Down
14 changes: 14 additions & 0 deletions lib/tpm2_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ void tpm2_util_hexdump(const BYTE *data, size_t len);
*/
void tpm2_util_hexdump2(FILE *f, const BYTE *data, size_t len);

/**
* Converts a binary string of bytes into a hex string.
*
* @param data
* The data to convert to hex
*
* @param len
* The length of the data in bytes.
*
* @returns
* A null terminated hex string on sucess or NULL on error (oom).
*/
char *tpm2_util_bin2hex(const BYTE *data, size_t len);

/**
* Read a hex string converting it to binary or a binary file and
* store into a binary buffer.
Expand Down
2 changes: 1 addition & 1 deletion tools/misc/tpm2_certifyX509certutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static tool_rc generate_partial_X509() {
}


static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);
UNUSED(ectx);
Expand Down
2 changes: 1 addition & 1 deletion tools/misc/tpm2_checkquote.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(ectx);
UNUSED(flags);
Expand Down
2 changes: 1 addition & 1 deletion tools/misc/tpm2_encodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static int encode(void) {
return rc;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {
UNUSED(flags);

tool_rc rc = check_opts();
Expand Down
2 changes: 1 addition & 1 deletion tools/misc/tpm2_eventlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);
UNUSED(ectx);
Expand Down
2 changes: 1 addition & 1 deletion tools/misc/tpm2_print.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {
UNUSED(ectx);
UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/misc/tpm2_rc_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);
UNUSED(ectx);
Expand Down
2 changes: 1 addition & 1 deletion tools/misc/tpm2_tr_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static bool check_options(void) {
return result;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);
UNUSED(ectx);
Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_certify.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_certifycreation.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_changeauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_changeeps.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_changepps.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_clear.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_clearcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_clockrateadjust.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_createak.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_createek.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_createpolicy.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_createprimary.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_dictionarylockout.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_duplicate.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_ecdhkeygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_ecdhzgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_ecephemeral.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_encryptdecrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_evictcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_flushcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_getcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *context, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *context, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_getcommandauditdigest.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static tool_rc process_outputs(ESYS_CONTEXT *ectx) {
return tool_rc_success;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_geteccparameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_getekcertificate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(ectx);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_getpolicydigest.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != 0;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_getrandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_getsessionauditdigest.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static tool_rc process_outputs(ESYS_CONTEXT *ectx) {
return tool_rc_success;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {

UNUSED(flags);

Expand Down
2 changes: 1 addition & 1 deletion tools/tpm2_gettestresult.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static bool tpm2_tool_onstart(tpm2_options **opts) {
return *opts != NULL;
}

static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, yaml_document_t *doc, tpm2_option_flags flags) {
UNUSED(flags);

tool_rc rc = tool_rc_general_error;
Expand Down
Loading

0 comments on commit df6a67a

Please sign in to comment.