1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-08-09 22:24:14 +03:00

speed improvements to the rc4 cipher

git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@107 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
cameronrich
2007-06-14 22:53:14 +00:00
parent 9efcfbaf81
commit 950d7ae488
2 changed files with 7 additions and 6 deletions

View File

@@ -64,7 +64,7 @@ void AES_convert_key(AES_CTX *ctx);
typedef struct typedef struct
{ {
int x, y, m[256]; uint8_t x, y, m[256];
} RC4_CTX; } RC4_CTX;
void RC4_setup(RC4_CTX *s, const uint8_t *key, int length); void RC4_setup(RC4_CTX *s, const uint8_t *key, int length);

View File

@@ -29,7 +29,8 @@
*/ */
void RC4_setup(RC4_CTX *ctx, const uint8_t *key, int length) 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->x = 0;
ctx->y = 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) 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; out = (uint8_t *)msg;
x = ctx->x; 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++) for (i = 0; i < length; i++)
{ {
x = (uint8_t)(x + 1); a = m[++x];
a = m[x]; y += a;
y = (uint8_t)(y + a);
m[x] = b = m[y]; m[x] = b = m[y];
m[y] = a; m[y] = a;
out[i] ^= m[(uint8_t)(a + b)]; out[i] ^= m[(uint8_t)(a + b)];