Fix for error code reporting. The `RC_VER1`, `RC_FMT1` and `RC_WARN` values are a bit-mask to indicate group. Only the LSB 8-bits indicate error code.

pull/6/head
David Garske 2018-02-27 23:58:57 +01:00
parent 85cd1a5b68
commit 6fa51c27a8
2 changed files with 27 additions and 2 deletions

View File

@ -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";
}

View File

@ -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,