svn commit: r246620 - head/sbin/geom/class/eli

Pawel Jakub Dawidek pjd at FreeBSD.org
Sun Feb 10 15:55:43 UTC 2013


Author: pjd
Date: Sun Feb 10 15:55:42 2013
New Revision: 246620
URL: http://svnweb.freebsd.org/changeset/base/246620

Log:
  Use arc4random_buf(3) instead of reimplementing it.

Modified:
  head/sbin/geom/class/eli/geom_eli.c

Modified: head/sbin/geom/class/eli/geom_eli.c
==============================================================================
--- head/sbin/geom/class/eli/geom_eli.c	Sun Feb 10 14:28:07 2013	(r246619)
+++ head/sbin/geom/class/eli/geom_eli.c	Sun Feb 10 15:55:42 2013	(r246620)
@@ -326,22 +326,6 @@ eli_main(struct gctl_req *req, unsigned 
 		gctl_error(req, "Unknown command: %s.", name);
 }
 
-static void
-arc4rand(unsigned char *buf, size_t size)
-{
-	uint32_t *buf4;
-	size_t size4;
-	unsigned int i;
-
-	buf4 = (uint32_t *)buf;
-	size4 = size / 4;
-
-	for (i = 0; i < size4; i++)
-		buf4[i] = arc4random();
-	for (i *= 4; i < size; i++)
-		buf[i] = arc4random() % 0xff;
-}
-
 static bool
 eli_is_attached(const char *prov)
 {
@@ -813,8 +797,8 @@ eli_init(struct gctl_req *req)
 	}
 
 	md.md_keys = 0x01;
-	arc4rand(md.md_salt, sizeof(md.md_salt));
-	arc4rand(md.md_mkeys, sizeof(md.md_mkeys));
+	arc4random_buf(md.md_salt, sizeof(md.md_salt));
+	arc4random_buf(md.md_mkeys, sizeof(md.md_mkeys));
 
 	/* Generate user key. */
 	if (eli_genkey(req, &md, key, true) == NULL) {
@@ -1146,7 +1130,7 @@ eli_delkey_detached(struct gctl_req *req
 
 	all = gctl_get_int(req, "all");
 	if (all)
-		arc4rand(md.md_mkeys, sizeof(md.md_mkeys));
+		arc4random_buf(md.md_mkeys, sizeof(md.md_mkeys));
 	else {
 		force = gctl_get_int(req, "force");
 		val = gctl_get_intmax(req, "keyno");
@@ -1170,7 +1154,7 @@ eli_delkey_detached(struct gctl_req *req
 			return;
 		}
 		mkeydst = md.md_mkeys + nkey * G_ELI_MKEYLEN;
-		arc4rand(mkeydst, G_ELI_MKEYLEN);
+		arc4random_buf(mkeydst, G_ELI_MKEYLEN);
 	}
 
 	eli_metadata_store(req, prov, &md);
@@ -1262,7 +1246,7 @@ eli_trash_metadata(struct gctl_req *req,
 
 	error = 0;
 	do {
-		arc4rand(sector, size);
+		arc4random_buf(sector, size);
 		if (pwrite(fd, sector, size, offset) != size) {
 			if (error == 0)
 				error = errno;


More information about the svn-src-head mailing list