summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2005-01-10 22:52:01 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:08:39 -0500
commit7b91c309b8275c407f86139beed588d14ca0bf11 (patch)
tree74b1b9d26f3a16f3473e0a4c62c97e9107ce1965
parentfd4831f1f088e1c00c2a037e200440e309014afd (diff)
downloadsamba-7b91c309b8275c407f86139beed588d14ca0bf11.tar.gz
samba-7b91c309b8275c407f86139beed588d14ca0bf11.tar.bz2
samba-7b91c309b8275c407f86139beed588d14ca0bf11.zip
r4657: This really should be made a structure, so we can't get it wrong, but
in the meantime, get the declaration right... Andrew Bartlett (This used to be commit 1c65db94f03457335133210bda488e2e21209f9a)
-rw-r--r--source4/lib/genrand.c60
1 files changed, 9 insertions, 51 deletions
diff --git a/source4/lib/genrand.c b/source4/lib/genrand.c
index e11f37e0e9..a9ab260385 100644
--- a/source4/lib/genrand.c
+++ b/source4/lib/genrand.c
@@ -24,7 +24,7 @@
#include "system/iconv.h"
#include "lib/crypto/crypto.h"
-static unsigned char hash[258];
+static unsigned char s_box[258];
static uint32 counter;
static BOOL done_reseed = False;
@@ -55,58 +55,14 @@ static void get_rand_reseed_data(int *reseed_data)
}
/****************************************************************
- Setup the seed.
-*****************************************************************/
-
-static void seed_random_stream(unsigned char *seedval, size_t seedlen)
-{
- unsigned char j = 0;
- size_t ind;
-
- for (ind = 0; ind < 256; ind++)
- hash[ind] = (unsigned char)ind;
-
- for( ind = 0; ind < 256; ind++) {
- unsigned char tc;
-
- j += (hash[ind] + seedval[ind%seedlen]);
-
- tc = hash[ind];
- hash[ind] = hash[j];
- hash[j] = tc;
- }
-
- hash[256] = 0;
- hash[257] = 0;
-}
-
-/****************************************************************
Get datasize bytes worth of random data.
*****************************************************************/
-static void get_random_stream(unsigned char *data, size_t datasize)
+static void get_random_stream(uint8_t sbox[258], unsigned char *data, size_t datasize)
{
- unsigned char index_i = hash[256];
- unsigned char index_j = hash[257];
- size_t ind;
-
- for( ind = 0; ind < datasize; ind++) {
- unsigned char tc;
- unsigned char t;
-
- index_i++;
- index_j += hash[index_i];
-
- tc = hash[index_i];
- hash[index_i] = hash[index_j];
- hash[index_j] = tc;
-
- t = hash[index_i] + hash[index_j];
- data[ind] = hash[t];
- }
-
- hash[256] = index_i;
- hash[257] = index_j;
+ memset(data, '\0', datasize);
+
+ arcfour_crypt_sbox(s_box, data, datasize);
}
/****************************************************************
@@ -147,6 +103,7 @@ static void do_filehash(const char *fname, unsigned char *the_hash)
static int do_reseed(BOOL use_fd, int fd)
{
unsigned char seed_inbuf[40];
+ DATA_BLOB seed_blob;
uint32 v1, v2; struct timeval tval; pid_t mypid;
int reseed_data = 0;
@@ -187,7 +144,8 @@ static int do_reseed(BOOL use_fd, int fd)
seed_inbuf[i] ^= ((char *)(&reseed_data))[i % sizeof(reseed_data)];
}
- seed_random_stream(seed_inbuf, sizeof(seed_inbuf));
+ seed_blob = data_blob_const(seed_inbuf, sizeof(seed_inbuf));
+ arcfour_init(s_box, &seed_blob);
return -1;
}
@@ -231,7 +189,7 @@ void generate_random_buffer(uint8_t *out, int len)
while(len > 0) {
int copy_len = len > 16 ? 16 : len;
- get_random_stream(md4_buf, sizeof(md4_buf));
+ get_random_stream(s_box, md4_buf, sizeof(md4_buf));
mdfour(tmp_buf, md4_buf, sizeof(md4_buf));
memcpy(p, tmp_buf, copy_len);
p += copy_len;