oscore: fix OSCORE replay window validation for out-of-order sequence numbers

This commit is contained in:
shruti gunwant authored and Jon Shallow committed 2026-03-27 14:05:48 +00:00
1 parent 80c37b7bc6
commit 12cf731531
1 file changed
+11 -7
+11 -7
View File
@@ -408,8 +408,12 @@ oscore_validate_sender_seq(oscore_recipient_ctx_t *ctx, cose_encrypt0_t *cose) {
} else if (incoming_seq > ctx->last_seq) {
/* Update the replay window */
uint64_t shift = incoming_seq - ctx->last_seq;
ctx->sliding_window = ctx->sliding_window << shift;
/* bitfield. B0 biggest seq seen. B1 seq-1 seen, B2 seq-2 seen etc. */
if (shift >= ctx->osc_ctx->replay_window_size || shift >= 64) {
ctx->sliding_window = 0;
} else {
ctx->sliding_window <<= shift;
}
ctx->sliding_window |= 1;
ctx->last_seq = incoming_seq;
} else if (incoming_seq == ctx->last_seq) {
@@ -417,14 +421,14 @@ oscore_validate_sender_seq(oscore_recipient_ctx_t *ctx, cose_encrypt0_t *cose) {
incoming_seq);
return 0;
} else { /* incoming_seq < last_seq */
uint64_t shift = ctx->last_seq - incoming_seq - 1;
uint64_t shift = ctx->last_seq - incoming_seq;
uint64_t pattern;
if (shift > ctx->osc_ctx->replay_window_size || shift > 63) {
coap_log_warn("OSCORE: Replay protection, SEQ outside of replay window (%"
PRIu64 " %" PRIu64 ")\n",
ctx->last_seq,
incoming_seq);
if (shift >= ctx->osc_ctx->replay_window_size || shift >= 64) {
coap_log_warn(
"OSCORE: Replay protection, SEQ outside of replay window (%" PRIu64
" %" PRIu64 ")\n",
ctx->last_seq, incoming_seq);
return 0;
}
/* seq + replay_window_size > last_seq */