From 1a24bab50f277a4fe62c5872be6410e050ce4370 Mon Sep 17 00:00:00 2001 From: Dimitar Tomov Date: Thu, 12 Nov 2020 16:15:14 +0200 Subject: [PATCH] Minor fixes for keyload usage, examples README and whitespaces Signed-off-by: Dimitar Tomov --- examples/README.md | 10 ++++++---- examples/keygen/keygen.c | 3 ++- examples/keygen/keyimport.c | 11 ++++++----- examples/keygen/keyload.c | 7 ++++--- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/examples/README.md b/examples/README.md index 2302971..79aabe7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -193,7 +193,7 @@ Creating new RSA key... Created new key (pub 280, priv 222 bytes) Wrote 840 bytes to keyblob.bin -$ ./examples/keygen/keyload keyblob.bin RSA +$ ./examples/keygen/keyload keyblob.bin TPM2.0 Key load example Loading SRK: Storage 0x81000200 (282 bytes) Reading 840 bytes from keyblob.bin @@ -207,7 +207,7 @@ Creating new ECC key... Created new key (pub 88, priv 126 bytes) Wrote 744 bytes to keyblob.bin -$ ./examples/keygen/keyload keyblob.bin ECC +$ ./examples/keygen/keyload keyblob.bin TPM2.0 Key load example Loading SRK: Storage 0x81000200 (282 bytes) Reading 744 bytes from keyblob.bin @@ -223,7 +223,7 @@ Loading SRK: Storage 0x81000200 (282 bytes) Imported key (pub 278, priv 222 bytes) Wrote 840 bytes to keyblob.bin -$ ./examples/keygen/keyload keyblob.bin RSA +$ ./examples/keygen/keyload keyblob.bin TPM2.0 Key load example Loading SRK: Storage 0x81000200 (282 bytes) Reading 840 bytes from keyblob.bin @@ -236,9 +236,11 @@ Loading SRK: Storage 0x81000200 (282 bytes) Imported key (pub 86, priv 126 bytes) Wrote 744 bytes to keyblob.bin -$ ./examples/keygen/keyload keyblob.bin ECC +$ ./examples/keygen/keyload keyblob.bin TPM2.0 Key load example Loading SRK: Storage 0x81000200 (282 bytes) Reading 744 bytes from keyblob.bin Loaded key to 0x80000001 ``` + +The `keyload` tool takes only one argument, the filename of the stored key. Because the information what is key scheme (RSA or ECC) is contained within the key blob. diff --git a/examples/keygen/keygen.c b/examples/keygen/keygen.c index dcf4d82..f5010f4 100644 --- a/examples/keygen/keygen.c +++ b/examples/keygen/keygen.c @@ -55,7 +55,8 @@ int TPM2_Keygen_Example(void* userCtx, int argc, char *argv[]) size_t fileSz = 0; if (argc >= 2) { - if (XSTRNCMP(argv[1], "-?", 2) == 0 || + if (XSTRNCMP(argv[1], "-?", 2) == 0 || + XSTRNCMP(argv[1], "-h", 2) == 0 || XSTRNCMP(argv[1], "--help", 6) == 0) { usage(); return 0; diff --git a/examples/keygen/keyimport.c b/examples/keygen/keyimport.c index 11eea2b..bbf84a4 100644 --- a/examples/keygen/keyimport.c +++ b/examples/keygen/keyimport.c @@ -56,7 +56,8 @@ int TPM2_Keyimport_Example(void* userCtx, int argc, char *argv[]) size_t fileSz = 0; if (argc >= 2) { - if (XSTRNCMP(argv[1], "-?", 2) == 0 || + if (XSTRNCMP(argv[1], "-?", 2) == 0 || + XSTRNCMP(argv[1], "-h", 2) == 0 || XSTRNCMP(argv[1], "--help", 6) == 0) { usage(); return 0; @@ -109,12 +110,12 @@ int TPM2_Keyimport_Example(void* userCtx, int argc, char *argv[]) rc = wolfTPM2_ImportRsaPrivateKey(&dev, &storage, &impKey, kRsaKeyPubModulus, (word32)sizeof(kRsaKeyPubModulus), kRsaKeyPubExponent, - kRsaKeyPrivQ, (word32)sizeof(kRsaKeyPrivQ), + kRsaKeyPrivQ, (word32)sizeof(kRsaKeyPrivQ), TPM_ALG_NULL, TPM_ALG_NULL); } else if (alg == TPM_ALG_ECC) { /* Import raw ECC private key into TPM */ - rc = wolfTPM2_ImportEccPrivateKey(&dev, &storage, &impKey, + rc = wolfTPM2_ImportEccPrivateKey(&dev, &storage, &impKey, TPM_ECC_NIST_P256, kEccKeyPubXRaw, (word32)sizeof(kEccKeyPubXRaw), kEccKeyPubYRaw, (word32)sizeof(kEccKeyPubYRaw), @@ -122,8 +123,8 @@ int TPM2_Keyimport_Example(void* userCtx, int argc, char *argv[]) } if (rc != 0) goto exit; - printf("Imported key (pub %d, priv %d bytes)\n", - impKey.pub.size, impKey.priv.size); + printf("Imported %s key (pub %d, priv %d bytes)\n", + TPM2_GetAlgName(alg), impKey.pub.size, impKey.priv.size); /* Save key as encrypted blob to the disk */ #if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_FILESYSTEM) diff --git a/examples/keygen/keyload.c b/examples/keygen/keyload.c index ba447f9..80bcf43 100644 --- a/examples/keygen/keyload.c +++ b/examples/keygen/keyload.c @@ -37,7 +37,7 @@ static void usage(void) { printf("Expected usage:\n"); - printf("keyload [keyblob.bin] [ECC/RSA]\n"); + printf("keyload [keyblob.bin]\n"); } int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[]) @@ -52,7 +52,8 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[]) const char* inputFile = "keyblob.bin"; if (argc >= 2) { - if (XSTRNCMP(argv[1], "-?", 2) == 0 || + if (XSTRNCMP(argv[1], "-?", 2) == 0 || + XSTRNCMP(argv[1], "-h", 2) == 0 || XSTRNCMP(argv[1], "--help", 6) == 0) { usage(); return 0; @@ -108,7 +109,7 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[]) rc = BUFFER_E; goto exit; } printf("Reading %d bytes from %s\n", (int)fileSz, inputFile); - + XFREAD(&newKey.pub, 1, sizeof(newKey.pub), f); if (fileSz > sizeof(newKey.pub)) { fileSz -= sizeof(newKey.pub);