Coverage report: /home/ellis/comp/ext/ironclad/src/prng/os-prng.lisp

KindCoveredAll%
expression241 4.9
branch04 0.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;;; os-prng.lisp -- OS-provided pseudo-random number generator
2
 (in-package :crypto)
3
 
4
 #+unix
5
 (defparameter *os-prng-stream* nil)
6
 #+unix
7
 (defparameter *os-prng-stream-lock* (std:make-mutex))
8
 
9
 (defclass os-prng ()
10
   ())
11
 
12
 (defmethod prng-random-data (num-bytes (prng os-prng))
13
   #+unix
14
   (let* ((seq (make-array num-bytes :element-type '(unsigned-byte 8)))
15
          (n (sb-thread:with-mutex (*os-prng-stream-lock*)
16
               (unless (and *os-prng-stream* (open-stream-p *os-prng-stream*))
17
                 (setf *os-prng-stream* (open #P"/dev/urandom"
18
                                              :element-type '(unsigned-byte 8))))
19
               (read-sequence seq *os-prng-stream*))))
20
     (if (< n num-bytes)
21
         (error 'ironclad-error :format-control "Failed to get random data.")
22
         seq))
23
   #-unix
24
   (error 'ironclad-error
25
          :format-control "OS-RANDOM-SEED is not supported on your platform."))
26
 
27
 (defmethod make-prng ((name (eql :os)) &key seed)
28
   (declare (ignorable seed))
29
   (make-instance 'os-prng))
30
 
31
 (setf *prng* (make-prng :os))
32
 
33
 #+thread-support
34
 (pushnew '(*prng* . (make-prng :os)) std:*default-special-bindings* :test #'equal)