ikev2: Make sure to correctly compare nonces of unequal length

The previous code would not correctly compare nonces of unequal length
where the shorter is the prefix of the longer one.
This commit is contained in:
Tobias Brunner
2026-07-24 08:47:39 +02:00
parent 8aca7f9231
commit 00830ddc36
4 changed files with 4 additions and 8 deletions
+1 -2
View File
@@ -2957,8 +2957,7 @@ METHOD(child_create_t, get_config, child_cfg_t*,
METHOD(child_create_t, get_lower_nonce, chunk_t,
private_child_create_t *this)
{
if (memcmp(this->my_nonce.ptr, this->other_nonce.ptr,
min(this->my_nonce.len, this->other_nonce.len)) < 0)
if (chunk_compare_prefix(this->my_nonce, this->other_nonce) < 0)
{
return this->my_nonce;
}
+1 -2
View File
@@ -564,8 +564,7 @@ static bool lost_collision(private_child_rekey_t *this)
this_nonce = this->child_create->get_lower_nonce(this->child_create);
other_nonce = other->child_create->get_lower_nonce(other->child_create);
return memcmp(this_nonce.ptr, other_nonce.ptr,
min(this_nonce.len, other_nonce.len)) < 0;
return chunk_compare_prefix(this_nonce, other_nonce) < 0;
}
/**
+1 -2
View File
@@ -1493,8 +1493,7 @@ METHOD(task_t, destroy, void,
METHOD(ike_init_t, get_lower_nonce, chunk_t,
private_ike_init_t *this)
{
if (memcmp(this->my_nonce.ptr, this->other_nonce.ptr,
min(this->my_nonce.len, this->other_nonce.len)) < 0)
if (chunk_compare_prefix(this->my_nonce, this->other_nonce) < 0)
{
return this->my_nonce;
}
+1 -2
View File
@@ -582,8 +582,7 @@ static bool collision_lost(private_ike_rekey_t *this, bool multi_ke)
/* the SA with the lowest nonce should be deleted (if already complete),
* check if we or the peer created that */
if (memcmp(this_nonce.ptr, other_nonce.ptr,
min(this_nonce.len, other_nonce.len)) < 0)
if (chunk_compare_prefix(this_nonce, other_nonce) < 0)
{
if (multi_ke)
{