Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows seed initialization #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cl-isaac.asd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-ISAAC; Base: 10 -*-
;;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-ISAAC; Base: 10 -*-
;;;; file: cl-isaac.asd

;; Copyright (c) 2008 Doug Hoyte, HCSW
Expand All @@ -24,6 +24,7 @@
:author "Doug Hoyte <[email protected]>"
:maintainer "\"the Phoeron\" Colin J.E. Lupton <[email protected]>"
:license "BSD Simplified"
:depends-on (#:secure-random)
:components ((:file "packages")
(:file "isaac-32")
#+:x86-64 (:file "isaac-64")
Expand Down
12 changes: 11 additions & 1 deletion cl-isaac.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
;; Update Seed and Output functions to handle both 32 and 64 bit ISAAC algorithms

(defun init-kernel-seed (&key (is64 nil))
"Initialize Kernel seed from /dev/arandom on BSD systems, /dev/urandom on Linux systems, or return an error. If :is64 t, use ISAAC-64 context."
"Initialize Kernel seed from /dev/arandom on BSD systems, /dev/urandom on Linux systems, secure-random on Windows systems, or return an error. If :is64 t, use ISAAC-64 context."
(let ((ctx (if is64
(handler-case (make-isaac64-ctx) (error () nil))
(make-isaac-ctx))))
Expand All @@ -25,6 +25,10 @@
(with-open-file (r "/dev/urandom" :direction :input :element-type '(unsigned-byte 64))
#1#
t))
(ignore-errors
(loop for i from 0 below 256 do
(setf (aref (isaac64-ctx-randrsl ctx) i) (secure-random::octets-to-integer (secure-random:bytes 8 secure-random:*generator*))))
t)
(error "couldn't open /dev/arandom or /dev/urandom"))
(scramble64 ctx))
(progn
Expand All @@ -38,9 +42,15 @@
(with-open-file (r "/dev/urandom" :direction :input :element-type '(unsigned-byte 32))
#2#
t))
(ignore-errors
(loop for i from 0 below 256 do
(setf (aref (isaac-ctx-randrsl ctx) i) (secure-random::octets-to-integer (secure-random:bytes 4 secure-random:*generator*))))
t)
(error "couldn't open /dev/arandom or /dev/urandom"))
(scramble ctx)))))



(defun init-common-lisp-random-seed (&key (is64 nil))
"Initialize random seed from CL:RANDOM. If :is64 t, use ISAAC-64 context."
(let ((ctx (if is64
Expand Down