2000-06-25 08:38:58 +00:00
|
|
|
/*-
|
2000-07-07 09:03:59 +00:00
|
|
|
* Copyright (c) 2000 Mark R V Murray
|
2000-06-25 08:38:58 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
|
|
|
* in this position and unchanged.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-09-10 13:52:19 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/kthread.h>
|
2000-06-25 08:38:58 +00:00
|
|
|
#include <sys/libkern.h>
|
2000-10-20 07:58:15 +00:00
|
|
|
#include <sys/mutex.h>
|
2001-01-09 04:33:49 +00:00
|
|
|
#include <sys/selinfo.h>
|
2000-06-25 08:38:58 +00:00
|
|
|
#include <sys/random.h>
|
|
|
|
#include <sys/types.h>
|
2000-09-11 04:09:08 +00:00
|
|
|
#include <sys/unistd.h>
|
2000-11-25 17:09:01 +00:00
|
|
|
|
2000-12-02 18:40:16 +00:00
|
|
|
#include <machine/atomic.h>
|
2000-11-25 17:09:01 +00:00
|
|
|
#include <machine/cpu.h>
|
|
|
|
|
2000-06-25 08:38:58 +00:00
|
|
|
#include <crypto/blowfish/blowfish.h>
|
|
|
|
|
2000-10-14 10:59:56 +00:00
|
|
|
#include <dev/random/hash.h>
|
|
|
|
#include <dev/random/yarrow.h>
|
2000-06-25 08:38:58 +00:00
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
/* #define DEBUG */
|
2000-06-25 08:38:58 +00:00
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
static void generator_gate(void);
|
|
|
|
static void reseed(int);
|
2000-11-25 17:09:01 +00:00
|
|
|
static void random_harvest_internal(u_int64_t, void *, u_int, u_int, u_int, enum esource);
|
2000-07-07 09:03:59 +00:00
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
static void random_kthread(void *);
|
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
/* Structure holding the entropy state */
|
|
|
|
struct random_state random_state;
|
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
/* These are used to queue harvested packets of entropy. The entropy
|
2000-10-14 10:59:56 +00:00
|
|
|
* buffer size is pretty arbitrary.
|
2000-07-23 11:08:16 +00:00
|
|
|
*/
|
2000-09-10 13:52:19 +00:00
|
|
|
struct harvest {
|
2000-11-25 17:09:01 +00:00
|
|
|
u_int64_t somecounter; /* fast counter for clock jitter */
|
2000-10-14 10:59:56 +00:00
|
|
|
u_char entropy[HARVESTSIZE]; /* the harvested entropy */
|
2000-09-10 13:52:19 +00:00
|
|
|
u_int size, bits, frac; /* stats about the entropy */
|
|
|
|
enum esource source; /* stats about the entropy */
|
|
|
|
};
|
|
|
|
|
2000-12-02 18:40:16 +00:00
|
|
|
/* Ring buffer holding harvested entropy */
|
|
|
|
static struct harvestring {
|
2001-02-11 16:21:35 +00:00
|
|
|
volatile int head;
|
|
|
|
volatile int tail;
|
2000-12-02 18:40:16 +00:00
|
|
|
struct harvest data[HARVEST_RING_SIZE];
|
|
|
|
} harvestring;
|
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
/* The reseed thread mutex */
|
2000-09-14 20:15:16 +00:00
|
|
|
static struct mtx random_reseed_mtx;
|
2000-09-10 13:52:19 +00:00
|
|
|
|
|
|
|
/* <0 to end the kthread, 0 to let it run */
|
|
|
|
static int random_kthread_control = 0;
|
|
|
|
|
|
|
|
static struct proc *random_kthread_proc;
|
2000-07-07 09:03:59 +00:00
|
|
|
|
|
|
|
static void
|
2000-10-14 10:59:56 +00:00
|
|
|
random_kthread(void *arg /* NOTUSED */)
|
2000-07-07 09:03:59 +00:00
|
|
|
{
|
2001-02-11 16:21:35 +00:00
|
|
|
int pl, src, overthreshhold[2], newtail;
|
2000-09-10 13:52:19 +00:00
|
|
|
struct harvest *event;
|
|
|
|
struct source *source;
|
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2000-12-02 18:40:16 +00:00
|
|
|
printf("OWNERSHIP Giant == %d sched_lock == %d\n",
|
|
|
|
mtx_owned(&Giant), mtx_owned(&sched_lock));
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for (pl = 0; pl < 2; pl++)
|
|
|
|
yarrow_hash_init(&random_state.pool[pl].hash, NULL, 0);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
2001-02-11 16:21:35 +00:00
|
|
|
if (harvestring.tail == harvestring.head)
|
|
|
|
tsleep(&harvestring, PUSER, "rndslp", hz/10);
|
2000-09-10 13:52:19 +00:00
|
|
|
|
2000-12-02 18:40:16 +00:00
|
|
|
else {
|
2000-09-10 13:52:19 +00:00
|
|
|
|
|
|
|
/* Suck the harvested entropy out of the queue and hash
|
2000-12-02 18:40:16 +00:00
|
|
|
* it into the appropriate pool.
|
2000-09-10 13:52:19 +00:00
|
|
|
*/
|
|
|
|
|
2001-02-11 16:21:35 +00:00
|
|
|
newtail = (harvestring.tail + 1) & HARVEST_RING_MASK;
|
2000-12-02 18:40:16 +00:00
|
|
|
event = &harvestring.data[harvestring.tail];
|
2001-02-11 16:21:35 +00:00
|
|
|
|
|
|
|
/* Bump the ring counter. This action is assumed
|
|
|
|
* to be atomic.
|
|
|
|
*/
|
2000-12-02 18:40:16 +00:00
|
|
|
harvestring.tail = newtail;
|
2000-09-10 13:52:19 +00:00
|
|
|
|
2001-02-11 16:21:35 +00:00
|
|
|
pl = random_state.which = !random_state.which;
|
|
|
|
|
|
|
|
source = &random_state.pool[pl].source[event->source];
|
|
|
|
yarrow_hash_iterate(&random_state.pool[pl].hash,
|
2000-12-02 18:40:16 +00:00
|
|
|
event->entropy, sizeof(event->entropy));
|
2001-02-11 16:21:35 +00:00
|
|
|
yarrow_hash_iterate(&random_state.pool[pl].hash,
|
2000-12-02 18:40:16 +00:00
|
|
|
&event->somecounter, sizeof(event->somecounter));
|
|
|
|
source->frac += event->frac;
|
|
|
|
source->bits += event->bits + source->frac/1024;
|
|
|
|
source->frac %= 1024;
|
2000-09-10 13:52:19 +00:00
|
|
|
|
|
|
|
/* Count the over-threshold sources in each pool */
|
|
|
|
for (pl = 0; pl < 2; pl++) {
|
|
|
|
overthreshhold[pl] = 0;
|
|
|
|
for (src = 0; src < ENTROPYSOURCE; src++) {
|
|
|
|
if (random_state.pool[pl].source[src].bits
|
|
|
|
> random_state.pool[pl].thresh)
|
|
|
|
overthreshhold[pl]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if any fast source over threshhold, reseed */
|
|
|
|
if (overthreshhold[FAST])
|
|
|
|
reseed(FAST);
|
2000-12-02 18:40:16 +00:00
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
/* if enough slow sources are over threshhold, reseed */
|
|
|
|
if (overthreshhold[SLOW] >= random_state.slowoverthresh)
|
|
|
|
reseed(SLOW);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the thread scheduled for a shutdown? */
|
2000-10-14 10:59:56 +00:00
|
|
|
if (random_kthread_control != 0) {
|
2000-09-10 13:52:19 +00:00
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
printf("Random kthread setting terminate\n");
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
#endif
|
2000-10-14 10:59:56 +00:00
|
|
|
random_set_wakeup_exit(&random_kthread_control);
|
|
|
|
/* NOTREACHED */
|
2000-09-10 13:52:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
}
|
2000-06-25 08:38:58 +00:00
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
int
|
2000-07-07 09:03:59 +00:00
|
|
|
random_init(void)
|
2000-06-25 08:38:58 +00:00
|
|
|
{
|
2000-09-10 13:52:19 +00:00
|
|
|
int error;
|
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
printf("Random initialise\n");
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-07-07 09:03:59 +00:00
|
|
|
#endif
|
2000-09-10 13:52:19 +00:00
|
|
|
|
2001-01-14 17:50:15 +00:00
|
|
|
/* This can be turned off by the very paranoid
|
|
|
|
* a reseed will turn it back on.
|
|
|
|
*/
|
|
|
|
random_state.seeded = 1;
|
|
|
|
|
2001-02-11 16:21:35 +00:00
|
|
|
/* Yarrow parameters. Do not adjust these unless you have
|
|
|
|
* have a very good clue about what they do!
|
|
|
|
*/
|
2000-07-07 09:03:59 +00:00
|
|
|
random_state.gengateinterval = 10;
|
|
|
|
random_state.bins = 10;
|
|
|
|
random_state.pool[0].thresh = 100;
|
|
|
|
random_state.pool[1].thresh = 160;
|
|
|
|
random_state.slowoverthresh = 2;
|
|
|
|
random_state.which = FAST;
|
2000-09-10 13:52:19 +00:00
|
|
|
|
|
|
|
mtx_init(&random_reseed_mtx, "random reseed", MTX_DEF);
|
2000-12-02 18:40:16 +00:00
|
|
|
|
|
|
|
harvestring.head = 0;
|
|
|
|
harvestring.tail = 0;
|
2000-09-10 13:52:19 +00:00
|
|
|
|
|
|
|
/* Start the hash/reseed thread */
|
2000-10-14 10:59:56 +00:00
|
|
|
error = kthread_create(random_kthread, NULL,
|
2000-09-11 04:09:08 +00:00
|
|
|
&random_kthread_proc, RFHIGHPID, "random");
|
2000-09-10 13:52:19 +00:00
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* Register the randomness harvesting routine */
|
2000-10-14 10:59:56 +00:00
|
|
|
random_init_harvester(random_harvest_internal, read_random_real);
|
2000-09-10 13:52:19 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-02-08 20:28:57 +00:00
|
|
|
printf("Random initialise finish\n");
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
2000-06-25 08:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-07-07 09:03:59 +00:00
|
|
|
random_deinit(void)
|
2000-06-25 08:38:58 +00:00
|
|
|
{
|
2000-07-07 09:03:59 +00:00
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-02-08 20:28:57 +00:00
|
|
|
printf("Random deinitialise\n");
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-07-07 09:03:59 +00:00
|
|
|
#endif
|
2000-09-10 13:52:19 +00:00
|
|
|
|
|
|
|
/* Deregister the randomness harvesting routine */
|
2000-07-07 09:03:59 +00:00
|
|
|
random_deinit_harvester();
|
2000-09-10 13:52:19 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-02-08 20:28:57 +00:00
|
|
|
printf("Random deinitialise waiting for thread to terminate\n");
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Command the hash/reseed thread to end and wait for it to finish */
|
|
|
|
random_kthread_control = -1;
|
2001-02-11 16:21:35 +00:00
|
|
|
tsleep((void *)&random_kthread_control, PUSER, "rndend", 0);
|
2000-09-10 13:52:19 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-02-08 20:28:57 +00:00
|
|
|
printf("Random deinitialise removing mutexes\n");
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
mtx_destroy(&random_reseed_mtx);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2001-02-08 20:28:57 +00:00
|
|
|
printf("Random deinitialise finish\n");
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
#endif
|
2000-07-07 09:03:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reseed(int fastslow)
|
|
|
|
{
|
2000-09-10 13:52:19 +00:00
|
|
|
/* Interrupt-context stack is a limited resource; make large
|
|
|
|
* structures static.
|
2000-07-23 11:08:16 +00:00
|
|
|
*/
|
2000-09-10 13:52:19 +00:00
|
|
|
static u_char v[TIMEBIN][KEYSIZE]; /* v[i] */
|
|
|
|
static struct yarrowhash context;
|
|
|
|
u_char hash[KEYSIZE]; /* h' */
|
|
|
|
u_char temp[KEYSIZE];
|
2000-06-25 08:38:58 +00:00
|
|
|
int i, j;
|
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2000-07-07 09:03:59 +00:00
|
|
|
printf("Reseed type %d\n", fastslow);
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-07-07 09:03:59 +00:00
|
|
|
#endif
|
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
/* The reseed task must not be jumped on */
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&random_reseed_mtx);
|
2000-09-10 13:52:19 +00:00
|
|
|
|
2000-06-25 08:38:58 +00:00
|
|
|
/* 1. Hash the accumulated entropy into v[0] */
|
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_hash_init(&context, NULL, 0);
|
|
|
|
/* Feed the slow pool hash in if slow */
|
|
|
|
if (fastslow == SLOW)
|
|
|
|
yarrow_hash_iterate(&context,
|
|
|
|
&random_state.pool[SLOW].hash, sizeof(struct yarrowhash));
|
2000-07-07 09:03:59 +00:00
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_hash_iterate(&context,
|
|
|
|
&random_state.pool[FAST].hash, sizeof(struct yarrowhash));
|
2000-06-25 08:38:58 +00:00
|
|
|
|
2000-07-23 11:08:16 +00:00
|
|
|
/* 2. Compute hash values for all v. _Supposed_ to be computationally
|
|
|
|
* intensive.
|
|
|
|
*/
|
2000-06-25 08:38:58 +00:00
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
if (random_state.bins > TIMEBIN)
|
|
|
|
random_state.bins = TIMEBIN;
|
|
|
|
for (i = 1; i < random_state.bins; i++) {
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_hash_init(&context, NULL, 0);
|
2000-07-07 09:03:59 +00:00
|
|
|
/* v[i] #= h(v[i-1]) */
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_hash_iterate(&context, v[i - 1], KEYSIZE);
|
2000-07-07 09:03:59 +00:00
|
|
|
/* v[i] #= h(v[0]) */
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_hash_iterate(&context, v[0], KEYSIZE);
|
2000-07-07 09:03:59 +00:00
|
|
|
/* v[i] #= h(i) */
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_hash_iterate(&context, &i, sizeof(int));
|
|
|
|
/* Return the hashval */
|
|
|
|
yarrow_hash_finish(&context, v[i]);
|
2000-06-25 08:38:58 +00:00
|
|
|
}
|
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
/* 3. Compute a new key; h' is the identity function here;
|
|
|
|
* it is not being ignored!
|
|
|
|
*/
|
2000-06-25 08:38:58 +00:00
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_hash_init(&context, NULL, 0);
|
|
|
|
yarrow_hash_iterate(&context, &random_state.key, KEYSIZE);
|
|
|
|
for (i = 1; i < random_state.bins; i++)
|
|
|
|
yarrow_hash_iterate(&context, &v[i], KEYSIZE);
|
|
|
|
yarrow_hash_finish(&context, temp);
|
|
|
|
yarrow_encrypt_init(&random_state.key, temp, KEYSIZE);
|
2000-06-25 08:38:58 +00:00
|
|
|
|
|
|
|
/* 4. Recompute the counter */
|
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
random_state.counter = 0;
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_encrypt(&random_state.key, &random_state.counter, temp,
|
|
|
|
sizeof(random_state.counter));
|
2000-07-07 09:03:59 +00:00
|
|
|
memcpy(&random_state.counter, temp, random_state.counter);
|
2000-06-25 08:38:58 +00:00
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
/* 5. Reset entropy estimate accumulators to zero */
|
2000-06-25 08:38:58 +00:00
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
for (i = 0; i <= fastslow; i++) {
|
|
|
|
for (j = 0; j < ENTROPYSOURCE; j++) {
|
2000-09-10 13:52:19 +00:00
|
|
|
if (random_state.pool[i].source[j].bits >
|
|
|
|
random_state.pool[i].thresh) {
|
|
|
|
random_state.pool[i].source[j].bits = 0;
|
|
|
|
random_state.pool[i].source[j].frac = 0;
|
|
|
|
}
|
2000-07-07 09:03:59 +00:00
|
|
|
}
|
|
|
|
}
|
2000-06-25 08:38:58 +00:00
|
|
|
|
|
|
|
/* 6. Wipe memory of intermediate values */
|
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
memset((void *)v, 0, sizeof(v));
|
|
|
|
memset((void *)temp, 0, sizeof(temp));
|
|
|
|
memset((void *)hash, 0, sizeof(hash));
|
2000-06-25 08:38:58 +00:00
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
/* 7. Dump to seed file */
|
|
|
|
/* XXX Not done here yet */
|
|
|
|
|
|
|
|
/* Release the reseed mutex */
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&random_reseed_mtx);
|
2000-09-10 13:52:19 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
printf("Reseed finish\n");
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
#endif
|
2000-06-25 08:38:58 +00:00
|
|
|
|
2000-10-14 10:59:56 +00:00
|
|
|
if (!random_state.seeded) {
|
|
|
|
random_state.seeded = 1;
|
|
|
|
selwakeup(&random_state.rsel);
|
|
|
|
wakeup(&random_state);
|
|
|
|
}
|
|
|
|
|
2000-06-25 08:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u_int
|
2000-10-14 10:59:56 +00:00
|
|
|
read_random_real(void *buf, u_int count)
|
2000-06-25 08:38:58 +00:00
|
|
|
{
|
2000-07-25 21:18:47 +00:00
|
|
|
static u_int64_t genval;
|
2000-06-25 08:38:58 +00:00
|
|
|
static int cur = 0;
|
|
|
|
static int gate = 1;
|
|
|
|
u_int i;
|
|
|
|
u_int retval;
|
2000-07-10 06:40:23 +00:00
|
|
|
|
|
|
|
/* The reseed task must not be jumped on */
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&random_reseed_mtx);
|
2000-06-25 08:38:58 +00:00
|
|
|
|
|
|
|
if (gate) {
|
|
|
|
generator_gate();
|
2000-07-07 09:03:59 +00:00
|
|
|
random_state.outputblocks = 0;
|
2000-06-25 08:38:58 +00:00
|
|
|
gate = 0;
|
|
|
|
}
|
2000-07-07 09:03:59 +00:00
|
|
|
if (count >= sizeof(random_state.counter)) {
|
2000-06-25 08:38:58 +00:00
|
|
|
retval = 0;
|
2000-07-07 09:03:59 +00:00
|
|
|
for (i = 0; i < count; i += sizeof(random_state.counter)) {
|
|
|
|
random_state.counter++;
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_encrypt(&random_state.key, &random_state.counter,
|
|
|
|
&genval, sizeof(random_state.counter));
|
2000-07-25 21:18:47 +00:00
|
|
|
memcpy((char *)buf + i, &genval,
|
|
|
|
sizeof(random_state.counter));
|
2000-07-07 09:03:59 +00:00
|
|
|
if (++random_state.outputblocks >= random_state.gengateinterval) {
|
2000-06-25 08:38:58 +00:00
|
|
|
generator_gate();
|
2000-07-07 09:03:59 +00:00
|
|
|
random_state.outputblocks = 0;
|
2000-06-25 08:38:58 +00:00
|
|
|
}
|
2000-07-07 09:03:59 +00:00
|
|
|
retval += sizeof(random_state.counter);
|
2000-06-25 08:38:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!cur) {
|
2000-07-07 09:03:59 +00:00
|
|
|
random_state.counter++;
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_encrypt(&random_state.key, &random_state.counter,
|
|
|
|
&genval, sizeof(random_state.counter));
|
2000-06-25 08:38:58 +00:00
|
|
|
memcpy(buf, &genval, count);
|
2000-07-07 09:03:59 +00:00
|
|
|
cur = sizeof(random_state.counter) - count;
|
|
|
|
if (++random_state.outputblocks >= random_state.gengateinterval) {
|
2000-06-25 08:38:58 +00:00
|
|
|
generator_gate();
|
2000-07-07 09:03:59 +00:00
|
|
|
random_state.outputblocks = 0;
|
2000-06-25 08:38:58 +00:00
|
|
|
}
|
|
|
|
retval = count;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
retval = cur < count ? cur : count;
|
|
|
|
memcpy(buf,
|
2000-07-25 21:18:47 +00:00
|
|
|
(char *)&genval +
|
|
|
|
(sizeof(random_state.counter) - cur),
|
2000-06-25 08:38:58 +00:00
|
|
|
retval);
|
|
|
|
cur -= retval;
|
|
|
|
}
|
|
|
|
}
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&random_reseed_mtx);
|
2000-06-25 08:38:58 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2000-07-17 12:23:04 +00:00
|
|
|
void
|
2000-07-25 21:18:47 +00:00
|
|
|
write_random(void *buf, u_int count)
|
2000-07-17 12:23:04 +00:00
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
|
2000-11-25 17:09:01 +00:00
|
|
|
/* Break the input up into HARVESTSIZE chunks.
|
|
|
|
* The writer has too much control here, so "estimate" the
|
|
|
|
* the entropy as zero.
|
|
|
|
*/
|
2000-10-14 10:59:56 +00:00
|
|
|
for (i = 0; i < count; i += HARVESTSIZE) {
|
2000-11-25 17:09:01 +00:00
|
|
|
random_harvest_internal(get_cyclecount(), (char *)buf + i,
|
|
|
|
HARVESTSIZE, 0, 0, RANDOM_WRITE);
|
2000-07-25 21:18:47 +00:00
|
|
|
}
|
2000-09-10 13:52:19 +00:00
|
|
|
|
2000-07-25 21:18:47 +00:00
|
|
|
/* Maybe the loop iterated at least once */
|
|
|
|
if (i > count)
|
2000-10-14 10:59:56 +00:00
|
|
|
i -= HARVESTSIZE;
|
2000-09-10 13:52:19 +00:00
|
|
|
|
2000-11-25 17:09:01 +00:00
|
|
|
/* Get the last bytes even if the input length is not
|
|
|
|
* a multiple of HARVESTSIZE.
|
|
|
|
*/
|
2000-10-14 10:59:56 +00:00
|
|
|
count %= HARVESTSIZE;
|
2000-07-25 21:18:47 +00:00
|
|
|
if (count) {
|
2000-12-02 18:40:16 +00:00
|
|
|
random_harvest_internal(get_cyclecount(), (char *)buf + i,
|
|
|
|
count, 0, 0, RANDOM_WRITE);
|
2000-07-17 12:23:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
static void
|
2000-06-25 08:38:58 +00:00
|
|
|
generator_gate(void)
|
|
|
|
{
|
|
|
|
int i;
|
2000-09-10 13:52:19 +00:00
|
|
|
u_char temp[KEYSIZE];
|
2000-06-25 08:38:58 +00:00
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2000-07-10 06:40:23 +00:00
|
|
|
printf("Generator gate\n");
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-07-07 09:03:59 +00:00
|
|
|
#endif
|
2000-07-10 06:40:23 +00:00
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
for (i = 0; i < KEYSIZE; i += sizeof(random_state.counter)) {
|
|
|
|
random_state.counter++;
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_encrypt(&random_state.key, &random_state.counter,
|
|
|
|
&(temp[i]), sizeof(random_state.counter));
|
2000-06-25 08:38:58 +00:00
|
|
|
}
|
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
yarrow_encrypt_init(&random_state.key, temp, KEYSIZE);
|
|
|
|
memset((void *)temp, 0, KEYSIZE);
|
2000-07-10 06:40:23 +00:00
|
|
|
|
2000-09-10 13:52:19 +00:00
|
|
|
#ifdef DEBUG
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_lock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
printf("Generator gate finish\n");
|
Change and clean the mutex lock interface.
mtx_enter(lock, type) becomes:
mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks)
mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized)
similarily, for releasing a lock, we now have:
mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN.
We change the caller interface for the two different types of locks
because the semantics are entirely different for each case, and this
makes it explicitly clear and, at the same time, it rids us of the
extra `type' argument.
The enter->lock and exit->unlock change has been made with the idea
that we're "locking data" and not "entering locked code" in mind.
Further, remove all additional "flags" previously passed to the
lock acquire/release routines with the exception of two:
MTX_QUIET and MTX_NOSWITCH
The functionality of these flags is preserved and they can be passed
to the lock/unlock routines by calling the corresponding wrappers:
mtx_{lock, unlock}_flags(lock, flag(s)) and
mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN
locks, respectively.
Re-inline some lock acq/rel code; in the sleep lock case, we only
inline the _obtain_lock()s in order to ensure that the inlined code
fits into a cache line. In the spin lock case, we inline recursion and
actually only perform a function call if we need to spin. This change
has been made with the idea that we generally tend to avoid spin locks
and that also the spin locks that we do have and are heavily used
(i.e. sched_lock) do recurse, and therefore in an effort to reduce
function call overhead for some architectures (such as alpha), we
inline recursion for this case.
Create a new malloc type for the witness code and retire from using
the M_DEV type. The new type is called M_WITNESS and is only declared
if WITNESS is enabled.
Begin cleaning up some machdep/mutex.h code - specifically updated the
"optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN
and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently
need those.
Finally, caught up to the interface changes in all sys code.
Contributors: jake, jhb, jasone (in no particular order)
2001-02-09 06:11:45 +00:00
|
|
|
mtx_unlock(&Giant);
|
2000-09-10 13:52:19 +00:00
|
|
|
#endif
|
2000-06-25 08:38:58 +00:00
|
|
|
}
|
2000-07-07 09:03:59 +00:00
|
|
|
|
2000-07-23 11:08:16 +00:00
|
|
|
/* Entropy harvesting routine. This is supposed to be fast; do
|
|
|
|
* not do anything slow in here!
|
|
|
|
*/
|
2000-07-07 09:03:59 +00:00
|
|
|
|
|
|
|
static void
|
2000-11-25 17:09:01 +00:00
|
|
|
random_harvest_internal(u_int64_t somecounter, void *entropy, u_int count,
|
2000-07-09 11:52:12 +00:00
|
|
|
u_int bits, u_int frac, enum esource origin)
|
2000-07-07 09:03:59 +00:00
|
|
|
{
|
2000-12-02 18:40:16 +00:00
|
|
|
struct harvest *harvest;
|
2001-02-11 16:21:35 +00:00
|
|
|
int newhead;
|
2000-07-07 09:03:59 +00:00
|
|
|
|
2001-02-11 16:21:35 +00:00
|
|
|
newhead = (harvestring.head + 1) & HARVEST_RING_MASK;
|
2000-07-07 09:03:59 +00:00
|
|
|
|
2001-02-11 16:21:35 +00:00
|
|
|
if (newhead != harvestring.tail) {
|
2000-07-07 09:03:59 +00:00
|
|
|
|
2001-02-11 16:21:35 +00:00
|
|
|
/* Add the harvested data to the ring buffer */
|
2000-07-07 09:03:59 +00:00
|
|
|
|
2001-02-11 16:21:35 +00:00
|
|
|
harvest = &harvestring.data[harvestring.head];
|
2000-07-07 09:03:59 +00:00
|
|
|
|
2001-02-11 16:21:35 +00:00
|
|
|
/* Stuff the harvested data into the ring */
|
|
|
|
harvest->somecounter = somecounter;
|
|
|
|
count = count > HARVESTSIZE ? HARVESTSIZE : count;
|
|
|
|
memcpy(harvest->entropy, entropy, count);
|
|
|
|
harvest->size = count;
|
|
|
|
harvest->bits = bits;
|
|
|
|
harvest->frac = frac;
|
|
|
|
harvest->source = origin < ENTROPYSOURCE ? origin : 0;
|
2000-07-07 09:03:59 +00:00
|
|
|
|
2001-02-11 16:21:35 +00:00
|
|
|
/* Bump the ring counter. This action is assumed
|
|
|
|
* to be atomic.
|
|
|
|
*/
|
|
|
|
harvestring.head = newhead;
|
2000-07-07 09:03:59 +00:00
|
|
|
|
|
|
|
}
|
2001-02-11 16:21:35 +00:00
|
|
|
|
2000-07-07 09:03:59 +00:00
|
|
|
}
|
2000-11-25 19:13:29 +00:00
|
|
|
|
|
|
|
/* Helper routine to perform explicit reseeds */
|
|
|
|
void
|
|
|
|
random_reseed(void)
|
|
|
|
{
|
|
|
|
reseed(FAST);
|
|
|
|
}
|