From e1d0fa2639db2ab3b1e6c267931299f5be9a1590 Mon Sep 17 00:00:00 2001 From: Damien Bergamini Date: Tue, 24 Jul 2007 19:35:21 +0000 Subject: 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@ --- sys/crypto/arc4.c | 12 +++++++++++- sys/crypto/arc4.h | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'sys') 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 * @@ -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 * @@ -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); -- cgit v1.2.3