Commit 3c246da8 authored by Niels Möller's avatar Niels Möller

* src/symmetric/arcfour.c (arcfour_update_key): #if:ed out this

nostandard function.
(arcfour_set_key): Use arcfour_init(). Made keyset loop less
obscure.

Rev: src/symmetric/arcfour.c:1.6
parent ec7611d7
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "arcfour.h" #include "arcfour.h"
#include <assert.h>
#ifdef RCSID #ifdef RCSID
RCSID("$Id$"); RCSID("$Id$");
#endif #endif
...@@ -44,6 +46,8 @@ void arcfour_init(struct arcfour_ctx *ctx) ...@@ -44,6 +46,8 @@ void arcfour_init(struct arcfour_ctx *ctx)
ctx->S[i] = i; ctx->S[i] = i;
} }
/* This mode of operation is non-standard and possibly insecure. */
#if 0
void arcfour_update_key(struct arcfour_ctx *ctx, void arcfour_update_key(struct arcfour_ctx *ctx,
UINT32 length, const UINT8 *key) UINT32 length, const UINT8 *key)
{ {
...@@ -60,6 +64,7 @@ void arcfour_update_key(struct arcfour_ctx *ctx, ...@@ -60,6 +64,7 @@ void arcfour_update_key(struct arcfour_ctx *ctx,
} }
ctx->i = i; ctx->j = j; ctx->i = i; ctx->j = j;
} }
#endif
void arcfour_stream(struct arcfour_ctx *ctx, void arcfour_stream(struct arcfour_ctx *ctx,
UINT32 length, UINT8 *dest) UINT32 length, UINT8 *dest)
...@@ -86,16 +91,18 @@ void arcfour_set_key(struct arcfour_ctx *ctx, UINT32 length, const UINT8 *key) ...@@ -86,16 +91,18 @@ void arcfour_set_key(struct arcfour_ctx *ctx, UINT32 length, const UINT8 *key)
UINT32 k; UINT32 k;
/* Initialize context */ /* Initialize context */
i = 0; arcfour_init(ctx);
do ctx->S[i] = i; while (++i < 256);
assert(length);
/* Expand key */ /* Expand key */
i = j = k = 0; i = j = k = 0;
do { for ( ; i<256; i++)
j += ctx->S[i] + key[k]; {
SWAP(ctx->S[i], ctx->S[j]); j += ctx->S[i] + key[k]; j &= 0xff;
k = (k+1) % length; /* Repeat key if needed */ SWAP(ctx->S[i], ctx->S[j]);
} while(++i < 256); k = (k+1) % length; /* Repeat key if needed */
}
ctx->i = ctx->j = 0; ctx->i = ctx->j = 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment