shithub: drawterm-fdroid

Download patch

ref: 8294a496424e030daa12c9c7eb5ab5217c7535e7
parent: 3d14bcb38754e98fbe669867f6291d3cc7dc6d15
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Sep 11 09:30:26 EDT 2016

replace custom randfill() with prng() calls, remove rand()/nrand() definitions from kernel

--- a/include/x.c
+++ /dev/null
@@ -1,6 +1,0 @@
-#include <stdio.h>
-
-void
-main(void)
-{
-}
--- a/kern/devcons.c
+++ b/kern/devcons.c
@@ -1020,30 +1020,3 @@
 
 	return n;
 }
-
-static	ulong	randn;
-
-static void
-seedrand(void)
-{
-	if(!waserror()){
-		randomread((void*)&randn, sizeof(randn));
-		poperror();
-	}
-}
-
-int
-nrand(int n)
-{
-	if(randn == 0)
-		seedrand();
-	randn = randn*1103515245 + 12345;
-	return (randn>>16) % n;
-}
-
-int
-rand(void)
-{
-	nrand(1);
-	return randn;
-}
--- a/kern/devssl.c
+++ b/kern/devssl.c
@@ -681,17 +681,6 @@
 	return n;
 }
 
-/*
- *  this algorithm doesn't have to be great since we're just
- *  trying to obscure the block fill
- */
-static void
-randfill(uchar *buf, int len)
-{
-	while(len-- > 0)
-		*buf++ = nrand(256);
-}
-
 static long
 sslbwrite(Chan *c, Block *b, ulong o)
 {
@@ -781,7 +770,7 @@
 		/* SSL style count */
 		if(pad){
 			nb = padblock(nb, -pad);
-			randfill(nb->wp, pad);
+			prng(nb->wp, pad);
 			nb->wp += pad;
 			m += pad;
 
--- a/kern/devtls.c
+++ b/kern/devtls.c
@@ -1231,13 +1231,6 @@
 	return n;
 }
 
-static void
-randfill(uchar *buf, int len)
-{
-	while(len-- > 0)
-		*buf++ = nrand(256);
-}
-
 /*
  *  write a block in tls records
  */
@@ -1322,7 +1315,7 @@
 				n = (*sec->aead_enc)(sec, aad, aadlen, p + RecHdrLen, p + RecHdrLen + ivlen, n) + ivlen;
 			else {
 				if(ivlen > 0)
-					randfill(p + RecHdrLen, ivlen);
+					prng(p + RecHdrLen, ivlen);
 				packMac(sec, aad, aadlen, p + RecHdrLen + ivlen, n, p + RecHdrLen + ivlen + n);
 				n = (*sec->enc)(sec, p + RecHdrLen, ivlen + n + maclen);
 			}
@@ -1520,7 +1513,7 @@
 	s->maclen = 16;
 	s->recivlen = 8;
 	memmove(s->mackey, iv, ea->ivlen);
-	randfill(s->mackey + ea->ivlen, s->recivlen);
+	prng(s->mackey + ea->ivlen, s->recivlen);
 	setupAESGCMstate(s->enckey, p, ea->keylen, nil, 0);
 }
 
--- a/kern/fns.h
+++ b/kern/fns.h
@@ -190,7 +190,6 @@
 void		nexterror(void);
 Cname*		newcname(char*);
 int		notify(Ureg*);
-int		nrand(int);
 int		okaddr(ulong, ulong, int);
 int		openmode(ulong);
 void		oserrstr(void);
@@ -271,7 +270,6 @@
 int		qwindow(Queue*);
 int		qwrite(Queue*, void*, int);
 void		qnoblock(Queue*, int);
-int		rand(void);
 void		randominit(void);
 ulong		randomread(void*, ulong);
 void		rdb(void);