Skip to content

Commit 76bc6e3

Browse files
committed
wolfcrypt/src/hpke.c, wolfssl/wolfcrypt/error-crypt.h, wolfcrypt/src/error.c: implement RFC 9180 overflow checks on context->seq in wc_HpkeContextSealBase() and wc_HpkeContextOpenBase(), and add SEQ_OVERFLOW_E to wolfCrypt_ErrorCodes (Fenrir M-70).
1 parent 4110887 commit 76bc6e3

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

wolfcrypt/src/error.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,9 @@ const char* wc_GetErrorString(int error)
665665
case ALREADY_E:
666666
return "Operation was redundant or preempted";
667667

668+
case SEQ_OVERFLOW_E:
669+
return "Sequence counter would overflow";
670+
668671
case MAX_CODE_E:
669672
case WC_SPAN1_MIN_CODE_E:
670673
case MIN_CODE_E:

wolfcrypt/src/hpke.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,11 @@ int wc_HpkeContextSealBase(Hpke* hpke, HpkeBaseContext* context,
865865
plaintext == NULL || out == NULL) {
866866
return BAD_FUNC_ARG;
867867
}
868+
869+
/* RFC 9180 requires error on sequence overflow. */
870+
if (context->seq == WC_MAX_SINT_OF(int))
871+
return SEQ_OVERFLOW_E;
872+
868873
WC_ALLOC_VAR_EX(aes, Aes, 1, hpke->heap, DYNAMIC_TYPE_AES,
869874
return MEMORY_E);
870875
ret = wc_AesInit(aes, hpke->heap, INVALID_DEVID);
@@ -1097,6 +1102,11 @@ int wc_HpkeContextOpenBase(Hpke* hpke, HpkeBaseContext* context, byte* aad,
10971102
if (hpke == NULL) {
10981103
return BAD_FUNC_ARG;
10991104
}
1105+
1106+
/* RFC 9180 requires error on sequence overflow. */
1107+
if (context->seq == WC_MAX_SINT_OF(int))
1108+
return SEQ_OVERFLOW_E;
1109+
11001110
XMEMSET(nonce, 0, sizeof(nonce));
11011111
WC_ALLOC_VAR_EX(aes, Aes, 1, hpke->heap, DYNAMIC_TYPE_AES,
11021112
return MEMORY_E);

wolfssl/wolfcrypt/error-crypt.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,9 @@ enum wolfCrypt_ErrorCodes {
312312
BUSY_E = -1006, /* Object is busy */
313313
ALREADY_E = -1007, /* Operation was redundant or preempted */
314314

315-
WC_SPAN2_LAST_E = -1007, /* Update to indicate last used error code */
316-
WC_LAST_E = -1007, /* the last code used either here or in
315+
SEQ_OVERFLOW_E = -1008, /* Sequence counter would overflow */
316+
WC_SPAN2_LAST_E = -1008, /* Update to indicate last used error code */
317+
WC_LAST_E = -1008, /* the last code used either here or in
317318
* error-ssl.h */
318319

319320
WC_SPAN2_MIN_CODE_E = -1999, /* Last usable code in span 2 */

0 commit comments

Comments
 (0)