summaryrefslogtreecommitdiff
path: root/src/lib/tests/keyrot_test.c
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2026-07-02 19:05:25 +0200
committerSander Vrijders <sander@ouroboros.rocks>2026-07-08 11:02:24 +0200
commit942e4c64ad03e537a77366c6bf1309241b71f1e8 (patch)
tree18f34aa34befd23673ecc1638919349821fa791f /src/lib/tests/keyrot_test.c
parentfca717aba18850d2e32a069905f03314cd836c17 (diff)
downloadouroboros-942e4c64ad03e537a77366c6bf1309241b71f1e8.tar.gz
ouroboros-942e4c64ad03e537a77366c6bf1309241b71f1e8.zip
lib: Separate rekey replay from epoch conflict
keyrot_rekey() treated any re-key attempt against a live epoch (current or previous) the same way, whether the offered root key matched the live one (a replay) or was genuinely different (a conflict). Compare the offered key against the live batch's root and return -EREPLAY for a match, keeping -1/-ECRYPT for an actual conflict, so callers can handle replayed re-keys distinctly from real ones. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/lib/tests/keyrot_test.c')
-rw-r--r--src/lib/tests/keyrot_test.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/lib/tests/keyrot_test.c b/src/lib/tests/keyrot_test.c
index 10baee5c..efdc718e 100644
--- a/src/lib/tests/keyrot_test.c
+++ b/src/lib/tests/keyrot_test.c
@@ -28,6 +28,7 @@
#ifdef HAVE_OPENSSL
#include <ouroboros/crypt.h>
+#include <ouroboros/errno.h>
#include <ouroboros/pthread.h>
#include "crypt/keyrot.h"
@@ -112,8 +113,8 @@ static int test_rekey_dup_epoch(void)
if (a == NULL)
goto fail;
- if (keyrot_rekey(a, SEED_B, 0) == 0) {
- printf("Re-key to the current epoch accepted.\n");
+ if (keyrot_rekey(a, SEED_B, 0) != -1) {
+ printf("New key to the current epoch not a conflict.\n");
goto fail_a;
}
@@ -122,13 +123,23 @@ static int test_rekey_dup_epoch(void)
goto fail_a;
}
- if (keyrot_rekey(a, SEED_A, 1) == 0) {
- printf("Re-key to the current epoch accepted.\n");
+ if (keyrot_rekey(a, SEED_B, 1) != -EREPLAY) {
+ printf("Same key to the current epoch not a replay.\n");
goto fail_a;
}
- if (keyrot_rekey(a, SEED_A, 0) == 0) {
- printf("Re-key to the previous epoch accepted.\n");
+ if (keyrot_rekey(a, SEED_A, 1) != -1) {
+ printf("New key to the current epoch not a conflict.\n");
+ goto fail_a;
+ }
+
+ if (keyrot_rekey(a, SEED_A, 0) != -EREPLAY) {
+ printf("Same key to the previous epoch not a replay.\n");
+ goto fail_a;
+ }
+
+ if (keyrot_rekey(a, SEED_B, 0) != -1) {
+ printf("New key to the previous epoch not a conflict.\n");
goto fail_a;
}