From 214bd23b80ed5b16e7f8cd7dc3c871c31c2cbc72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Wed, 25 Aug 1999 19:32:54 +0200 Subject: [PATCH] Added some doc. Fixed typo. Changed some macros into constants. Rev: lib/modules/Crypto/randomness.pmod:1.11 --- .gitattributes | 1 + lib/modules/Crypto/randomness.pmod | 48 +++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.gitattributes b/.gitattributes index de6c4d5f5b..c0bdd8e791 100644 --- a/.gitattributes +++ b/.gitattributes @@ -34,6 +34,7 @@ testfont binary /lib/modules/Crypto/des3_cbc.pike foreign_ident /lib/modules/Crypto/des_cbc.pike foreign_ident /lib/modules/Crypto/idea_cbc.pike foreign_ident +/lib/modules/Crypto/randomness.pmod foreign_ident /lib/modules/Crypto/rsa.pike foreign_ident /lib/modules/Filesystem.pmod/Tar.pmod foreign_ident /lib/modules/GLU.pmod foreign_ident diff --git a/lib/modules/Crypto/randomness.pmod b/lib/modules/Crypto/randomness.pmod index 969f217cfc..7a6f3e7a71 100644 --- a/lib/modules/Crypto/randomness.pmod +++ b/lib/modules/Crypto/randomness.pmod @@ -1,36 +1,44 @@ -/* randomness.pmod - * - * Assorted stronger or weaker randomnumber generators. +/* $Id: randomness.pmod,v 1.11 1999/08/25 17:32:54 grubba Exp $ */ +//! module Crypto +//! submodule randomness +//! Assorted stronger or weaker randomnumber generators. + /* These devices tries to collect entropy from the environment. * They differ in behaviour when they run low on entropy, /dev/random * will block if it can't provide enough random bits, while /dev/urandom * will degenerate into a reasonably strong pseudo random generator */ -#define RANDOM_DEVICE "/dev/random" -#define PRANDOM_DEVICE "/dev/urandom" +static constant RANDOM_DEVICE = "/dev/random"; +static constant PRANDOM_DEVICE = "/dev/urandom"; /* Collect somewhat random data from the environment. Unfortunately, * this is quite system dependent */ -#define PATH "/usr/sbin:/usr/etc:/usr/bin/:/sbin/:/etc:/bin" +static constant PATH = "/usr/sbin:/usr/etc:/usr/bin/:/sbin/:/etc:/bin"; #ifndef __NT__ -#define SYSTEM_COMMANDS ({ "last -256", "arp -a", \ - "netstat -anv","netstat -mv","netstat -sv", \ - "uptime","ps -fel","ps aux", \ - "vmstat -s","vmstat -M", \ - "iostat","iostat -cdDItx"}) +static constant SYSTEM_COMMANDS = ({ + "last -256", "arp -a", + "netstat -anv","netstat -mv","netstat -sv", + "uptime","ps -fel","ps aux", + "vmstat -s","vmstat -M", + "iostat","iostat -cdDItx" +}); #else -#define SYSTEM_COMMANDS ({ "mem /c", "arp -a", "vol", "dir", "net view", \ - "net statistics workstation","net statistics server", "net view" \ - "net user" }) +static constant SYSTEM_COMMANDS = ({ + "mem /c", "arp -a", "vol", "dir", "net view", + "net statistics workstation","net statistics server", + "net user" +}); #endif #define PRIVATE PRIVATE object global_rc4; +// method string some_entropy() +// Executes several programs to generate some entropy from their output. PRIVATE string some_entropy() { string res; @@ -67,7 +75,11 @@ PRIVATE string some_entropy() } +//! class pike_random +//! A pseudo random generator based on the ordinary random() function. class pike_random { + //! method string read(int len) + //! Returns a string of length len with pseudo random values. string read(int len) { if (len > 16384) return read(len/2)+read(len-len/2); @@ -75,9 +87,13 @@ class pike_random { } } +//! class rc4_random +//! A pseudo random generator based on the rc4 crypto. class rc4_random { inherit Crypto.rc4 : rc4; + //! method void create(string secret) + //! Initialize and seed the rc4 random generator. void create(string secret) { object hash = Crypto.sha(); @@ -86,6 +102,9 @@ class rc4_random { rc4::set_encrypt_key(hash->digest()); } + //! method string read(int len) + //! Return a string of the next len random characters from the + //! rc4 random generator. string read(int len) { if (len > 16384) return read(len/2)+read(len-len/2); @@ -93,6 +112,7 @@ class rc4_random { } } + object reasonably_random() { if (file_stat(PRANDOM_DEVICE)) -- GitLab