| 1 | ## | ||||||||||||||||||||||||||||||||||
| 2 | ## Copyright (c) 1998-2025, Vipul Ved Prakash. All rights reserved. | ||||||||||||||||||||||||||||||||||
| 3 | ## This code is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||
| 4 | ## it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | package Crypt::Random::Provider::egd; | ||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use IO::Socket; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Math::Pari qw(pari2num); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 3 | our $VERSION = '1.57'; | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | sub _defaultsource { | ||||||||||||||||||||||||||||||||
|
Subroutine
_defaultsource: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | 5 | my $source; | |||||||||||||||||||||||||||||||||
| 19 | 5 | for my $d (qw( /var/run/egd-pool /dev/egd-pool /etc/entropy )) { | |||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | if (IO::Socket::UNIX->new(Peer => $d)) { $source = $d; last } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||
| 22 | 5 | return $source; | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $self = { Source => $args{Source} || $args{Device} || $args{Filename} }; | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$args{'Source'} || $args{'Device'} || $args{'Filename'}
$args{"Source"} or $args{"Device"}
MC/DC0%0/3
$args{'Source'} || $args{'Device'} || $args{'Filename'}
$args{"Source"}
$args{"Device"}
$args{'Filename'}
Truth table0%0/4
A or B || C
A= $args{"Source"}B= $args{"Device"}C= $args{'Filename'}
| |||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $$self{Source} = $class->_defaultsource() unless $$self{Source}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | croak "egd entropy pool file not found.\n" unless $$self{Source}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 33 | 0 | return bless $self, $class; | |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub get_data { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_data: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | 0 | my ( $self, %params ) = @_; | |||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $self = {} unless ref $self; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | my $bytes = $params{Length} || | ||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | (int( pari2num($params{ Size }) / 8) + 1); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params{'Length'} || int(&pari2num($params{'Size'}) / 8) + 1
MC/DC0%0/2
$params{'Length'} || int(&pari2num($params{'Size'}) / 8) + 1
$params{'Length'}
int(&pari2num($params{'Size'}) / 8) + 1
Truth table0%0/3
A || B
A= $params{'Length'}B= int(&pari2num($params{'Size'}) / 8) + 1
| |||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $dev = $params{Source} || $$self{Source}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$params{'Source'} || $self->{'Source'}
MC/DC0%0/2
$params{'Source'} || $self->{'Source'}
$params{'Source'}
$self->{'Source'}
Truth table0%0/3
A || B
A= $params{'Source'}B= $self->{'Source'}
| |||||||||||||||||||||||||||||||||||
| 47 | 0 | my $skip = $params{Skip}; | |||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | croak "$dev doesn't exist. aborting." unless $dev && -e $dev; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$dev and -e $dev
MC/DC0%0/2
$dev and -e $dev
$dev
-e $dev
Truth table0%0/3
A and B
A= $devB= -e $dev
| |||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | 0 | my $s = IO::Socket::UNIX->new(Peer => $dev); | |||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | croak "couldn't talk to egd. $!" unless $s; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 0 | my($r, $read) = ('', 0); | |||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | while ($read < $bytes) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 56 | 0 | my $msg = pack "CC", 0x01, 1; | |||||||||||||||||||||||||||||||||
| 57 | 0 | $s->syswrite($msg, length $msg); | |||||||||||||||||||||||||||||||||
| 58 | 0 | my $rt; | |||||||||||||||||||||||||||||||||
| 59 | 0 | my $nread = $s->sysread($rt, 1); | |||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | croak "read from entropy socket failed" unless $nread == 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 61 | 0 | my $count = unpack("C", $rt); | |||||||||||||||||||||||||||||||||
| 62 | 0 | $nread = $s->sysread($rt, $count); | |||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | croak "couldn't get all the requested entropy. aborting." | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | unless $nread == $count; | ||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | unless ($skip && $skip =~ /\Q$rt\E/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$skip and $skip =~ /\Q$rt\E/
MC/DC0%0/2
$skip and $skip =~ /\Q$rt\E/
$skip
$skip =~ /\Q$rt\E/
Truth table0%0/3
A and B
A= $skipB= $skip =~ /\Q$rt\E/
| |||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if ($params{Verbosity}) { print '.' unless $read % 2 } | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 67 | 0 | $r .= $rt; | |||||||||||||||||||||||||||||||||
| 68 | 0 | $read++; | |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 0 | $r; | |||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 5 | ▶ | sub available { | ||||||||||||||||||||||||||||||||
|
Subroutine
available: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | 5 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 79 | 5 | ▶ | return 1 if $class->_defaultsource(); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | 5 | return; | |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | 3 | 1; | |||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||