Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== SRFI 271 Random port libraries [[toc:]] === Description This library contains deterministic RNGs (and the system entropy source) wrapped in custom ports. This means that one can use the port IO procedures to read bytes from them. The deterministic RNGs have serializable state. RNGs can be seeded from other binary input ports. The algorithms (except for {{trivial}}) are written in C, so reading bulk pseudorandom data is fast. Benchmarks show a 100x speedup over writing the algorithms in Scheme. Available algorithms: #* {{(srfi 271)}}, {{(srfi 271 randomized)}}: Wrapper around {{random-bytes}} #* {{(srfi 271 determinized)}}, {{(srfi 271 determinized chacha20-fast-key-erasure-768)}}: Forward-secure crytpographic RNG #* {{(srfi 271 determinized chacha20)}}: Non-forward secure cryptographic RNG that allows for seeking to any 512 byte block for a given key #* {{(srfi 271 determinized splitmix64)}}: Non-cryptographic RNG with 64 bit state space, very fast, and can be seeded with any integer value. #* {{(srfi 271 determinized xoshiro256++)}}: Non-cryptographic RNG with 256 bit state space, nearly as fast as splitmix64, preferred over splitmix64 but has stronger requirements for seeds '''WARNING''': This package ships cryptographic RNGs. They are implemented by an amateur. '''Use at your own risk!''' === Author Peter McGoron === Repository https://codeberg.org/phm/srfi-271-egg === API The API description here will go from least complex to most complex. ==== Terminology A ''randomized'' port is one that returns difficult to guess random data. In this CHICKEN implementation, there is only one ''randomized'' port, which wraps the {{random-bytes}} procedure in {{(chicken random)}}. A ''determinized'' port is one that is completely characterized by a ''state'' that can be saved as a datum value and restored. These ports can also be seeded from other binary input ports. This allows one to use one algorithm to take a small amount of data (such as the current time) into a seed for an algorithm that requires a larger seed with better distribution properties. ==== {{(srfi 271)}} and {{(srfi 271 randomized)}} <procedure>(make-random-port)</procedure> Create a binary input port that outputs an infinite stream of difficult-to-guess random bytes. ==== Determinized port library schema Each determinized port library has the following identifiers exported from it: <procedure>(make-random-port [initializer])</procedure> Create a random port. If no {{initializer}} is given, then it defaults to a random port made from {{(make-random-port)}}: that is, it is seeded from a system entropy source. If {{initializer}} is given and it satisfies {{random-port-state?}}, then the port is initialized to that state. If {{initializer}} is a binary input port, then the procedure will draw data from the random port until it gets a sufficient amount of random data, and will initialize the state of the RNG based entirely off of this random data. If {{initializer}} is not a special value that the input port can accept, then the procedure will raise an exception. <procedure>(random-port-state port)</procedure> Returns the random port state from {{port}}. The procedure will raise an error if the port is not a port made with {{make-random-port}} from the same library. <procedure>(random-port-initialization-error? port)</procedure> Predicate for exceptions raised by the {{make-random-port}} exported from this library. ==== {{(srfi 271 determinized trivial)}} Repeats an input bytevector forever. The {{initializer}} can be any non-empty bytevector. The resulting input port will output the elements of the bytevector in sequence, and then start over. ==== {{(srfi 271 determinized splitmix64)}} An algorithm with a 64 bit state. The {{initializer}} can be any 64 bit integer. ==== {{(srfi 271 determinized xoshiro256++)}} An algorithm with a 256-bit state. The {{initializer}} can be a u64vector of 4 values, which must not all be zero. If they are, an exception is raised. If {{initializer}} is a binary input port, and the bytes that the initializer reads are all zeros, then the port is initialized to an arbitrary but fixed seed. ==== ChaCha 20 ChaCha20 is a stream cipher. For the purposes of random number generation, the state of ChaCha20 can be split up into two items *# The seed (256 bits) *# The counter (128 bits) (For the purposes of random number generation, the nonce is merged with the counter.) ChaCha20 transforms the seed and the counter into a 512 bit block. There are two ways to make a large stream of bytes using this method: increment the counter each block, or take part of the output and use it as a seed. ==== {{(srfi 271 determinized chacha20)}} The initializer can either be #* A vector of two elements: A seed (u32vector of 8 values) and a counter (u32vector of 4 values). The counter can be any values. #* A u32vector of 8 values (the ''seed''). These can be any values. This is equivalent to the first version, but with an all-zero counter. This is a non-forward-secure version of chacha20. It will emit bytes from sequences of 512 bit blocks with the same seed, but with the counter value increased by one each time. This means that one can seek to any block in the sequence started from an initial seed. ==== {{(srfi 271 determinized chacha20-fast-key-erasure-768)}} and {{(srfi 271 determinized)}} The initializer can be a u32vector of 8 values. This is a forward-secure version of chacha20. It works by: *# Generating 768 bytes of data from the current seed. *# Overwriting the seed with the first 256 bits and reset the counter to 0. *# Returning the rest as random data. This is the default determinized port. == Version History ; 0.2.0 : Bugfixes: write everything in C ; 0.1.0 : Initial Release === License All code: Copyright (C) Peter McGoron 2026 Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. SRFI text: © 2026 Wolfgang Corcoran-Mathe. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you multiply 2 by 7?