diff options
| author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2026-07-02 19:05:25 +0200 |
|---|---|---|
| committer | Sander Vrijders <sander@ouroboros.rocks> | 2026-07-08 11:02:24 +0200 |
| commit | 942e4c64ad03e537a77366c6bf1309241b71f1e8 (patch) | |
| tree | 18f34aa34befd23673ecc1638919349821fa791f /src/lib/crypt.c | |
| parent | fca717aba18850d2e32a069905f03314cd836c17 (diff) | |
| download | ouroboros-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/crypt.c')
| -rw-r--r-- | src/lib/crypt.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/lib/crypt.c b/src/lib/crypt.c index e4cf7885..cbbb9bc2 100644 --- a/src/lib/crypt.c +++ b/src/lib/crypt.c @@ -887,11 +887,17 @@ int crypt_get_headsz(struct crypt_ctx * ctx) int crypt_rekey(struct crypt_ctx * ctx, struct crypt_sk * sk) { + int ret; + assert(ctx != NULL); assert(sk != NULL); assert(ctx->kr != NULL); - return keyrot_rekey(ctx->kr, sk->key, sk->epoch) == 0 ? 0 : -ECRYPT; + ret = keyrot_rekey(ctx->kr, sk->key, sk->epoch); + if (ret == -EREPLAY) + return -EREPLAY; + + return ret == 0 ? 0 : -ECRYPT; } int crypt_get_tagsz(struct crypt_ctx * ctx) |
