mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-04 13:14:45 +02:00
1. Split SetTagged into SetExplicit and SetImplicit.
2. Updated code using SetTagged to use new functions.
This commit is contained in:
@@ -2279,9 +2279,17 @@ CYASSL_LOCAL word32 SetSet(word32 len, byte* output)
|
|||||||
return SetLength(len, output + 1) + 1;
|
return SetLength(len, output + 1) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
CYASSL_LOCAL word32 SetTagged(byte tag, word32 len, byte* output)
|
CYASSL_LOCAL word32 SetImplicit(byte tag, byte number, word32 len, byte* output)
|
||||||
{
|
{
|
||||||
output[0] = ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC | tag;
|
|
||||||
|
output[0] = ((tag == ASN_SEQUENCE || tag == ASN_SET) ? ASN_CONSTRUCTED : 0)
|
||||||
|
| ASN_CONTEXT_SPECIFIC | number;
|
||||||
|
return SetLength(len, output + 1) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
CYASSL_LOCAL word32 SetExplicit(byte number, word32 len, byte* output)
|
||||||
|
{
|
||||||
|
output[0] = ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC | number;
|
||||||
return SetLength(len, output + 1) + 1;
|
return SetLength(len, output + 1) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,7 +30,6 @@
|
|||||||
#include <cyassl/ctaocrypt/pkcs7.h>
|
#include <cyassl/ctaocrypt/pkcs7.h>
|
||||||
#include <cyassl/ctaocrypt/error.h>
|
#include <cyassl/ctaocrypt/error.h>
|
||||||
#include <cyassl/ctaocrypt/logging.h>
|
#include <cyassl/ctaocrypt/logging.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#ifndef min
|
#ifndef min
|
||||||
static INLINE word32 min(word32 a, word32 b)
|
static INLINE word32 min(word32 a, word32 b)
|
||||||
@@ -331,7 +330,7 @@ int PKCS7_EncodeSignedData(PKCS7* pkcs7, byte* output, word32 outputSz)
|
|||||||
}
|
}
|
||||||
|
|
||||||
esd.innerOctetsSz = SetOctetString(pkcs7->contentSz, esd.innerOctets);
|
esd.innerOctetsSz = SetOctetString(pkcs7->contentSz, esd.innerOctets);
|
||||||
esd.innerContSeqSz = SetTagged(0, esd.innerOctetsSz + pkcs7->contentSz,
|
esd.innerContSeqSz = SetExplicit(0, esd.innerOctetsSz + pkcs7->contentSz,
|
||||||
esd.innerContSeq);
|
esd.innerContSeq);
|
||||||
esd.contentInfoSeqSz = SetSequence(pkcs7->contentSz + esd.innerOctetsSz +
|
esd.contentInfoSeqSz = SetSequence(pkcs7->contentSz + esd.innerOctetsSz +
|
||||||
innerOidSz + esd.innerContSeqSz,
|
innerOidSz + esd.innerContSeqSz,
|
||||||
@@ -387,7 +386,7 @@ int PKCS7_EncodeSignedData(PKCS7* pkcs7, byte* output, word32 outputSz)
|
|||||||
return MEMORY_E;
|
return MEMORY_E;
|
||||||
FlattenAttributes(flatSignedAttribs,
|
FlattenAttributes(flatSignedAttribs,
|
||||||
esd.signedAttribs, esd.signedAttribsCount);
|
esd.signedAttribs, esd.signedAttribsCount);
|
||||||
esd.signedAttribSetSz = SetTagged(0, esd.signedAttribsSz,
|
esd.signedAttribSetSz = SetImplicit(ASN_SET, 0, esd.signedAttribsSz,
|
||||||
esd.signedAttribSet);
|
esd.signedAttribSet);
|
||||||
}
|
}
|
||||||
/* Calculate the final hash and encrypt it. */
|
/* Calculate the final hash and encrypt it. */
|
||||||
@@ -437,7 +436,7 @@ int PKCS7_EncodeSignedData(PKCS7* pkcs7, byte* output, word32 outputSz)
|
|||||||
esd.signerInfoSetSz = SetSet(signerInfoSz, esd.signerInfoSet);
|
esd.signerInfoSetSz = SetSet(signerInfoSz, esd.signerInfoSet);
|
||||||
signerInfoSz += esd.signerInfoSetSz;
|
signerInfoSz += esd.signerInfoSetSz;
|
||||||
|
|
||||||
esd.certsSetSz = SetTagged(0, pkcs7->singleCertSz, esd.certsSet);
|
esd.certsSetSz = SetImplicit(ASN_SET, 0, pkcs7->singleCertSz, esd.certsSet);
|
||||||
|
|
||||||
esd.singleDigAlgoIdSz = SetAlgoID(pkcs7->hashOID, esd.singleDigAlgoId,
|
esd.singleDigAlgoIdSz = SetAlgoID(pkcs7->hashOID, esd.singleDigAlgoId,
|
||||||
hashType, 0);
|
hashType, 0);
|
||||||
@@ -453,7 +452,7 @@ int PKCS7_EncodeSignedData(PKCS7* pkcs7, byte* output, word32 outputSz)
|
|||||||
signerInfoSz;
|
signerInfoSz;
|
||||||
esd.innerSeqSz = SetSequence(totalSz, esd.innerSeq);
|
esd.innerSeqSz = SetSequence(totalSz, esd.innerSeq);
|
||||||
totalSz += esd.innerSeqSz;
|
totalSz += esd.innerSeqSz;
|
||||||
esd.outerContentSz = SetTagged(0, totalSz, esd.outerContent);
|
esd.outerContentSz = SetExplicit(0, totalSz, esd.outerContent);
|
||||||
totalSz += esd.outerContentSz + outerOidSz;
|
totalSz += esd.outerContentSz + outerOidSz;
|
||||||
esd.outerSeqSz = SetSequence(totalSz, esd.outerSeq);
|
esd.outerSeqSz = SetSequence(totalSz, esd.outerSeq);
|
||||||
totalSz += esd.outerSeqSz;
|
totalSz += esd.outerSeqSz;
|
||||||
@@ -769,7 +768,8 @@ int PKCS7_EncodeEnvelopeData(PKCS7* pkcs7, byte* output, word32 outputSz)
|
|||||||
Des3_CbcEncrypt(&des3, encryptedContent, plain, desOutSz);
|
Des3_CbcEncrypt(&des3, encryptedContent, plain, desOutSz);
|
||||||
}
|
}
|
||||||
|
|
||||||
encContentOctetSz = SetOctetString(desOutSz, encContentOctet);
|
encContentOctetSz = SetImplicit(ASN_OCTET_STRING, 0,
|
||||||
|
desOutSz, encContentOctet);
|
||||||
|
|
||||||
encContentSeqSz = SetSequence(contentTypeSz + contentEncAlgoSz +
|
encContentSeqSz = SetSequence(contentTypeSz + contentEncAlgoSz +
|
||||||
encContentOctetSz + desOutSz, encContentSeq);
|
encContentOctetSz + desOutSz, encContentSeq);
|
||||||
@@ -783,8 +783,7 @@ int PKCS7_EncodeEnvelopeData(PKCS7* pkcs7, byte* output, word32 outputSz)
|
|||||||
totalSz += envDataSeqSz;
|
totalSz += envDataSeqSz;
|
||||||
|
|
||||||
/* outer content */
|
/* outer content */
|
||||||
outerContent[0] = (ASN_CONSTRUCTED | ASN_CONTEXT_SPECIFIC | 0);
|
outerContentSz = SetExplicit(0, totalSz, outerContent);
|
||||||
outerContentSz = 1 + SetLength(totalSz, outerContent + 1);
|
|
||||||
totalSz += outerContentTypeSz;
|
totalSz += outerContentTypeSz;
|
||||||
totalSz += outerContentSz;
|
totalSz += outerContentSz;
|
||||||
|
|
||||||
@@ -1003,8 +1002,8 @@ CYASSL_API int PKCS7_DecodeEnvelopedData(PKCS7* pkcs7, byte* pkiMsg,
|
|||||||
if (GetAlgoId(pkiMsg, &idx, &encOID, pkiMsgSz) < 0)
|
if (GetAlgoId(pkiMsg, &idx, &encOID, pkiMsgSz) < 0)
|
||||||
return ASN_PARSE_E;
|
return ASN_PARSE_E;
|
||||||
|
|
||||||
/* read encryptedContent */
|
/* read encryptedContent, cont[0] */
|
||||||
if (pkiMsg[idx++] != ASN_OCTET_STRING)
|
if (pkiMsg[idx++] != (ASN_CONTEXT_SPECIFIC | 0))
|
||||||
return ASN_PARSE_E;
|
return ASN_PARSE_E;
|
||||||
|
|
||||||
if (GetLength(pkiMsg, &idx, &encryptedContentSz, pkiMsgSz) < 0)
|
if (GetLength(pkiMsg, &idx, &encryptedContentSz, pkiMsgSz) < 0)
|
||||||
|
@@ -459,7 +459,8 @@ CYASSL_LOCAL int GetAlgoId(const byte* input, word32* inOutIdx, word32* oid,
|
|||||||
CYASSL_LOCAL word32 SetLength(word32 length, byte* output);
|
CYASSL_LOCAL word32 SetLength(word32 length, byte* output);
|
||||||
CYASSL_LOCAL word32 SetSequence(word32 len, byte* output);
|
CYASSL_LOCAL word32 SetSequence(word32 len, byte* output);
|
||||||
CYASSL_LOCAL word32 SetOctetString(word32 len, byte* output);
|
CYASSL_LOCAL word32 SetOctetString(word32 len, byte* output);
|
||||||
CYASSL_LOCAL word32 SetTagged(byte tag, word32 len, byte* output);
|
CYASSL_LOCAL word32 SetImplicit(byte tag, byte number, word32 len,byte* output);
|
||||||
|
CYASSL_LOCAL word32 SetExplicit(byte number, word32 len, byte* output);
|
||||||
CYASSL_LOCAL word32 SetSet(word32 len, byte* output);
|
CYASSL_LOCAL word32 SetSet(word32 len, byte* output);
|
||||||
CYASSL_LOCAL word32 SetAlgoID(int algoOID, byte* output, int type, int curveSz);
|
CYASSL_LOCAL word32 SetAlgoID(int algoOID, byte* output, int type, int curveSz);
|
||||||
CYASSL_LOCAL int SetMyVersion(word32 version, byte* output, int header);
|
CYASSL_LOCAL int SetMyVersion(word32 version, byte* output, int header);
|
||||||
|
Reference in New Issue
Block a user