Skip to content

Commit a6894fc

Browse files
committed
Store crlNumber as an MP_INT
1 parent 8a93883 commit a6894fc

File tree

6 files changed

+60
-56
lines changed

6 files changed

+60
-56
lines changed

src/crl.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ static int InitCRL_Entry(CRL_Entry* crle, DecodedCRL* dcrl, const byte* buff,
139139
#endif
140140
dcrl->certs = NULL;
141141
crle->totalCerts = dcrl->totalCerts;
142+
#ifndef NO_BIG_INT
142143
crle->crlNumber = dcrl->crlNumber;
144+
#endif
143145
crle->verified = verified;
144146
if (!verified) {
145147
crle->tbsSz = dcrl->sigIndex - dcrl->certBegin;
@@ -590,7 +592,9 @@ static void SetCrlInfo(CRL_Entry* entry, CrlInfo *info)
590592
info->nextDate = (byte *)entry->nextDate;
591593
info->nextDateMaxLen = MAX_DATE_SIZE;
592594
info->nextDateFormat = entry->nextDateFormat;
593-
info->crlNumber = (sword32)entry->crlNumber;
595+
#ifndef NO_BIG_INT
596+
info->crlNumber = entry->crlNumber;
597+
#endif
594598
}
595599

596600
static void SetCrlInfoFromDecoded(DecodedCRL* entry, CrlInfo *info)
@@ -603,7 +607,9 @@ static void SetCrlInfoFromDecoded(DecodedCRL* entry, CrlInfo *info)
603607
info->nextDate = (byte *)entry->nextDate;
604608
info->nextDateMaxLen = MAX_DATE_SIZE;
605609
info->nextDateFormat = entry->nextDateFormat;
606-
info->crlNumber = (sword32)entry->crlNumber;
610+
#ifndef NO_BIG_INT
611+
info->crlNumber = entry->crlNumber;
612+
#endif
607613
}
608614
#endif
609615

@@ -648,13 +654,14 @@ static int AddCRL(WOLFSSL_CRL* crl, DecodedCRL* dcrl, const byte* buff,
648654

649655
for (curr = crl->crlList; curr != NULL; curr = curr->next) {
650656
if (XMEMCMP(curr->issuerHash, crle->issuerHash, CRL_DIGEST_SIZE) == 0) {
651-
if (crle->crlNumber <= curr->crlNumber) {
657+
#ifndef NO_BIG_INT
658+
if (mp_cmp(&crle->crlNumber, &curr->crlNumber) <= 0) {
652659
WOLFSSL_MSG("Same or newer CRL entry already exists");
653660
CRL_Entry_free(crle, crl->heap);
654661
wc_UnLockRwLock(&crl->crlLock);
655662
return BAD_FUNC_ARG;
656663
}
657-
664+
#endif
658665
crle->next = curr->next;
659666
if (prev != NULL) {
660667
prev->next = crle;

src/x509.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8941,6 +8941,8 @@ static int X509CRLPrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509_CRL* crl,
89418941
int indent)
89428942
{
89438943
char tmp[MAX_WIDTH]; /* buffer for XSNPRINTF */
8944+
char crlNumberStr[50]; /* RFC5280 states that CRL number can be up to 20
8945+
* octets long i.e 49 digits */
89448946

89458947
if (XSNPRINTF(tmp, MAX_WIDTH, "%*s%s\n", indent, "",
89468948
"CRL extensions:") >= MAX_WIDTH) {
@@ -8951,7 +8953,8 @@ static int X509CRLPrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509_CRL* crl,
89518953
return WOLFSSL_FAILURE;
89528954
}
89538955

8954-
if (crl->crlList->crlNumber) {
8956+
#ifndef NO_BIG_INT
8957+
if (crl->crlList->crlNumber.used) {
89558958
if (XSNPRINTF(tmp, MAX_WIDTH, "%*s%s\n", indent + 4, "",
89568959
"X509v3 CRL Number:") >= MAX_WIDTH) {
89578960
return WOLFSSL_FAILURE;
@@ -8961,16 +8964,22 @@ static int X509CRLPrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509_CRL* crl,
89618964
return WOLFSSL_FAILURE;
89628965
}
89638966

8964-
if (XSNPRINTF(tmp, MAX_WIDTH, "%*s%d\n", indent + 8, "",
8965-
crl->crlList->crlNumber) >= MAX_WIDTH)
8966-
{
8967+
if (mp_toradix(&crl->crlList->crlNumber, crlNumberStr, MP_RADIX_DEC)
8968+
!= MP_OKAY) {
8969+
return WOLFSSL_FAILURE;
8970+
}
8971+
8972+
if (XSNPRINTF(tmp, MAX_WIDTH, "%*s%s\n", indent + 8, "",
8973+
crlNumberStr) >= MAX_WIDTH) {
89678974
return WOLFSSL_FAILURE;
89688975
}
8976+
89698977
if (wolfSSL_BIO_write(bio, tmp, (int)XSTRLEN(tmp)) <= 0) {
89708978
return WOLFSSL_FAILURE;
89718979
}
89728980
XMEMSET(tmp, 0, sizeof(tmp));
89738981
}
8982+
#endif
89748983

89758984
#if !defined(NO_SKID)
89768985
if (crl->crlList->extAuthKeyIdSet && crl->crlList->extAuthKeyId[0] != 0) {

wolfcrypt/src/asn.c

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38507,6 +38507,11 @@ void FreeDecodedCRL(DecodedCRL* dcrl)
3850738507
#ifdef OPENSSL_EXTRA
3850838508
XFREE(dcrl->issuer, NULL, DYNAMIC_TYPE_OPENSSL);
3850938509
#endif
38510+
38511+
mp_free(&dcrl->crlNumber);
38512+
#ifdef WOLFSSL_SMALL_STACK
38513+
XFREE(&dcrl->crlNumber, NULL, DYNAMIC_TYPE_BIGINT);
38514+
#endif
3851038515
}
3851138516

3851238517

@@ -39077,50 +39082,31 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf,
3907739082
return ret;
3907839083
}
3907939084
else {
39080-
if (length > 1) {
39081-
int i;
39082-
#ifdef WOLFSSL_SMALL_STACK
39083-
mp_int* m = (mp_int*)XMALLOC(sizeof(*m), NULL,
39084-
DYNAMIC_TYPE_BIGINT);
39085-
if (m == NULL) {
39086-
return MEMORY_E;
39087-
}
39088-
#else
39089-
mp_int m[1];
39090-
#endif
39091-
39092-
if (mp_init(m) != MP_OKAY) {
39093-
ret = MP_INIT_E;
39094-
}
39095-
39096-
if (ret == 0)
39097-
ret = mp_read_unsigned_bin(m, buf + idx, length);
39098-
if (ret != MP_OKAY)
39099-
ret = BUFFER_E;
39085+
#ifdef WOLFSSL_SMALL_STACK
39086+
mp_int* m = (mp_int*)XMALLOC(sizeof(*m), NULL,
39087+
DYNAMIC_TYPE_BIGINT);
39088+
if (m == NULL) {
39089+
return MEMORY_E;
39090+
}
39091+
#else
39092+
mp_int m[1];
39093+
#endif
3910039094

39101-
if (ret == 0) {
39102-
dcrl->crlNumber = 0;
39103-
for (i = 0; i < (int)(*m).used; ++i) {
39104-
if (i > (CHAR_BIT *
39105-
(int)sizeof(word32) / DIGIT_BIT)) {
39106-
break;
39107-
}
39108-
dcrl->crlNumber |= ((word32)(*m).dp[i]) <<
39109-
(DIGIT_BIT * i);
39110-
}
39111-
}
39095+
if (mp_init(m) != MP_OKAY) {
39096+
ret = MP_INIT_E;
39097+
}
3911239098

39113-
mp_free(m);
39114-
#ifdef WOLFSSL_SMALL_STACK
39115-
XFREE(m, NULL, DYNAMIC_TYPE_BIGINT);
39116-
#endif
39099+
if (ret == 0)
39100+
ret = mp_read_unsigned_bin(m, buf + idx, length);
39101+
if (ret != MP_OKAY)
39102+
ret = BUFFER_E;
3911739103

39118-
if (ret != 0)
39119-
return ret;
39120-
}
39121-
else if (length == 1) {
39122-
dcrl->crlNumber = buf[idx];
39104+
if (ret == 0) {
39105+
dcrl->crlNumber = *m;
3912339106
}
39107+
39108+
if (ret != 0)
39109+
return ret;
3912439110
}
3912539111
}
3912639112
}
@@ -39199,13 +39185,9 @@ static int ParseCRL_Extensions(DecodedCRL* dcrl, const byte* buf, word32 idx,
3919939185
ret = GetInt(m, buf, &localIdx, maxIdx);
3920039186
}
3920139187
if (ret == 0) {
39202-
dcrl->crlNumber = (int)m->dp[0];
39188+
dcrl->crlNumber = *m;
3920339189
}
3920439190

39205-
mp_free(m);
39206-
#ifdef WOLFSSL_SMALL_STACK
39207-
XFREE(m, NULL, DYNAMIC_TYPE_BIGINT);
39208-
#endif
3920939191
}
3921039192
/* TODO: check criticality */
3921139193
/* Move index on to next extension. */

wolfssl/internal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2590,7 +2590,9 @@ struct CRL_Entry {
25902590
byte extAuthKeyIdSet;
25912591
byte extAuthKeyId[KEYID_SIZE];
25922592
#endif
2593-
int crlNumber; /* CRL number extension */
2593+
#ifndef NO_BIG_INT
2594+
mp_int crlNumber; /* CRL number extension */
2595+
#endif
25942596
};
25952597

25962598

wolfssl/ssl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3756,7 +3756,9 @@ typedef struct CrlInfo {
37563756
byte *nextDate;
37573757
word32 nextDateMaxLen;
37583758
byte nextDateFormat;
3759-
sword32 crlNumber;
3759+
#ifndef NO_BIG_INT
3760+
mp_int crlNumber;
3761+
#endif
37603762
} CrlInfo;
37613763

37623764
typedef void (*CbUpdateCRL)(CrlInfo* old, CrlInfo* cnew);

wolfssl/wolfcrypt/asn.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2882,7 +2882,9 @@ struct DecodedCRL {
28822882
byte extAuthKeyIdSet;
28832883
byte extAuthKeyId[SIGNER_DIGEST_SIZE]; /* Authority Key ID */
28842884
#endif
2885-
int crlNumber; /* CRL number extension */
2885+
#ifndef NO_BIG_INT
2886+
mp_int crlNumber; /* CRL number extension */
2887+
#endif
28862888
};
28872889

28882890
WOLFSSL_LOCAL void InitDecodedCRL(DecodedCRL* dcrl, void* heap);

0 commit comments

Comments
 (0)