summaryrefslogtreecommitdiffstats
path: root/TPM2-Plugin/lib/tpm2_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'TPM2-Plugin/lib/tpm2_util.c')
-rw-r--r--TPM2-Plugin/lib/tpm2_util.c67
1 files changed, 11 insertions, 56 deletions
diff --git a/TPM2-Plugin/lib/tpm2_util.c b/TPM2-Plugin/lib/tpm2_util.c
index 7a42df7..c0a6cc4 100644
--- a/TPM2-Plugin/lib/tpm2_util.c
+++ b/TPM2-Plugin/lib/tpm2_util.c
@@ -31,13 +31,16 @@
#include <ctype.h>
#include <errno.h>
#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
#include "log.h"
#include "files.h"
#include "tpm2_alg_util.h"
#include "tpm2_attr_util.h"
+#include "tpm2_tool.h"
#include "tpm2_util.h"
-bool output_enabled;
+
bool tpm2_util_concat_buffer(TPM2B_MAX_BUFFER *result, TPM2B *append) {
if (!result || !append) {
@@ -131,45 +134,19 @@ int tpm2_util_hex_to_byte_structure(const char *inStr, UINT16 *byteLength,
return 0;
}
-void tpm2_util_hexdump(const BYTE *data, size_t len, bool plain) {
+void tpm2_util_hexdump(const BYTE *data, size_t len) {
if (!output_enabled) {
return;
}
- if (plain) {
- size_t i;
- for (i=0; i < len; i++) {
- printf("%02x", data[i]);
- }
- return;
- }
-
size_t i;
- size_t j;
- for (i = 0; i < len; i += 16) {
- printf("%06zx: ", i);
-
- for (j = 0; j < 16; j++) {
- if (i + j < len) {
- printf("%02x ", data[i + j]);
- } else {
- printf(" ");
- }
- }
-
- printf(" ");
-
- for (j = 0; j < 16; j++) {
- if (i + j < len) {
- printf("%c", isprint(data[i + j]) ? data[i + j] : '.');
- }
- }
- printf("\n");
+ for (i=0; i < len; i++) {
+ printf("%02x", data[i]);
}
}
-bool tpm2_util_hexdump_file(FILE *fd, size_t len, bool plain) {
+bool tpm2_util_hexdump_file(FILE *fd, size_t len) {
BYTE* buff = (BYTE*)malloc(len);
if (!buff) {
LOG_ERR("malloc() failed");
@@ -183,7 +160,7 @@ bool tpm2_util_hexdump_file(FILE *fd, size_t len, bool plain) {
return false;
}
- tpm2_util_hexdump(buff, len, plain);
+ tpm2_util_hexdump(buff, len);
free(buff);
return true;
@@ -197,29 +174,7 @@ bool tpm2_util_print_tpm2b_file(FILE *fd)
LOG_ERR("File read failed");
return false;
}
- return tpm2_util_hexdump_file(fd, len, true);
-}
-
-/* TODO OPTIMIZE ME */
-UINT16 tpm2_util_copy_tpm2b(TPM2B *dest, TPM2B *src) {
- int i;
- UINT16 rval = 0;
-
- if (dest != 0) {
- if (src == 0) {
- dest->size = 0;
- rval = 0;
- } else {
- dest->size = src->size;
- for (i = 0; i < src->size; i++)
- dest->buffer[i] = src->buffer[i];
- rval = (sizeof(UINT16) + src->size);
- }
- } else {
- rval = 0;
- }
-
- return rval;
+ return tpm2_util_hexdump_file(fd, len);
}
bool tpm2_util_is_big_endian(void) {
@@ -386,7 +341,7 @@ void tpm2_util_public_to_yaml(TPM2B_PUBLIC *public) {
if (public->publicArea.authPolicy.size) {
tpm2_tool_output("authorization policy: ");
tpm2_util_hexdump(public->publicArea.authPolicy.buffer,
- public->publicArea.authPolicy.size, true);
+ public->publicArea.authPolicy.size);
tpm2_tool_output("\n");
}
}