diff --git a/src/tpm2_wrap.c b/src/tpm2_wrap.c index a720ffa..a3143e8 100755 --- a/src/tpm2_wrap.c +++ b/src/tpm2_wrap.c @@ -177,7 +177,10 @@ const char* wolfTPM2_GetAlgName(TPM_ALG_ID alg) const char* wolfTPM2_GetRCString(TPM_RC rc) { - switch (rc) { + if (rc & RC_VER1) { + rc &= RC_MAX_FM0; + + switch (rc) { case TPM_RC_SUCCESS: return "Success"; case TPM_RC_BAD_TAG: @@ -259,6 +262,15 @@ const char* wolfTPM2_GetRCString(TPM_RC rc) case TPM_RC_SENSITIVE: return "The sensitive area did not unmarshal correctly after " "decryption"; + default: + break; + } + } + + if (rc & RC_FMT1) { + rc &= RC_MAX_FMT1; + + switch (rc) { case TPM_RC_ASYMMETRIC: return "Asymmetric algorithm not supported or not correct"; case TPM_RC_ATTRIBUTES: @@ -332,6 +344,15 @@ const char* wolfTPM2_GetRCString(TPM_RC rc) return "Curve not supported"; case TPM_RC_ECC_POINT: return "Point is not on the required curve"; + default: + break; + } + } + + if (rc & RC_WARN) { + rc &= RC_MAX_WARN; + + switch (rc) { case TPM_RC_CONTEXT_GAP: return "Gap for context ID is too large"; case TPM_RC_OBJECT_MEMORY: @@ -369,6 +390,7 @@ const char* wolfTPM2_GetRCString(TPM_RC rc) "TPM"; default: break; + } } return "Unknown"; } diff --git a/wolftpm/tpm2.h b/wolftpm/tpm2.h index 952ba0f..5870924 100644 --- a/wolftpm/tpm2.h +++ b/wolftpm/tpm2.h @@ -544,6 +544,7 @@ typedef enum { TPM_RC_BINDING = RC_FMT1 + 0x025, TPM_RC_CURVE = RC_FMT1 + 0x026, TPM_RC_ECC_POINT = RC_FMT1 + 0x027, + RC_MAX_FMT1 = RC_FMT1 + 0x03F, RC_WARN = 0x900, TPM_RC_CONTEXT_GAP = RC_WARN + 0x001, @@ -574,7 +575,9 @@ typedef enum { TPM_RC_LOCKOUT = RC_WARN + 0x021, TPM_RC_RETRY = RC_WARN + 0x022, TPM_RC_NV_UNAVAILABLE = RC_WARN + 0x023, - TPM_RC_NOT_USED = RC_WARN + 0x7F, + RC_MAX_WARN = RC_WARN + 0x03F, + + TPM_RC_NOT_USED = RC_WARN + 0x07F, TPM_RC_H = 0x000, TPM_RC_P = 0x040,