summaryrefslogtreecommitdiffstats
path: root/TPM2-Plugin/lib/tpm2_util.c
diff options
context:
space:
mode:
authorNingSun <ning.sun@intel.com>2018-03-27 10:42:51 -0700
committerNingSun <ning.sun@intel.com>2018-03-28 16:03:21 -0700
commit8a5b33a9ba846d785d244e29bc29a46f7be34928 (patch)
treea5b6ad7d3950a57fefd60dd1200c4ce52dd959b5 /TPM2-Plugin/lib/tpm2_util.c
parentda00ff6db5e68773996ec79d711c45fb3444c580 (diff)
Add more codes in tpm2-plugin
Implement tpm2_plugin_load_key() and tpm2_plugin_rsa_sign() APIs Issue-ID: AAF-94 Change-Id: I5f4329fdf973e52264d9e0e8aabc864c5fbdeebf Signed-off-by: NingSun <ning.sun@intel.com>
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");
}
}