svn commit: samba r4657 - in branches/SAMBA_4_0/source/lib: .

abartlet at samba.org abartlet at samba.org
Mon Jan 10 22:52:02 GMT 2005


Author: abartlet
Date: 2005-01-10 22:52:01 +0000 (Mon, 10 Jan 2005)
New Revision: 4657

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=4657

Log:
This really should be made a structure, so we can't get it wrong, but
in the meantime, get the declaration right...

Andrew Bartlett

Modified:
   branches/SAMBA_4_0/source/lib/genrand.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/genrand.c
===================================================================
--- branches/SAMBA_4_0/source/lib/genrand.c	2005-01-10 20:33:41 UTC (rev 4656)
+++ branches/SAMBA_4_0/source/lib/genrand.c	2005-01-10 22:52:01 UTC (rev 4657)
@@ -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 @@
 }
 
 /**************************************************************** 
- 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 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 @@
 			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 @@
 	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;



More information about the samba-cvs mailing list