summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>1995-12-29 08:04:32 +0000
committermarkm <markm@FreeBSD.org>1995-12-29 08:04:32 +0000
commit79b9c69957eb15af87d447bcfbbb5141f341523d (patch)
tree9af57d25fd0a99ae9376d4c58a27ad60ed8da68d /sys
parent38f0506d5b8d40abf3043cf5b5e5ea4c723d8232 (diff)
downloadFreeBSD-src-79b9c69957eb15af87d447bcfbbb5141f341523d.zip
FreeBSD-src-79b9c69957eb15af87d447bcfbbb5141f341523d.tar.gz
1) ifdef out some unused functions (for now)
2) improve 586 support 3) add 686 support 4) clean up comments etc Submitted by: bde
Diffstat (limited to 'sys')
-rw-r--r--sys/i386/include/random.h7
-rw-r--r--sys/i386/isa/random_machdep.c46
-rw-r--r--sys/kern/kern_random.c46
-rw-r--r--sys/sys/random.h7
4 files changed, 66 insertions, 40 deletions
diff --git a/sys/i386/include/random.h b/sys/i386/include/random.h
index 8e7b359..5fe7ffc 100644
--- a/sys/i386/include/random.h
+++ b/sys/i386/include/random.h
@@ -52,6 +52,7 @@
#if defined(KERNEL)
#include <i386/isa/icu.h>
+#include <i386/isa/isa_device.h>
#endif
#include <sys/ioctl.h>
@@ -71,12 +72,18 @@ extern int sec_intr_unit[ICU_LEN];
void rand_initialize(void);
void add_keyboard_randomness(u_char scancode);
void add_interrupt_randomness(int irq);
+#ifdef notused
void add_blkdev_randomness(int major);
+#endif
+#ifdef notused
void get_random_bytes(void *buf, u_int nbytes);
+#endif
u_int read_random(char *buf, u_int size);
u_int read_random_unlimited(char *buf, u_int size);
+#ifdef notused
u_int write_random(const char *buf, u_int nbytes);
+#endif
#endif
diff --git a/sys/i386/isa/random_machdep.c b/sys/i386/isa/random_machdep.c
index c62db13..507d875 100644
--- a/sys/i386/isa/random_machdep.c
+++ b/sys/i386/isa/random_machdep.c
@@ -1,7 +1,7 @@
/*
- * random.c -- A strong random number generator
+ * random_machdep.c -- A strong random number generator
*
- * $Id: random_machdep.c,v 1.2 1995/12/27 11:22:01 markm Exp $
+ * $Id$
*
* Version 0.95, last modified 18-Oct-95
*
@@ -42,16 +42,17 @@
#define MAX_BLKDEV 4
#include <sys/param.h>
-#include <sys/cdefs.h>
-#include <sys/kernel.h>
-#include <sys/uio.h>
#include <sys/systm.h>
-#include <i386/isa/isa.h>
-#include <i386/isa/timerreg.h>
-#include <i386/isa/isa_device.h>
+#include <sys/kernel.h>
+
+#include <machine/clock.h>
#include <machine/cpu.h>
#include <machine/random.h>
+#include <i386/isa/isa.h>
+#include <i386/isa/isa_device.h>
+#include <i386/isa/timerreg.h>
+
/*
* The pool is stirred with a primitive polynomial of degree 128
* over GF(2), namely x^128 + x^99 + x^59 + x^31 + x^9 + x^7 + 1.
@@ -170,8 +171,6 @@ add_entropy_word(struct random_bucket *r, const u_int32_t input)
* keyboard scan codes, and 256 upwards for interrupts.
* On the i386, this is assumed to be at most 16 bits, and the high bits
* are used for a high-resolution timer.
- *
- * TODO: Read the time stamp register on the Pentium.
*/
static void
add_timer_randomness(struct random_bucket *r, struct timer_rand_state *state,
@@ -181,23 +180,24 @@ add_timer_randomness(struct random_bucket *r, struct timer_rand_state *state,
u_int nbits;
u_int32_t time;
-#if defined(I586_CPU)
- if (cpu_class == CPUCLASS_586) {
+#if defined(I586_CPU) || defined(I686_CPU)
+ if (i586_ctr_rate != 0) {
u_long low, high;
- __asm__(".byte 0x0f,0x31" :"=a" (low), "=d" (high)); /* RDTSC */
- time = (u_int32_t) low;
- num ^= (u_int32_t) high;
+ /* RDTSC. */
+ __asm __volatile(".byte 0x0f,0x31" :"=a" (low), "=d" (high));
+ num ^= low << 16;
r->entropy_count += 2;
- }
- else {
+ } else {
#endif
- outb(TIMER_MODE, TIMER_LATCH|TIMER_SEL0); /* latch ASAP */
+ disable_intr();
+ outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
num ^= inb(TIMER_CNTR0) << 16;
num ^= inb(TIMER_CNTR0) << 24;
+ enable_intr();
r->entropy_count += 2;
-#if defined(I586_CPU)
- } /* cpu_class == CPUCLASS_586 */
+#if defined(I586_CPU) || defined(I686_CPU)
+ }
#endif
time = ticks;
@@ -242,6 +242,7 @@ add_interrupt_randomness(int irq)
add_timer_randomness(&random_state, &irq_timer_state[irq], irq);
}
+#ifdef notused
void
add_blkdev_randomness(int major)
{
@@ -251,6 +252,7 @@ add_blkdev_randomness(int major)
add_timer_randomness(&random_state, &blkdev_timer_state[major],
0x200+major);
}
+#endif /* notused */
/*
* MD5 transform algorithm, taken from code written by Colin Plumb,
@@ -432,6 +434,7 @@ extract_entropy(struct random_bucket *r, char *buf, int nbytes)
return ret;
}
+#ifdef notused /* XXX NOT the exported kernel interface */
/*
* This function is the exported kernel interface. It returns some
* number of good random numbers, suitable for seeding TCP sequence
@@ -442,6 +445,7 @@ get_random_bytes(void *buf, u_int nbytes)
{
extract_entropy(&random_state, (char *) buf, nbytes);
}
+#endif /* notused */
u_int
read_random(char *buf, u_int nbytes)
@@ -458,6 +462,7 @@ read_random_unlimited(char *buf, u_int nbytes)
return extract_entropy(&random_state, buf, nbytes);
}
+#ifdef notused
u_int
write_random(const char *buf, u_int nbytes)
{
@@ -475,3 +480,4 @@ write_random(const char *buf, u_int nbytes)
}
return nbytes;
}
+#endif /* notused */
diff --git a/sys/kern/kern_random.c b/sys/kern/kern_random.c
index c62db13..507d875 100644
--- a/sys/kern/kern_random.c
+++ b/sys/kern/kern_random.c
@@ -1,7 +1,7 @@
/*
- * random.c -- A strong random number generator
+ * random_machdep.c -- A strong random number generator
*
- * $Id: random_machdep.c,v 1.2 1995/12/27 11:22:01 markm Exp $
+ * $Id$
*
* Version 0.95, last modified 18-Oct-95
*
@@ -42,16 +42,17 @@
#define MAX_BLKDEV 4
#include <sys/param.h>
-#include <sys/cdefs.h>
-#include <sys/kernel.h>
-#include <sys/uio.h>
#include <sys/systm.h>
-#include <i386/isa/isa.h>
-#include <i386/isa/timerreg.h>
-#include <i386/isa/isa_device.h>
+#include <sys/kernel.h>
+
+#include <machine/clock.h>
#include <machine/cpu.h>
#include <machine/random.h>
+#include <i386/isa/isa.h>
+#include <i386/isa/isa_device.h>
+#include <i386/isa/timerreg.h>
+
/*
* The pool is stirred with a primitive polynomial of degree 128
* over GF(2), namely x^128 + x^99 + x^59 + x^31 + x^9 + x^7 + 1.
@@ -170,8 +171,6 @@ add_entropy_word(struct random_bucket *r, const u_int32_t input)
* keyboard scan codes, and 256 upwards for interrupts.
* On the i386, this is assumed to be at most 16 bits, and the high bits
* are used for a high-resolution timer.
- *
- * TODO: Read the time stamp register on the Pentium.
*/
static void
add_timer_randomness(struct random_bucket *r, struct timer_rand_state *state,
@@ -181,23 +180,24 @@ add_timer_randomness(struct random_bucket *r, struct timer_rand_state *state,
u_int nbits;
u_int32_t time;
-#if defined(I586_CPU)
- if (cpu_class == CPUCLASS_586) {
+#if defined(I586_CPU) || defined(I686_CPU)
+ if (i586_ctr_rate != 0) {
u_long low, high;
- __asm__(".byte 0x0f,0x31" :"=a" (low), "=d" (high)); /* RDTSC */
- time = (u_int32_t) low;
- num ^= (u_int32_t) high;
+ /* RDTSC. */
+ __asm __volatile(".byte 0x0f,0x31" :"=a" (low), "=d" (high));
+ num ^= low << 16;
r->entropy_count += 2;
- }
- else {
+ } else {
#endif
- outb(TIMER_MODE, TIMER_LATCH|TIMER_SEL0); /* latch ASAP */
+ disable_intr();
+ outb(TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
num ^= inb(TIMER_CNTR0) << 16;
num ^= inb(TIMER_CNTR0) << 24;
+ enable_intr();
r->entropy_count += 2;
-#if defined(I586_CPU)
- } /* cpu_class == CPUCLASS_586 */
+#if defined(I586_CPU) || defined(I686_CPU)
+ }
#endif
time = ticks;
@@ -242,6 +242,7 @@ add_interrupt_randomness(int irq)
add_timer_randomness(&random_state, &irq_timer_state[irq], irq);
}
+#ifdef notused
void
add_blkdev_randomness(int major)
{
@@ -251,6 +252,7 @@ add_blkdev_randomness(int major)
add_timer_randomness(&random_state, &blkdev_timer_state[major],
0x200+major);
}
+#endif /* notused */
/*
* MD5 transform algorithm, taken from code written by Colin Plumb,
@@ -432,6 +434,7 @@ extract_entropy(struct random_bucket *r, char *buf, int nbytes)
return ret;
}
+#ifdef notused /* XXX NOT the exported kernel interface */
/*
* This function is the exported kernel interface. It returns some
* number of good random numbers, suitable for seeding TCP sequence
@@ -442,6 +445,7 @@ get_random_bytes(void *buf, u_int nbytes)
{
extract_entropy(&random_state, (char *) buf, nbytes);
}
+#endif /* notused */
u_int
read_random(char *buf, u_int nbytes)
@@ -458,6 +462,7 @@ read_random_unlimited(char *buf, u_int nbytes)
return extract_entropy(&random_state, buf, nbytes);
}
+#ifdef notused
u_int
write_random(const char *buf, u_int nbytes)
{
@@ -475,3 +480,4 @@ write_random(const char *buf, u_int nbytes)
}
return nbytes;
}
+#endif /* notused */
diff --git a/sys/sys/random.h b/sys/sys/random.h
index 8e7b359..5fe7ffc 100644
--- a/sys/sys/random.h
+++ b/sys/sys/random.h
@@ -52,6 +52,7 @@
#if defined(KERNEL)
#include <i386/isa/icu.h>
+#include <i386/isa/isa_device.h>
#endif
#include <sys/ioctl.h>
@@ -71,12 +72,18 @@ extern int sec_intr_unit[ICU_LEN];
void rand_initialize(void);
void add_keyboard_randomness(u_char scancode);
void add_interrupt_randomness(int irq);
+#ifdef notused
void add_blkdev_randomness(int major);
+#endif
+#ifdef notused
void get_random_bytes(void *buf, u_int nbytes);
+#endif
u_int read_random(char *buf, u_int size);
u_int read_random_unlimited(char *buf, u_int size);
+#ifdef notused
u_int write_random(const char *buf, u_int nbytes);
+#endif
#endif
OpenPOWER on IntegriCloud