svn commit: r265355 - projects/random_number_generator/sys/dev/random
Mark Murray
markm at FreeBSD.org
Mon May 5 10:53:18 UTC 2014
Author: markm
Date: Mon May 5 10:53:16 2014
New Revision: 265355
URL: http://svnweb.freebsd.org/changeset/base/265355
Log:
Fix unit tests. These are userland programs so a bit of nasty "ifdeffing" is present.
Modified:
projects/random_number_generator/sys/dev/random/build.sh
projects/random_number_generator/sys/dev/random/fortuna.c
projects/random_number_generator/sys/dev/random/unit_test.c
projects/random_number_generator/sys/dev/random/yarrow.c
Modified: projects/random_number_generator/sys/dev/random/build.sh
==============================================================================
--- projects/random_number_generator/sys/dev/random/build.sh Mon May 5 10:49:09 2014 (r265354)
+++ projects/random_number_generator/sys/dev/random/build.sh Mon May 5 10:53:16 2014 (r265355)
@@ -1,2 +1,20 @@
-cc -g -O0 -pthread -DRANDOM_DEBUG -DRANDOM_YARROW -I../.. -lstdthreads -Wall unit_test.c yarrow.c hash.c ../../crypto/rijndael/rijndael-api-fst.c ../../crypto/rijndael/rijndael-alg-fst.c ../../crypto/sha2/sha2.c -o yunit_test
-cc -g -O0 -pthread -DRANDOM_DEBUG -DRANDOM_FORTUNA -I../.. -lstdthreads -Wall unit_test.c fortuna.c hash.c ../../crypto/rijndael/rijndael-api-fst.c ../../crypto/rijndael/rijndael-alg-fst.c ../../crypto/sha2/sha2.c -o funit_test
+cc -g -O0 -pthread -DRANDOM_DEBUG -DRANDOM_YARROW \
+ -I../.. -lstdthreads -Wall \
+ unit_test.c \
+ yarrow.c \
+ hash.c \
+ ../../crypto/rijndael/rijndael-api-fst.c \
+ ../../crypto/rijndael/rijndael-alg-fst.c \
+ ../../crypto/sha2/sha2.c \
+ ../../crypto/sha2/sha256c.c \
+ -o yunit_test
+cc -g -O0 -pthread -DRANDOM_DEBUG -DRANDOM_FORTUNA \
+ -I../.. -lstdthreads -Wall \
+ unit_test.c \
+ fortuna.c \
+ hash.c \
+ ../../crypto/rijndael/rijndael-api-fst.c \
+ ../../crypto/rijndael/rijndael-alg-fst.c \
+ ../../crypto/sha2/sha2.c \
+ ../../crypto/sha2/sha256c.c \
+ -o funit_test
Modified: projects/random_number_generator/sys/dev/random/fortuna.c
==============================================================================
--- projects/random_number_generator/sys/dev/random/fortuna.c Mon May 5 10:49:09 2014 (r265354)
+++ projects/random_number_generator/sys/dev/random/fortuna.c Mon May 5 10:53:16 2014 (r265355)
@@ -122,7 +122,7 @@ static struct fortuna_state {
} fortuna_state;
/* The random_reseed_mtx mutex protects seeding and polling/blocking. */
-static struct mtx random_reseed_mtx;
+static mtx_t random_reseed_mtx;
static struct fortuna_start_cache {
uint8_t junk[PAGE_SIZE];
@@ -148,7 +148,11 @@ random_fortuna_init_alg(void)
randomdev_hash_init(&fortuna_start_cache.hash);
/* Set up a lock for the reseed process */
+#ifdef _KERNEL
mtx_init(&random_reseed_mtx, "reseed mutex", NULL, MTX_DEF);
+#else /* !_KERNEL */
+ mtx_init(&random_reseed_mtx, mtx_plain);
+#endif /* _KERNEL */
#ifdef _KERNEL
/* Fortuna parameters. Do not adjust these unless you have
Modified: projects/random_number_generator/sys/dev/random/unit_test.c
==============================================================================
--- projects/random_number_generator/sys/dev/random/unit_test.c Mon May 5 10:49:09 2014 (r265354)
+++ projects/random_number_generator/sys/dev/random/unit_test.c Mon May 5 10:53:16 2014 (r265355)
@@ -61,7 +61,6 @@ Where <alg> is YARROW or FORTUNA.
#define NUM_THREADS 3
-static mtx_t random_reseed_mtx;
static volatile int stopseeding = 0;
void
@@ -220,12 +219,11 @@ main(int argc, char *argv[])
int rc;
long t;
- mtx_init(&random_reseed_mtx, mtx_plain);
#ifdef RANDOM_YARROW
- random_yarrow_init_alg(NULL, &random_reseed_mtx);
+ random_yarrow_init_alg();
#endif
#ifdef RANDOM_FORTUNA
- random_fortuna_init_alg(NULL, &random_reseed_mtx);
+ random_fortuna_init_alg();
#endif
for (t = 0; t < NUM_THREADS; t++) {
@@ -251,7 +249,6 @@ main(int argc, char *argv[])
#ifdef RANDOM_FORTUNA
random_fortuna_deinit_alg();
#endif
- mtx_destroy(&random_reseed_mtx);
/* Last thing that main() should do */
thrd_exit(0);
Modified: projects/random_number_generator/sys/dev/random/yarrow.c
==============================================================================
--- projects/random_number_generator/sys/dev/random/yarrow.c Mon May 5 10:49:09 2014 (r265354)
+++ projects/random_number_generator/sys/dev/random/yarrow.c Mon May 5 10:53:16 2014 (r265355)
@@ -118,7 +118,7 @@ static struct yarrow_state {
} yarrow_state;
/* The random_reseed_mtx mutex protects seeding and polling/blocking. */
-static struct mtx random_reseed_mtx;
+static mtx_t random_reseed_mtx;
#ifdef _KERNEL
static struct sysctl_ctx_list random_clist;
@@ -146,7 +146,11 @@ random_yarrow_init_alg(void)
randomdev_hash_init(&yarrow_state.start_cache.hash);
/* Set up the lock for the reseed/gate state */
+#ifdef _KERNEL
mtx_init(&random_reseed_mtx, "reseed mutex", NULL, MTX_DEF);
+#else /* !_KERNEL */
+ mtx_init(&random_reseed_mtx, mtx_plain);
+#endif /* _KERNEL */
/* Start unseeded, therefore blocked. */
yarrow_state.seeded = 0;
@@ -223,7 +227,9 @@ random_yarrow_deinit_alg(void)
mtx_destroy(&random_reseed_mtx);
memset((void *)(&yarrow_state), 0, sizeof(struct yarrow_state));
+#ifdef _KERNEL
sysctl_ctx_free(&random_clist);
+#endif
}
static __inline void
More information about the svn-src-projects
mailing list