From owner-svn-src-head@freebsd.org Mon Apr 25 21:14:33 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9D7FDB1CDDC; Mon, 25 Apr 2016 21:14:33 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 752C3143E; Mon, 25 Apr 2016 21:14:33 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u3PLEWee012124; Mon, 25 Apr 2016 21:14:32 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u3PLEWuQ012120; Mon, 25 Apr 2016 21:14:32 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201604252114.u3PLEWuQ012120@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Mon, 25 Apr 2016 21:14:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r298593 - head/sys/dev/random X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Apr 2016 21:14:33 -0000 Author: pfg Date: Mon Apr 25 21:14:32 2016 New Revision: 298593 URL: https://svnweb.freebsd.org/changeset/base/298593 Log: dev/random: use our roundup() macro instead of re-implementing it. While here also use howmany() macro from sys/param.h No functional change. Reviewed by: markm (roundup replacement part) Approved by: so Modified: head/sys/dev/random/fortuna.c head/sys/dev/random/randomdev.c head/sys/dev/random/yarrow.c Modified: head/sys/dev/random/fortuna.c ============================================================================== --- head/sys/dev/random/fortuna.c Mon Apr 25 20:58:54 2016 (r298592) +++ head/sys/dev/random/fortuna.c Mon Apr 25 21:14:32 2016 (r298593) @@ -324,7 +324,7 @@ random_fortuna_genrandom(uint8_t *buf, u * - K = GenerateBlocks(2) */ KASSERT((bytecount <= RANDOM_FORTUNA_MAX_READ), ("invalid single read request to Fortuna of %d bytes", bytecount)); - blockcount = (bytecount + RANDOM_BLOCKSIZE - 1)/RANDOM_BLOCKSIZE; + blockcount = howmany(bytecount, RANDOM_BLOCKSIZE); random_fortuna_genblocks(buf, blockcount); random_fortuna_genblocks(temp, RANDOM_KEYS_PER_BLOCK); randomdev_encrypt_init(&fortuna_state.fs_key, temp); Modified: head/sys/dev/random/randomdev.c ============================================================================== --- head/sys/dev/random/randomdev.c Mon Apr 25 20:58:54 2016 (r298592) +++ head/sys/dev/random/randomdev.c Mon Apr 25 21:14:32 2016 (r298593) @@ -68,9 +68,6 @@ static u_int READ_RANDOM(void *, u_int); #define READ_RANDOM read_random #endif -/* Return the largest number >= x that is a multiple of m */ -#define CEIL_TO_MULTIPLE(x, m) ((((x) + (m) - 1)/(m))*(m)) - static d_read_t randomdev_read; static d_write_t randomdev_write; static d_poll_t randomdev_poll; @@ -164,7 +161,7 @@ READ_RANDOM_UIO(struct uio *uio, bool no * which is what the underlying generator is expecting. * See the random_buf size requirements in the Yarrow/Fortuna code. */ - read_len = CEIL_TO_MULTIPLE(read_len, RANDOM_BLOCKSIZE); + read_len = roundup(read_len, RANDOM_BLOCKSIZE); /* Work in chunks page-sized or less */ read_len = MIN(read_len, PAGE_SIZE); p_random_alg_context->ra_read(random_buf, read_len); @@ -204,7 +201,7 @@ READ_RANDOM(void *random_buf, u_int len) * Round up the read length to a crypto block size multiple, * which is what the underlying generator is expecting. */ - read_len = CEIL_TO_MULTIPLE(len, RANDOM_BLOCKSIZE); + read_len = roundup(len, RANDOM_BLOCKSIZE); p_random_alg_context->ra_read(local_buf, read_len); memcpy(random_buf, local_buf, len); } Modified: head/sys/dev/random/yarrow.c ============================================================================== --- head/sys/dev/random/yarrow.c Mon Apr 25 20:58:54 2016 (r298592) +++ head/sys/dev/random/yarrow.c Mon Apr 25 21:14:32 2016 (r298593) @@ -374,7 +374,7 @@ random_yarrow_read(uint8_t *buf, u_int b KASSERT((bytecount % RANDOM_BLOCKSIZE) == 0, ("%s(): bytecount (= %d) must be a multiple of %d", __func__, bytecount, RANDOM_BLOCKSIZE )); RANDOM_RESEED_LOCK(); - blockcount = (bytecount + RANDOM_BLOCKSIZE - 1)/RANDOM_BLOCKSIZE; + blockcount = howmany(bytecount, RANDOM_BLOCKSIZE); for (i = 0; i < blockcount; i++) { if (yarrow_state.ys_outputblocks++ >= yarrow_state.ys_gengateinterval) { random_yarrow_generator_gate();