Crypt-URandom-0.54/0000755000175000017500000000000014765245340012540 5ustar davedaveCrypt-URandom-0.54/lib/0000755000175000017500000000000014765245340013306 5ustar davedaveCrypt-URandom-0.54/lib/Crypt/0000755000175000017500000000000014765245340014407 5ustar davedaveCrypt-URandom-0.54/lib/Crypt/URandom.pm0000644000175000017500000003206514765245056016324 0ustar davedavepackage Crypt::URandom; use warnings; use strict; use Carp(); use English qw( -no_match_vars ); use Exporter(); *import = \&Exporter::import; our @EXPORT_OK = qw( urandom urandom_ub getrandom ); our %EXPORT_TAGS = ( 'all' => \@EXPORT_OK, ); our @CARP_NOT = ('Crypt::URandom'); BEGIN { our $VERSION = '0.54'; eval { require XSLoader; XSLoader::load( __PACKAGE__, $VERSION ); } or do { }; } ## no critic (ProhibitConstantPragma) # using constant for the speed benefit of constant-folding of values use constant CRYPT_SILENT => 64; # hex 40 use constant PROV_RSA_FULL => 1; use constant VERIFY_CONTEXT => 4_026_531_840; # hex 'F0000000' use constant W2K_MAJOR_VERSION => 5; use constant W2K_MINOR_VERSION => 0; use constant OS_FREEBSD => $OSNAME eq 'freebsd'; use constant OS_WIN32 => $OSNAME eq 'MSWin32'; use constant PATH => do { my $path = '/dev/urandom'; if ( OS_FREEBSD() ) { $path = '/dev/random'; # FreeBSD's /dev/random is non-blocking } $path; }; use constant GETRANDOM_AVAILABLE => do { my $result = 0; eval { my $correct_length = 2; $result = getrandom($correct_length); } or do { $result = undef; }; $result; }; use constant SYSTEM_CALL_FAILED => -1; ## use critic my $_initialised; my $_context; my $_cryptgenrandom; my $_rtlgenrand; my $_urandom_handle; sub _init { if ( !( ( defined $_initialised ) && ( $_initialised == $PROCESS_ID ) ) ) { if ( OS_WIN32() ) { require Win32; require Win32::API; require Win32::API::Type; my ( $major, $minor ) = ( Win32::GetOSVersion() )[ 1, 2 ]; my $ntorlower = ( $major < W2K_MAJOR_VERSION() ) ? 1 : 0; my $w2k = ( $major == W2K_MAJOR_VERSION() and $minor == W2K_MINOR_VERSION() ) ? 1 : 0; if ($ntorlower) { Carp::croak( 'No secure alternative for random number generation for Win32 versions older than W2K' ); } elsif ($w2k) { my $crypt_acquire_context_a = Win32::API->new( 'advapi32', 'CryptAcquireContextA', 'PPPNN', 'I' ); if ( !defined $crypt_acquire_context_a ) { Carp::croak( "Could not import CryptAcquireContext: $EXTENDED_OS_ERROR" ); } my $context = chr(0) x Win32::API::Type->sizeof('PULONG'); my $result = $crypt_acquire_context_a->Call( $context, 0, 0, PROV_RSA_FULL(), CRYPT_SILENT() | VERIFY_CONTEXT() ); my $pack_type = Win32::API::Type::packing('PULONG'); $context = unpack $pack_type, $context; if ( !$result ) { Carp::croak( "CryptAcquireContext failed: $EXTENDED_OS_ERROR"); } my $crypt_gen_random = Win32::API->new( 'advapi32', 'CryptGenRandom', 'NNP', 'I' ); if ( !defined $crypt_gen_random ) { Carp::croak( "Could not import CryptGenRandom: $EXTENDED_OS_ERROR"); } $_context = $context; $_cryptgenrandom = $crypt_gen_random; } else { my $rtlgenrand = Win32::API->new( 'advapi32', <<'_RTLGENRANDOM_PROTO_'); INT SystemFunction036( PVOID RandomBuffer, ULONG RandomBufferLength ) _RTLGENRANDOM_PROTO_ if ( !defined $rtlgenrand ) { Carp::croak( "Could not import SystemFunction036: $EXTENDED_OS_ERROR" ); } $_rtlgenrand = $rtlgenrand; } } else { require FileHandle; $_urandom_handle = FileHandle->new( PATH(), Fcntl::O_RDONLY() ) or Carp::croak( q[Failed to open ] . PATH() . qq[ for reading:$OS_ERROR] ); binmode $_urandom_handle; } $_initialised = $PROCESS_ID; } return; } sub urandom_ub { my ($length) = @_; return _urandom( 'sysread', $length ); } sub urandom { my ($length) = @_; return _urandom( 'read', $length ); } sub _urandom { my ( $type, $length ) = @_; my $length_ok; if ( defined $length ) { if ( $length =~ /^\d+$/xms ) { $length_ok = 1; } } if ( !$length_ok ) { Carp::croak( 'The length argument must be supplied and must be an integer'); } if ( !GETRANDOM_AVAILABLE() ) { _init(); } if ( OS_WIN32() ) { my $urandom = chr(0) x $length; if ($_cryptgenrandom) { my $result = $_cryptgenrandom->Call( $_context, $length, $urandom ); if ( !$result ) { Carp::croak("CryptGenRandom failed: $EXTENDED_OS_ERROR"); } } elsif ($_rtlgenrand) { my $result = $_rtlgenrand->Call( $urandom, $length ); if ( !$result ) { Carp::croak("RtlGenRand failed: $EXTENDED_OS_ERROR"); } } return $urandom; } elsif ( GETRANDOM_AVAILABLE() ) { return getrandom($length); } else { return _read_urandom_fs( $type, $length ); } return; } sub _read_urandom_fs { my ( $type, $length ) = @_; my $original_length = $length; my $urandom; BUFFER_FILLED: { my $result; if ( defined $urandom ) { $length = $original_length - ( length $urandom ); $result = $_urandom_handle->$type( my $buffer, $length ); if ( defined $buffer ) { $urandom .= $buffer; } } else { $result = $_urandom_handle->$type( my $buffer, $length ); if ( defined $buffer ) { $urandom .= $buffer; } } if ( ( defined $urandom ) && ( length $urandom == $original_length ) ) { } elsif (( $result == SYSTEM_CALL_FAILED() ) && ( $OS_ERROR == POSIX::EINTR() ) ) { redo BUFFER_FILLED; } elsif ( $result != SYSTEM_CALL_FAILED() ) { redo BUFFER_FILLED; } else { my $error = $EXTENDED_OS_ERROR; $_urandom_handle = undef; $_initialised = undef; Carp::croak( q[Failed to read from ] . PATH() . qq[:$error] ); } } return $urandom; } 1; # Magic true value required at end of module __END__ =head1 NAME Crypt::URandom - Provide non blocking randomness =head1 VERSION This document describes Crypt::URandom version 0.54 =head1 SYNOPSIS use Crypt::URandom(); my $random_string_50_bytes_long = Crypt::URandom::urandom(50); OR use Crypt::URandom qw( urandom ); my $random_string_50_bytes_long = urandom(50); =head1 DESCRIPTION This Module is intended to provide an interface to the strongest available source of non-blocking randomness on the current platform. Platforms currently supported are anything supporting L, /dev/urandom and versions of Windows greater than or equal to Windows 2000. =head1 SUBROUTINES/METHODS =over =item C =for stopwords cryptographic Win32 initialize This function accepts an integer and returns a string of the same size filled with random data. It will throw an exception if the requested amount of random data is not returned. The first call will initialize the native cryptographic libraries (if necessary) and load all the required Perl libraries. This call is a buffered read on non Win32 platforms that do not support L or equivalent. =item C =for stopwords cryptographic Win32 initialize unbuffered sysread This function accepts an integer and returns a string of the same size filled with random data. It will throw an exception if the requested amount of random data is not returned. The first call will initialize the native cryptographic libraries (if necessary) and load all the required Perl libraries. This call is a unbuffered sysread on non Win32 platforms that do not support L or equivalent. =item C This function accepts an integer and returns a string of the same size filled with random data on platforms that implement L. It will throw an exception if the requested amount of random data is not returned. This is NOT portable across all operating systems, but is made available if high-speed generation of random numbers is required. =back =head1 DIAGNOSTICS =over =item C The module cannot run on versions of Windows earlier than Windows 2000 as there is no cryptographic functions provided by the operating system. =item C =for stopwords CryptAcquireContextA advapi32 The module was unable to load the CryptAcquireContextA function from the advapi32 dynamic library. The advapi32 library cannot probably be loaded. =item C =for stopwords advapi32 The module was unable to call the CryptAcquireContextA function from the advapi32 dynamic library. =item C =for stopwords advapi32 CryptGenRandom The module was unable to load the CryptGenRandom function from the advapi32 dynamic library. =item C =for stopwords SystemFunction036 The module was unable to load the SystemFunction036 function from the advapi32 dynamic library. =item C The get method must be called with an integer argument to describe how many random bytes are required. =item C The Windows 2000 CryptGenRandom method call failed to generate the required amount of randomness =item C =for stopwords RtlGenRand The post Windows 2000 RtlGenRand method call failed to generate the required amount of randomness =item C The /dev/urandom device did not return the desired amount of random bytes =item C The /dev/urandom device returned an error when being read from =item C The /dev/urandom device returned an error when being opened =back =head1 CONFIGURATION AND ENVIRONMENT Crypt::URandom requires no configuration files or environment variables. If the environment variable CRYPT_URANDOM_BUILD_DEBUG is specified when running C or C AND L or it's equivalents cannot be detected, extra debug will be shown to show the failures to detect these functions. =head1 DEPENDENCIES =over =for stopwords perl If the platform is Win32, the Win32::API module will be required. Otherwise no other modules other than those provided by perl will be required =back =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS To report a bug, or view the current list of bugs, please visit L =head1 AUTHOR David Dick C<< >> =for stopwords ACKNOWLEDGEMENTS =head1 ACKNOWLEDGEMENTS =for stopwords CryptoAPI Kanat-Alexander The Win32::API code for interacting with Microsoft's L was copied with extreme gratitude from L by L =head1 LICENSE AND COPYRIGHT Copyright (c) 2025, David Dick C<< >>. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 DISCLAIMER OF WARRANTY =for stopwords MERCHANTABILITY LICENCE BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Crypt-URandom-0.54/README0000644000175000017500000001421514765245056013427 0ustar davedaveNAME Crypt::URandom - Provide non blocking randomness VERSION This document describes Crypt::URandom version 0.54 SYNOPSIS use Crypt::URandom(); my $random_string_50_bytes_long = Crypt::URandom::urandom(50); OR use Crypt::URandom qw( urandom ); my $random_string_50_bytes_long = urandom(50); DESCRIPTION This Module is intended to provide an interface to the strongest available source of non-blocking randomness on the current platform. Platforms currently supported are anything supporting getrandom(2), /dev/urandom and versions of Windows greater than or equal to Windows 2000. SUBROUTINES/METHODS urandom This function accepts an integer and returns a string of the same size filled with random data. It will throw an exception if the requested amount of random data is not returned. The first call will initialize the native cryptographic libraries (if necessary) and load all the required Perl libraries. This call is a buffered read on non Win32 platforms that do not support getrandom(2) or equivalent. urandom_ub This function accepts an integer and returns a string of the same size filled with random data. It will throw an exception if the requested amount of random data is not returned. The first call will initialize the native cryptographic libraries (if necessary) and load all the required Perl libraries. This call is a unbuffered sysread on non Win32 platforms that do not support getrandom(2) or equivalent. getrandom This function accepts an integer and returns a string of the same size filled with random data on platforms that implement getrandom(2). It will throw an exception if the requested amount of random data is not returned. This is NOT portable across all operating systems, but is made available if high-speed generation of random numbers is required. DIAGNOSTICS No secure alternative for random number generation for Win32 versions older than W2K The module cannot run on versions of Windows earlier than Windows 2000 as there is no cryptographic functions provided by the operating system. Could not import CryptAcquireContext The module was unable to load the CryptAcquireContextA function from the advapi32 dynamic library. The advapi32 library cannot probably be loaded. CryptAcquireContext failed The module was unable to call the CryptAcquireContextA function from the advapi32 dynamic library. Could not import CryptGenRandom The module was unable to load the CryptGenRandom function from the advapi32 dynamic library. Could not import SystemFunction036 The module was unable to load the SystemFunction036 function from the advapi32 dynamic library. The length argument must be supplied and must be an integer The get method must be called with an integer argument to describe how many random bytes are required. CryptGenRandom failed The Windows 2000 CryptGenRandom method call failed to generate the required amount of randomness RtlGenRand failed The post Windows 2000 RtlGenRand method call failed to generate the required amount of randomness Only read n bytes from path The /dev/urandom device did not return the desired amount of random bytes Failed to read from path The /dev/urandom device returned an error when being read from Failed to open path The /dev/urandom device returned an error when being opened CONFIGURATION AND ENVIRONMENT Crypt::URandom requires no configuration files or environment variables. If the environment variable CRYPT_URANDOM_BUILD_DEBUG is specified when running perl Makefile.PL or make test AND getrandom(2) or it's equivalents cannot be detected, extra debug will be shown to show the failures to detect these functions. DEPENDENCIES If the platform is Win32, the Win32::API module will be required. Otherwise no other modules other than those provided by perl will be required INCOMPATIBILITIES None reported. BUGS AND LIMITATIONS To report a bug, or view the current list of bugs, please visit https://github.com/david-dick/crypt-urandom/issues AUTHOR David Dick ACKNOWLEDGEMENTS The Win32::API code for interacting with Microsoft's CryptoAPI was copied with extreme gratitude from Crypt::Random::Source::Strong::Win32 by Max Kanat-Alexander LICENSE AND COPYRIGHT Copyright (c) 2025, David Dick . All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Crypt-URandom-0.54/t/0000755000175000017500000000000014765245340013003 5ustar davedaveCrypt-URandom-0.54/t/getrandom.t0000644000175000017500000001064714765244526015165 0ustar davedaveuse Test::More; use FileHandle(); use POSIX(); use Encode(); use Config; use strict; use warnings; my %optional; if ($^O eq 'MSWin32') { } else { eval `cat ./check_random.inc`; if ($optional{DEFINE}) { diag("check_random.inc produced the flag of $optional{DEFINE}"); } } SKIP: { if ($^O eq 'linux') { # LD_PRELOAD trick works here require Crypt::URandom; my $can_load_getrandom = !!(eval 'defined Crypt::URandom::getrandom(1)'); if (!$can_load_getrandom) { chomp $@; skip("Cannot load getrandom in $^O':$@", 1); } elsif (($optional{DEFINE}) && ($optional{DEFINE} eq '-DHAVE_CRYPT_URANDOM_NATIVE_GETRANDOM')) { my $is_covering = !!(eval 'Devel::Cover::get_coverage()'); my @extra_args = $is_covering ? ('-MDevel::Cover') : (); my $correct_length = 27; my $failed_number_of_bytes = 13; my $error_number = POSIX::EINTR() + 0; my $c_path = 'getrandom.c'; unlink $c_path or ($! == POSIX::ENOENT()) or die "Failed to unlink $c_path:$!"; my $c_handle = FileHandle->new($c_path, Fcntl::O_CREAT() | Fcntl::O_WRONLY() | Fcntl::O_EXCL()) or die "Failed to open $c_path for writing:$!"; print $c_handle <<"_OUT_"; #include #include #include int count = 0; ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) { count = count + 1; if (count <= 2) { errno = $error_number; return $failed_number_of_bytes; } else { errno = 0; return buflen; } } _OUT_ my $binary_path = './getrandom.so'; my $result = system { $Config{cc} } $Config{cc}, $Config{cccdlflags}, '-shared', '-o', $binary_path, $c_path; ok($result == 0, "Compiled a LD_PRELOAD binary at $binary_path:$?"); my $handle = FileHandle->new(); if (my $pid = $handle->open(q[-|])) { my $result = $handle->read(my $line, $correct_length + 5); chomp $line; my $actual_length = length $line; ok($actual_length == $correct_length, "getrandom hit with INT signal after $failed_number_of_bytes bytes recovers to produce correct length of $correct_length bytes:$actual_length"); waitpid $pid, 0; ok($? == 0, "Successfully processed getrandom"); } elsif (defined $pid) { local $ENV{LD_PRELOAD} = $binary_path; eval { exec { $^X } $^X, (map { "-I$_" } @INC), @extra_args, '-MCrypt::URandom', '-e', 'my $data = Crypt::URandom::getrandom(' . $correct_length . '); print "$data\n"; exit 0;' or die "Failed to exec $^X:$!"; } or do { warn "$@"; }; exit 1; } else { die "Failed to fork:$!"; } unlink $c_path or die "Failed to unlink $c_path:$!"; unlink $binary_path or die "Failed to unlink $binary_path:$!";; $failed_number_of_bytes = -1; $error_number = POSIX::EAGAIN() + 0; $c_handle = FileHandle->new($c_path, Fcntl::O_CREAT() | Fcntl::O_WRONLY() | Fcntl::O_EXCL()) or die "Failed to open $c_path for writing:$!"; print $c_handle <<"_OUT_"; #include #include #include ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) { errno = $error_number; return $failed_number_of_bytes; } _OUT_ $result = system { $Config{cc} } $Config{cc}, $Config{cccdlflags}, '-shared', '-o', $binary_path, $c_path; ok($result == 0, "Compiled a LD_PRELOAD binary at $binary_path:$!"); $handle = FileHandle->new(); if (my $pid = $handle->open(q[-|])) { my $result = $handle->read(my $line, 4000); chomp $line; my ($actual_error, $entire_message) = split /\t/smx, $line; chomp $entire_message; $! = POSIX::EAGAIN(); my $correct_error = "$!"; ok($actual_error eq $correct_error, "Correct error caught:'$actual_error' vs '$correct_error'"); diag("EAGAIN looks like '$entire_message'"); waitpid $pid, 0; ok($? == 0, "Successfully caught exception for broken getrandom:$?"); } elsif (defined $pid) { local $ENV{LD_PRELOAD} = $binary_path; eval { exec { $^X } $^X, (map { "-I$_" } @INC), @extra_args, '-MEncode', '-MCrypt::URandom', '-e', 'eval { Crypt::URandom::getrandom(28); } or do { print Encode::encode("UTF-8", "$!\t$@\n"); exit 0 }; exit 1;' or die "Failed to exec $^X:$!"; } or do { warn "$@"; }; exit 1; } else { die "Failed to fork:$!"; } unlink $c_path or die "Failed to unlink $c_path:$!"; unlink $binary_path or die "Failed to unlink $binary_path:$!";; } else { skip("Not sure about alternative function signatures for $optional{DEFINE}", 1); } } else { skip("Not sure about LD_PRELOAD support in $^O", 1); } } done_testing(); Crypt-URandom-0.54/t/core_sysopen.t0000644000175000017500000000204714737570303015702 0ustar davedave#! /usr/bin/perl -w use strict; use warnings; use Test::More; use English(); use Carp(); use POSIX(); use English qw( -no_match_vars ); use Exporter(); use XSLoader(); use constant; use overload; SKIP: { if ($^O eq 'MSWin32') { skip("No functions to override in Win32", 1); } else { no warnings; *CORE::GLOBAL::sysopen = sub { $! = POSIX::EACCES(); return }; use warnings; my $required_error_message = q[(?:] . (quotemeta POSIX::strerror(POSIX::EACCES())) . q[|Permission[ ]denied)]; require FileHandle; @INC = qw(blib/lib); # making sure we're testing pure perl version require Crypt::URandom; my $generated = 0; eval { Crypt::URandom::urandom(1); $generated = 1; }; chomp $@; ok(!$generated && $@ =~ /$required_error_message/smx, "Correct exception thrown when sysopen is overridden:$@"); $generated = 0; eval { Crypt::URandom::urandom(1); $generated = 1; }; chomp $@; ok(!$generated && $@ =~ /$required_error_message/smx, "Correct exception thrown when sysopen is overridden twice:$@"); } } done_testing(); Crypt-URandom-0.54/t/core_fork_pp.t0000644000175000017500000000252314743120627015636 0ustar davedave#! /usr/bin/perl -w use strict; use warnings; use Test::More; use English(); use Carp(); use English qw( -no_match_vars ); use Exporter(); use XSLoader(); use constant; use overload; SKIP: { if ($^O eq 'MSWin32') { skip("No functions to override in Win32", 1); } else { require FileHandle; @INC = qw(blib/lib); # making sure we're testing pure perl version require Crypt::URandom; my $initial_length = 20; my $initial_data = Crypt::URandom::urandom($initial_length); ok(length $initial_data == $initial_length, "Correct number of bytes returned before fork:$initial_length"); if (my $pid = fork) { my $parent_length = 30; my $parent_data = Crypt::URandom::urandom($parent_length); ok(length $parent_data == $parent_length, "Correct number of bytes returned in parent after fork:$parent_length"); waitpid $pid, 0; ok($? == 0, "Correct number of bytes returned in child after fork"); } elsif (defined $pid) { my $child_length = 15; my $child_data = Crypt::URandom::urandom($child_length); if (length $child_data == $child_length) { exit 0; } else { exit 1; } } else { die "Failed to fork:$!"; } my $post_length = 20; my $post_data = Crypt::URandom::urandom($post_length); ok(length $post_data == $post_length, "Correct number of bytes returned after fork:$post_length"); } } done_testing(); Crypt-URandom-0.54/t/core_partial_read.t0000644000175000017500000000447414743376313016641 0ustar davedave#! /usr/bin/perl -w use strict; use warnings; use Test::More; use English(); use Carp(); use English qw( -no_match_vars ); use Exporter(); use XSLoader(); use POSIX(); use constant; use overload; SKIP: { if ($^O eq 'MSWin32') { skip("No functions to override in Win32", 1); } else { no warnings; *CORE::GLOBAL::read = sub { $_[1] = undef; $! = POSIX::EAGAIN(); return -1 }; *CORE::GLOBAL::sysread = sub { $_[1] = undef; $! = POSIX::EAGAIN(); return -1 }; use warnings; my $required_error_message = quotemeta "Failed to read from"; require FileHandle; @INC = qw(blib/lib); # making sure we're testing pure perl version require Crypt::URandom; my $generated = 0; eval { Crypt::URandom::urandom(1); $generated = 1; }; chomp $@; ok(!$generated && $@ =~ /$required_error_message/smx, "Correct exception thrown when partial read returns:$@"); $generated = 0; eval { Crypt::URandom::urandom_ub(1); $generated = 1; }; chomp $@; ok(!$generated && $@ =~ /$required_error_message/smx, "Correct exception thrown when partial sysread returns:$@"); my @sample_random_data = ('a', 'bc'); no warnings; *CORE::GLOBAL::read = sub { $_[1] = shift @sample_random_data; $! = POSIX::EINTR(); return length $_[1] }; use warnings; my $expected_result = join q[], @sample_random_data; my $actual_result = Crypt::URandom::urandom(3); ok($actual_result eq $expected_result, "Correctly survived an EINTR in urandom:$actual_result vs $expected_result"); @sample_random_data = ('a', 'bc'); no warnings; *CORE::GLOBAL::sysread = sub { $_[1] = shift @sample_random_data; $! = POSIX::EINTR(); return length $_[1] }; use warnings; $actual_result = Crypt::URandom::urandom_ub(3); ok($actual_result eq $expected_result, "Correctly survived an EINTR in urandom_nb:$actual_result vs $expected_result"); @sample_random_data = ('a', 'bc'); my $count = 0; no warnings; *CORE::GLOBAL::sysread = sub { $count += 1; if ($count == 1 || $count == 3) { $_[1] = undef; $! == POSIX::EINTR(); return -1 } else { $_[1] = shift @sample_random_data; ($count == 2 ? $! =0 : $! = POSIX::EINTR()); return length $_[1] } }; use warnings; $actual_result = Crypt::URandom::urandom_ub(3); ok($actual_result eq $expected_result, "Correctly survived an EINTR in urandom_nb:$actual_result vs $expected_result"); } } done_testing(); Crypt-URandom-0.54/t/core_fork.t0000644000175000017500000000217714735734005015146 0ustar davedave#! /usr/bin/perl -w use strict; use warnings; use Test::More; SKIP: { if ($^O eq 'MSWin32') { skip("No functions to override in Win32", 1); } else { require Crypt::URandom; my $initial_length = 20; my $initial_data = Crypt::URandom::urandom($initial_length); ok(length $initial_data == $initial_length, "Correct number of bytes returned before fork:$initial_length"); if (my $pid = fork) { my $parent_length = 30; my $parent_data = Crypt::URandom::urandom($parent_length); ok(length $parent_data == $parent_length, "Correct number of bytes returned in parent after fork:$parent_length"); waitpid $pid, 0; ok($? == 0, "Correct number of bytes returned in child after fork"); } elsif (defined $pid) { my $child_length = 15; my $child_data = Crypt::URandom::urandom($child_length); if (length $child_data == $child_length) { exit 0; } else { exit 1; } } else { die "Failed to fork:$!"; } my $post_length = 20; my $post_data = Crypt::URandom::urandom($post_length); ok(length $post_data == $post_length, "Correct number of bytes returned after fork:$post_length"); } } done_testing(); Crypt-URandom-0.54/t/boilerplate.t0000644000175000017500000000264514563733503015500 0ustar davedave#!perl -T use 5.006; use strict; use warnings FATAL => 'all'; use Test::More; plan tests => 3; sub not_in_file_ok { my ($filename, %regex) = @_; open( my $fh, '<', $filename ) or die "couldn't open $filename for reading: $!"; my %violated; while (my $line = <$fh>) { while (my ($desc, $regex) = each %regex) { if ($line =~ $regex) { push @{$violated{$desc}||=[]}, $.; } } } if (%violated) { fail("$filename contains boilerplate text"); diag "$_ appears on lines @{$violated{$_}}" for keys %violated; } else { pass("$filename contains no boilerplate text"); } } 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]/, 'rt.cpan.org' => qr/rt.cpan.org/, # preferred bug tracker. ); } not_in_file_ok(README => "The README is used..." => qr/The README is used/, "'version information here'" => qr/to provide version information/, 'rt.cpan.org' => qr/rt.cpan.org/, # preferred bug tracker. ); not_in_file_ok(Changes => "placeholder date/time" => qr(Date/time) ); module_boilerplate_ok('lib/Crypt/URandom.pm'); Crypt-URandom-0.54/t/pod.t0000644000175000017500000000021414426673062013747 0ustar davedave#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok(); Crypt-URandom-0.54/t/core_read.t0000644000175000017500000000370114743271614015113 0ustar davedave#! /usr/bin/perl -w use strict; use warnings; use Test::More; use English(); use Carp(); use English qw( -no_match_vars ); use POSIX(); use Exporter(); use XSLoader(); use constant; use overload; BEGIN { if ($^O eq 'MSWin32') { require Win32; require Win32::API; require Win32::API::Type; } } SKIP: { if ($^O eq 'MSWin32') { no warnings; sub Win32::API::new { return } use warnings; my $required_error_message = quotemeta "Could not import"; require Crypt::URandom; my $generated = 0; eval { Crypt::URandom::urandom(1); $generated = 1; }; chomp $@; ok(!$generated && $@ =~ /$required_error_message/smx, "Correct exception thrown when Win32::API->new() is overridden:$@"); } else { no warnings; *CORE::GLOBAL::read = sub { $! = POSIX::EACCES(); return -1 }; *CORE::GLOBAL::sysread = sub { $! = POSIX::EACCES(); return -1 }; use warnings; my $required_error_message = q[(?:] . (quotemeta POSIX::strerror(POSIX::EACCES())) . q[|Permission[ ]denied)]; require FileHandle; @INC = qw(blib/lib); # making sure we're testing pure perl version require Crypt::URandom; my $generated = 0; eval { Crypt::URandom::urandom(1); $generated = 1; }; chomp $@; ok(!$generated && $@ =~ /$required_error_message/smx, "Correct exception thrown when read is overridden:$@"); $generated = 0; eval { Crypt::URandom::urandom(1); $generated = 1; }; chomp $@; ok(!$generated && $@ =~ /$required_error_message/smx, "Correct exception thrown when read is overridden twice:$@"); $generated = 0; eval { Crypt::URandom::urandom_ub(1); $generated = 1; }; chomp $@; ok(!$generated && $@ =~ /$required_error_message/smx, "Correct exception thrown when sysread is overridden:$@"); $generated = 0; eval { Crypt::URandom::urandom_ub(1); $generated = 1; }; chomp $@; ok(!$generated && $@ =~ /$required_error_message/smx, "Correct exception thrown when sysread is overridden twice:$@"); } } done_testing(); Crypt-URandom-0.54/t/00.load.t0000644000175000017500000000017614426673062014331 0ustar davedaveuse Test::More tests => 1; BEGIN { use_ok( 'Crypt::URandom' ); } diag( "Testing Crypt::URandom $Crypt::URandom::VERSION" ); Crypt-URandom-0.54/t/pp.t0000644000175000017500000000155114743126025013603 0ustar davedave use Test::More; use English(); use Carp(); use English qw( -no_match_vars ); use Exporter(); use XSLoader(); use constant; use overload; BEGIN { if ($^O eq 'MSWin32') { require Win32; require Win32::API; require Win32::API::Type; } else { require FileHandle; } } @INC = qw(blib/lib); # making sure we're testing pure perl version require Crypt::URandom; foreach my $correct (qw(500000 500 50)) { my $actual = length Crypt::URandom::urandom($correct); ok($actual == $correct, "Crypt::URandom::urandom($correct) returned $actual bytes"); $actual = length Crypt::URandom::urandom_ub($correct); ok($actual == $correct, "Crypt::URandom::urandom_ub($correct) returned $actual bytes"); eval { Crypt::URandom::getrandom($correct); }; ok($@, "Crypt::URandom::getrandom throws an exception when the .so library is unavailable:$@"); } done_testing(); Crypt-URandom-0.54/t/manifest.t0000644000175000017500000000057214734164336015003 0ustar davedave#!perl -T use 5.006; use strict; use warnings FATAL => 'all'; use Test::More; unless ( $ENV{RELEASE_TESTING} ) { plan( skip_all => "Author tests not required for installation" ); } my $min_tcm = 0.9; eval "use Test::CheckManifest $min_tcm"; plan skip_all => "Test::CheckManifest $min_tcm required" if $@; ok_manifest({filter => [qr/\.git/, qr/URandom.(?:bs|c|o|def)/]}); Crypt-URandom-0.54/t/rand.t0000644000175000017500000000234014743126025014105 0ustar davedaveuse Test::More tests => 10; use Crypt::URandom(); foreach my $correct (qw(500000 500 50)) { my $actual = length Crypt::URandom::urandom($correct); ok($actual == $correct, "Crypt::URandom::urandom($correct) returned $actual bytes"); $actual = length Crypt::URandom::urandom_ub($correct); ok($actual == $correct, "Crypt::URandom::urandom_ub($correct) returned $actual bytes"); } SKIP: { eval { require Encode; }; if ($@) { skip("Encode module cannot be loaded", 1); } else { my $returns_binary_data = 1; if (Encode::is_utf8(Crypt::URandom::urandom(2))) { $returns_binary_data = 0; } ok($returns_binary_data, 'Crypt::Urandom::urandom returns binary data'); $returns_binary_data = 1; if (Encode::is_utf8(Crypt::URandom::urandom_ub(2))) { $returns_binary_data = 0; } ok($returns_binary_data, 'Crypt::Urandom::urandom_ub returns binary data'); } } my $exception_thrown = 1; eval { Crypt::URandom::urandom(); $exception_thrown = 0; }; chomp $@; ok($exception_thrown, "Correctly throws exception with no parameter:$@"); $exception_thrown = 1; eval { Crypt::URandom::urandom("sdfadsf"); $exception_thrown = 0; }; chomp $@; ok($exception_thrown, "Correctly throws exception with non integer parameter:$@"); Crypt-URandom-0.54/t/export.t0000644000175000017500000000145314734651065014515 0ustar davedaveuse Test::More; use Crypt::URandom qw(urandom urandom_ub getrandom); ok(length(urandom(5000)) == 5000, 'urandom(5000) called successfully'); ok(length(urandom(1)) == 1, 'urandom(1) called successfully'); ok(length(urandom(0)) == 0, 'urandom(0) called successfully'); ok(length(urandom_ub(5000)) == 5000, 'urandom_ub(5000) called successfully'); ok(length(urandom_ub(1)) == 1, 'urandom_ub(1) called successfully'); ok(length(urandom_ub(0)) == 0, 'urandom_ub(0) called successfully'); my $getrandom = 1; eval { getrandom(1); 1; } or do { $getrandom = 0; }; if ($getrandom) { ok(length(getrandom(5000)) == 5000, 'getrandom(5000) called successfully'); ok(length(getrandom(1)) == 1, 'getrandom(1) called successfully'); ok(length(getrandom(0)) == 0, 'getrandom(0) called successfully'); } done_testing(); Crypt-URandom-0.54/README.md0000644000175000017500000001430014765245056014021 0ustar davedave# NAME Crypt::URandom - Provide non blocking randomness # VERSION This document describes Crypt::URandom version 0.54 # SYNOPSIS use Crypt::URandom(); my $random_string_50_bytes_long = Crypt::URandom::urandom(50); OR use Crypt::URandom qw( urandom ); my $random_string_50_bytes_long = urandom(50); # DESCRIPTION This Module is intended to provide an interface to the strongest available source of non-blocking randomness on the current platform. Platforms currently supported are anything supporting [getrandom(2)](http://man.he.net/man2/getrandom), /dev/urandom and versions of Windows greater than or equal to Windows 2000. # SUBROUTINES/METHODS - `urandom` This function accepts an integer and returns a string of the same size filled with random data. It will throw an exception if the requested amount of random data is not returned. The first call will initialize the native cryptographic libraries (if necessary) and load all the required Perl libraries. This call is a buffered read on non Win32 platforms that do not support [getrandom(2)](http://man.he.net/man2/getrandom) or equivalent. - `urandom_ub` This function accepts an integer and returns a string of the same size filled with random data. It will throw an exception if the requested amount of random data is not returned. The first call will initialize the native cryptographic libraries (if necessary) and load all the required Perl libraries. This call is a unbuffered sysread on non Win32 platforms that do not support [getrandom(2)](http://man.he.net/man2/getrandom) or equivalent. - `getrandom` This function accepts an integer and returns a string of the same size filled with random data on platforms that implement [getrandom(2)](http://man.he.net/man2/getrandom). It will throw an exception if the requested amount of random data is not returned. This is NOT portable across all operating systems, but is made available if high-speed generation of random numbers is required. # DIAGNOSTICS - `No secure alternative for random number generation for Win32 versions older than W2K` The module cannot run on versions of Windows earlier than Windows 2000 as there is no cryptographic functions provided by the operating system. - `Could not import CryptAcquireContext` The module was unable to load the CryptAcquireContextA function from the advapi32 dynamic library. The advapi32 library cannot probably be loaded. - `CryptAcquireContext failed` The module was unable to call the CryptAcquireContextA function from the advapi32 dynamic library. - `Could not import CryptGenRandom` The module was unable to load the CryptGenRandom function from the advapi32 dynamic library. - `Could not import SystemFunction036` The module was unable to load the SystemFunction036 function from the advapi32 dynamic library. - `The length argument must be supplied and must be an integer` The get method must be called with an integer argument to describe how many random bytes are required. - `CryptGenRandom failed` The Windows 2000 CryptGenRandom method call failed to generate the required amount of randomness - `RtlGenRand failed` The post Windows 2000 RtlGenRand method call failed to generate the required amount of randomness - `Only read n bytes from path` The /dev/urandom device did not return the desired amount of random bytes - `Failed to read from path` The /dev/urandom device returned an error when being read from - `Failed to open path` The /dev/urandom device returned an error when being opened # CONFIGURATION AND ENVIRONMENT Crypt::URandom requires no configuration files or environment variables. If the environment variable CRYPT\_URANDOM\_BUILD\_DEBUG is specified when running `perl Makefile.PL` or `make test` AND [getrandom(2)](http://man.he.net/man2/getrandom) or it's equivalents cannot be detected, extra debug will be shown to show the failures to detect these functions. # DEPENDENCIES > If the platform is Win32, the Win32::API module will be required. Otherwise > no other modules other than those provided by perl will be required # INCOMPATIBILITIES None reported. # BUGS AND LIMITATIONS To report a bug, or view the current list of bugs, please visit [https://github.com/david-dick/crypt-urandom/issues](https://github.com/david-dick/crypt-urandom/issues) # AUTHOR David Dick `` # ACKNOWLEDGEMENTS The Win32::API code for interacting with Microsoft's [CryptoAPI](https://en.wikipedia.org/wiki/Microsoft_CryptoAPI) was copied with extreme gratitude from [Crypt::Random::Source::Strong::Win32](https://metacpan.org/pod/Crypt%3A%3ARandom%3A%3ASource%3A%3AStrong%3A%3AWin32) by [Max Kanat-Alexander](https://metacpan.org/author/MKANAT) # LICENSE AND COPYRIGHT Copyright (c) 2025, David Dick ``. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. # DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Crypt-URandom-0.54/Changes0000644000175000017500000000752414765245212014041 0ustar davedaveRevision history for Crypt-URandom 0.54 Sat Mar 15 20:37:13 2025 - Reverse solaris changes and remove errstr checks. Thanks to eserte for GH#18 0.53 Sat Feb 08 20:03:30 2025 - Changes to try and catch CPAN Tester failures on solaris 0.52 Thu Jan 23 06:33:51 2025 - Fixes to test suite. Thanks to Petr Pisar for GH#17 0.51 Wed Jan 22 22:18:19 2025 - Improvements to handling SIGINT. Thanks to Leon Timmermans for GH#14 - Memory leak fix. Thanks to Leon Timmermans for GH#15 - Using arc4random_buf for OpenBSD/OSX. Thanks to Leon Timmermans for GH#16 - Documentation fixes 0.50 Thu Jan 09 08:50:18 2025 - Adding explicit requirements for tests. Thanks to Leon Timmermans for GH#13 0.49 Wed Jan 08 08:24:35 2025 - Fix URL for Artistic License. Thanks to Petr Pisar for GH#12 0.48 Tue Jan 07 08:01:04 2025 - Documentation fixes 0.47 Mon Jan 06 21:40:53 2025 - Adding LICENSE file - Hiding compiler output behind CRYPT_URANDOM_BUILD_DEBUG - Small cleanups 0.46 Sat Jan 04 19:44:05 2025 - CPAN Testers fixes and cleanups 0.45 Sat Jan 04 09:25:36 2025 - Fixing links in SECURITY.md. Thanks to Robert Rothenberg for GH#11 0.44 Sat Jan 04 08:12:40 2025 - Added SECURITY.md. Thanks to Robert Rothenberg for GH#10 - Fixed GH#8 and GH#9 related to getrandom(2) support. Thanks to Petr Pisar 0.43 Fri Jan 03 19:58:22 2025 - More fixes to test suite. Thanks to Slaven Rezić for GH#6 0.42 Fri Jan 03 10:49:20 2025 - Fixes to test suite. Thanks to Slaven Rezić for GH#6 0.41 Thu Jan 02 09:51:36 2025 - Adding getrandom(2) support including a dedicated method. Thanks to Robert Rothenberg and H.Merijn Brand for GH#5 0.40 Sat Feb 17 06:34:33 2024 - Moving $OSNAME checks to compile time with GH#4. Thanks to Aristotle. - Test and documentation fixes in GH#1, GH#2, GH#3. Thanks to guest20. 0.39 Sun May 21 18:58:33 2023 - Adding support for test suite in non english locales - Test and documentation fixes 0.38 Thu May 11 05:52:03 2023 - Adding support for github actions - Improving test support 0.37 Wed May 10 21:48:03 2023 - Adding urandom_ub method for unbuffered sysreads - Copying with possible?? failures in reading from /dev/urandom - Improved coverage testing 0.36 Mon Jun 01 21:37:26 2011 - Fixing bug that caused errors when requesting urandom before and after forking 0.35 Thu May 14 06:07:03 2011 - Corrected Manifest - RT#101208 - Removed Build.PL - RT#104406 0.34 Sun Mar 10 20:18:43 2011 - Removed t/pod-coverage.t 0.33 Sat Mar 09 15:29:41 2011 - Added @CARP_NOT 0.32 Sat Mar 09 15:15:37 2011 - Reformatting 0.31 Fri Mar 01 17:56:58 2011 - More test case fixes 0.30 Mon Feb 25 07:55:00 2011 - Fixed test cases 0.29 Thu Feb 14 06:40:41 2011 - Added binmode call to the open for /dev/urandom - Optimised /dev/urandom access to only open a filehandle once and only reopen after read errors 0.28 Wed Apr 20 06:45:41 2011 - Dropped extra 0 in version number - Now passes perlcritic -1 0.0.27 Wed Apr 20 06:45:41 2011 - Included t/export.t in MANIFEST - Formatting changes - Changed module name from Crypt::Random::NonBlocking to Crypt::URandom 0.0.25 Mon Apr 18 18:55:30 2011 - Removed t/perlcritic.t due to other Perl::Critic policies being testing on cpan.org - Changed the interface to be Crypt::Random::NonBlocking::urandom(); - Allowed urandom to be exported 0.0.23 Mon Apr 18 07:56:17 2011 - Added t/rand.t to actually test the module 0.0.21 Mon Apr 18 07:00:17 2011 - Removed dependency Readonly entirely as it is a non-core module 0.0.19 Sun Apr 17 20:42:17 2011 - Added dependency Readonly to fix RT Ticket 67532 filed by YSAWANT 0.0.11 Sun Apr 17 10:45:13 2011 - Initial release. Crypt-URandom-0.54/LICENSE0000644000175000017500000004702514737314700013551 0ustar davedaveThis is free software; you can redistribute it and/or modify it under the same terms as the Perl5 (v5.0.0 ~ v5.40.0) programming language system itself: under the terms of either: a) the "Artistic License 1.0" as published by The Perl Foundation https://www.perlfoundation.org/artistic-license-10.html b) the GNU General Public License as published by the Free Software Foundation; either version 1 http://www.gnu.org/licenses/gpl-1.0.html or (at your option) any later version PLEASE NOTE: It is the current maintainers intention to keep the dual licensing intact. Until this notice is removed, releases will continue to be available under both the standard GPL and the less restrictive Artistic licenses. Verbatim copies of both licenses are included below: --- The Artistic License 1.0 --- The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. --- end of The Artistic License 1.0 --- --- The GNU General Public License, Version 1, February 1989 --- GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy 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 the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- end of The GNU General Public License, Version 1, February 1989 --- Crypt-URandom-0.54/META.json0000644000175000017500000000304014765245340014156 0ustar davedave{ "abstract" : "Provide non blocking randomness", "author" : [ "David Dick " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Crypt-URandom", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp" : "1.26", "English" : "0", "Exporter" : "0", "FileHandle" : "0", "constant" : "0", "perl" : "5.006" } }, "test" : { "requires" : { "Encode" : "0", "POSIX" : "0", "Test::More" : "0", "Test::Pod" : "1.14" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/david-dick/crypt-urandom/issues" }, "repository" : { "type" : "git", "url" : "https://github.com/david-dick/crypt-urandom", "web" : "https://github.com/david-dick/crypt-urandom" } }, "version" : "0.54", "x_serialization_backend" : "JSON::PP version 4.16" } Crypt-URandom-0.54/MANIFEST0000644000175000017500000000070414743120712013661 0ustar davedaveChanges check_random.inc LICENSE MANIFEST Makefile.PL README README.md SECURITY.md lib/Crypt/URandom.pm t/00.load.t t/boilerplate.t t/getrandom.t t/pod.t t/pp.t t/rand.t t/export.t t/core_fork.t t/core_fork_pp.t t/core_partial_read.t t/core_read.t t/core_sysopen.t t/manifest.t URandom.xs META.yml Module meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Crypt-URandom-0.54/Makefile.PL0000644000175000017500000000407014737571143014515 0ustar davedaveuse strict; use warnings; use ExtUtils::MakeMaker; my %optional; if ($^O eq 'MSWin32') { $optional{OBJECT} = q[]; $optional{C} = []; $optional{MYEXTLIB} = q[]; } else { eval `cat ./check_random.inc`; if (($optional{DEFINE}) && ($optional{DEFINE} eq '-DNO_COMPILER_FOUND')) { # figured this out from ExtUtils/MM_Unix.pm in has_link_code $optional{OBJECT} = q[]; $optional{C} = []; $optional{MYEXTLIB} = q[]; delete $optional{DEFINE}; } elsif (($optional{DEFINE}) && ($optional{DEFINE} eq '-DUNKNOWN_ENVIRONMENT')) { $optional{OBJECT} = q[]; $optional{C} = []; $optional{MYEXTLIB} = q[]; delete $optional{DEFINE}; } } WriteMakefile( NAME => 'Crypt::URandom', AUTHOR => 'David Dick ', VERSION_FROM => 'lib/Crypt/URandom.pm', %optional, ABSTRACT_FROM => 'lib/Crypt/URandom.pm', ( $ExtUtils::MakeMaker::VERSION >= 6.3002 ? ( 'LICENSE' => 'perl' ) : () ), ( $ExtUtils::MakeMaker::VERSION >= 6.48 ? ( 'MIN_PERL_VERSION' => '5.006' ) : () ), META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { url => 'https://github.com/david-dick/crypt-urandom', web => 'https://github.com/david-dick/crypt-urandom', type => 'git', }, bugtracker => { web => 'https://github.com/david-dick/crypt-urandom/issues' }, }, }, PL_FILES => {}, CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => 0, }, TEST_REQUIRES => { 'Encode' => 0, 'POSIX' => 0, 'Test::More' => 0, 'Test::Pod' => 1.14, }, PREREQ_PM => { 'Exporter' => 0, 'Carp' => 1.26, # used on RHEL7 'constant' => 0, 'English' => 0, ($^O eq 'MSWin32') ? ( 'Win32::API' => 0 ) : ( 'FileHandle' => 0 ), }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Crypt-URandom-*' }, ); Crypt-URandom-0.54/check_random.inc0000644000175000017500000001051714743154452015653 0ustar davedaveuse Config; sub warn_or_diag { if ($INC{'Test/More.pm'}) { diag(@_); } else { warn @_; } } my $test_file_name = 'test.c'; my $binary_name = 'a.out'; my $output = q[]; open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!"; print FOO <<'_OUT_'; #include #include int main(void) { char buf[5]; int l = 5; unsigned int o = 1; int r = getrandom(buf, l, o); return 0; } _OUT_ close FOO or die "Failed to close $test_file_name:$!"; $output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`; unlink $test_file_name or die "Failed to unlink $test_file_name:$!"; if ($? == 0) { warn_or_diag "getrandom from sys/random is AVAILABLE\n"; unlink $binary_name or die "Failed to unlink $binary_name:$!"; $optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_NATIVE_GETRANDOM'; } else { warn_or_diag "getrandom from sys/random is unavailable\n"; open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!"; print FOO <<'_OUT_'; #include int main(void) { char buf[5]; int l = 5; unsigned int o = 1; int r = syscall(SYS_getrandom, buf, l, o); return 0; } _OUT_ close FOO or die "Failed to close $test_file_name:$!"; $output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`; if ($? == 0) { warn_or_diag "SYS_getrandom from sys/syscall is AVAILABLE\n"; unlink $binary_name or die "Failed to unlink $binary_name:$!"; $optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_SYSCALL_GETRANDOM'; } else { warn_or_diag "SYS_getrandom from sys/syscall is unavailable\n"; open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!"; print FOO <<'_OUT_'; #include #include int main(void) { char buf[5]; int l = 5; arc4random_buf(buf, l); return l; } _OUT_ close FOO or die "Failed to close $test_file_name:$!"; $output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`; if ($? == 0) { warn_or_diag "arc4random_buf from sys/random is AVAILABLE\n"; unlink $binary_name or die "Failed to unlink $binary_name:$!"; $optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_NATIVE_ARC4RANDOM_BUF'; } else { warn_or_diag "arc4random_buf from sys/random is unavailable\n"; open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!"; print FOO <<'_OUT_'; #include int main(void) { char buf[5]; int l = 5; arc4random_buf(buf, l); return l; } _OUT_ close FOO or die "Failed to close $test_file_name:$!"; $output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`; if ($? == 0) { warn_or_diag "arc4random_buf from unistd is AVAILABLE\n"; unlink $binary_name or die "Failed to unlink $binary_name:$!"; $optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_UNISTD_ARC4RANDOM_BUF'; } else { warn_or_diag "arc4random_buf from unistd is unavailable\n"; open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!"; print FOO <<'_OUT_'; #include int main(void) { char buf[5]; int l = 5; arc4random_buf(buf, l); return l; } _OUT_ close FOO or die "Failed to close $test_file_name:$!"; $output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`; if ($? == 0) { warn_or_diag "arc4random_buf from stdlib is AVAILABLE\n"; unlink $binary_name or die "Failed to unlink $binary_name:$!"; $optional{DEFINE} = '-DHAVE_CRYPT_URANDOM_STDLIB_ARC4RANDOM_BUF'; } else { warn_or_diag "arc4random_buf from unistd is unavailable\n"; open FOO, ">$test_file_name" or die "Failed to open $test_file_name for writing:$!"; print FOO <<'_OUT_'; int main(void) { return 0; } _OUT_ close FOO or die "Failed to close $test_file_name:$!"; $output .= `$Config{cc} -o $binary_name $test_file_name 2>&1`; if ($? == 0) { warn_or_diag "C compiler is AVAILABLE\n"; if ($ENV{CRYPT_URANDOM_BUILD_DEBUG}) { warn_or_diag $output; } unlink $binary_name or die "Failed to unlink $binary_name:$!"; $optional{DEFINE} = '-DUNKNOWN_ENVIRONMENT'; } else { warn_or_diag "C compiler is unavailable\n"; $optional{DEFINE} = '-DNO_COMPILER_FOUND'; } } } } } unlink $test_file_name or die "Failed to unlink $test_file_name:$!"; } Crypt-URandom-0.54/URandom.xs0000644000175000017500000000355514765156464014501 0ustar davedave#define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include #ifdef HAVE_CRYPT_URANDOM_NATIVE_GETRANDOM #include #else #ifdef HAVE_CRYPT_URANDOM_SYSCALL_GETRANDOM #include #else #ifdef HAVE_CRYPT_URANDOM_NATIVE_ARC4RANDOM_BUF #include #else #ifdef HAVE_CRYPT_URANDOM_UNISTD_ARC4RANDOM_BUF #include #else #ifdef HAVE_CRYPT_URANDOM_STDLIB_ARC4RANDOM_BUF #include #endif #endif #endif #endif #endif #ifdef GRND_NONBLOCK #else #define GRND_NONBLOCK 0x0001 #endif #include MODULE = Crypt::URandom PACKAGE = Crypt::URandom PREFIX = crypt_urandom_ PROTOTYPES: ENABLE SV * crypt_urandom_getrandom(length) ssize_t length PREINIT: char *data; int result; CODE: Newx(data, length + 1u, char); GETRANDOM: #ifdef HAVE_CRYPT_URANDOM_NATIVE_GETRANDOM result = getrandom(data, length, GRND_NONBLOCK); #else #ifdef HAVE_CRYPT_URANDOM_SYSCALL_GETRANDOM result = syscall(SYS_getrandom, data, length, GRND_NONBLOCK); #else #ifdef HAVE_CRYPT_URANDOM_NATIVE_ARC4RANDOM_BUF arc4random_buf(data, length); result = length; #else #ifdef HAVE_CRYPT_URANDOM_UNISTD_ARC4RANDOM_BUF arc4random_buf(data, length); result = length; #else #ifdef HAVE_CRYPT_URANDOM_STDLIB_ARC4RANDOM_BUF arc4random_buf(data, length); result = length; #else croak("Unable to find getrandom or an alternative"); #endif #endif #endif #endif #endif if (result != length) { if (errno == EINTR) { goto GETRANDOM; } else { Safefree(data); croak("Failed to getrandom:%s", strerror(errno)); } } data[result] = '\0'; RETVAL = newSVpv(data, result); Safefree(data); OUTPUT: RETVAL Crypt-URandom-0.54/SECURITY.md0000644000175000017500000000700714740100713014320 0ustar davedaveThis is the Security Policy for the Perl distribution Crypt-URandom. The latest version of this Security Policy can be found in the git repository at [https://github.com/david-dick/crypt-urandom/security/policy](https://github.com/david-dick/crypt-urandom/security/policy). This text is based on the CPAN Security Group's Guidelines for Adding a Security Policy to Perl Distributions (version 0.1.9). https://security.metacpan.org/docs/guides/security-policy-for-authors.html # How to Report a Security Vulnerability Security vulnerabilties can be reported by e-mail to the current project maintainer(s) at . Please include as many details as possible, including code samples or test cases, so that we can reproduce the issue. If you would like any help with triaging the issue, or if the issue is being actively exploited, please copy the report to the CPAN Security Group (CPANSec) at . Please *do not* use the public issue reporting system on RT or GitHub issues for reporting security vulnerabilities. Please do not disclose the security vulnerability in public forums until past any proposed date for public disclosure, or it has been made public by the maintainers or CPANSec. That includes patches or pull requests. For more information, see [Report a Security Issue](https://security.metacpan.org/docs/report.html) on the CPANSec website. ## Response to Reports The maintainer(s) aim to acknowledge your security report as soon as possible. However, this project is maintained by a single person in their spare time, and they cannot guarantee a rapid response. If you have not received a response from the them within a week, then please send a reminder to them and copy the report to CPANSec at . Please note that the initial response to your report will be an acknowledgement, with a possible query for more information. It will not necessarily include any fixes for the issue. The project maintainer(s) may forward this issue to the security contacts for other projects where we believe it is relevant. This may include embedded libraries, system libraries, prerequisite modules or downstream software that uses this software. They may also forward this issue to CPANSec. # What Software this Policy Applies to Any security vulnerabilities in Crypt-URandom are covered by this policy. Security vulnerabilities are considered anything that allows users to execute unauthorised code, access unauthorised resources, or to have an adverse impact on accessibility or performance of a system. Security vulnerabilities in upstream software (embedded libraries, prerequisite modules or system libraries, or in Perl), are not covered by this policy unless they affect Crypt-URandom, or Crypt-URandom can be used to exploit vulnerabilities in them. Security vulnerabilities in downstream software (any software that uses Crypt-URandom, or plugins to it that are not included with the Crypt-URandom distribution) are not covered by this policy. ## Which Versions of this Software are Supported? The maintainer(s) will only commit to releasing security fixes for the latest version of Crypt-URandom. Note that the Crypt-URandom project only supports major versions of Perl released in the past ten (10) years, even though Crypt-URandom will run on older versions of Perl. If a security fix requires us to increase the minimum version of Perl that is supported, then we may do that. # Installation and Usage Issues Please see the module documentation for more information. Crypt-URandom-0.54/META.yml0000644000175000017500000000150014765245340014005 0ustar davedave--- abstract: 'Provide non blocking randomness' author: - 'David Dick ' build_requires: Encode: '0' ExtUtils::MakeMaker: '0' POSIX: '0' Test::More: '0' Test::Pod: '1.14' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Crypt-URandom no_index: directory: - t - inc requires: Carp: '1.26' English: '0' Exporter: '0' FileHandle: '0' constant: '0' perl: '5.006' resources: bugtracker: https://github.com/david-dick/crypt-urandom/issues repository: https://github.com/david-dick/crypt-urandom version: '0.54' x_serialization_backend: 'CPAN::Meta::YAML version 0.018'