summaryrefslogtreecommitdiffstats
path: root/src/antireplay.h
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-22 23:29:40 +0200
committerMatt Dunwoodie <ncon@mail.noconroy.net>2019-09-22 23:29:40 +0200
commitb5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8 (patch)
tree212ffdb10ef22925af143eaa036eaded05de626f /src/antireplay.h
parentMove antireplay to it's own header (diff)
downloadwireguard-openbsd-b5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8.tar.xz
wireguard-openbsd-b5ba2568f9800eacb9bc0bef1d53bf9b1efcacb8.zip
Move functions from header files into dedicated file
The header files were nice while experimenting, but they are not ideal. Currently we have all the custom data structures in kerk/kern_wg.c, which would ideally not be named after wireguard, But for the time being, at least they're organised.
Diffstat (limited to 'src/antireplay.h')
-rw-r--r--src/antireplay.h44
1 files changed, 2 insertions, 42 deletions
diff --git a/src/antireplay.h b/src/antireplay.h
index 0df6a5f8e06..a903d586b3a 100644
--- a/src/antireplay.h
+++ b/src/antireplay.h
@@ -25,47 +25,7 @@ struct antireplay {
uint64_t ar_bitmap[ARB_BITS / ARI_BITS];
};
-static void antireplay_init(struct antireplay *);
-static int antireplay_update(struct antireplay *, uint64_t);
-
-/*
- * The following defines assist the antireplay_check function. *
- * ANTIREPLAY_INTEGER: the integer in the bitmap corresponding to num *
- * ANTIREPLAY_INTEGERBIT: the integer with corresponding single bit set
- */
-#define ANTIREPLAY_INTEGER(ctx, num) (ctx->ar_bitmap[num % ARB_BITS / ARI_BITS])
-#define ANTIREPLAY_INTEGERBIT(num) (1llu << (num & (ARI_BITS - 1)))
-
-static void
-antireplay_init(struct antireplay *ctx)
-{
- /* We just zero out the struct, expecting that then ctx->ar_head == 0 */
- explicit_bzero(ctx, sizeof(struct antireplay));
-}
-
-static int
-antireplay_update(struct antireplay *ctx, uint64_t num)
-{
- /* Bits after ctx->ar_head need to be zeroed. This is called when num is
- * in front of ctx->ar_head, and those bits need to be set to 0 */
- if (num < ctx->ar_head + ARB_BITS / ARI_BITS) {
- for (; ctx->ar_head <= num; ctx->ar_head += ARI_BITS) {
- ANTIREPLAY_INTEGER(ctx, (ctx->ar_head + 1)) = 0;
- }
- } else {
- bzero(ctx->ar_bitmap, ARB_BITS / ARI_BITS);
- }
-
- if (ctx->ar_head > (num + ARB_BITS - ARI_BITS)) {
- /* Expired */
- return 1;
- } else if (ANTIREPLAY_INTEGER(ctx, num) & ANTIREPLAY_INTEGERBIT(num)) {
- /* Replayed */
- return 1;
- } else {
- /* Unseen */
- return 0;
- }
-}
+void antireplay_init(struct antireplay *);
+int antireplay_update(struct antireplay *, uint64_t);
#endif /* __ANTIREPLAY_H__ */