<commit_before>;;;; -*- mode: lisp; indent-tabs-mode: nil -*-
;;;; os-prng.lisp -- OS-provided pseudo-random number generator

(in-package :crypto)

(defclass os-prng ()
  (#+unix source))

(defmethod prng-random-data (num-bytes (prng os-prng))
  #+unix
  (let ((seq (make-array num-bytes :element-type 'unsigned-byte)))
    (unless (slot-boundp prng 'source)
      (setf (slot-value prng 'source)
            (open #P"/dev/urandom" :element-type 'unsigned-byte)))
    (assert (>= (read-sequence seq (slot-value prng 'source)) num-bytes))
    seq)
  #+(and win32 sb-dynamic-core)(sb-win32:crypt-gen-random num-bytes)
  #+(and os-windows ccl) (multiple-value-bind (buff buffp)
                             (ccl:make-heap-ivector num-bytes '(unsigned-byte 8))
                           (when (= (ccl:external-call "SystemFunction036" :address buffp :unsigned-long num-bytes :boolean) 0)<commit_msg>Switch PRNG-RANDOM-DATA to (UNSIGNED-BYTE 8)<commit_after>;;;; -*- mode: lisp; indent-tabs-mode: nil -*-
;;;; os-prng.lisp -- OS-provided pseudo-random number generator

(in-package :crypto)

(defclass os-prng ()
  (#+unix source))

(defmethod prng-random-data (num-bytes (prng os-prng))
  #+unix
  (let ((seq (make-array num-bytes :element-type '(unsigned-byte 8))))
    (unless (slot-boundp prng 'source)
      (setf (slot-value prng 'source)
            (open #P"/dev/urandom" :element-type '(unsigned-byte 8))))
    (assert (>= (read-sequence seq (slot-value prng 'source)) num-bytes))
    seq)
  #+(and win32 sb-dynamic-core)(sb-win32:crypt-gen-random num-bytes)
  #+(and os-windows ccl) (multiple-value-bind (buff buffp)
                             (ccl:make-heap-ivector num-bytes '(unsigned-byte 8))
                           (when (= (ccl:external-call "SystemFunction036" :address buffp :unsigned-long num-bytes :boolean) 0)
{'fraction_non_alphanumeric': 0.1696672122204037, 'fraction_numerical': 0.011456628477905073, 'mean_word_length': 3.0219298245614037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7111394', 'n_tokens_mistral': 656, 'n_tokens_neox': 623, 'n_words': 147}