Bytes-Random-Secure-0.28/0000755000175000017500000000000012243457720014477 5ustar davidodavidoBytes-Random-Secure-0.28/README0000644000175000017500000000322412112053716015350 0ustar davidodavidoBytes::Random::Secure Generate strings of cryptographic-quality pseudo-random bytes as a string of raw bytes, hex digits, MIME Base64, MIME QuotedPrintable, or just long ints. CONFIGURATION If you require better performance, install Math::Random::ISAAC::XS. It will be automatically detected, and will provide better performance as you generate random bytes. INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install Or preferably, let your favorite CPAN installer do the work for you. Users are encouraged to use a fairly modern version of their CPAN installer, particularly if building this distribution on Perl versions that preceed Perl 5.8.9. SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc Bytes::Random::Secure You can also look for information at: Github Repository https://github.com/daoswald/Bytes-Random-Secure.git RT, CPAN's request tracker (report bugs here) http://rt.cpan.org/NoAuth/Bugs.html?Dist=Bytes-Random-Secure AnnoCPAN, Annotated CPAN documentation http://annocpan.org/dist/Bytes-Random-Secure CPAN Ratings http://cpanratings.perl.org/d/Bytes-Random-Secure Search CPAN http://search.cpan.org/dist/Bytes-Random-Secure/ LICENSE AND COPYRIGHT Copyright (C) 2012 David Oswald This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. Bytes-Random-Secure-0.28/META.yml0000644000175000017500000000126312243457720015752 0ustar davidodavido--- abstract: 'Perl extension to generate cryptographically-secure random bytes.' author: - 'David Oswald ' build_requires: Test::More: 0.98 configure_requires: ExtUtils::MakeMaker: 6.56 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.78, CPAN::Meta::Converter version 2.132140' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Bytes-Random-Secure no_index: directory: - t - inc requires: Carp: 0 Crypt::Random::Seed: 0 MIME::Base64: 0 MIME::QuotedPrint: 3.03 Math::Random::ISAAC: 0 Scalar::Util: 1.21 perl: 5.006000 resources: Metaspec: version: 2 version: 0.28 Bytes-Random-Secure-0.28/lib/0000755000175000017500000000000012243457720015245 5ustar davidodavidoBytes-Random-Secure-0.28/lib/Bytes/0000755000175000017500000000000012243457720016333 5ustar davidodavidoBytes-Random-Secure-0.28/lib/Bytes/Random/0000755000175000017500000000000012243457720017553 5ustar davidodavidoBytes-Random-Secure-0.28/lib/Bytes/Random/Secure.pm0000644000175000017500000010277412243456751021355 0ustar davidodavido## no critic (constant,unpack) package Bytes::Random::Secure; use strict; use warnings; use 5.006000; use Carp; use Scalar::Util qw( looks_like_number ); use Math::Random::ISAAC; use Crypt::Random::Seed; use MIME::Base64 'encode_base64'; use MIME::QuotedPrint 'encode_qp'; use Exporter; our @ISA = qw( Exporter ); our @EXPORT_OK = qw( random_bytes random_bytes_hex random_bytes_base64 random_bytes_qp random_string_from ); our @EXPORT = qw( random_bytes ); ## no critic(export) our $VERSION = '0.28'; # Seed size: 256 bits is eight 32-bit integers. use constant SEED_SIZE => 256; # In bits use constant SEED_MIN => 64; use constant SEED_MAX => 8192; use constant PRNG => 'ISAAC'; use constant OO_ATTRIBS => { Weak => 0, # Boolean. (0) Crypt::Random::Seed NonBlocking => 0, # Boolean. (0) Crypt::Random::Seed Only => undef, # Aref of strings. Crypt::Random::Seed Never => undef, # Aref of strings. Crypt::Random::Seed Source => undef, # Subref or ARef. Crypt::Random::Seed PRNG => PRNG, # String. Alt RNG. Internal (ISAAC) Bits => SEED_SIZE, # Seed 64 <= Bits <= 8192. Internal (256) }; # Function interface seed attributes (standard, and lite). use constant FUNC_STD => { Weak => 0, NonBlocking => 0, Bits => SEED_SIZE, }; use constant CRYPT_RANDOM_SEED_OPTS => [ qw( Weak NonBlocking Only Never Source ) ]; ################################################################################ # OO interface class/object methods: ## ################################################################################ # Constructor sub new { my ( $class, @config ) = @_; my $self = bless {}, $class; my $args_href = $self->_build_args(@config); $self->_build_attributes($args_href); return $self; } sub _build_args { my ( $self, @args ) = @_; @args = %{ $args[0] } if ref $args[0] eq 'HASH'; croak "Illegal argument list; key => value pairs expected." if @args % 2; my %args = $self->_validate_args( OO_ATTRIBS, @args ); if ( exists $args{Bits} ) { $args{Bits} = $self->_round_bits_to_ge_32( $args{Bits} ); $args{Bits} = $self->_constrain_bits( $args{Bits}, SEED_MIN, SEED_MAX ); } return \%args; } # _build_args() helpers: # Verify drop illegal or 'undef' args. sub _validate_args { my( $self, $legal_args_href, %args ) = @_; # Iterate through input args. while( my ( $arg_key, $arg_value ) = each %args ) { # Disqualify if not in white list. if( ! exists $legal_args_href->{$arg_key} ) { carp "Illegal argument ($arg_key) will be ignored."; delete $args{$arg_key}; next; } # Disqualify if undef passed. if( ! defined $arg_value ) { carp "Undefined value specified for attribute ($arg_key). " . "Attribute will be ignored."; delete $args{$arg_key}; } } return %args; } # Round bits parameter to nearest greater or equal 32-bit "long". sub _round_bits_to_ge_32 { my( $self, $bits ) = @_; my $remainder = $bits % 32; return $bits if $remainder == 0; carp "Bits field must be a multiple of 32. Rounding up."; return $bits + 32 - $remainder; } # Constrain bits argument to a reasonable range. sub _constrain_bits { my( $self, $bits, $min, $max ) = @_; if( $bits < $min ) { carp "Bits field must be >= 64 (two longs). Rounding up."; $bits = $min; } elsif( $bits > $max ) { carp "Bits field must be <= 8192 (256 longs). Rounding down."; $bits = $max; } # No need for an 'else' here. return $bits; } # Build attributes set by new(). Any not explicitly set will use defaults # as described in the constant OO_ATTRIBS. sub _build_attributes { my ( $self, $args ) = @_; while ( my ( $arg, $default ) = each %{ OO_ATTRIBS() } ) { $self->{$arg} = exists $args->{$arg} ? $args->{$arg} : $default; } $self->{_RNG} = undef; # Lazy initialization. return $self; } # Get a seed and use it to instantiate a RNG. # Note: Currently we specify only Math::Random::ISAAC. However, the PRNG # object attribute may be used in the future to specify alternate RNG's. sub _instantiate_rng { my $self = shift; my ( %seed_opts ) = $self->_build_seed_options; my @seeds = $self->_generate_seed( %seed_opts ); $self->{_RNG} = Math::Random::ISAAC->new(@seeds); return $self->{_RNG}; } # Set up seed options for Crypt::Random::Seed sub _build_seed_options { my( $self ) = @_; my %crs_opts; # CRYPT_RANDOM_SEED_OPTS enumerates the options that Crypt::Random::Seed # supports. We have already built object attributes for those options. foreach my $opt ( @{ CRYPT_RANDOM_SEED_OPTS() } ) { $crs_opts{$opt} = $self->{$opt} if defined $self->{$opt}; } return %crs_opts; } # Use Crypt::Random::Seed to generate some high-quality long int # seeds for Math::Random::ISAAC. sub _generate_seed { my ( $self, %options_hash ) = @_; my $seed_size = $self->{Bits} / 32; my $source = Crypt::Random::Seed->new(%options_hash); croak 'Unable to obtain a strong seed source from Crypt::Random::Seed.' unless defined $source; return $source->random_values($seed_size); # List of unsigned longs. } # Validate that we are getting an integer >= 0. # If not, throw an exception. sub _validate_int { my( $self, $input ) = @_; croak "Byte count must be a positive integer." unless looks_like_number( $input ) && $input == int( $input ) && $input >= 0; return 1; } # Random bytes string. sub bytes { my( $self, $bytes ) = @_; $bytes = defined $bytes ? $bytes : 0; # Default to zero bytes. $self->_validate_int( $bytes ); # Throws on violation. $self->_instantiate_rng unless defined $self->{_RNG}; my $str = ''; while ( $bytes >= 4 ) { # Utilize irand()'s 32 bits. $str .= pack( "L", $self->{_RNG}->irand ); $bytes -= 4; } if ( $bytes > 0 ) { my $rval = $self->{_RNG}->irand; $str .= pack( "S", ( $rval >> 8 ) & 0xFFFF ) if $bytes >= 2; # 16 bits. $str .= pack( "C", $rval & 0xFF ) if $bytes % 2; # 8 bits. } return $str; } # Base64 encoding of random byte string. sub bytes_base64 { my ( $self, $bytes, $eol ) = @_; return encode_base64( $self->bytes($bytes), defined($eol) ? $eol : qq{\n} ); } # Hex digits representing random byte string (No whitespace, no '0x'). sub bytes_hex { my ( $self, $bytes ) = @_; return unpack 'H*', $self->bytes($bytes); } # Quoted Printable representation of random byte string. sub bytes_qp { my ( $self, $bytes, $eol ) = @_; return encode_qp $self->bytes($bytes), defined($eol) ? $eol : qq{\n}, 1; } sub string_from { my( $self, $bag, $bytes ) = @_; $bag = defined $bag ? $bag : ''; $bytes = defined $bytes ? $bytes : 0; my $range = length $bag; $self->_validate_int( $bytes ); croak "Bag's size must be at least 1 character." if $range < 1; my $rand_bytes = q{}; # We need an empty (and defined) string. for my $random ( $self->_ranged_randoms( $range, $bytes ) ) { $rand_bytes .= substr( $bag, $random, 1 ); } return $rand_bytes; } # Helpers for string_from() sub _ranged_randoms { my ( $self, $range, $count ) = @_; $count = defined $count ? $count : 0; # Lazily seed the RNG so we don't waste available strong entropy. $self->_instantiate_rng unless defined $self->{_RNG}; my $divisor = $self->_closest_divisor($range); my @randoms; $#randoms = $count - 1; # Pre-extend the @randoms array so 'push' avoids # copy on resize. @randoms = (); # Then purge it, but its memory won't be released. for my $n ( 1 .. $count ) { my $random; # The loop rolls, and re-rolls if the random number is out of the bag's # range. This is to avoid a solution that would introduce modulo bias. do { $random = $self->{_RNG}->irand % $divisor; } while ( $random >= $range ); push @randoms, $random; } return @randoms; } # Find nearest factor of 2**32 >= $range. sub _closest_divisor { my ( $self, $range ) = @_; $range = defined $range ? $range : 0; croak "$range must be positive." if $range < 0; croak "$range exceeds irand max limit of 2**32." if $range > 2**32; my $n = 0; my $d; while ( $n <= 32 ) { $d = 2 ** $n++; last if $d >= $range; } return $d; } # irand, so that people who don't need "bytes" can enjoy B::R::S's convenience # without jumping through "unpack" hoops. (A suggestion from Dana Jacobsen.) sub irand { my( $self ) = @_; $self->_instantiate_rng unless defined $self->{_RNG}; return $self->{_RNG}->irand; } ################################################################################ ## Functions interface ## ################################################################################ # Instantiate our random number generator(s) inside of a lexical closure, # limiting the scope of the RNG object so it can't be tampered with. { my $RNG_object = undef; # Lazily, instantiate the RNG object, but only once. my $fetch_RNG = sub { $RNG_object = Bytes::Random::Secure->new( FUNC_STD ) unless defined $RNG_object; return $RNG_object; }; sub random_bytes { return $fetch_RNG->()->bytes( @_ ); } sub random_string_from { return $fetch_RNG->()->string_from( @_ ); } } # Base64 encoded random bytes functions sub random_bytes_base64 { my ( $bytes, $eof ) = @_; return encode_base64 random_bytes($bytes), defined($eof) ? $eof : qq{\n}; } # Hex digit encoded random bytes sub random_bytes_hex { return unpack 'H*', random_bytes( shift ); } # Quoted Printable encoded random bytes sub random_bytes_qp { my ( $bytes, $eof ) = @_; return encode_qp random_bytes($bytes), defined($eof) ? $eof : qq{\n}, 1; } 1; =pod =head1 NAME Bytes::Random::Secure - Perl extension to generate cryptographically-secure random bytes. =head1 SYNOPSIS use Bytes::Random::Secure qw( random_bytes random_bytes_base64 random_bytes_hex ); my $bytes = random_bytes(32); # A string of 32 random bytes. my $bytes = random_string_from( 'abcde', 10 ); # 10 random a,b,c,d, and e's. my $bytes_as_base64 = random_bytes_base64(57); # Base64 encoded rand bytes. my $bytes_as_hex = random_bytes_hex(8); # Eight random bytes as hex digits. my $bytes_as_quoted_printable = random_bytes_qp(100); # QP encoded bytes. my $random = Bytes::Random::Secure->new( Bits => 64, NonBlocking => 1, ); # Seed with 64 bits, and use /dev/urandom (or other non-blocking). my $bytes = $random->bytes(32); # A string of 32 random bytes. my $long = $random->irand; # 32-bit random integer. =head1 DESCRIPTION L provides two interfaces for obtaining crypto-quality random bytes. The simple interface is built around plain functions. For greater control over the Random Number Generator's seeding, there is an Object Oriented interface that provides much more flexibility. The "functions" interface provides functions that can be used any time you need a string of a specific number of random bytes. The random bytes are available as simple strings, or as hex-digits, Quoted Printable, or MIME Base64. There are equivalent methods available from the OO interface, plus a few others. This module can be a drop-in replacement for L, with the primary enhancement of using a cryptographic-quality random number generator to create the random data. The C function emulates the user interface of L's function by the same name. But with Bytes::Random::Secure the random number generator comes from L, and is suitable for cryptographic purposes. The harder problem to solve is how to seed the generator. This module uses L to generate the initial seeds for Math::Random::ISAAC. In addition to providing C, this module also provides several functions not found in L: C, C, C, and C. And finally, for those who need finer control over how L generates its seed, there is an object oriented interface with a constructor that facilitates configuring the seeding process, while providing methods that do everything the "functions" interface can do (truth be told, the functions interface is just a thin wrapper around the OO version, with some sane defaults selected). The OO interface also provides an C method, not available through the functions interface. =head1 RATIONALE There are many uses for cryptographic quality randomness. This module aims to provide a generalized tool that can fit into many applications while providing a minimal dependency chain, and a user interface that is simple. You're free to come up with your own use-cases, but there are several obvious ones: =over 4 =item * Creating temporary passphrases (C). =item * Generating per-account random salt to be hashed along with passphrases (and stored alongside them) to prevent rainbow table attacks. =item * Generating a secret that can be hashed along with a cookie's session content to prevent cookie forgeries. =item * Building raw cryptographic-quality pseudo-random data sets for testing or sampling. =item * Feeding secure key-gen utilities. =back Why use this module? This module employs several well-designed CPAN tools to first generate a strong random seed, and then to instantiate a high quality random number generator based on the seed. The code in this module really just glues together the building blocks. However, it has taken a good deal of research to come up with what I feel is a strong tool-chain that isn't going to fall back to a weak state on some systems. The interface is designed with simplicity in mind, to minimize the potential for misconfiguration. =head1 EXPORTS By default C is the only function exported. Optionally C, C, C, and C may be exported. =head1 FUNCTIONS The B seeds the ISAAC generator on first use with a 256 bit seed that uses Crypt::Random::Seed's default configuration as a strong random seed source. =head2 random_bytes my $random_bytes = random_bytes( 512 ); Returns a string containing as many random bytes as requested. Obviously the string isn't useful for display, as it can contain any byte value from 0 through 255. The parameter is a byte-count, and must be an integer greater or equal to zero. =head2 random_string_from my $random_bytes = random_string_from( $bag, $length ); my $random_bytes = random_string_from( 'abc', 50 ); C<$bag> is a string of characters from which C may choose in building a random string. We call it a 'bag', because it's permissible to have repeated chars in the bag (if not, we could call it a set). Repeated digits get more weight. For example, C would have a 66.67% chance of returning an 'a', and a 33.33% chance of returning a 'b'. For unweighted distribution, ensure there are no duplicates in C<$bag>. This I a "draw and discard", or a permutation algorithm; each character selected is independent of previous or subsequent selections; duplicate selections are possible by design. Return value is a string of size C<$length>, of characters chosen at random from the 'bag' string. It is perfectly legal to pass a Unicode string as the "bag", and in that case, the yield will include Unicode characters selected from those passed in via the bag string. This function is useful for random string generation such as temporary random passwords. =head2 random_bytes_base64 my $random_bytes_b64 = random_bytes_base64( $num_bytes ); my $random_bytes_b64_formatted = random_bytes_base64( $num_bytes, $eol ); Returns a MIME Base64 encoding of a string of $number_of_bytes random bytes. Note, it should be obvious, but is worth mentioning that a base64 encoding of base256 data requires more digits to represent the bytes requested. The actual number of digits required, including padding is C<4(n/3)>. Furthermore, the Base64 standard is to add padding to the end of any string for which C is a non-zero value. If an C<$eol> is specified, the character(s) specified will be used as line delimiters after every 76th character. The default is C. If you wish to eliminate line-break insertions, specify an empty string: C. =head2 random_bytes_hex my $random_bytes_as_hex = random_bytes_hex( $num_bytes ); Returns a string of hex digits representing the string of $number_of_bytes random bytes. It's worth mentioning that a hex (base16) representation of base256 data requires two digits for every byte requested. So C will return 32, as it takes 32 hex digits to represent 16 bytes. Simple stuff, but better to mention it now than forget and set a database field that's too narrow. =head2 random_bytes_qp my $random_bytes_qp = random_bytes_qp( $num_bytes ); my $random_bytes_qp_formatted = random_bytes_qp( $num_bytes, $eol ); Produces a string of C<$num_bytes> random bytes, using MIME Quoted Printable encoding (as produced by L's C function. The default configuration uses C<\n> as a line break after every 76 characters, and the "binmode" setting is used to guarantee a lossless round trip. If no line break is wanted, pass an empty string as C<$eol>. =head1 METHODS The B provides methods that mirror the "functions" interface. However, the OO interface offers the advantage that the user can control how many bits of entropy are used in seeding, and even how L is configured. =head2 new my $random = Bytes::Random::Secure->new( Bits => 512 ); my $bytes = $random->bytes( 32 ); The constructor is used to specify how the ISAAC generator is seeded. Future versions may also allow for alternate CSPRNGs to be selected. If no parameters are passed the default configuration specifies 256 bits for the seed. The rest of the default configuration accepts the L defaults, which favor the strongest operating system provided entropy source, which in many cases may be "blocking". =head3 CONSTRUCTOR PARAMETERS =head4 Bits my $random = Bytes::Random::Secure->new( Bits => 128 ); The C parameter specifies how many bits (rounded up to nearest multiple of 32) will be used in seeding the ISAAC random number generator. The default is 256 bits of entropy. But in some cases it may not be necessary, or even wise to pull so many bits of entropy out of C (a blocking source). Any value between 64 and 8192 will be accepted. If an out-of-range value is specified, or a value that is not a multiple of 32, a warning will be generated and the parameter will be rounded up to the nearest multiple of 32 within the range of 64 through 8192 bits. So if 16384 is specified, you will get 8192. If 33 is specified, you will get 64. B In the Perlish spirit of "I", the maximum number of bits this module accepts is 8192, which is the maximum number that ISAAC can utilize. But just because you I specify a seed of 8192 bits doesn't mean you ought to, much less need to. And if you do, you probably want to use the C option, discussed below. 8192 bits is a lot to ask from a blocking source such as C, and really anything beyond 512 bits in the seed is probably wasteful. =head4 PRNG Reserved for future use. Eventually the user will be able to select other RNGs aside from Math::Random::ISAAC. =head4 Unique Reserved for future use. =head4 Other Crypt::Random::Seed Configuration Parameters For additional seeding control, refer to the POD for L. By supplying a Crypt::Random::Seed parameter to Bytes::Random::Secure's constructor, it will be passed through to Crypt::Random::Seed. For example: my $random = Bytes::Random::Secure->new( NonBlocking => 1, Bits => 64 ); In this example, C is used internally, while C is passed through to Crypt::Random::Seed. =head2 bytes my $random_bytes = $random->bytes(1024); This works just like the C function. =head2 string_from my $random_string = $random->string_from( 'abcdefg', 10 ); Just like C: Returns a string of random octets selected from the "Bag" string (in this case ten octets from 'abcdefg'). =head2 bytes_hex my $random_hex = $random->bytes_hex(12); Identical in function to C. =head2 bytes_base64 my $random_base64 = $random->bytes_base64( 32, EOL => "\n" ); Identical in function to C. =head2 bytes_qp my $random_qp = $random->bytes_qp( 80 ); You guessed it: Identical in function to C. =head2 irand my $unsigned_long = $random->irand; Returns a random 32-bit unsigned integer. The value will satisfy C<< 0 <= x <= 2**32-1 >>. This functionality is only available through the OO interface. =head1 CONFIGURATION L's interface tries to I. There is generally nothing to configure. This design, eliminates much of the potential for diminishing the quality of the random byte stream through misconfiguration. The ISAAC algorithm is used as our factory, seeded with a strong source. There may be times when the default seed characteristics carry too heavy a burden on system resources. The default seed for the functions interface is 256 bits of entropy taken from /dev/random (a blocking source on many systems), or via API calls on Windows. The default seed size for the OO interface is also 256 bits. If /dev/random should become depleted at the time that this module attempts to seed the ISAAC generator, there could be delay while additional system entropy is generated. If this is a problem, it is possible to override the default seeding characteristics using the OO interface instead of the functions interface. However, under most circumstances, this capability may be safely ignored. Beginning with Bytes::Random::Secure version 0.20, L provides our strong seed (previously it was Crypt::Random::Source). This module gives us excellent "strong source" failsafe behavior, while keeping the non-core dependencies to a bare minimum. Best of all, it performs well across a wide variety of platforms, and is compatible with Perl versions back through 5.6.0. And as mentioned earlier in this document, there may be circumstances where the performance of the operating system's strong random source is prohibitive from using the module's default seeding configuration. Use the OO interface instead, and read the documentation for L to learn what options are available. Prior to version 0.20, a heavy dependency chain was required for reliably and securely seeding the ISAAC generator. Earlier versions required L, which in turn required L. Thanks to Dana Jacobsen's new Crypt::Random::Seed module, this situation has been resolved. So if you're looking for a secure random bytes solution that "just works" portably, and on Perl versions as far back as 5.6.0, you've come to the right place. Users of older versions of this module are encouraged to update to version 0.20 or higher to benefit from the improved user interface and lighter dependency chain. =head2 OPTIONAL (RECOMMENDED) DEPENDENCY If performance is a consideration, you may also install L. Bytes::Random::Secure's random number generator uses L. That module implements the ISAAC algorithm in pure Perl. However, if you install L, you get the same algorithm implemented in C/XS, which will provide better performance. If you need to produce your random bytes more quickly, simply installing Math::Random::ISAAC::XS will result in it automatically being used, and a pretty good performance improvement will coincide. =head1 CAVEATS =head2 FORK AND THREAD SAFETY When programming for parallel computation, avoid the "functions" interface B use the Object Oriented interface, and create a unique C object within each process or thread. Bytes::Random::Secure uses a CSPRNG, and sharing the same RNG between threads or processes will share the same seed and the same starting point. This is probably not what one would want to do. By instantiating the B::R::S object after forking or creating threads, a unique randomness stream will be created per thread or process. =head2 STRONG RANDOMNESS It's easy to generate weak pseudo-random bytes. It's also easy to think you're generating strong pseudo-random bytes when really you're not. And it's hard to test for pseudo-random cryptographic acceptable quality. There are many high quality random number generators that are suitable for statistical purposes, but not necessarily up to the rigors of cryptographic use. Assuring strong (ie, secure) random bytes in a way that works across a wide variety of platforms is also challenging. A primary goal for this module is to provide cryptographically secure pseudo-random bytes. A secondary goal is to provide a simple user experience (thus reducing the propensity for getting it wrong). A tertiary goal is to minimize the dependencies required to achieve the primary and secondary goals, to the extent that is practical. =head2 ISAAC The ISAAC algorithm is considered to be a cryptographically strong pseudo-random number generator. There are 1.0e2466 initial states. The best known attack for discovering initial state would theoretically take a complexity of approximately 4.67e1240, which has no practical impact on ISAAC's security. Cycles are guaranteed to have a minimum length of 2**40, with an average cycle of 2**8295. Because there is no practical attack capable of discovering initial state, and because the average cycle is so long, it's generally unnecessary to re-seed a running application. The results are uniformly distributed, unbiased, and unpredictable unless the seed is known. To confirm the quality of the CSPRNG, this module's test suite implements the L tests for strong random number generators. See the comments in C for details. =head2 DEPENDENCIES To keep the dependencies as light as possible this module uses some ideas from L. That module is an excellent resource, but implements a broader range of functionality than is needed here. So we just borrowed from it. The primary source of random data in this module comes from the excellent L. To be useful and secure, even Math::Random::ISAAC needs a cryptographically sound seed, which we derive from L. There are no known weaknesses in the ISAAC algorithm. And Crypt::Random::Seed does a very good job of preventing fall-back to weak seed sources. This module requires Perl 5.6 or newer. The module also uses a number of core modules, some of which require newer versions than those contemporary with 5.6. Unicode support in C is best with Perl 5.8.9 or newer. See the INSTALLATION section in this document for details. If L is installed, test coverage is 100%. For those who don't want to bother installing Test::Warn, you can just take our word for it. It's an optional installation dependency. =head2 BLOCKING ENTROPY SOURCE It is possible (and has been seen in testing) that the system's random entropy source might not have enough entropy in reserve to generate the seed requested by this module without blocking. If you suspect that you're a victim of blocking from reads on C, one option is to manipulate the random seed configuration by using the object oriented interface. This module seeds as lazily as possible so that using the module, and even instantiating a Bytes::Random::Secure object will not trigger reads from C. Only the first time the object is used to deliver random bytes will the RNG be seeded. Long-running scripts may prefer to force early seeding as close to start-up time as possible, rather than allowing it to happen later in a program's run-time. This can be achieved simply by invoking any of the functions or methods that return a random byte. As soon as a random byte is requested for the first time, the CSPRNG will be seeded. =head2 UNICODE SUPPORT The C function, and C method permit the user to pass a "bag" (or source) string containing Unicode characters. For any modern Perl version, this will work just as you would hope. But some versions of Perl older than 5.8.9 exhibited varying degrees of bugginess in their handling of Unicode. If you're depending on the Unicode features of this module while using Perl versions older than 5.8.9 be sure to test thoroughly, and don't be surprised when the outcome isn't as expected. ...this is to be expected. Upgrade. No other functions or methods in this module get anywhere near Perl's Unicode features. So as long as you're not passing Unicode source strings to C, you have nothing to worry about, even if you're using Perl 5.6.0. =head2 MODULO BIAS Care is taken so that there is no modulo bias in the randomness returned either by C or its siblings, nor by C. As a matter if fact, this is exactly I the C function is useful. However, the algorithm to eliminate modulo bias can impact the performance of the C function. Any time the length of the bag string is significantly less than the nearest greater or equal factor of 2**32, performance will degrade. Unfortunately there is no known algorithm that improves upon this situation. Fortunately, for sanely sized strings, it's a minor issue. To put it in perspective, even in the case of passing a "bag" string of length 2**31 (which is huge), the expected time to return random bytes will only double. Given that the entire Unicode range is just over a million possible code-points, it seems unlikely that the normal use case would ever have to be concerned with the performance of the C function. =head1 INSTALLATION This module should install without any fuss on modern versions of Perl. For older Perl versions (particularly 5.6 and early 5.8.x's), it may be necessary to update your CPAN installer to a more modern version before installing this this module. Another alternative for those with old Perl versions who don't want to update their CPAN installer (You must know you're crazy, right?): Review C and assure that you've got the dependencies listed under C and C, in at least the minimum versions specified. Then proceed as usual. This module only has two non-Core dependencies. But it does expect that some of the Core dependencies are newer than those supplied with 5.6 or early 5.8's. If you keep your CPAN installer up-to-date, you shouldn't have to think about this, as it will usually just "do the right thing", pulling in newer dependency versions as directed by the module's META files. Test coverage for Bytes::Random::Secure is 100% (per Devel::Cover) on any system that has L installed. But to keep the module light-weight, Test::Warn is not dragged in by default at installation time. =head1 AUTHOR David Oswald C<< >> =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Bytes::Random::Secure You can also look for information at: =over 4 =item * Github Repo: L =item * RT: CPAN's request tracker (report bugs here) L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 ACKNOWLEDGEMENTS Dana Jacobsen ( I<< >> ) for his work that led to L, thereby significantly reducing the dependencies while improving the portability and backward compatibility of this module. Also for providing a patch to this module that greatly improved the performance of C. Dana Jacosen also provided extensive input, code reviews, and testing that helped to guide the direction this module has taken. The code for the FIPS-140-1 tests was taken directly from L. Thanks! L for implementing a nice, simple interface that this module patterns itself after. =head1 LICENSE AND COPYRIGHT Copyright 2012 David Oswald. This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information. =cut Bytes-Random-Secure-0.28/Changes0000644000175000017500000001775612243456455016016 0ustar davidodavidoRevision history for Bytes::Random::Secure 0.28 2013-11-21 - Removed silly micro-optimization that was responsible for generating a warning in Perl versions prior to 5.18. 0.27 2013-10-06 - Merged pull request from David Steinbrunner: specifying meta-spec so metadata can be seen/used. - Fixed t/05-kwalitee.t to work with latest revisions on Test::Kwalitee. 0.26 2012-06-22 - Improved a test comment in t/27....t. Removed a comment paragraph that isn't relevant now that the timing has been removed. - POD edits. - POD spelling corrections (closes RT#86326). - Add "FORK AND THREAD SAFETY section to CAVIATS. 0.25 2012-02-23 - Removed the speed test / fall-back from t/27-fips140-1.t; it's unnecessary, and could cause divide by zero errors on really fast systems. 0.24 2012-02-22 - Added a small explanation of Test::Warn optional dependency to the DEPENDENCIES section of the POD. Most of the explanation is in the INSTALLATION section. - Added t/27-fips140-1.t: Code taken directly from Dana Jacobsen's Crypt::Random::TESHA2 module's test suite. This test implements the FIPS 140-1 tests. See http://csrc.nist.gov/publications/fips/fips1401.htm - Removed "slow" tests from t/20-functions.t: The FIPS-140 tests are superior and make the older slow tests unnecessary. 0.23 2012-02-11 - Clarified the (small) magnitude of the performance issues surrounding random_string_from() (MODULO BIAS section of POD). (DANAJ's suggestion.) - Added a test for _closest_divisor(). - Added a POD section discussing ISAAC's strengths. - Increased SEED_MAX bits from 512 (arbitrary) to 8192 (theoretical max for ISAAC). Added explanation to POD, and adjusted tests. - Minor corrections in # code comments (accuracy). - Added irand() object method per Dana Jacobsen's request and code contribution. - POD and tests for irand(). - Test::Warn is now an optional dependency. By ensuring that Test::Warn is installed, the module has 100% test coverage (per Devel::Cover). 0.22 2013-01-29 - Implement suggestions from Dana Jacobsen (Unicode tests, specify minimum versions for dependencies, document installation on older Perls). - POD correction -- Removed reference to config_seed. - POD: Added INSTALLATION section to address issues with older Perls. - POD: Clarified "CAVEATS" with discussion of Unicode support in pre-5.8.9. - Added t/23-string_from_unicode.t to test Unicode on Perl 5.8.9+. - Added a Unicode example to examples/random_from.pl. - Set a CONFIGURE_REQUIRES to pull in a recent ExtUtils::MakeMaker. - Set minimum versions on some Core modules from which we're using newer features, or which behaved badly in old 5.6.x-contemporary versions. 0.21 2013-01-24 - All functions and methods will now throw an exception if the byte-count parameter is passed something that doesn't look like an integer >= 0. - examples/*.pl updated to demonstrate new features. - Remove silly check for "bag" strings longer than 2**32. - Eliminate a line of unreachable code from _closest_divisor(). - Test coverage is now 100%. 0.20 2013-01-24 - This is a major release. Much thanks to Dana Jacobson for his ideas, suggestions, code reviews, and for writing Crypt::Random::Seed. - Major refactoring / rewrite. - Built an OO base layer over which the functions interface is a thin wrapper. - OO interface exposed publically. - Documented all functions. (POD) - removed config_seed() (never publically released). - Seed defaults for both interfaces are 256 bits. - Major enhancements to test suite. (Coverage is 99.3%) - ALL OF THE FOLLOWING CHANGES ARE FROM (UNRELEASED) 0.13: - * Compatible with Perl 5.6. - * Dropped Crypt::Random::Source dependency in favor of Crypt::Random::Seed. - * Seeding is lazy. - * Minimum seed size: 2-longs (64 bits). Maximum, 16 longs (512 bits). - * Documented how to configure seeding. 0.13 2013-01-15 (Never released) - POD clarification, enhancement. - Improved backwards compatibility support for Perl v5.6.x. - Eliminated Crypt::Random::Source dependency in favor of Crypt::Random::Seed; Thanks to Dana Jacobsen for creating that light-weight and powerful tool. - Added some seed tests. - Made Test::Pod::Coverage a 'RELEASE_TESTING' only test. - Made seeding and RNG-instantiation "lazy" so that "use Bytes::Random::Secure;" only drains system entropy if random bytes are actually requested. (Thanks again to Dana Jacobsen for the idea). - Modified _seed() to pass seed configuration through to Crypt::Random::Seed's constructor. - Added a config_seed() class method to facilitate configuration of the Crypt::Random::Seed object used in seeding the ISAAC algorithm. - Minimum seed size set to 2-longs, max to 16-longs (default). - Documented how to configure the seeding, and explained why it might be useful to do so (drain less system entropy). - Added META.* tests. 0.12 2012-12-09 - Applied rewrite of random_bytes() from Dana Jacobsen, that improves performance while at the same time making better use of the 32 bit random value returned by ISAAC. - POD fixes/tweaks. 0.11 2012-12-05 - Fixed a few issues where v0.10 broke compatibility with Perls older than v5.10. (Removed // operator.) - POD improvements. - Added a few entries in MANIFEST.SKIP. 0.10 2012-12-04 - Better handling of random_bytes() (no parameter passed): Now defaults to zero bytes explicitly, so we don't get "uninitialized values" warnings. - Added random_string_from($bag,$length) function. - Added tests for no param list, as well as for new random_string_from() function and its support functions. - POD enhancements. - Removed bytes pragma; it wasn't necessary, and prevented support for unicode code points in random_string_from()'s bag. 0.09 2012-11-02 - "Changes" is now CPAN::Changes::Spec compliant. - Added t/09-changes.t to verify spec compliance. 0.08 2012-10-28 - Added an example in the ./examples/ directory. - Added a minimum Perl version to the distribution metadata. 0.07 2012-09-23 - Refined t/20-functionality.t's approach toward verifying bytes seem well behaved. - Corrected a couple of POD problems. - Note: Under Moose the test suite generates a few warnings. Not sure what the best solution will be (they're harmless but annoying). 0.06 2012-09-21 - Fixed the optionality of t/21-bytes_random_tests.t. - Documented the install process in README. 0.05 2012-09-20 - POD revisions: Better details on dependencies, minimizing bloat, and Win32-specific requirements. - 21-bytes_random_tests.t is now optional, because Statistics::Basic will fail to install in some environments due to a problem in one of its dependencies (Number::Format). 0.04 2012-09-19 - Added t/21-bytes_random_tests.t, which is an adaptation of the test suite for the Bytes::Random module. - Added a BUILD_REQUIRES dependency to accommodate the Bytes::Random tests. 0.03 2012-09-18 - POD enhancements, explaining the dependency chain, and how to minimize the Any::Moose impact by ensuring Mouse is installed. - Removed syntax that was only valid for newer versions of Perl. We should be 5.6.x compatible now. - Placed the random number factory in a closure, making it only accessable by the accessor random_bytes(). - Added some tests for seed generation since we took that functionality away from Math::Random::Secure when we removed it from our list of dependencies in v0.02. - Added a Win32 test to Makefile.PL so that a Windows-only dependency will be included if necessary. 0.02 2012-09-17 - Removed Math::Random::Secure dependency. - Added Math::Random::ISAAC and Crypt::Random::Source dependencies (they were already dependencies of Math::Random::Secure, so we're actually a little lighter-weight now). - POD enhancements: Explain Math::Random::ISAAC::XS plugin, explain dependency chain, and explain why it gets a whole lot worse under Windows. 0.01 2012-09-06 - Initial CPAN release. Bytes-Random-Secure-0.28/examples/0000755000175000017500000000000012243457720016315 5ustar davidodavidoBytes-Random-Secure-0.28/examples/random-sha512-oo.pl0000644000175000017500000000074712100421533021537 0ustar davidodavido use strict; use warnings; use Bytes::Random::Secure qw(); use Digest::SHA qw( sha512_base64 ); my $quantity = 128; # Instantiate a random generator with a customized seed: my $random = Bytes::Random::Secure->new( Bits => 64, NonBlocking => 1 ); # Get a string of 128 random bytes. my $bytes = $random->bytes($quantity); # And just for fun, generate a base64 encoding of a sha2-512 digest of the # random byte string. my $digest = sha512_base64( $bytes ); print "$digest\n"; Bytes-Random-Secure-0.28/examples/random-from.pl0000644000175000017500000000077612100663100021064 0ustar davidodavidouse strict; use warnings; use utf8; use Bytes::Random::Secure qw( random_string_from ); my $quantity = 64; my $bag = 'abcde'; # Generate a random string of 64 characters, each selected from # the "bag" of 'a' through 'e', inclusive. my $string = random_string_from( $bag, $quantity ); print $string, "\n"; # Unicode strings are ok too (Perl 5.8.9 or better): if( $^V && $^V ge v5.8.9 ) { $string = random_string_from( 'Ѧѧ', 64 ); binmode STDOUT, ':encoding(UTF-8)'; print $string, "\n"; } Bytes-Random-Secure-0.28/examples/random-sha512.pl0000644000175000017500000000055712100421210021113 0ustar davidodavido use strict; use warnings; use Bytes::Random::Secure qw( random_bytes ); use Digest::SHA qw( sha512_base64 ); my $quantity = 128; # Get a string of 128 random bytes. my $bytes = random_bytes($quantity); # And just for fun, generate a base64 encoding of a sha2-512 digest of the # random byte string. my $digest = sha512_base64( $bytes ); print "$digest\n"; Bytes-Random-Secure-0.28/t/0000755000175000017500000000000012243457720014742 5ustar davidodavidoBytes-Random-Secure-0.28/t/24-oo_construct.t0000644000175000017500000001602512106351670020072 0ustar davidodavido## no critic (RCS,VERSION,encapsulation,Module,eval,constant) use strict; use warnings; use Test::More; # We only test code that can generate warnings if Test::Warn is available to # trap and examine the warnings. Install Test::Warn for full test coverage. BEGIN{ $main::test_warn = eval 'use Test::Warn; 1;'; } use constant SKIP_WHY => 'Test::Warn required for full test coverage.'; use 5.006000; use Bytes::Random::Secure; # Test the constructor, and its helper functions. # There are also a few "private functions" tests that do not pertain directly # to the constructor. can_ok( 'Bytes::Random::Secure', qw/ new _build_args _validate_args _round_bits_to_ge_32 _constrain_bits _build_attributes _build_seed_options _generate_seed _instantiate_rng _validate_int / ); # A dummy source so we don't drain entropy. # Note, this will result in four identical longs: 1633771873. sub null_source { return join( '', 'a' x shift ); } # Instantiate with a dummy callback so we don't drain entropy. my $random = new_ok 'Bytes::Random::Secure' => [ Source => \&null_source, Weak => 1, NonBlocking => 1, Bits => 128, ]; ####################### # Test _build_args(): # ####################### # Test when hashref is passed in. my $args_ref = $random->_build_args( { Weak => 1 } ); is( ref( $args_ref ), 'HASH', '_build_args(): Hashref param returns a hashref.' ); is( scalar keys %{$args_ref}, 1, '_build_args(): One named param in, one named param out.' ); ok( exists $args_ref->{Weak}, '_build_args() We got the proper arg back from hashref.' ); $args_ref = $random->_build_args( Weak => 1 ); is( ref( $args_ref ), 'HASH', '_build_args(): Flat key/value list in, hashref out.' ); is( scalar keys %{$args_ref}, 1, '_build_args(): One key/value in, hashref of one key/value out.' ); ok( exists $args_ref->{Weak}, '_build_args(): We got the proper arg back from flat list.' ); ok( ! eval { $random->_build_args( 'Weak' ); 1; }, '_build_args(): Croak when passed odd length param list.' ); like( $@, qr/key\s=>\svalue\spairs\sexpected/, '_build_args(): Correct exception thrown for odd length param list.' ); $args_ref = $random->_build_args( { Weak => 1, NonBlocking => 1 } ); is( scalar keys %{$args_ref}, 2, '_build_args(): Passed in two args, got two back.' ); $args_ref = $random->_build_args(); is( scalar keys %{$args_ref}, 0, '_build_args(): No args in, none out.' ); ######################### # Test _validate_args() # ######################### my %validated = $random->_validate_args( { valid => 1 }, valid => 2 ); ok( $validated{valid} == 2, '_validate_args(): Passed in a valid arg and got it back.' ); SKIP: { skip SKIP_WHY, 2, unless $main::test_warn; warning_like { %validated = $random->_validate_args( { valid => 1 }, invalid => 1 ) } qr/^Illegal argument \(invalid\)/, "_validate_args(): Invalid warns."; ok( 0 == scalar keys %validated, '_validate_args(): Invalid args ignored.' ); } SKIP: { skip SKIP_WHY, 2, unless $main::test_warn; warning_like { %validated = $random->_validate_args( { valid => 1 }, valid => undef ) } qr/^Undefined value specified for attribute \(valid\)/, "_validate_args(): Undefined attribute value warns."; ok( 0 == scalar keys %validated, '_validate_args(): Args dropped if value is undefined.' ); } ############################### # Test _round_bits_to_ge_32() # ############################### is( $random->_round_bits_to_ge_32(32), 32, '_round_bits_to_ge_32(32): Returns 32' ); is( $random->_round_bits_to_ge_32(0), 0, '_round_bits_to_ge_32(0): Returns 0 (never occurs)' ); SKIP: { skip SKIP_WHY, 4 unless $main::test_warn; my $got; warning_like { $got = $random->_round_bits_to_ge_32(1) } qr/^Bits field must be a multiple of 32\./, '_round_bits_to_ge_32Rounding up of bits generates warning.'; is( $got, 32, '_round_bits_to_ge_32(1): Returns 32' ); warning_like { $got = $random->_round_bits_to_ge_32(33) } qr/^Bits field must be a multiple of 32\./, '_round_bits_to_ge_32Rounding up of bits generates warning.'; is( $got, 64, '_round_bits_to_ge_32(33): Returns 64' ); } is( $random->_round_bits_to_ge_32(512), 512, '_round_bits_to_ge_32(512): Returns 512' ); ########################## # Test _constrain_bits() # ########################## SKIP: { skip SKIP_WHY, 4 unless $main::test_warn; my $bits = 0; warning_like { $bits = $random->_constrain_bits( 63, 64, 512 ); } qr/^Bits field must be >= 64/, '_constrain_bits(63,64,512) warns.'; is( $bits, 64, '_constrain_bits(): underflow rounds to in-range.' ); warning_like { $bits = $random->_constrain_bits( 8193, 64, 512 ); } qr/^Bits field must be <= 8192/, '_constrain_bits(8193,64,512)warns'; is( $bits, 512, '_constrain_bits(): overflow rounds to in-range.' ); } is( $random->_constrain_bits( 128, 64, 512 ), 128, '_constrain_bits(128,64,512) returns input unchanged.' ); ############################## # Test _build_seed_options() # ############################## is_deeply( { $random->_build_seed_options() }, { NonBlocking => 1, Weak => 1, Source => \&null_source }, "_build_seed_options(): Options hash returned." ); ######################### # Test _generate_seed() # ######################### is( scalar @{[$random->_generate_seed( Source => \&null_source )]}, 4, '_generate_seed() returns four longs when seed size set to 128 bits.' ); my $crs = undef; eval { $crs = $random->_generate_seed( Only => [] ); }; like( $@, qr/Unable to obtain a strong seed source/, '_generate_seed(): If unable to seed appropriately, throw exception.' ); ok( ! defined $crs, '_generate_seed(): Nothing returned if unable to seed.' ); ########################### # Test _instantiate_rng() # ########################### is( ref $random->_instantiate_rng(), 'Math::Random::ISAAC', '_instantiate_rng(): Default RNG is Math::Random::ISAAC' ); ######################## # Test _validate_int() # ######################## ok( eval { $random->_validate_int(1); 1; }, '_validate_int(1): Legitimate positive int passes.' ); ok( eval { $random->_validate_int( 0 ); 1; }, '_validate_int(0): Allow zero.' ); { local $@; eval { $random->_validate_int( { Illegal => 1 } ); }; like( $@, qr/Byte count must be a positive integer/, '_validate_int(): Non integer input throws.' ); } { local $@; eval { $random->_validate_int( 'illegal' ); }; like( $@, qr/Byte count must be a positive integer/, '_validate_int(): Must "look like a number".' ); } { local $@; eval { $random->_validate_int( -1 ); }; like( $@, qr/Byte count must be a positive integer/, '_validate_int(-1): Must be >= 0.' ); } { local $@; eval { $random->_validate_int( 1.5 ); }; like( $@, qr/Byte count must be a positive integer/, '_validate_int(1.5): Must be an integer.' ); } done_testing(); Bytes-Random-Secure-0.28/t/01-manifest.t0000644000175000017500000000046112025715266017154 0ustar davidodavido#!/usr/bin/env perl use strict; use warnings; use Test::More; unless ( $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } eval "use Test::CheckManifest 0.9"; ## no critic (eval) plan skip_all => "Test::CheckManifest 0.9 required" if $@; ok_manifest(); Bytes-Random-Secure-0.28/t/22-random_string_from.t0000644000175000017500000000614312104133274021234 0ustar davidodavido## no critic (RCS,VERSION,encapsulation,Module) use strict; use warnings; use Test::More; use Bytes::Random::Secure; # We'll use a weaker source because we're testing for function, quality # isn't being contested here. Weak=>1 should assure we use /dev/urandom where # it's available. Low entropy chosen to preserve our source. my $random = Bytes::Random::Secure->new( NonBlocking => 1, Weak => 1, Bits => 64 ); # Tests for _closest_divisor(). my @divisors = ( 1, 1, 2, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32 ); # Nearest factor of 2**32 >= $ix; for my $ix ( 0 .. $#divisors ) { is( $random->_closest_divisor($ix), $divisors[$ix], "_closest_divisor($ix) == $divisors[$ix]" ); } is( $random->_closest_divisor(), 1, '_closest_divisor() == 1; No param list defaults to zero.' ); ok( ! eval { $random->_closest_divisor(-1); 1; }, '_closest_divisor(-1) throws on negative input.' ); ok( ! eval { $random->_closest_divisor(2**33); 1 }, '_closest_divisor(2**33) throws (out of range input).' ); is( $random->_closest_divisor(2**32), 2**32, "_closest_divisor(2**32) == 2**32." ); is( $random->_closest_divisor( 2**32 - 1 ), 2**32, '_closest_divisor(2**32-1) == 2**32' ); # Tests for _ranged_randoms(). for my $count ( 0 .. 11 ) { is( scalar @{[ $random->_ranged_randoms(16,$count) ]}, $count, "Requested $count ranged randoms, and got $count." ); } is( scalar @{[ $random->_ranged_randoms(16) ]}, 0, 'Requested undefined quantity of ranged randoms, and got zero (default).' ); my( $min, $max ); $min = $max = $random->_ranged_randoms(200, 1); my $MAX_TRIES = 1_000_000; my $tries = 0; while( ( $min > 0 || $max < 199 ) && $tries++ < $MAX_TRIES ) { my $random = ($random->_ranged_randoms(200,1))[0]; $min = $random < $min ? $random : $min; $max = $random > $max ? $random : $max; } is( $min, 0, '_ranged_randoms generates range minimum.' ); is( $max, 199, '_ranged_randoms generates range maximum.' ); note "It took $tries tries to hit both min and max."; # Testing random_string_from(). is( $random->string_from( 'abc', 0 ), '', 'string_from() with a quantity of zero returns empty string.' ); is( $random->string_from( 'abc' ), '', 'string_from() with an undefined quantity defaults to zero.' ); is( length( $random->string_from( 'abc', 5 ) ), 5, 'string_from(): Requested 5, got 5.' ); my %bag; $tries = 0; while( scalar( keys %bag ) < 26 && $tries++ < $MAX_TRIES ) { $bag{ $random->string_from( 'abcdefghijklmnopqrstuvwxyz', 1 ) }++; } is( scalar( keys %bag ), 26, 'string_from() returned all bytes from bag, and only bytes from bag.' ); ok( ! scalar( grep{ $_ =~ m/[^abcdefghijklmnopqrstuvwxyz]/ } keys %bag ), 'string_from(): No out of range characters in output.' ); ok( $tries >= 26, 'string_from():Test validation: took at least 26 tries to hit all 26.' ); note "It took $tries tries to hit them all at least once."; ok( ! eval { $random->string_from(); 1; }, 'No bag string passed (or bag of zero length) throws an exception.' ); done_testing(); Bytes-Random-Secure-0.28/t/23-string_from_unicode.t0000644000175000017500000000175712100663163021412 0ustar davidodavido## no critic (RCS,VERSION,encapsulation,Module) use strict; use warnings; use Test::More; use Bytes::Random::Secure; if( ! $^V || $^V lt v5.8.9 ) { plan skip_all => 'Cannot reliably test Unicode support on Perl\'s older than 5.8.9.'; } binmode STDOUT, ':encoding(UTF-8)'; my $num_octets = 80; my $random = Bytes::Random::Secure->new( NonBlocking => 1, Bits => 64 ); my $string = $random->string_from( 'Ѧѧ', $num_octets ); is( length $string, $num_octets, 'string_from(unicode): Returned proper length string.' ); like( $string, qr/^[Ѧѧ]+$/, 'string_from(unicode): String contained only Ѧѧ characters.' ); # There's only an 8.27e-23% chance of NOT having both Ѧ and ѧ in the output. # It would be incredibly poor luck for these tests to fail randomly. # So we'll take failure to mean there's a bug. like( $string, qr/Ѧ/, 'string_from(unicode): Ѧ found in output.' ); like( $string, qr/ѧ/, 'string_from(unicode): ѧ found in output.' ); done_testing(); Bytes-Random-Secure-0.28/t/07-meta-json.t0000644000175000017500000000063012075333371017245 0ustar davidodavido## no critic(RCS,VERSION,explicit,Module,eval) use strict; use warnings; use Test::More; if( ! $ENV{RELEASE_TESTING} ) { plan skip_all => 'Author only test: META.json tests run only if RELEASE_TESTING set.'; } elsif ( ! eval 'use Test::CPAN::Meta::JSON; 1;' ) { plan skip_all => 'Author META.json test requires Test::CPAN::Meta::JSON.' } else { note 'Testing META.json'; } meta_json_ok(); Bytes-Random-Secure-0.28/t/10-prereqs.t0000644000175000017500000000037212100113450017005 0ustar davidodavido## no critic (RCS,VERSION,encapsulation,Module) use strict; use warnings; use Test::More; BEGIN { use_ok('MIME::Base64'); use_ok('MIME::QuotedPrint'); use_ok('Math::Random::ISAAC'); use_ok('Crypt::Random::Seed'); } done_testing(); Bytes-Random-Secure-0.28/t/02-pod.t0000644000175000017500000000060312075123062016117 0ustar davidodavido## no critic(RCS,VERSION,explicit,Module) use strict; use warnings; use Test::More; if ( $ENV{RELEASE_TESTING} ) { eval 'use Test::Pod 1.00'; ## no critic (eval) if ($@) { plan skip_all => 'Test::Pod 1.00 required for testing POD'; } } else { plan skip_all => 'Skip Test::Pod tests unless environment variable ' . 'RELEASE_TESTING is set.'; } all_pod_files_ok(); Bytes-Random-Secure-0.28/t/21-bytes_random_tests.t0000644000175000017500000000205012100113450021231 0ustar davidodavido## no critic (RCS,VERSION,encapsulation,Module) use strict; use warnings; use Test::More; eval "use Statistics::Basic;"; ## no critic (eval) if ( $@ ) { plan( skip_all => "Statistics::Basic needed for random quality tests." ); } use Bytes::Random::Secure; # Default seed entropy of 16 longs is more than we need in testing. my $random = Bytes::Random::Secure->new( Bits => 64, Weak => 1, NonBlocking => 1 ); # Minimum allowed is sufficient here. for( 1..40 ) { is( length( $random->bytes($_) ) => $_, "Got $_ random bytes" ); } { my $amount = 1e6; my %dispersion; $dispersion{ord $random->bytes(1)}++ for 1..$amount; my @slots = 0..0xff; for my $slot (@slots) { ok exists $dispersion{$slot}, "could produce bytes of numeric value $slot"; } my $s = Statistics::Basic::stddev( map {defined $_ ? $_ : 0} @dispersion{@slots} )->query; ok 2 > log($s) / log(10), "$amount values are roughly evenly distributed " . "(standard deviation was $s, should be about 60)"; } done_testing(); Bytes-Random-Secure-0.28/t/27-fips140-1.t0000644000175000017500000001134612112065124016672 0ustar davidodavido## no critic (RCS,VERSION,encapsulation,Module) # Assure that the crypto-quality of the RNG meets FIPS PUB 140-1: # Security Requirements for Cryptographic Modules. # See: http://csrc.nist.gov/publications/fips/fips1401.htm # "Statistical random number generator tests. Cryptographic modules # that implement a random or pseudorandom number generator shall # incorporate the capability to perform statistical tests for # randomness. For Levels 1 and 2, the tests are not required. For # Level 3, the tests shall be callable upon demand. For level 4, # the tests shall be performed at power-up and shall also be # callable upon demand. The tests specified below are recommended. # However, alternative tests which provide equivalent or superior # randomness checking may be substituted." # These tests were adapted from the algorithms described in the FIPS-140-1 # document (link provided above). Dana Jacobsen performed the Perl adaptation # for use with Crypt::Random::TESHA2. Bytes::Random::Secure incorporates the # tests without change, except for the randomness source. # As this set of tests is run at install time, and thereafter upon demand, this # should comply with the FIPS 140-1 Level 3 specification, with the exception # that upon failure there will be a test-suite failure, rather than the module # entering an "error state" as described in the FIPS 140-1 document. # Test failure at install time would typically force the CPAN installers to # abort installation, which is the "Perlish" solution. use 5.006000; use strict; use warnings; use Test::More; use Bytes::Random::Secure qw(); use Time::HiRes qw/gettimeofday/; my $random = Bytes::Random::Secure->new( NonBlocking => 1, Bits => 128, Weak => 1, ); plan tests => 2 + 2 + 2 + 24 + 2; my @rbytes; push @rbytes, $random->bytes(1) for 1..2500; # FIPS-140 test { is( scalar @rbytes, 2500, "2500 bytes were collected." ); my $str = join("", map { unpack("B8", $_) } @rbytes); is( length($str), 20000, "binary string is length 20000" ); # Monobit my $nzeros = $str =~ tr/0//; my $nones = $str =~ tr/1//; cmp_ok($nones, '>', 9654, "Monobit: Number of ones is > 9654"); cmp_ok($nones, '<', 10346, "Monobit: Number of ones is < 10346"); # Long Run ok($str !~ /0{34}/, "Longrun: No string of 34+ zeros"); ok($str !~ /1{34}/, "Longrun: No string of 34+ ones"); # Runs my @l0; my @l1; $l0[$_] = 0 for 1 .. 34; $l1[$_] = 0 for 1 .. 34; { my $s = $str; while (length($s) > 0) { if ($s =~ s/^(0+)//) { $l0[length($1)]++; } if ($s =~ s/^(1+)//) { $l1[length($1)]++; } } } # Fold all runs of >= 6 into 6. $l0[6] += $l0[$_] for 7 .. 34; $l1[6] += $l1[$_] for 7 .. 34; # Test thresholds cmp_ok($l0[1], '>=', 2267, "Runs: zero length 1 ($l0[1]) >= 2267"); cmp_ok($l1[1], '>=', 2267, "Runs: one length 1 ($l1[1]) >= 2267"); cmp_ok($l0[1], '<=', 2733, "Runs: zero length 1 ($l0[1]) <= 2733"); cmp_ok($l1[1], '<=', 2733, "Runs: one length 1 ($l1[1]) <= 2733"); cmp_ok($l0[2], '>=', 1079, "Runs: zero length 2 ($l0[2]) >= 1079"); cmp_ok($l1[2], '>=', 1079, "Runs: one length 2 ($l1[2]) >= 1079"); cmp_ok($l0[2], '<=', 1421, "Runs: zero length 2 ($l0[2]) <= 1421"); cmp_ok($l1[2], '<=', 1421, "Runs: one length 2 ($l1[2]) <= 1421"); cmp_ok($l0[3], '>=', 502, "Runs: zero length 3 ($l0[3]) >= 502"); cmp_ok($l1[3], '>=', 502, "Runs: one length 3 ($l1[3]) >= 502"); cmp_ok($l0[3], '<=', 748, "Runs: zero length 3 ($l0[3]) <= 748"); cmp_ok($l1[3], '<=', 748, "Runs: one length 3 ($l1[3]) <= 748"); cmp_ok($l0[4], '>=', 223, "Runs: zero length 4 ($l0[4]) >= 223"); cmp_ok($l1[4], '>=', 223, "Runs: one length 4 ($l1[4]) >= 223"); cmp_ok($l0[4], '<=', 402, "Runs: zero length 4 ($l0[4]) <= 402"); cmp_ok($l1[4], '<=', 402, "Runs: one length 4 ($l1[4]) <= 402"); cmp_ok($l0[5], '>=', 90, "Runs: zero length 5 ($l0[5]) >= 90"); cmp_ok($l1[5], '>=', 90, "Runs: one length 5 ($l1[5]) >= 90"); cmp_ok($l0[5], '<=', 223, "Runs: zero length 5 ($l0[5]) <= 223"); cmp_ok($l1[5], '<=', 223, "Runs: one length 5 ($l1[5]) <= 223"); cmp_ok($l0[6], '>=', 90, "Runs: zero length 6+($l0[5]) >= 90"); cmp_ok($l1[6], '>=', 90, "Runs: one length 6+($l1[5]) >= 90"); cmp_ok($l0[6], '<=', 223, "Runs: zero length 6+($l0[5]) <= 223"); cmp_ok($l1[6], '<=', 223, "Runs: one length 6+($l1[5]) <= 223"); # Poker { my @segment; $segment[$_] = 0 for 0 .. 15; my $s = $str; while ($s =~ s/^(....)//) { $segment[oct("0b$1")]++; } my $X = 0; $X += $segment[$_]*$segment[$_] for 0..15; $X = (16 / 5000) * $X - 5000; cmp_ok($X, '>', 1.03, "Poker: X > 1.03"); cmp_ok($X, '<', 57.4 , "Poker: X < 57.4"); } } done_testing(); Bytes-Random-Secure-0.28/t/20-functions.t0000644000175000017500000000676712112053001017351 0ustar davidodavido## no critic (RCS,VERSION,encapsulation,Module) use strict; use warnings; use Test::More; use 5.006000; BEGIN{ @main::functions = qw/ random_bytes random_bytes_hex random_bytes_base64 random_bytes_qp random_string_from /; use_ok( 'Bytes::Random::Secure', @main::functions ); } can_ok( 'Bytes::Random::Secure', @main::functions ); # Fully qualified. can_ok( 'main', @main::functions ); # Imported. foreach my $want ( qw/ 0 1 2 3 4 5 6 7 8 16 17 1024 10000 / ) { my $correct = $want >= 0 ? $want : 0; is( length random_bytes( $want ), $correct, "random_bytes($want) returns $correct bytes." ); } { local $@; eval { my $bytes = random_bytes( -1 ); }; like( $@, qr/Byte count must be a positive integer/, 'random_bytes: requesting negative byte count throws an exception.' ); } { local $@; eval { my $bytes = random_bytes( { Illegal => 1 } ); }; like( $@, qr/Byte count must be a positive integer/, 'random_bytes: Non-integer input throws an exception.' ); } # random_bytes_hex (and _lite) tests. foreach my $want ( qw/ 0 1 2 3 4 5 6 7 8 16 17 1024 10000 / ) { my $result = random_bytes_hex( $want ); my $correct = $want >= 0 ? $want * 2 : 0; is( length random_bytes_hex( $want ), $correct, "random_bytes_hex($want) returned $correct hex digits." ); }; ok( random_bytes_hex(128) =~ /^[[:xdigit:]]+$/, 'random_bytes_hex only produces hex digits.' ); # random_bytes_base64 (and _lite) tests. is( length random_bytes_base64(0), 0, 'random_bytes_base64(0) returns an empty string.' ); ok( length random_bytes_base64(1) > 0, 'random_bytes_base64(1) returns a string of some non-zero length.' ); ok( length random_bytes_base64(5) < length random_bytes_base64( 16 ), 'random_bytes_base64(5) returns a shorter string than ' . 'random_bytes_base64(16)' ); ok( random_bytes_base64(128) =~ /^[^\n]{76}\n/, 'random_bytes_base64 uses "\n" appropriately' ); ok( random_bytes_base64(128, q{}) =~ /^[^\n]+$/, 'random_bytes_base64 passes EOL delimiter correctly.' ); # random_bytes_qp (and _lite) tests. is( length random_bytes_qp(0), 0, 'random_bytes_qp(0) returns an empty string.' ); ok( length random_bytes_qp(1) > 0, 'random_bytes_qp(1) returns a string of some non-zero length.' ); ok( length random_bytes_qp(5) < length random_bytes_qp( 16 ), 'random_bytes_qp(5) returns a shorter string than ' . 'random_bytes_qp(16)' ); ok( random_bytes_qp(100) =~ m/^[^\n]{1,76}\n/, 'random_bytes_qp uses "\n" appropriately' ); ok( random_bytes_qp(128, q{}) =~ /^[^\n]+$/, 'random_bytes_qp passes EOL delimiter correctly.' ); is( length random_bytes(), 0, 'random_bytes(): No param defaults to zero bytes.' ); # Basic tests for random_string_from # (More exhaustive tests in 22-random_string_from.t) my $MAX_TRIES = 1_000_000; my %bag; my $tries = 0; while( scalar( keys %bag ) < 26 && $tries++ < $MAX_TRIES ) { $bag{ random_string_from( 'abcdefghijklmnopqrstuvwxyz', 1 ) }++; } is( scalar( keys %bag ), 26, 'random_string_from() returned all bytes from bag, and only bytes from bag.' ); ok( ! scalar( grep{ $_ =~ m/[^abcdefghijklmnopqrstuvwxyz]/ } keys %bag ), 'No out of range characters in output.' ); like( random_string_from( 'abc', 100 ), qr/^[abc]{100}$/, 'random_string_from() returns only correct digits, and length.' ); done_testing(); Bytes-Random-Secure-0.28/t/06-meta-yaml.t0000644000175000017500000000076612243457143017250 0ustar davidodavido## no critic(RCS,VERSION,explicit,Module,eval) use strict; use warnings; use Test::More; if( $] lt '5.018000' ) { plan skip_all => 'YAML test not avaiable pre-5.18'; exit(0); } if( ! $ENV{RELEASE_TESTING} ) { plan skip_all => 'Author only test: META.yml tests run only if RELEASE_TESTING set.'; } elsif ( ! eval 'use Test::CPAN::Meta::YAML; 1;' ) { plan skip_all => 'Author META.yml test requires Test::CPAN::Meta::YAML.'; } else { note 'Testing META.yml'; meta_yaml_ok(); } Bytes-Random-Secure-0.28/t/26-oo_public.t0000644000175000017500000000453112106345640017325 0ustar davidodavido## no critic (RCS,VERSION,encapsulation,Module) use strict; use warnings; use MIME::Base64; use MIME::QuotedPrint; use Data::Dumper; use Test::More; use Bytes::Random::Secure; # Public methods tested here (bytes(), etc.). # Much of this has already been put through the paces via the "functions" layer # tests in 20-functions.t, so we're only going for coverage here. my $random = Bytes::Random::Secure->new( Bits => 64, NonBlocking=>1, Weak=>1 ); is( length $random->bytes(10), 10, 'bytes(10) returns ten bytes.' ); is( length decode_base64($random->bytes_base64(111)), 111, 'decode_base64() can be decoded, and returns correct number of bytes.'); like( $random->bytes_base64(111,"\n\n"), qr/\n\n/, 'bytes_base64(111,"\n\n"): EOL handled properly.' ); is( length decode_qp( $random->bytes_qp(200) ), 200, 'bytes_qp(): Decodable Quoted Printable returned.' . ' Decodes to proper length.' ); like( $random->bytes_qp(200, "\n\n"), qr/\n\n/, 'bytes_qp(): EOL handled properly.' ); like( $random->bytes_hex(16), qr/^[1234567890abcdef]{32}$/, 'bytes_hex() returns only hex digits, of correct length.' ); like( $random->string_from('abc', 100 ), qr/^[abc]{100}$/, 'string_from() returns proper length and proper string.' ); { local $@; eval { my $bytes = $random->bytes( -5 ); }; like( $@, qr/Byte count must be a positive integer/, 'bytes() throws on invalid input.' ); } { local $@; eval { my $bytes = $random->string_from( 'abc', -5 ); }; like( $@, qr/Byte count must be a positive integer/, 'string_from(): Throws an exception on invalid byte count.' ); } my $rv = $random->irand; ok( $rv == int( $rv ), 'irand produces an integer.' ); { my( $min, $max ); for( 1 .. 10000 ) { my $ir = $random->irand; $min = $ir if ! defined $min; $min = $ir < $min ? $ir : $min; $max = $ir if ! defined $max; $max = $ir > $max ? $ir : $max; } ok( $min >= 0, 'irand(): Minimum return value is >= 0.' ); ok( $max <= 2**32-1, 'irand(): Maximum return value is <= 2**32-1.' ); } my $newirand = Bytes::Random::Secure->new( NonBlocking => 1, Bits => 64 )->irand; ok( $newirand == int( $newirand ), 'irand instantiates a new RNG on first call with fresh object.' ); ok( $newirand >= 0 && $newirand <= 2**32-1, 'First irand call with a new RNG is in range.' ); done_testing(); Bytes-Random-Secure-0.28/t/03-pod-coverage.t0000644000175000017500000000117512100113450017703 0ustar davidodavido#!/usr/bin/env perl use strict; use warnings; use Test::More; # Minimum versions: my $min_tpc = '1.08'; # Test::Pod::Coverage minimum. # Older versions of Pod::Coverage don't recognize some common POD styles. my $min_pc = '0.18'; # Pod::Coverage minimum. unless( $ENV{RELEASE_TESTING} && eval "use Test::Pod::Coverage $min_tpc; 1;" ## no critic (eval) && eval "use Pod::Coverage $min_pc; 1;" ## no critic (eval) ) { plan skip_all => "POD Coverage tests only run when RELEASE_TESTING is set, *and*\n" . "both Test::Pod::Coverage and Pod::Coverage are available on target system."; } all_pod_coverage_ok(); Bytes-Random-Secure-0.28/t/04-perlcritic.t0000644000175000017500000000221612045050536017503 0ustar davidodavido#!/usr/bin/env perl use strict; use warnings; use Test::More; use English qw( -no_match_vars ); # To enable this suite one must set the RELEASE_TESTING environment variable # to a true value. # This prevents author tests from running on a user install. # It's possible users would have their own conflicting Perl::Critic config, # so it would be a bad idea to let this test run on users systems. if ( not $ENV{RELEASE_TESTING} ) { my $msg = 'Author Test: Set $ENV{RELEASE_TESTING} to a true value to run.'; plan( skip_all => $msg ); } # We also don't want to force a dependency on Test::Perl::Critic, so if the # user doesn't have the module, we won't run the test. eval { require Test::Perl::Critic; 1; }; if ($EVAL_ERROR) { my $msg = 'Author Test: Test::Perl::Critic required to criticise code.'; plan( skip_all => $msg ); } # Set a higher severity level. Note: List/BinarySearch.pm meets level 2. Test::Perl::Critic->import( -severity => 4 ); # We want to test the primary module components (blib/) as well as the # test suite (t/). my @directories = qw{ blib/ t/ }; Test::Perl::Critic::all_critic_ok(@directories); done_testing(); Bytes-Random-Secure-0.28/t/09-changes.t0000644000175000017500000000051612045051077016762 0ustar davidodavido#!/usr/bin/env perl use strict; use warnings; use Test::More; plan skip_all => 'Author tests skipped. Set $ENV{RELEASE_TESTING} to run' unless $ENV{RELEASE_TESTING}; plan skip_all => 'Test::CPAN::Changes required for this test' unless eval 'use Test::CPAN::Changes; 1;'; ## no critic (eval) changes_ok(); done_testing(); Bytes-Random-Secure-0.28/t/11-load.t0000644000175000017500000000041412100113450016241 0ustar davidodavido## no critic (RCS,VERSION,encapsulation,Module) use strict; use warnings; use Test::More tests => 1; BEGIN { use_ok( 'Bytes::Random::Secure' ) || print "Bail out!\n"; } diag( "Testing Bytes::Random::Secure $Bytes::Random::Secure::VERSION, Perl $], $^X" ); Bytes-Random-Secure-0.28/t/00-boilerplate.t0000644000175000017500000000246512025715266017655 0ustar davidodavido#!/usr/bin/env perl use 5.006; use strict; use warnings; use Test::More tests => 3; sub not_in_file_ok { my ( $filename, %regex ) = @_; my %violated; ## no critic (RequireBriefOpen) open my $fh, '<', $filename or die "couldn't open $filename for reading: $!"; while ( my $line = <$fh> ) { while ( my ( $desc, $regex ) = each %regex ) { if ( $line =~ $regex ) { push @{ $violated{$desc} ||= [] }, $.; } } } close $fh; if (%violated) { fail("$filename contains boilerplate text"); diag "$_ appears on lines @{$violated{$_}}" for keys %violated; } else { pass("$filename contains no boilerplate text"); } return; } sub module_boilerplate_ok { my ($module) = @_; not_in_file_ok( $module => 'the great new $MODULENAME' => qr/ - The great new /, 'boilerplate description' => qr/Quick summary of what the module/, 'stub function definition' => qr/function[12]/, ); return; } not_in_file_ok( README => "The README is used..." => qr/The README is used/, "'version information here'" => qr/to provide version information/, ); not_in_file_ok( Changes => "placeholder date/time" => qr(Date/time) ); module_boilerplate_ok('lib/Bytes/Random/Secure.pm'); Bytes-Random-Secure-0.28/t/05-kwalitee.t0000644000175000017500000000132412212152312017137 0ustar davidodavido#!/usr/bin/env perl use strict; use warnings; use Test::More; # To enable this suite one must set $ENV{RELEASE_TESTING} to a true value. # This prevents author tests from running on a user install. if ( not $ENV{RELEASE_TESTING} ) { my $msg = 'Author Test: Set $ENV{RELEASE_TESTING} to a true value to run.'; plan( skip_all => $msg ); done_testing(); } unless( eval { require Test::Kwalitee; Test::Kwalitee->import(); # Clean up. I don't know why this persists, but we certainly don't need to # leave clutter behind. unlink 'Debian_CPANTS.txt' if -e 'Debian_CPANTS.txt'; 1; } ) { plan( skip_all => 'Test::Kwalitee not installed; skipping' ) if $@; done_testing(); } Bytes-Random-Secure-0.28/Makefile.PL0000644000175000017500000000274012224433115016443 0ustar davidodavidouse 5.006000; use strict; use warnings; use ExtUtils::MakeMaker; my %PREREQ_PM = ( 'Crypt::Random::Seed' => '0', # Provides a high quality seed. 'Math::Random::ISAAC' => '0', # Provides our random number generator. 'MIME::Base64' => '0', # Core. 'MIME::QuotedPrint' => '3.03', # Core, but minimum version requirement. 'Carp' => '0', # Core. 'Scalar::Util' => '1.21', # Core, but minimum version requirement. ); WriteMakefile( NAME => 'Bytes::Random::Secure', AUTHOR => q{David Oswald }, VERSION_FROM => 'lib/Bytes/Random/Secure.pm', ABSTRACT_FROM => 'lib/Bytes/Random/Secure.pm', ( $ExtUtils::MakeMaker::VERSION >= 6.3002 ? ( 'LICENSE' => 'perl' ) : () ), PL_FILES => {}, CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => '6.56', }, BUILD_REQUIRES => { 'Test::More' => '0.98', # A recent version is needed. }, MIN_PERL_VERSION => '5.006000', PREREQ_PM => \%PREREQ_PM, META_MERGE => { 'resources' => { 'meta-spec' => { version => 2 }, 'repository' => { 'url' => 'git://github.com/daoswald/Bytes-Random-Secure.git', 'web' => 'http://github.com/daoswald/Bytes-Random-Secure', 'type' => 'git', }, }, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Bytes-Random-Secure-*', }, ); Bytes-Random-Secure-0.28/META.json0000644000175000017500000000230012243457720016113 0ustar davidodavido{ "abstract" : "Perl extension to generate cryptographically-secure random bytes.", "author" : [ "David Oswald " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.78, CPAN::Meta::Converter version 2.132140", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Bytes-Random-Secure", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "Test::More" : "0.98" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.56" } }, "runtime" : { "requires" : { "Carp" : "0", "Crypt::Random::Seed" : "0", "MIME::Base64" : "0", "MIME::QuotedPrint" : "3.03", "Math::Random::ISAAC" : "0", "Scalar::Util" : "1.21", "perl" : "5.006000" } } }, "release_status" : "stable", "resources" : { "x_Metaspec" : { "version" : 2 } }, "version" : "0.28" } Bytes-Random-Secure-0.28/MANIFEST0000644000175000017500000000101712112053233015611 0ustar davidodavidoChanges lib/Bytes/Random/Secure.pm Makefile.PL MANIFEST This list of files README META.json META.yml t/00-boilerplate.t t/01-manifest.t t/02-pod.t t/03-pod-coverage.t t/04-perlcritic.t t/05-kwalitee.t t/06-meta-yaml.t t/07-meta-json.t t/09-changes.t t/10-prereqs.t t/11-load.t t/20-functions.t t/21-bytes_random_tests.t t/22-random_string_from.t t/23-string_from_unicode.t t/24-oo_construct.t t/26-oo_public.t t/27-fips140-1.t examples/random-sha512.pl examples/random-sha512-oo.pl examples/random-from.pl