diff --git a/src/tpm2_wrap.c b/src/tpm2_wrap.c index 71e337f7..3c10706c 100644 --- a/src/tpm2_wrap.c +++ b/src/tpm2_wrap.c @@ -528,8 +528,8 @@ int wolfTPM2_SetKeyAuthPassword(WOLFTPM2_KEY *key, const byte* auth, } /* specify auth password for storage key */ - if (authSz > (int)sizeof(key->handle.auth.size)) { - authSz = (int)sizeof(key->handle.auth.size); /* truncate */ + if (authSz > (int)sizeof(key->handle.auth.buffer)) { + authSz = (int)sizeof(key->handle.auth.buffer); /* truncate */ } key->handle.auth.size = (UINT16)authSz; if (auth != NULL) { diff --git a/wrapper/CSharp/wolfTPM-tests.cs b/wrapper/CSharp/wolfTPM-tests.cs index 1b4849f1..7f89b9ef 100644 --- a/wrapper/CSharp/wolfTPM-tests.cs +++ b/wrapper/CSharp/wolfTPM-tests.cs @@ -127,6 +127,8 @@ namespace tpm_csharp_test Template template = new Template(); byte[] blob_buffer = new byte[Device.MAX_KEYBLOB_BYTES]; + Console.WriteLine("Generating {0} key", algorithm); + if (algorithm == "RSA") { rc = template.GetKeyTemplate_RSA((ulong)( @@ -158,6 +160,7 @@ namespace tpm_csharp_test rc = blob.GetKeyBlobAsBuffer(blob_buffer); if (rc > 0) { + Console.WriteLine("Key Blob Size: {0} bytes", rc); Array.Resize(ref blob_buffer, rc); if (algorithm == "RSA") { @@ -190,6 +193,8 @@ namespace tpm_csharp_test KeyBlob blob = new KeyBlob(); byte[] blob_buffer; + Console.WriteLine("Loading {0} key", algorithm); + if (algorithm == "RSA") { blob_buffer = generatedRSA; @@ -213,6 +218,28 @@ namespace tpm_csharp_test rc = blob.SetKeyAuthPassword("ThisIsMyKeyAuth"); Assert.AreEqual((int)Status.TPM_RC_SUCCESS, rc); + /* Use key to make sure authentication works */ + if (algorithm == "RSA") { + const int RsaKeySz = 256; + const int HashDigestSz = 32; + byte[] sig = new byte[RsaKeySz]; + byte[] digest = new byte[HashDigestSz]; + + /* Perform RSA sign / verify - PKCSv1.5 (SSA) padding */ + for (int i=0; i