Skip to content

Commit 1769a3a

Browse files
committed
Fixes for build error without wolfCrpyt (--disable-wolfcrypt). Fixes to better propagate errors when features are not compiled in. Add wolf error code descriptions when wolfCrypt is disabled.
1 parent 53563ac commit 1769a3a

4 files changed

Lines changed: 38 additions & 18 deletions

File tree

examples/keygen/keygen.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <examples/tpm_test_keys.h>
3030

3131
#include <stdio.h>
32+
#include <stdlib.h> /* atoi */
3233

3334
#ifndef WOLFTPM2_NO_WRAPPER
3435

src/tpm2.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ static int TPM2_CommandProcess(TPM2_CTX* ctx, TPM2_Packet* packet,
226226
#else
227227
(void)handleValue;
228228
(void)handlePos;
229+
return NOT_COMPILED_IN;
229230
#endif
230231
}
231232

@@ -328,6 +329,9 @@ static int TPM2_ResponseProcess(TPM2_CTX* ctx, TPM2_Packet* packet,
328329
return TPM_RC_HMAC;
329330
}
330331
}
332+
#else
333+
(void)cmdCode;
334+
return NOT_COMPILED_IN;
331335
#endif
332336

333337
/* Handle session request for decryption */
@@ -339,12 +343,12 @@ static int TPM2_ResponseProcess(TPM2_CTX* ctx, TPM2_Packet* packet,
339343
#ifdef DEBUG_WOLFTPM
340344
printf("Response parameter decryption failed\n");
341345
#endif
342-
return TPM_RC_FAILURE;
346+
return rc;
343347
}
344348
}
345349
}
346350
}
347-
(void)cmdCode;
351+
348352
return rc;
349353
}
350354

@@ -5345,6 +5349,16 @@ const char* TPM2_GetRCString(int rc)
53455349
#else
53465350
return wc_GetErrorString(rc);
53475351
#endif
5352+
#else
5353+
switch (rc) {
5354+
TPM_RC_STR(BAD_FUNC_ARG, "Bad function argument provided");
5355+
TPM_RC_STR(BUFFER_E, "Output buffer too small or input too large");
5356+
TPM_RC_STR(NOT_COMPILED_IN, "Feature not compiled in");
5357+
TPM_RC_STR(BAD_MUTEX_E, "Bad mutex operation");
5358+
TPM_RC_STR(WC_TIMEOUT_E, "Timeout error");
5359+
default:
5360+
break;
5361+
}
53485362
#endif
53495363
}
53505364
else if (rc == 0) {
@@ -5729,7 +5743,7 @@ int TPM2_HashNvPublic(TPMS_NV_PUBLIC* nvPublic, byte* buffer, UINT16* size)
57295743
(void)nvPublic;
57305744
(void)buffer;
57315745
(void)size;
5732-
return TPM_RC_SUCCESS;
5746+
return NOT_COMPILED_IN;
57335747
#endif
57345748
}
57355749

src/tpm2_param_enc.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ static int TPM2_ParamDec_XOR(TPM2_AUTH_SESSION *session, TPM2B_AUTH* keyIn,
267267
return rc;
268268
}
269269

270-
#ifdef WOLFSSL_AES_CFB
270+
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && defined(WOLFSSL_AES_CFB)
271271
/* Perform AES CFB encryption over the first parameter of a TPM packet */
272272
static int TPM2_ParamEnc_AESCFB(TPM2_AUTH_SESSION *session, TPM2B_AUTH* keyIn,
273273
TPM2B_NONCE* nonceCaller, TPM2B_NONCE* nonceTPM, BYTE *paramData,
@@ -551,13 +551,15 @@ TPM_RC TPM2_ParamEnc_CmdRequest(TPM2_AUTH_SESSION *session,
551551
rc = TPM2_ParamEnc_XOR(session, &session->auth, &session->nonceCaller,
552552
&session->nonceTPM, paramData, paramSz);
553553
}
554-
#ifdef WOLFSSL_AES_CFB
555554
else if (session->symmetric.algorithm == TPM_ALG_AES &&
556555
session->symmetric.mode.aes == TPM_ALG_CFB) {
556+
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && defined(WOLFSSL_AES_CFB)
557557
rc = TPM2_ParamEnc_AESCFB(session, &session->auth, &session->nonceCaller,
558558
&session->nonceTPM, paramData, paramSz);
559+
#else
560+
rc = NOT_COMPILED_IN;
561+
#endif
559562
}
560-
#endif
561563

562564
return rc;
563565
}
@@ -580,13 +582,15 @@ TPM_RC TPM2_ParamDec_CmdResponse(TPM2_AUTH_SESSION *session,
580582
rc = TPM2_ParamDec_XOR(session, &session->auth, &session->nonceCaller,
581583
&session->nonceTPM, paramData, paramSz);
582584
}
583-
#ifdef WOLFSSL_AES_CFB
584585
else if (session->symmetric.algorithm == TPM_ALG_AES &&
585586
session->symmetric.mode.aes == TPM_ALG_CFB) {
587+
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && defined(WOLFSSL_AES_CFB)
586588
rc = TPM2_ParamDec_AESCFB(session, &session->auth, &session->nonceCaller,
587589
&session->nonceTPM, paramData, paramSz);
590+
#else
591+
rc = NOT_COMPILED_IN;
592+
#endif
588593
}
589-
#endif
590594

591595
return rc;
592596
}

src/tpm2_wrap.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,7 @@ int wolfTPM2_Cleanup(WOLFTPM2_DEV* dev)
534534
#endif
535535
}
536536

537-
#ifndef WOLFTPM2_NO_WOLFCRYPT
538-
#ifndef NO_RSA
537+
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(NO_RSA)
539538
/* returns both the plaintext and encrypted salt, based on the salt key bPublic. */
540539
int wolfTPM2_RSA_Salt(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* tpmKey,
541540
TPM2B_DIGEST *salt, TPM2B_ENCRYPTED_SECRET *encSalt, TPMT_PUBLIC *publicArea)
@@ -601,7 +600,7 @@ int wolfTPM2_RSA_Salt(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* tpmKey,
601600

602601
return 0;
603602
}
604-
#endif /* !NO_RSA */
603+
#endif /* !WOLFTPM2_NO_WOLFCRYPT && !NO_RSA */
605604

606605
int wolfTPM2_EncryptSalt(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* tpmKey,
607606
StartAuthSession_In* in, TPM2B_AUTH* bindAuth, TPM2B_DIGEST* salt)
@@ -613,6 +612,7 @@ int wolfTPM2_EncryptSalt(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* tpmKey,
613612
return TPM_RC_SUCCESS;
614613
}
615614

615+
#ifndef WOLFTPM2_NO_WOLFCRYPT
616616
/* generate a salt */
617617
salt->size = TPM2_GetHashDigestSize(in->authHash);
618618
if (salt->size <= 0) {
@@ -645,12 +645,17 @@ int wolfTPM2_EncryptSalt(WOLFTPM2_DEV* dev, WOLFTPM2_KEY* tpmKey,
645645
rc = NOT_COMPILED_IN;
646646
break;
647647
}
648+
#else
649+
(void)dev;
650+
(void)in;
651+
(void)salt;
652+
rc = NOT_COMPILED_IN;
653+
#endif /* !WOLFTPM2_NO_WOLFCRYPT */
648654

649655
(void)bindAuth; /* TODO: Add bind support */
650656

651657
return rc;
652658
}
653-
#endif /* !WOLFTPM2_NO_WOLFCRYPT */
654659

655660
int wolfTPM2_StartSession(WOLFTPM2_DEV* dev, WOLFTPM2_SESSION* session,
656661
WOLFTPM2_KEY* tpmKey, WOLFTPM2_HANDLE* bind, TPM_SE sesType,
@@ -693,15 +698,12 @@ int wolfTPM2_StartSession(WOLFTPM2_DEV* dev, WOLFTPM2_SESSION* session,
693698
}
694699

695700
authSesIn.sessionType = sesType;
696-
#ifdef WOLFSSL_AES_CFB
697701
if (encDecAlg == TPM_ALG_CFB) {
698702
authSesIn.symmetric.algorithm = TPM_ALG_AES;
699703
authSesIn.symmetric.keyBits.aes = 128;
700704
authSesIn.symmetric.mode.aes = TPM_ALG_CFB;
701705
}
702-
else
703-
#endif
704-
if (encDecAlg == TPM_ALG_XOR) {
706+
else if (encDecAlg == TPM_ALG_XOR) {
705707
authSesIn.symmetric.algorithm = TPM_ALG_XOR;
706708
authSesIn.symmetric.keyBits.xorr = TPM_ALG_SHA256;
707709
authSesIn.symmetric.mode.sym = TPM_ALG_NULL;
@@ -719,16 +721,15 @@ int wolfTPM2_StartSession(WOLFTPM2_DEV* dev, WOLFTPM2_SESSION* session,
719721
return rc;
720722
}
721723

722-
#ifndef WOLFTPM2_NO_WOLFCRYPT
723724
/* Generate and Encrypt salt using "SECRET" */
724725
rc = wolfTPM2_EncryptSalt(dev, tpmKey, &authSesIn, bindAuth, &session->salt);
725726
if (rc != 0) {
726727
#ifdef DEBUG_WOLFTPM
727728
printf("Building encrypted salt failed %d: %s!\n", rc,
728729
wolfTPM2_GetRCString(rc));
729730
#endif
731+
return rc;
730732
}
731-
#endif
732733

733734
rc = TPM2_StartAuthSession(&authSesIn, &authSesOut);
734735
if (rc != TPM_RC_SUCCESS) {

0 commit comments

Comments
 (0)