Minor fixes for keyload usage, examples README and whitespaces

Signed-off-by: Dimitar Tomov <dimi@designfirst.ee>
pull/132/head
Dimitar Tomov 2020-11-12 16:15:14 +02:00
parent 4ce00ecb26
commit 1a24bab50f
4 changed files with 18 additions and 13 deletions

View File

@ -193,7 +193,7 @@ Creating new RSA key...
Created new key (pub 280, priv 222 bytes) Created new key (pub 280, priv 222 bytes)
Wrote 840 bytes to keyblob.bin Wrote 840 bytes to keyblob.bin
$ ./examples/keygen/keyload keyblob.bin RSA $ ./examples/keygen/keyload keyblob.bin
TPM2.0 Key load example TPM2.0 Key load example
Loading SRK: Storage 0x81000200 (282 bytes) Loading SRK: Storage 0x81000200 (282 bytes)
Reading 840 bytes from keyblob.bin Reading 840 bytes from keyblob.bin
@ -207,7 +207,7 @@ Creating new ECC key...
Created new key (pub 88, priv 126 bytes) Created new key (pub 88, priv 126 bytes)
Wrote 744 bytes to keyblob.bin Wrote 744 bytes to keyblob.bin
$ ./examples/keygen/keyload keyblob.bin ECC $ ./examples/keygen/keyload keyblob.bin
TPM2.0 Key load example TPM2.0 Key load example
Loading SRK: Storage 0x81000200 (282 bytes) Loading SRK: Storage 0x81000200 (282 bytes)
Reading 744 bytes from keyblob.bin Reading 744 bytes from keyblob.bin
@ -223,7 +223,7 @@ Loading SRK: Storage 0x81000200 (282 bytes)
Imported key (pub 278, priv 222 bytes) Imported key (pub 278, priv 222 bytes)
Wrote 840 bytes to keyblob.bin Wrote 840 bytes to keyblob.bin
$ ./examples/keygen/keyload keyblob.bin RSA $ ./examples/keygen/keyload keyblob.bin
TPM2.0 Key load example TPM2.0 Key load example
Loading SRK: Storage 0x81000200 (282 bytes) Loading SRK: Storage 0x81000200 (282 bytes)
Reading 840 bytes from keyblob.bin Reading 840 bytes from keyblob.bin
@ -236,9 +236,11 @@ Loading SRK: Storage 0x81000200 (282 bytes)
Imported key (pub 86, priv 126 bytes) Imported key (pub 86, priv 126 bytes)
Wrote 744 bytes to keyblob.bin Wrote 744 bytes to keyblob.bin
$ ./examples/keygen/keyload keyblob.bin ECC $ ./examples/keygen/keyload keyblob.bin
TPM2.0 Key load example TPM2.0 Key load example
Loading SRK: Storage 0x81000200 (282 bytes) Loading SRK: Storage 0x81000200 (282 bytes)
Reading 744 bytes from keyblob.bin Reading 744 bytes from keyblob.bin
Loaded key to 0x80000001 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.

View File

@ -55,7 +55,8 @@ int TPM2_Keygen_Example(void* userCtx, int argc, char *argv[])
size_t fileSz = 0; size_t fileSz = 0;
if (argc >= 2) { 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) { XSTRNCMP(argv[1], "--help", 6) == 0) {
usage(); usage();
return 0; return 0;

View File

@ -56,7 +56,8 @@ int TPM2_Keyimport_Example(void* userCtx, int argc, char *argv[])
size_t fileSz = 0; size_t fileSz = 0;
if (argc >= 2) { 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) { XSTRNCMP(argv[1], "--help", 6) == 0) {
usage(); usage();
return 0; return 0;
@ -109,12 +110,12 @@ int TPM2_Keyimport_Example(void* userCtx, int argc, char *argv[])
rc = wolfTPM2_ImportRsaPrivateKey(&dev, &storage, &impKey, rc = wolfTPM2_ImportRsaPrivateKey(&dev, &storage, &impKey,
kRsaKeyPubModulus, (word32)sizeof(kRsaKeyPubModulus), kRsaKeyPubModulus, (word32)sizeof(kRsaKeyPubModulus),
kRsaKeyPubExponent, kRsaKeyPubExponent,
kRsaKeyPrivQ, (word32)sizeof(kRsaKeyPrivQ), kRsaKeyPrivQ, (word32)sizeof(kRsaKeyPrivQ),
TPM_ALG_NULL, TPM_ALG_NULL); TPM_ALG_NULL, TPM_ALG_NULL);
} }
else if (alg == TPM_ALG_ECC) { else if (alg == TPM_ALG_ECC) {
/* Import raw ECC private key into TPM */ /* Import raw ECC private key into TPM */
rc = wolfTPM2_ImportEccPrivateKey(&dev, &storage, &impKey, rc = wolfTPM2_ImportEccPrivateKey(&dev, &storage, &impKey,
TPM_ECC_NIST_P256, TPM_ECC_NIST_P256,
kEccKeyPubXRaw, (word32)sizeof(kEccKeyPubXRaw), kEccKeyPubXRaw, (word32)sizeof(kEccKeyPubXRaw),
kEccKeyPubYRaw, (word32)sizeof(kEccKeyPubYRaw), kEccKeyPubYRaw, (word32)sizeof(kEccKeyPubYRaw),
@ -122,8 +123,8 @@ int TPM2_Keyimport_Example(void* userCtx, int argc, char *argv[])
} }
if (rc != 0) goto exit; if (rc != 0) goto exit;
printf("Imported key (pub %d, priv %d bytes)\n", printf("Imported %s key (pub %d, priv %d bytes)\n",
impKey.pub.size, impKey.priv.size); TPM2_GetAlgName(alg), impKey.pub.size, impKey.priv.size);
/* Save key as encrypted blob to the disk */ /* Save key as encrypted blob to the disk */
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_FILESYSTEM) #if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_FILESYSTEM)

View File

@ -37,7 +37,7 @@
static void usage(void) static void usage(void)
{ {
printf("Expected usage:\n"); 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[]) 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"; const char* inputFile = "keyblob.bin";
if (argc >= 2) { 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) { XSTRNCMP(argv[1], "--help", 6) == 0) {
usage(); usage();
return 0; return 0;
@ -108,7 +109,7 @@ int TPM2_Keyload_Example(void* userCtx, int argc, char *argv[])
rc = BUFFER_E; goto exit; rc = BUFFER_E; goto exit;
} }
printf("Reading %d bytes from %s\n", (int)fileSz, inputFile); printf("Reading %d bytes from %s\n", (int)fileSz, inputFile);
XFREAD(&newKey.pub, 1, sizeof(newKey.pub), f); XFREAD(&newKey.pub, 1, sizeof(newKey.pub), f);
if (fileSz > sizeof(newKey.pub)) { if (fileSz > sizeof(newKey.pub)) {
fileSz -= sizeof(newKey.pub); fileSz -= sizeof(newKey.pub);