Skip to content

Commit c843064

Browse files
update macro guard
1 parent 75762d4 commit c843064

1 file changed

Lines changed: 53 additions & 10 deletions

File tree

wolfcrypt/src/pkcs7.c

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,7 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
24632463
esd->contentInfoSeqSz = SetSequence(pkcs7->contentTypeSz,
24642464
esd->contentInfoSeq);
24652465
}
2466+
#ifdef ASN_BER_TO_DER
24662467
else if (pkcs7->encodeStream) {
24672468
byte tmp[] = { 0xA0, 0x80 };
24682469
byte tmpSeq[] = { 0x30, 0x80 };
@@ -2477,6 +2478,7 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
24772478
XMEMCPY(esd->innerOctets, tmpStr, 2);
24782479
esd->innerOctetsSz = 2;
24792480
}
2481+
#endif
24802482
else {
24812483
esd->innerOctetsSz = SetOctetString(pkcs7->contentSz, esd->innerOctets);
24822484
esd->innerContSeqSz = SetExplicit(0, esd->innerOctetsSz +
@@ -2622,14 +2624,17 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
26222624
esd->contentInfoSeqSz + pkcs7->contentTypeSz +
26232625
esd->innerContSeqSz + esd->innerOctetsSz;
26242626

2627+
#ifdef ASN_BER_TO_DER
26252628
if (pkcs7->encodeStream) {
26262629
word32 sz = 0, tmpIdx = 0;
26272630
totalSz += 6; /* 00's for BER with inner content */
26282631

26292632
StreamOctetString(pkcs7->content, pkcs7->contentSz, NULL, &sz, &tmpIdx);
26302633
totalSz += sz + 6;
26312634
}
2632-
else {
2635+
else
2636+
#endif
2637+
{
26332638
totalSz += pkcs7->contentSz;
26342639
}
26352640
total2Sz = esd->certsSetSz + certSetSz + signerInfoSz;
@@ -2638,6 +2643,7 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
26382643
totalSz -= pkcs7->contentSz;
26392644
}
26402645

2646+
#ifdef ASN_BER_TO_DER
26412647
if (pkcs7->encodeStream) {
26422648
byte tmp[] = { 0xA0, 0x80 };
26432649
byte tmpSeq[] = { 0x30, 0x80 };
@@ -2654,7 +2660,9 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
26542660
esd->outerSeqSz = 2;
26552661
totalSz += esd->outerSeqSz + 2;
26562662
}
2657-
else {
2663+
else
2664+
#endif
2665+
{
26582666
esd->innerSeqSz = SetSequence(totalSz + total2Sz, esd->innerSeq);
26592667
totalSz += esd->innerSeqSz;
26602668
esd->outerContentSz = SetExplicit(0, totalSz + total2Sz, esd->outerContent);
@@ -2736,6 +2744,7 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
27362744
}
27372745
else {
27382746
if (!pkcs7->detached && pkcs7->content != NULL && pkcs7->contentSz > 0) {
2747+
#ifdef ASN_BER_TO_DER
27392748
if (pkcs7->encodeStream) {
27402749
StreamOctetString(pkcs7->content, pkcs7->contentSz, output,
27412750
outputSz, (word32*)&idx);
@@ -2746,7 +2755,9 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
27462755
output[idx++] = 0x00;
27472756
output[idx++] = 0x00;
27482757
}
2749-
else {
2758+
else
2759+
#endif
2760+
{
27502761
XMEMCPY(output + idx, pkcs7->content, pkcs7->contentSz);
27512762
idx += pkcs7->contentSz;
27522763
}
@@ -2818,6 +2829,7 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
28182829
XMEMCPY(output2 + idx, esd->encContentDigest, esd->encContentDigestSz);
28192830
idx += esd->encContentDigestSz;
28202831

2832+
#ifdef ASN_BER_TO_DER
28212833
if (pkcs7->encodeStream) {
28222834
byte tmp[] = { 0x00, 0x00 };
28232835

@@ -2830,6 +2842,7 @@ static int PKCS7_EncodeSigned(PKCS7* pkcs7, ESD* esd,
28302842
XMEMCPY(output2 + idx, tmp, 2);
28312843
idx += 2;
28322844
}
2845+
#endif
28332846

28342847
if (output2Sz) {
28352848
*output2Sz = idx;
@@ -8659,6 +8672,7 @@ int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7, byte* output, word32 outputSz)
86598672
return ret;
86608673
}
86618674

8675+
#ifdef ASN_BER_TO_DER
86628676
if (pkcs7->encodeStream) {
86638677
int err;
86648678
byte tmp[] = { 0x30, 0x80};
@@ -8674,7 +8688,9 @@ int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7, byte* output, word32 outputSz)
86748688
XMEMCPY(encContentSeq, tmp, 2);
86758689
encContentSeqSz = 2;
86768690
}
8677-
else {
8691+
else
8692+
#endif
8693+
{
86788694
encContentOctetSz = SetImplicit(ASN_OCTET_STRING, 0, encryptedOutSz,
86798695
encContentOctet);
86808696
encContentSeqSz = SetSequence(contentTypeSz + contentEncAlgoSz +
@@ -8689,6 +8705,7 @@ int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7, byte* output, word32 outputSz)
86898705
encContentOctetSz + encryptedOutSz;
86908706

86918707
/* EnvelopedData */
8708+
#ifdef ASN_BER_TO_DER
86928709
if (pkcs7->encodeStream) {
86938710
byte tmp[] = { 0x30, 0x80};
86948711

@@ -8699,33 +8716,41 @@ int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7, byte* output, word32 outputSz)
86998716
envDataSeqSz = 2;
87008717
totalSz += 2; /* 30 80 00 00 */
87018718
}
8702-
else {
8719+
else
8720+
#endif
8721+
{
87038722
envDataSeqSz = SetSequence(totalSz, envDataSeq);
87048723
}
87058724
totalSz += envDataSeqSz;
87068725

87078726
/* outer content */
8727+
#ifdef ASN_BER_TO_DER
87088728
if (pkcs7->encodeStream) {
87098729
byte tmp[] = { 0xA0, 0x80};
87108730
XMEMCPY(outerContent, tmp, 2);
87118731
outerContentSz = 2;
87128732
totalSz += 2; /* A0 80 00 00 */
87138733
}
8714-
else {
8734+
else
8735+
#endif
8736+
{
87158737
outerContentSz = SetExplicit(0, totalSz, outerContent);
87168738
}
87178739
totalSz += outerContentTypeSz;
87188740
totalSz += outerContentSz;
87198741

87208742
if (pkcs7->contentOID != FIRMWARE_PKG_DATA) {
87218743
/* ContentInfo */
8744+
#ifdef ASN_BER_TO_DER
87228745
if (pkcs7->encodeStream) {
87238746
byte tmp[] = { 0x30, 0x80};
87248747
XMEMCPY(contentInfoSeq, tmp, 2);
87258748
contentInfoSeqSz = 2;
87268749
totalSz += contentInfoSeqSz + 2; /* 30 80 00 00 */
87278750
}
8728-
else {
8751+
else
8752+
#endif
8753+
{
87298754
contentInfoSeqSz = SetSequence(totalSz, contentInfoSeq);
87308755
totalSz += contentInfoSeqSz;
87318756
}
@@ -8775,6 +8800,7 @@ int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7, byte* output, word32 outputSz)
87758800
idx += blockSz;
87768801

87778802
/* stream the content (octet string with multiple octet elements) */
8803+
#ifdef ASN_BER_TO_DER
87788804
if (pkcs7->encodeStream) {
87798805
int err;
87808806
byte* tmp;
@@ -8811,7 +8837,9 @@ int wc_PKCS7_EncodeEnvelopedData(PKCS7* pkcs7, byte* output, word32 outputSz)
88118837
idx += 2;
88128838
XFREE(tmp, pkcs7->heap, DYNAMIC_TYPE_PKCS7);
88138839
}
8814-
else {
8840+
else
8841+
#endif
8842+
{
88158843
XMEMCPY(output + idx, encContentOctet, encContentOctetSz);
88168844
idx += encContentOctetSz;
88178845
XMEMCPY(output + idx, encryptedContent, encryptedOutSz);
@@ -11816,6 +11844,7 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output,
1181611844
return BAD_FUNC_ARG;
1181711845
}
1181811846

11847+
#ifdef ASN_BER_TO_DER
1181911848
if (pkcs7->encodeStream) {
1182011849
int err;
1182111850

@@ -11827,7 +11856,9 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output,
1182711856
}
1182811857
encContentOctetSz -= encryptedOutSz;
1182911858
}
11830-
else {
11859+
else
11860+
#endif
11861+
{
1183111862
encContentOctetSz = SetImplicit(ASN_OCTET_STRING, 0, encryptedOutSz,
1183211863
encContentOctet);
1183311864
}
@@ -11905,6 +11936,7 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output,
1190511936
idx += macIntSz;
1190611937

1190711938

11939+
#ifdef ASN_BER_TO_DER
1190811940
if (pkcs7->encodeStream) {
1190911941
int err;
1191011942

@@ -11918,7 +11950,9 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output,
1191811950
XMEMCPY(output + idx, tmp, encContentOctetSz);
1191911951
idx += encContentOctetSz;
1192011952
}
11921-
else {
11953+
else
11954+
#endif
11955+
{
1192211956
XMEMCPY(output + idx, encContentOctet, encContentOctetSz);
1192311957
idx += encContentOctetSz;
1192411958
XMEMCPY(output + idx, encryptedContent, encryptedOutSz);
@@ -13293,8 +13327,13 @@ int wc_PKCS7_SetStreamMode(PKCS7* pkcs7, byte flag)
1329313327
if (pkcs7 == NULL) {
1329413328
return BAD_FUNC_ARG;
1329513329
}
13330+
#ifdef ASN_BER_TO_DER
1329613331
pkcs7->encodeStream = flag;
1329713332
return 0;
13333+
#else
13334+
(void)flag;
13335+
return NOT_COMPILED_IN;
13336+
#endif
1329813337
}
1329913338

1330013339

@@ -13304,7 +13343,11 @@ int wc_PKCS7_GetStreamMode(PKCS7* pkcs7)
1330413343
if (pkcs7 == NULL) {
1330513344
return BAD_FUNC_ARG;
1330613345
}
13346+
#ifdef ASN_BER_TO_DER
1330713347
return pkcs7->encodeStream;
13348+
#else
13349+
return 0;
13350+
#endif
1330813351
}
1330913352

1331013353

0 commit comments

Comments
 (0)