summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordamien <damien@openbsd.org>2007-07-24 19:35:20 +0000
committerdamien <damien@openbsd.org>2007-07-24 19:35:20 +0000
commitc5823ff2899dc23bf01c945069e4bb125c7ccd19 (patch)
treec05e796172cce0f2b9f8f6f26a4925d77652ba8c
parentreformat to 8 chars tab, zap unneeded comment (no binary change) (diff)
downloadwireguard-openbsd-c5823ff2899dc23bf01c945069e4bb125c7ccd19.tar.xz
wireguard-openbsd-c5823ff2899dc23bf01c945069e4bb125c7ccd19.zip
add rc4_skip() function that can be used to discard bytes from
the arc4 key stream. rc4_skip(ctx, len); is equivalent to: u_int8_t dummy[len]; rc4_crypt(ctx, dummy, dummy, len); except that is does not require storage space and that it saves some cpu cycles. ok deraadt@
-rw-r--r--sys/crypto/arc4.c12
-rw-r--r--sys/crypto/arc4.h3
2 files changed, 13 insertions, 2 deletions
diff --git a/sys/crypto/arc4.c b/sys/crypto/arc4.c
index fe621dbcd9e..3bb3be4d78a 100644
--- a/sys/crypto/arc4.c
+++ b/sys/crypto/arc4.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4.c,v 1.1 2003/10/07 07:07:14 markus Exp $ */
+/* $OpenBSD: arc4.c,v 1.2 2007/07/24 19:35:20 damien Exp $ */
/*
* Copyright (c) 2003 Markus Friedl <markus@openbsd.org>
*
@@ -57,3 +57,13 @@ rc4_crypt(struct rc4_ctx *ctx, u_char *src, u_char *dst,
(ctx->state[ctx->x] + ctx->state[ctx->y]) % RC4STATE];
}
}
+
+void
+rc4_skip(struct rc4_ctx *ctx, u_int32_t len)
+{
+ for (; len > 0; len--) {
+ ctx->x = (ctx->x + 1) % RC4STATE;
+ ctx->y = (ctx->state[ctx->x] + ctx->y) % RC4STATE;
+ RC4SWAP(ctx->x, ctx->y);
+ }
+}
diff --git a/sys/crypto/arc4.h b/sys/crypto/arc4.h
index 2bbf9227ceb..b4e96ea44b4 100644
--- a/sys/crypto/arc4.h
+++ b/sys/crypto/arc4.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: arc4.h,v 1.1 2003/10/07 07:07:14 markus Exp $ */
+/* $OpenBSD: arc4.h,v 1.2 2007/07/24 19:35:20 damien Exp $ */
/*
* Copyright (c) 2003 Markus Friedl <markus@openbsd.org>
*
@@ -25,3 +25,4 @@ struct rc4_ctx {
void rc4_keysetup(struct rc4_ctx *, u_char *, u_int32_t);
void rc4_crypt(struct rc4_ctx *, u_char *, u_char *, u_int32_t);
+void rc4_skip(struct rc4_ctx *, u_int32_t);