summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorDamien Bergamini <damien@cvs.openbsd.org>2007-07-24 19:35:21 +0000
committerDamien Bergamini <damien@cvs.openbsd.org>2007-07-24 19:35:21 +0000
commite1d0fa2639db2ab3b1e6c267931299f5be9a1590 (patch)
tree7895be61105dced0b6ce6ecdec96db64070b8823 /sys
parentfd111e0fb247537d083f9baa800974cfbc4ea25e (diff)
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@
Diffstat (limited to 'sys')
-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);