fix for building with clang

This commit is contained in:
Jacob Barthelmeh
2018-10-26 11:34:26 -06:00
committed by David Garske
parent 773a81ef6a
commit afbf09b970
2 changed files with 204 additions and 36 deletions

View File

@ -63,7 +63,7 @@ typedef enum {
#ifndef NO_PKCS7_STREAM #ifndef NO_PKCS7_STREAM
#define MAX_PKCS7_STREAM_BUFFER 256 #define MAX_PKCS7_STREAM_BUFFER 256
typedef struct PKCS7State { struct PKCS7State {
byte* tmpCert; byte* tmpCert;
byte* bufferPt; byte* bufferPt;
byte* key; byte* key;
@ -97,7 +97,7 @@ typedef struct PKCS7State {
#endif #endif
byte multi:1; /* flag for if content is in multiple parts */ byte multi:1; /* flag for if content is in multiple parts */
byte flagOne:1; byte flagOne:1;
} PKCS7State; };
enum PKCS7_MaxLen { enum PKCS7_MaxLen {
@ -754,21 +754,21 @@ int wc_PKCS7_Init(PKCS7* pkcs7, void* heap, int devId)
/* Certificate structure holding der pointer, size, and pointer to next /* Certificate structure holding der pointer, size, and pointer to next
* Pkcs7Cert struct. Used when creating SignedData types with multiple * Pkcs7Cert struct. Used when creating SignedData types with multiple
* certificates. */ * certificates. */
typedef struct Pkcs7Cert { struct Pkcs7Cert {
byte* der; byte* der;
word32 derSz; word32 derSz;
Pkcs7Cert* next; Pkcs7Cert* next;
} Pkcs7Cert; };
/* Linked list of ASN.1 encoded RecipientInfos */ /* Linked list of ASN.1 encoded RecipientInfos */
typedef struct Pkcs7EncodedRecip { struct Pkcs7EncodedRecip {
byte recip[MAX_RECIP_SZ]; byte recip[MAX_RECIP_SZ];
word32 recipSz; word32 recipSz;
int recipType; int recipType;
int recipVersion; int recipVersion;
Pkcs7EncodedRecip* next; Pkcs7EncodedRecip* next;
} Pkcs7EncodedRecip; };
/* free all members of Pkcs7Cert linked list */ /* free all members of Pkcs7Cert linked list */
@ -3574,7 +3574,15 @@ static int PKCS7_VerifySignedData(PKCS7* pkcs7, const byte* hashBuf,
break; break;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK,
in, inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
wc_PKCS7_StreamGetVar(pkcs7, &pkiMsg2Sz, (int*)&localIdx, &length); wc_PKCS7_StreamGetVar(pkcs7, &pkiMsg2Sz, (int*)&localIdx, &length);
if (pkcs7->stream->length > 0) { if (pkcs7->stream->length > 0) {
@ -6979,7 +6987,15 @@ static int wc_PKCS7_DecryptKtri(PKCS7* pkcs7, byte* in, word32 inSz,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK,
in, inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
if (GetMyVersion(pkiMsg, idx, &version, pkiMsgSz) < 0) if (GetMyVersion(pkiMsg, idx, &version, pkiMsgSz) < 0)
@ -7015,7 +7031,15 @@ static int wc_PKCS7_DecryptKtri(PKCS7* pkcs7, byte* in, word32 inSz,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK,
in, inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
wc_PKCS7_StreamGetVar(pkcs7, NULL, &sidType, &version); wc_PKCS7_StreamGetVar(pkcs7, NULL, &sidType, &version);
/* @TODO get expected size for next part, does not account for /* @TODO get expected size for next part, does not account for
@ -7659,8 +7683,15 @@ static int wc_PKCS7_DecryptOri(PKCS7* pkcs7, byte* in, word32 inSz,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz); inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
/* get OtherRecipientInfo sequence length */ /* get OtherRecipientInfo sequence length */
if (GetLength(pkiMsg, idx, &seqSz, pkiMsgSz) < 0) if (GetLength(pkiMsg, idx, &seqSz, pkiMsgSz) < 0)
@ -7745,7 +7776,15 @@ static int wc_PKCS7_DecryptPwri(PKCS7* pkcs7, byte* in, word32 inSz,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
/* remove KeyDerivationAlgorithmIdentifier */ /* remove KeyDerivationAlgorithmIdentifier */
if (pkiMsg[(*idx)++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC | 0)) if (pkiMsg[(*idx)++] != (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC | 0))
@ -7944,16 +7983,23 @@ static int wc_PKCS7_DecryptKekri(PKCS7* pkcs7, byte* in, word32 inSz,
switch (pkcs7->state) { switch (pkcs7->state) {
case WC_PKCS7_DECRYPT_KEKRI: case WC_PKCS7_DECRYPT_KEKRI:
//@TODO for now just get full buffer, needs divided up
#ifndef NO_PKCS7_STREAM #ifndef NO_PKCS7_STREAM
/* @TODO for now just get full buffer, needs divided up */
if ((ret = wc_PKCS7_AddDataToStream(pkcs7, in, inSz, if ((ret = wc_PKCS7_AddDataToStream(pkcs7, in, inSz,
(pkcs7->stream->maxLen - pkcs7->stream->totalRd) + (pkcs7->stream->maxLen - pkcs7->stream->totalRd) +
pkcs7->stream->length, &pkiMsg, idx)) != 0) { pkcs7->stream->length, &pkiMsg, idx)) != 0) {
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
/* remove KEKIdentifier */ /* remove KEKIdentifier */
if (GetSequence(pkiMsg, idx, &length, pkiMsgSz) < 0) if (GetSequence(pkiMsg, idx, &length, pkiMsgSz) < 0)
@ -8073,16 +8119,23 @@ static int wc_PKCS7_DecryptKari(PKCS7* pkcs7, byte* in, word32 inSz,
switch (pkcs7->state) { switch (pkcs7->state) {
case WC_PKCS7_DECRYPT_KARI: { case WC_PKCS7_DECRYPT_KARI: {
//@TODO for now just get full buffer, needs divided up
#ifndef NO_PKCS7_STREAM #ifndef NO_PKCS7_STREAM
/* @TODO for now just get full buffer, needs divided up */
if ((ret = wc_PKCS7_AddDataToStream(pkcs7, in, inSz, if ((ret = wc_PKCS7_AddDataToStream(pkcs7, in, inSz,
(pkcs7->stream->maxLen - pkcs7->stream->totalRd) + (pkcs7->stream->maxLen - pkcs7->stream->totalRd) +
pkcs7->stream->length, &pkiMsg, idx)) != 0) { pkcs7->stream->length, &pkiMsg, idx)) != 0) {
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
WC_PKCS7_KARI* kari; WC_PKCS7_KARI* kari;
@ -8310,7 +8363,13 @@ static int wc_PKCS7_DecryptRecipientInfos(PKCS7* pkcs7, byte* in,
savedIdx = *idx; savedIdx = *idx;
#ifndef NO_PKCS7_STREAM #ifndef NO_PKCS7_STREAM
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz);
if (rc < 0) {
return (int)rc;
}
pkiMsgSz = (word32)rc;
}
if (pkcs7->stream->length > 0) pkiMsg = pkcs7->stream->buffer; if (pkcs7->stream->length > 0) pkiMsg = pkcs7->stream->buffer;
#endif #endif
@ -8547,7 +8606,15 @@ static int wc_PKCS7_ParseToRecipientInfoSet(PKCS7* pkcs7, byte* in,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK,
in, inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
len = 0; len = 0;
@ -8628,7 +8695,15 @@ static int wc_PKCS7_ParseToRecipientInfoSet(PKCS7* pkcs7, byte* in,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
/* remove EnvelopedData and version */ /* remove EnvelopedData and version */
if (ret == 0 && GetSequence(pkiMsg, idx, &length, pkiMsgSz) < 0) if (ret == 0 && GetSequence(pkiMsg, idx, &length, pkiMsgSz) < 0)
@ -8657,7 +8732,15 @@ static int wc_PKCS7_ParseToRecipientInfoSet(PKCS7* pkcs7, byte* in,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
version = pkcs7->stream->varOne; version = pkcs7->stream->varOne;
#endif #endif
@ -8840,7 +8923,15 @@ WOLFSSL_API int wc_PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* in,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
/* remove EncryptedContentInfo */ /* remove EncryptedContentInfo */
@ -8904,7 +8995,15 @@ WOLFSSL_API int wc_PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* in,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
wc_PKCS7_StreamGetVar(pkcs7, 0, 0, &length); wc_PKCS7_StreamGetVar(pkcs7, 0, 0, &length);
tmpIv = pkcs7->stream->tmpIv; tmpIv = pkcs7->stream->tmpIv;
#endif #endif
@ -9218,7 +9317,7 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output,
/* otherwise, try to set from custom content type */ /* otherwise, try to set from custom content type */
} else if (ret <= 0) { } else if (ret <= 0) {
if (pkcs7->contentType == NULL || pkcs7->contentTypeSz == 0) { if (pkcs7->contentTypeSz == 0) {
WOLFSSL_MSG("CMS pkcs7->contentType must be set if " WOLFSSL_MSG("CMS pkcs7->contentType must be set if "
"contentOID is not"); "contentOID is not");
return BAD_FUNC_ARG; return BAD_FUNC_ARG;
@ -9612,8 +9711,15 @@ WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(PKCS7* pkcs7, byte* in,
break; break;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK,
in, inSz); in, inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
/* remove EncryptedContentInfo */ /* remove EncryptedContentInfo */
@ -9667,7 +9773,15 @@ WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(PKCS7* pkcs7, byte* in,
break; break;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
if (ret == 0 && GetLength(pkiMsg, &idx, &nonceSz, pkiMsgSz) < 0) { if (ret == 0 && GetLength(pkiMsg, &idx, &nonceSz, pkiMsgSz) < 0) {
ret = ASN_PARSE_E; ret = ASN_PARSE_E;
@ -9754,7 +9868,15 @@ WOLFSSL_API int wc_PKCS7_DecodeAuthEnvelopedData(PKCS7* pkcs7, byte* in,
break; break;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
encryptedContentSz = pkcs7->stream->expected; encryptedContentSz = pkcs7->stream->expected;
#endif #endif
@ -9864,8 +9986,15 @@ authenv_atrbend:
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK,
in, inSz); in, inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
if (pkcs7->stream->aadSz > 0) { if (pkcs7->stream->aadSz > 0) {
encodedAttribSz = pkcs7->stream->aadSz; encodedAttribSz = pkcs7->stream->aadSz;
encodedAttribs = pkcs7->stream->aad; encodedAttribs = pkcs7->stream->aad;
@ -10410,7 +10539,15 @@ int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* in, word32 inSz,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
if (ret == 0 && pkiMsg[idx++] != (ASN_CONSTRUCTED | if (ret == 0 && pkiMsg[idx++] != (ASN_CONSTRUCTED |
ASN_CONTEXT_SPECIFIC | 0)) ASN_CONTEXT_SPECIFIC | 0))
@ -10441,7 +10578,15 @@ int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* in, word32 inSz,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
#endif #endif
/* get version, check later */ /* get version, check later */
haveAttribs = 0; haveAttribs = 0;
@ -10487,7 +10632,15 @@ int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* in, word32 inSz,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
/* restore saved variables */ /* restore saved variables */
expBlockSz = pkcs7->stream->varOne; expBlockSz = pkcs7->stream->varOne;
@ -10524,7 +10677,15 @@ int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* in, word32 inSz,
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
/* use IV buffer from stream structure */ /* use IV buffer from stream structure */
tmpIv = pkcs7->stream->tmpIv; tmpIv = pkcs7->stream->tmpIv;
@ -10563,13 +10724,20 @@ int wc_PKCS7_DecodeEncryptedData(PKCS7* pkcs7, byte* in, word32 inSz,
case WC_PKCS7_STAGE6: case WC_PKCS7_STAGE6:
#ifndef NO_PKCS7_STREAM #ifndef NO_PKCS7_STREAM
//@TODO
if ((ret = wc_PKCS7_AddDataToStream(pkcs7, in, inSz, if ((ret = wc_PKCS7_AddDataToStream(pkcs7, in, inSz,
pkcs7->stream->expected, &pkiMsg, &idx)) != 0) { pkcs7->stream->expected, &pkiMsg, &idx)) != 0) {
return ret; return ret;
} }
pkiMsgSz = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in, inSz); {
long rc = wc_PKCS7_GetMaxStream(pkcs7, PKCS7_DEFAULT_PEEK, in,
inSz);
if (rc < 0) {
ret = (int)rc;
break;
}
pkiMsgSz = (word32)rc;
}
/* restore saved variables */ /* restore saved variables */
expBlockSz = pkcs7->stream->varOne; expBlockSz = pkcs7->stream->varOne;

View File

@ -203,7 +203,7 @@ typedef int (*CallbackOriEncrypt)(PKCS7* pkcs7, byte* cek, word32 cekSz,
/* Public Structure Warning: /* Public Structure Warning:
* Existing members must not be changed to maintain backwards compatibility! * Existing members must not be changed to maintain backwards compatibility!
*/ */
typedef struct PKCS7 { struct PKCS7 {
WC_RNG* rng; WC_RNG* rng;
PKCS7Attrib* signedAttribs; PKCS7Attrib* signedAttribs;
byte* content; /* inner content, not owner */ byte* content; /* inner content, not owner */
@ -283,7 +283,7 @@ typedef struct PKCS7 {
word32 state; word32 state;
/* !! NEW DATA MEMBERS MUST BE ADDED AT END !! */ /* !! NEW DATA MEMBERS MUST BE ADDED AT END !! */
} PKCS7; };
WOLFSSL_API PKCS7* wc_PKCS7_New(void* heap, int devId); WOLFSSL_API PKCS7* wc_PKCS7_New(void* heap, int devId);