| 1 | package Crypt::Random::Source; # git description: v0.13-4-g0edcf44 | ||||||||||||||||||||
| 2 | # ABSTRACT: Get weak or strong random data from pluggable sources | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.14'; | |||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use 5.008; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | ▶ | use Sub::Exporter -setup => { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | exports => [qw( | ||||||||||||||||||||
| 12 | get get_weak get_strong | ||||||||||||||||||||
| 13 | factory | ||||||||||||||||||||
| 14 | )], | ||||||||||||||||||||
| 15 | groups => { default => [qw(get get_weak get_strong)] }, | ||||||||||||||||||||
| 16 | 1 | }; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | ▶ | use Crypt::Random::Source::Factory; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 1 | our ( $factory, $weak, $strong, $any ); | |||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | # silence some stupid destructor warnings | ||||||||||||||||||||
| 23 | 1 | ▶ | END { undef $weak; undef $strong; undef $any; undef $factory } | ||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 1 | ▶ | sub factory () { $factory ||= Crypt::Random::Source::Factory->new } | ||||||||||||||||||
|
Subroutine
factory: called CC=2 SCAR=9.2
Pod
undocumented
Condition33%1/3
$Crypt::Random::Source::factory ||= "Crypt::Random::Source::Factory"->new
MC/DC0%0/2
$Crypt::Random::Source::factory ||= "Crypt::Random::Source::Factory"->new
$Crypt::Random::Source::factory
"Crypt::Random::Source::Factory"->new
Truth table33%1/3
A ||= B
A= $Crypt::Random::Source::factoryB= "Crypt::Random::Source::Factory"->new
| |||||||||||||||||||||
| 26 | 1 | ▶ | sub _weak () { $weak ||= factory->get_weak } | ||||||||||||||||||
|
Subroutine
_weak: called CC=2 SCAR=9.2
Condition33%1/3
$Crypt::Random::Source::weak ||= &factory()->get_weak
MC/DC0%0/2
$Crypt::Random::Source::weak ||= &factory()->get_weak
$Crypt::Random::Source::weak
&factory()->get_weak
Truth table33%1/3
A ||= B
A= $Crypt::Random::Source::weakB= &factory()->get_weak
| |||||||||||||||||||||
| 27 | 0 | ▶ | sub _strong () { $strong ||= factory->get_strong } | ||||||||||||||||||
|
Subroutine
_strong: not called CC=2 SCAR=17.9
Condition0%0/3
$Crypt::Random::Source::strong ||= &factory()->get_strong
MC/DC0%0/2
$Crypt::Random::Source::strong ||= &factory()->get_strong
$Crypt::Random::Source::strong
&factory()->get_strong
Truth table0%0/3
A ||= B
A= $Crypt::Random::Source::strongB= &factory()->get_strong
| |||||||||||||||||||||
| 28 | 0 | ▶ | sub _any () { $any ||= factory->get } | ||||||||||||||||||
|
Subroutine
_any: not called CC=2 SCAR=17.9
Condition0%0/3
$Crypt::Random::Source::any ||= &factory()->get
MC/DC0%0/2
$Crypt::Random::Source::any ||= &factory()->get
$Crypt::Random::Source::any
&factory()->get
Truth table0%0/3
A ||= B
A= $Crypt::Random::Source::anyB= &factory()->get
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | ▶ | sub get ($;@) { _any->get(@_) } | ||||||||||||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 31 | 1 | ▶ | sub get_weak ($;@) { _weak->get(@_) } | ||||||||||||||||||
|
Subroutine
get_weak: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 32 | 0 | ▶ | sub get_strong ($;@) { _strong->get(@_) } | ||||||||||||||||||
|
Subroutine
get_strong: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | # silence some stupid destructor warnings | ||||||||||||||||||||
| 35 | 1 | ▶ | END { undef $weak; undef $strong; undef $any; undef $factory } | ||||||||||||||||||
|
Subroutine
END: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 1 | 1; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | =pod | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | =encoding UTF-8 | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | =head1 NAME | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | Crypt::Random::Source - Get weak or strong random data from pluggable sources | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =head1 VERSION | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | version 0.14 | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | =head1 SYNOPSIS | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | use Crypt::Random::Source qw(get_strong); | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | # get 10 cryptographically strong random bytes from an available source | ||||||||||||||||||||
| 56 | my $bytes = get_strong(10); | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =head1 DESCRIPTION | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | This module provides implementations for a number of byte oriented sources of | ||||||||||||||||||||
| 61 | random data. | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | See L<Crypt::Random::Source::Factory> for a more powerful way to locate | ||||||||||||||||||||
| 64 | sources, and the various sources for specific implementations. | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =head1 EXPORTS | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | =over 4 | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =item get | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =item get_weak | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =item get_strong | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | These functions delegate to a source chosen by an instance of | ||||||||||||||||||||
| 77 | L<Crypt::Random::Source::Factory>, calling get | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =back | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =head1 CAVEATS | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | In versions prior to 0.13, C<rand> could be used as a result of calling | ||||||||||||||||||||
| 84 | C<get_weak>, or C<get>, if no random device was available. This implies that | ||||||||||||||||||||
| 85 | not explicitly asking for C<get_strong> on a non POSIX operating system (e.g. | ||||||||||||||||||||
| 86 | Win32 without the Win32 backend) could have resulted in non cryptographically | ||||||||||||||||||||
| 87 | random data. | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | Relatedly, the characterization of C<urandom> as a weak source of randomness is | ||||||||||||||||||||
| 90 | also largely a misconception, see L<https://www.2uo.de/myths-about-urandom/> | ||||||||||||||||||||
| 91 | for example. | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | =head1 SEE ALSO | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | L<Crypt::Random>, L<Crypt::Util> | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =head1 SUPPORT | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Crypt-Random-Source> | ||||||||||||||||||||
| 100 | (or L<bug-Crypt-Random-Source@rt.cpan.org|mailto:bug-Crypt-Random-Source@rt.cpan.org>). | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =head1 AUTHOR | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | =head1 CONTRIBUTORS | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =for stopwords Karen Etheridge Florian Ragwitz Graham Knop David Pottage Max Kanat-Alexander Edward Betts | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | =over 4 | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | =item * | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | Karen Etheridge <ether@cpan.org> | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =item * | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | Florian Ragwitz <rafl@debian.org> | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =item * | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | Graham Knop <haarg@haarg.org> | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =item * | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | David Pottage <spudsoup@cpan.org> | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | =item * | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | Max Kanat-Alexander <mkanat@es-compy.(none)> | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | =item * | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | Edward Betts <edward@4angle.com> | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | =back | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | This software is copyright (c) 2008 by Yuval Kogman. | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 143 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | __END__ | ||||||||||||||||||||