From 950d7ae488c1fd5ca9778784af0e6a29216e0565 Mon Sep 17 00:00:00 2001 From: cameronrich Date: Thu, 14 Jun 2007 22:53:14 +0000 Subject: [PATCH] speed improvements to the rc4 cipher git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@107 9a5d90b5-6617-0410-8a86-bb477d3ed2e3 --- ssl/crypto.h | 2 +- ssl/rc4.c | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ssl/crypto.h b/ssl/crypto.h index 9bf446f24..d4e4bc016 100644 --- a/ssl/crypto.h +++ b/ssl/crypto.h @@ -64,7 +64,7 @@ void AES_convert_key(AES_CTX *ctx); typedef struct { - int x, y, m[256]; + uint8_t x, y, m[256]; } RC4_CTX; void RC4_setup(RC4_CTX *s, const uint8_t *key, int length); diff --git a/ssl/rc4.c b/ssl/rc4.c index 7250a669b..83e4363dd 100644 --- a/ssl/rc4.c +++ b/ssl/rc4.c @@ -29,7 +29,8 @@ */ void RC4_setup(RC4_CTX *ctx, const uint8_t *key, int length) { - int i, j = 0, k = 0, *m, a; + int i, j = 0, k = 0, a; + uint8_t *m; ctx->x = 0; ctx->y = 0; @@ -56,7 +57,8 @@ void RC4_setup(RC4_CTX *ctx, const uint8_t *key, int length) */ void RC4_crypt(RC4_CTX *ctx, const uint8_t *msg, uint8_t *out, int length) { - int i, x, y, *m, a, b; + int i; + uint8_t *m, x, y, a, b; out = (uint8_t *)msg; x = ctx->x; @@ -65,9 +67,8 @@ void RC4_crypt(RC4_CTX *ctx, const uint8_t *msg, uint8_t *out, int length) for (i = 0; i < length; i++) { - x = (uint8_t)(x + 1); - a = m[x]; - y = (uint8_t)(y + a); + a = m[++x]; + y += a; m[x] = b = m[y]; m[y] = a; out[i] ^= m[(uint8_t)(a + b)];