Get the basic random number generator functions to compile
authorRonald G. Minnich <rminnich@gmail.com>
Thu, 4 Feb 2016 02:48:37 +0000 (18:48 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 4 Feb 2016 19:56:13 +0000 (14:56 -0500)
Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/include/random/fortuna.h [new file with mode: 0644]
kern/lib/Kbuild
kern/lib/random/Kbuild [new file with mode: 0644]
kern/lib/random/fortuna.c
kern/lib/random/rijndael.c
kern/lib/random/sha2.c

diff --git a/kern/include/random/fortuna.h b/kern/include/random/fortuna.h
new file mode 100644 (file)
index 0000000..5060943
--- /dev/null
@@ -0,0 +1,3 @@
+
+void fortuna_add_entropy(const uint8_t *data, unsigned len);
+void fortuna_get_bytes(unsigned len, uint8_t *dst);
index 6d332bb..645b58f 100644 (file)
@@ -4,3 +4,4 @@ obj-y                                           += slice.o
 obj-y                                          += sort.o
 obj-y                                          += zlib_deflate/
 obj-y                                          += zlib_inflate/
+obj-y                                          += random/
diff --git a/kern/lib/random/Kbuild b/kern/lib/random/Kbuild
new file mode 100644 (file)
index 0000000..8581ea8
--- /dev/null
@@ -0,0 +1,4 @@
+obj-y                                          += fortuna.o
+obj-y                                          += rijndael.o
+obj-y                                          += sha2.o
+
index ab54c99..90c86cf 100644 (file)
  * contrib/pgcrypto/fortuna.c
  */
 
-#include <u.h>
-#include <rijndael.h>
-#include <sha2.h>
+#include <arch/arch.h>
+#include <time.h>
+
+#include <random/fortuna.h>
+#include <random/rijndael.h>
+#include <random/sha2.h>
 
-#include "../port/lib.h"
-#include "mem.h"
-#include "dat.h"
-#include "fns.h"
 
 /*
  * Why Fortuna-like: There does not seem to be any definitive reference
@@ -210,7 +209,7 @@ static int enough_time_passed(FState *st)
        int32_t now;
        int32_t last = st->lastReseedTime;
 
-       now = seconds();
+       now = tsc2sec(read_tsc());
 
        /* check how much time has passed */
        ok = 0;
index f65261d..144ec61 100644 (file)
@@ -39,10 +39,8 @@ Decrypt:        498 cycles =    51.4 mbits/sec
 Mean:             500 cycles =    51.2 mbits/sec
 
 */
-#include <u.h>
-#include <libc.h>
 
-#include "rijndael.h"
+#include <random/rijndael.h>
 
 #include "rijndael.tbl"
 
index d22603f..ebd1556 100644 (file)
@@ -36,9 +36,7 @@
  * contrib/pgcrypto/sha2.c
  */
 
-#include "u.h"
-#include <libc.h>
-#include "sha2.h"
+#include <random/sha2.h>
 
 /*** SHA-256/512 Various Length Definitions ***********************/
 enum {
@@ -172,7 +170,7 @@ static const uint64_t sha512_initial_hash_value[8] = {
 /*** SHA-256: *********************************************************/
 void SHA256_Init(SHA256Ctx *context)
 {
-       if (context == nil)
+       if (context == NULL)
                return;
        memmove(context->state, sha256_initial_hash_value, SHA256DigestLength);
        memset(context->buffer, 0, SHA256BlockLength);
@@ -340,7 +338,7 @@ static void SHA256_Last(SHA256Ctx *context)
 void SHA256_Final(uint8_t digest[], SHA256Ctx *context)
 {
        /* If no digest buffer is passed, we don't bother doing this: */
-       if (digest != nil) {
+       if (digest != NULL) {
                SHA256_Last(context);
 
                memmove(digest, context->state, SHA256DigestLength);
@@ -353,7 +351,7 @@ void SHA256_Final(uint8_t digest[], SHA256Ctx *context)
 /*** SHA-512: *********************************************************/
 void SHA512_Init(SHA512Ctx *context)
 {
-       if (context == nil)
+       if (context == NULL)
                return;
        memmove(context->state, sha512_initial_hash_value, SHA512DigestLength);
        memset(context->buffer, 0, SHA512_block_length);
@@ -525,7 +523,7 @@ static void SHA512_Last(SHA512Ctx *context)
 void SHA512_Final(uint8_t digest[], SHA512Ctx *context)
 {
        /* If no digest buffer is passed, we don't bother doing this: */
-       if (digest != nil) {
+       if (digest != NULL) {
                SHA512_Last(context);
 
                /* Save the hash data for output: */
@@ -539,7 +537,7 @@ void SHA512_Final(uint8_t digest[], SHA512Ctx *context)
 /*** SHA-384: *********************************************************/
 void SHA384_Init(SHA384Ctx *context)
 {
-       if (context == nil)
+       if (context == NULL)
                return;
        memmove(context->state, sha384_initial_hash_value, SHA512DigestLength);
        memset(context->buffer, 0, SHA384BlockLength);
@@ -554,7 +552,7 @@ void SHA384_Update(SHA384Ctx *context, const uint8_t *data, size_t len)
 void SHA384_Final(uint8_t digest[], SHA384Ctx *context)
 {
        /* If no digest buffer is passed, we don't bother doing this: */
-       if (digest != nil) {
+       if (digest != NULL) {
                SHA512_Last((SHA512Ctx *)context);
 
                /* Save the hash data for output: */
@@ -568,7 +566,7 @@ void SHA384_Final(uint8_t digest[], SHA384Ctx *context)
 /*** SHA-224: *********************************************************/
 void SHA224_Init(SHA224Ctx *context)
 {
-       if (context == nil)
+       if (context == NULL)
                return;
        memmove(context->state, sha224_initial_hash_value, SHA256DigestLength);
        memset(context->buffer, 0, SHA256BlockLength);
@@ -583,7 +581,7 @@ void SHA224_Update(SHA224Ctx *context, const uint8_t *data, size_t len)
 void SHA224_Final(uint8_t digest[], SHA224Ctx *context)
 {
        /* If no digest buffer is passed, we don't bother doing this: */
-       if (digest != nil) {
+       if (digest != NULL) {
                SHA256_Last(context);
 
                memmove(digest, context->state, SHA224DigestLength);