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

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


Author: abartlet
Date: 2005-01-10 22:56:51 +0000 (Mon, 10 Jan 2005)
New Revision: 4659

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

Log:
Revert -r 4657 committed by mistake, until I review and test the
changes (which were to use the common ARCFOUR code for random number
generation).

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 22:53:52 UTC (rev 4658)
+++ branches/SAMBA_4_0/source/lib/genrand.c	2005-01-10 22:56:51 UTC (rev 4659)
@@ -24,7 +24,7 @@
 #include "system/iconv.h"
 #include "lib/crypto/crypto.h"
 
-static unsigned char s_box[258];
+static unsigned char hash[258];
 static uint32 counter;
 
 static BOOL done_reseed = False;
@@ -55,14 +55,58 @@
 }
 
 /**************************************************************** 
+ 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(uint8_t sbox[258], unsigned char *data, size_t datasize)
+static void get_random_stream(unsigned char *data, size_t datasize)
 {
-	memset(data, '\0', datasize);
-	
-	arcfour_crypt_sbox(s_box, data, 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;
 }
 
 /****************************************************************
@@ -103,7 +147,6 @@
 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;
 
@@ -144,8 +187,7 @@
 			seed_inbuf[i] ^= ((char *)(&reseed_data))[i % sizeof(reseed_data)];
 	}
 
-	seed_blob = data_blob_const(seed_inbuf, sizeof(seed_inbuf));
-	arcfour_init(s_box, &seed_blob);
+	seed_random_stream(seed_inbuf, sizeof(seed_inbuf));
 
 	return -1;
 }
@@ -189,7 +231,7 @@
 	while(len > 0) {
 		int copy_len = len > 16 ? 16 : len;
 
-		get_random_stream(s_box, md4_buf, sizeof(md4_buf));
+		get_random_stream(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