FreeBSD/contrib/ipfilter/arc4random.c
/*
 * This is not very strong, and this is understood, but the aim isn't to
 * be cryptographically strong - it is just to make up something that is
 * pseudo random.
 */
This is not very strong, and this is understood, but the aim isn't to
be cryptographically strong - it is just to make up something that is
pseudo random.
This is not very strong and this is understood but the aim isn ' t to be cryptographically strong - it is just to make up something that is pseudo random .
void
ipf_rand_push(void *src, int length)
{
	static int arc4_inited = 0;
	u_char *nsrc;
	int mylen;
	if (arc4_inited == 0) {
		arc4_init();
		arc4_inited = 1;
	}
	if (length < 64) {
		MD5Update(&md5ctx, src, length);
		return;
	}
	nsrc = src;
	mylen = length;
#if defined(_SYS_MD5_H) && defined(SOLARIS2)
# define	buf	buf_un.buf8
#endif
	MUTEX_ENTER(&arc4_mtx);
	while ((mylen > 64)  && (sizeof(pot) - inpot > sizeof(md5ctx.buf))) {
		MD5Update(&md5ctx, nsrc, 64);
		mylen -= 64;
		nsrc += 64;
		if (pottail + sizeof(md5ctx.buf) > pot + sizeof(pot)) {
			int left, numbytes;
			numbytes = pot + sizeof(pot) - pottail;
			bcopy(md5ctx.buf, pottail, numbytes);
			left = sizeof(md5ctx.buf) - numbytes;
			pottail = pot;
			bcopy(md5ctx.buf + sizeof(md5ctx.buf) - left,
			      pottail, left);
			pottail += left;
		} else {
			bcopy(md5ctx.buf, pottail, sizeof(md5ctx.buf));
			pottail += sizeof(md5ctx.buf);
		}
		inpot += 64;
	}
	MUTEX_EXIT(&arc4_mtx);
#if defined(_SYS_MD5_H) && defined(SOLARIS2)
# undef buf
#endif
}
void ipf_rand_push ( void * src , int length ) { static int arc4_inited = 0 ; u_char * nsrc ; int mylen ; if ( arc4_inited == 0 ) { arc4_init ( ) ; arc4_inited = 1 ; } if ( length < 64 ) { MD5Update ( & md5ctx , src , length ) ; return ; } nsrc = src ; mylen = length ; #if defined ( _SYS_MD5_H ) && defined ( SOLARIS2 ) # define buf 	buf_un.buf8 #endif MUTEX_ENTER ( & arc4_mtx ) ; while ( ( mylen > 64 ) && ( sizeof ( pot ) - inpot > sizeof ( md5ctx . buf ) ) ) { MD5Update ( & md5ctx , nsrc , 64 ) ; mylen -= 64 ; nsrc += 64 ; if ( pottail + sizeof ( md5ctx . buf ) > pot + sizeof ( pot ) ) { int left , numbytes ; numbytes = pot + sizeof ( pot ) - pottail ; bcopy ( md5ctx . buf , pottail , numbytes ) ; left = sizeof ( md5ctx . buf ) - numbytes ; pottail = pot ; bcopy ( md5ctx . buf + sizeof ( md5ctx . buf ) - left , pottail , left ) ; pottail += left ; } else { bcopy ( md5ctx . buf , pottail , sizeof ( md5ctx . buf ) ) ; pottail += sizeof ( md5ctx . buf ) ; } inpot += 64 ; } MUTEX_EXIT ( & arc4_mtx ) ; #if defined ( _SYS_MD5_H ) && defined ( SOLARIS2 ) # undef  buf #endif }
This is not very strong, and this is understood, but the aim isn't to
 be cryptographically strong - it is just to make up something that is
 pseudo random.
This is not very strong and this is understood but the aim isn ' t to be cryptographically strong - it is just to make up something that is pseudo random .