From 1c405ec4d169c4539863149f96693b8c0d4f523c Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Tue, 11 Apr 2000 03:46:57 +0000 Subject: [PATCH] Define RANDOM-BYTE-VECTOR to generate random bytes. This is useful for cryptographic applications that don't require an RNG with cryptographic properties, e.g. to generate an init vector or to salt a password. --- v7/src/runtime/random.scm | 12 ++++++++++-- v7/src/runtime/runtime.pkg | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/v7/src/runtime/random.scm b/v7/src/runtime/random.scm index 967f31c1b..d30afcf82 100644 --- a/v7/src/runtime/random.scm +++ b/v7/src/runtime/random.scm @@ -1,8 +1,8 @@ #| -*-Scheme-*- -$Id: random.scm,v 14.22 1999/08/09 19:33:44 cph Exp $ +$Id: random.scm,v 14.23 2000/04/11 03:46:50 cph Exp $ -Copyright (c) 1993-1999 Massachusetts Institute of Technology +Copyright (c) 1993-2000 Massachusetts Institute of Technology This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -86,6 +86,14 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (fix:+ index 1)))) (set-interrupt-enables! mask) (flo:/ element b.))))) + +(define (random-byte-vector n #!optional state) + (let ((state (if (default-object? state) #f state)) + (s (make-string n))) + (do ((i 0 (fix:+ i 1))) + ((fix:= i n)) + (vector-8b-set! s i (random 256 state))) + s)) (define (make-random-state #!optional state) (let ((state (if (default-object? state) #f state))) diff --git a/v7/src/runtime/runtime.pkg b/v7/src/runtime/runtime.pkg index 589953f06..89777debb 100644 --- a/v7/src/runtime/runtime.pkg +++ b/v7/src/runtime/runtime.pkg @@ -1,6 +1,6 @@ #| -*-Scheme-*- -$Id: runtime.pkg,v 14.342 2000/04/10 19:01:31 cph Exp $ +$Id: runtime.pkg,v 14.343 2000/04/11 03:46:57 cph Exp $ Copyright (c) 1988-2000 Massachusetts Institute of Technology @@ -1950,6 +1950,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. flo:random-unit make-random-state random + random-byte-vector random-state?) (initialization (initialize-package!))) -- 2.25.1