From 007755626aecbbb77acb634bc17a8f7c675187ca Mon Sep 17 00:00:00 2001 From: pjd Date: Sun, 10 Feb 2013 15:55:42 +0000 Subject: Use arc4random_buf(3) instead of reimplementing it. --- sbin/geom/class/eli/geom_eli.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/sbin/geom/class/eli/geom_eli.c b/sbin/geom/class/eli/geom_eli.c index f209800..ed65fff 100644 --- a/sbin/geom/class/eli/geom_eli.c +++ b/sbin/geom/class/eli/geom_eli.c @@ -326,22 +326,6 @@ eli_main(struct gctl_req *req, unsigned int flags) 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, const char *prov) 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, const char *prov) 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, const char *prov, int fd, off_t offset) error = 0; do { - arc4rand(sector, size); + arc4random_buf(sector, size); if (pwrite(fd, sector, size, offset) != size) { if (error == 0) error = errno; -- cgit v1.1