PHP Seed Spring: Generate 128 bit pseudo-random numbers

Recommend this page to a friend!
  Info   View files Documentation   View files View files (8)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-12-22 (3 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 26 All time: 10,183 This week: 342Up
Version License PHP version Categories
seedspring 1.0MIT/X Consortium ...7Cryptography, PHP 7
Description Author

This package can generate 128 bit pseudo-random numbers.

It can take a seed string of data and generates 128 bit random numbers.

The generated numbers may be returned as strings of bytes or integers that can be restricted to be withing a range of numbers given the initial and the end integer values of that range.

Picture of Scott Arciszewski
  Performance   Level  
Name: Scott Arciszewski <contact>
Classes: 28 packages by
Country: United States United States
Innovation award
Innovation award
Nominee: 21x

Winner: 1x

Details

seedspring

Build Status

Seeded, Deterministic PRNG (based on AES-CTR instead of LCG) (Requires PHP 7 or random_compat)

Security Warning

This is not meant to replace random_bytes(). Think of this as an improvement to srand() + rand(). Do not use this for security purposes.

Installing

composer require paragonie/seedspring

Usage

use \ParagonIE\SeedSpring\SeedSpring;

// For example
$sharedSeed = str_repeat("\x80", 16);

$rng = new SeedSpring($sharedSeed);

$data = $rng->getBytes(1024);
$int = $rng->getInt(1, 100);

Motivation

A cryptographically secure pseudorandom number generator, such as random_int(), is wonderful for security purposes. However, there are situations where you need to generate a deterministic, pseudorandom byte stream on two devices from a shared seed. (e.g. something like Minecraft's world generator).

PHP's native seedable (and insecure) RNGs, rand() and mt_rand(), only support a 32-bit integer seed, which severely limits the possible outputs. Our deterministic RNG supports up to 2^128 possible outputs, since it's based on a 128-bit block cipher.

Our implementation uses AES-128-CTR to turn a finite, 128-bit key into an practically endless stream of random bytes. (It will repeat after 2^132 bytes of output. You should consider rekeying after 2^66 bytes.)

  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Files folder imagetest (1 file)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file psalm.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Accessible without login Plain text file SeedSpring.php Class Class source

  Files folder image Files  /  test  
File Role Description
  Accessible without login Plain text file SeedSpringTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:26
This week:0
All time:10,183
This week:342Up

For more information send a message to info at phpclasses dot org.