summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2016-04-25 21:14:32 +0000
committerpfg <pfg@FreeBSD.org>2016-04-25 21:14:32 +0000
commit0431769ee9ec66a615119290fe5841320f96682e (patch)
tree1fc6430078595e4fd65e3bd353a84fb7186f1082 /sys/dev
parentae5f8198e178dfcf10a5c049c67655f057346d49 (diff)
downloadFreeBSD-src-0431769ee9ec66a615119290fe5841320f96682e.zip
FreeBSD-src-0431769ee9ec66a615119290fe5841320f96682e.tar.gz
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
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/random/fortuna.c2
-rw-r--r--sys/dev/random/randomdev.c7
-rw-r--r--sys/dev/random/yarrow.c2
3 files changed, 4 insertions, 7 deletions
diff --git a/sys/dev/random/fortuna.c b/sys/dev/random/fortuna.c
index 800c397..f3c74ce 100644
--- a/sys/dev/random/fortuna.c
+++ b/sys/dev/random/fortuna.c
@@ -324,7 +324,7 @@ random_fortuna_genrandom(uint8_t *buf, u_int bytecount)
* - 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);
diff --git a/sys/dev/random/randomdev.c b/sys/dev/random/randomdev.c
index 978a564..7edfca8 100644
--- a/sys/dev/random/randomdev.c
+++ b/sys/dev/random/randomdev.c
@@ -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 nonblock)
* 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);
}
diff --git a/sys/dev/random/yarrow.c b/sys/dev/random/yarrow.c
index 8d5f389..49cc8d0 100644
--- a/sys/dev/random/yarrow.c
+++ b/sys/dev/random/yarrow.c
@@ -374,7 +374,7 @@ random_yarrow_read(uint8_t *buf, u_int bytecount)
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();
OpenPOWER on IntegriCloud