← Index
NYTProf Performance Profile   « line view »
For /Users/brian/bin/perls/cpan5.26.1
  Run on Sat Dec 30 01:41:10 2017
Reported on Sat Dec 30 01:44:15 2017

Filename/usr/local/perls/perl-5.26.1/lib/5.26.1/darwin-2level/Digest/SHA.pm
StatementsExecuted 31 statements in 3.99ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
89113.01ms3.01msDigest::SHA::::addDigest::SHA::add (xsub)
111810µs810µsDigest::SHA::::bootstrapDigest::SHA::bootstrap (xsub)
111526µs530µsDigest::SHA::::BEGIN@9Digest::SHA::BEGIN@9
11146µs46µsDigest::SHA::::newSHADigest::SHA::newSHA (xsub)
11129µs35µsDigest::SHA::::BEGIN@196Digest::SHA::BEGIN@196
11128µs33µsDigest::SHA::::BEGIN@5Digest::SHA::BEGIN@5
11118µs67µsDigest::SHA::::newDigest::SHA::new
11116µs31µsDigest::SHA::::BEGIN@6Digest::SHA::BEGIN@6
11114µs74µsDigest::SHA::::BEGIN@7Digest::SHA::BEGIN@7
11114µs62µsDigest::SHA::::BEGIN@8Digest::SHA::BEGIN@8
1118µs8µsDigest::SHA::::hexdigestDigest::SHA::hexdigest (xsub)
1117µs7µsDigest::SHA::::BEGIN@55Digest::SHA::BEGIN@55
1113µs3µsDigest::SHA::::CORE:substDigest::SHA::CORE:subst (opcode)
1113µs3µsDigest::SHA::::DESTROYDigest::SHA::DESTROY (xsub)
0000s0sDigest::SHA::::_addfileDigest::SHA::_addfile
0000s0sDigest::SHA::::_bailDigest::SHA::_bail
0000s0sDigest::SHA::::_istextDigest::SHA::_istext
0000s0sDigest::SHA::::add_bitsDigest::SHA::add_bits
0000s0sDigest::SHA::::addfileDigest::SHA::addfile
0000s0sDigest::SHA::::dumpDigest::SHA::dump
0000s0sDigest::SHA::::getstateDigest::SHA::getstate
0000s0sDigest::SHA::::loadDigest::SHA::load
0000s0sDigest::SHA::::putstateDigest::SHA::putstate
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Digest::SHA;
2
3123µsrequire 5.003000;
4
5274µs238µs
# spent 33µs (28+5) within Digest::SHA::BEGIN@5 which was called: # once (28µs+5µs) by CPAN::has_inst at line 5
use strict;
# spent 33µs making 1 call to Digest::SHA::BEGIN@5 # spent 5µs making 1 call to strict::import
6242µs246µs
# spent 31µs (16+15) within Digest::SHA::BEGIN@6 which was called: # once (16µs+15µs) by CPAN::has_inst at line 6
use warnings;
# spent 31µs making 1 call to Digest::SHA::BEGIN@6 # spent 15µs making 1 call to warnings::import
7242µs2134µs
# spent 74µs (14+60) within Digest::SHA::BEGIN@7 which was called: # once (14µs+60µs) by CPAN::has_inst at line 7
use vars qw($VERSION @ISA @EXPORT_OK);
# spent 74µs making 1 call to Digest::SHA::BEGIN@7 # spent 60µs making 1 call to vars::import
8243µs2110µs
# spent 62µs (14+48) within Digest::SHA::BEGIN@8 which was called: # once (14µs+48µs) by CPAN::has_inst at line 8
use Fcntl qw(O_RDONLY);
# spent 62µs making 1 call to Digest::SHA::BEGIN@8 # spent 48µs making 1 call to Exporter::import
92872µs2534µs
# spent 530µs (526+4) within Digest::SHA::BEGIN@9 which was called: # once (526µs+4µs) by CPAN::has_inst at line 9
use integer;
# spent 530µs making 1 call to Digest::SHA::BEGIN@9 # spent 4µs making 1 call to integer::import
10
1111µs$VERSION = '5.96';
12
1312µsrequire Exporter;
1411µsrequire DynaLoader;
15125µs@ISA = qw(Exporter DynaLoader);
1615µs@EXPORT_OK = qw(
17 hmac_sha1 hmac_sha1_base64 hmac_sha1_hex
18 hmac_sha224 hmac_sha224_base64 hmac_sha224_hex
19 hmac_sha256 hmac_sha256_base64 hmac_sha256_hex
20 hmac_sha384 hmac_sha384_base64 hmac_sha384_hex
21 hmac_sha512 hmac_sha512_base64 hmac_sha512_hex
22 hmac_sha512224 hmac_sha512224_base64 hmac_sha512224_hex
23 hmac_sha512256 hmac_sha512256_base64 hmac_sha512256_hex
24 sha1 sha1_base64 sha1_hex
25 sha224 sha224_base64 sha224_hex
26 sha256 sha256_base64 sha256_hex
27 sha384 sha384_base64 sha384_hex
28 sha512 sha512_base64 sha512_hex
29 sha512224 sha512224_base64 sha512224_hex
30 sha512256 sha512256_base64 sha512256_hex);
31
32# Inherit from Digest::base if possible
33
3413µseval {
351649µs require Digest::base;
36119µs push(@ISA, 'Digest::base');
37};
38
39# The following routines aren't time-critical, so they can be left in Perl
40
41
# spent 67µs (18+49) within Digest::SHA::new which was called: # once (18µs+49µs) by CPAN::Distribution::eq_CHECKSUM at line 1590 of CPAN/Distribution.pm
sub new {
4211µs my($class, $alg) = @_;
43110µs13µs $alg =~ s/\D+//g if defined $alg;
# spent 3µs making 1 call to Digest::SHA::CORE:subst
4410s if (ref($class)) { # instance method
45 if (!defined($alg) || ($alg == $class->algorithm)) {
46 sharewind($class);
47 return($class);
48 }
49 return shainit($class, $alg) ? $class : undef;
50 }
5111µs $alg = 1 unless defined $alg;
52156µs146µs return $class->newSHA($alg);
# spent 46µs making 1 call to Digest::SHA::newSHA
53}
54
5511.65ms17µs
# spent 7µs within Digest::SHA::BEGIN@55 which was called: # once (7µs+0s) by CPAN::has_inst at line 55
BEGIN { *reset = \&new }
# spent 7µs making 1 call to Digest::SHA::BEGIN@55
56
57sub add_bits {
58 my($self, $data, $nbits) = @_;
59 unless (defined $nbits) {
60 $nbits = length($data);
61 $data = pack("B*", $data);
62 }
63 $nbits = length($data) * 8 if $nbits > length($data) * 8;
64 shawrite($data, $nbits, $self);
65 return($self);
66}
67
68sub _bail {
69 my $msg = shift;
70
71 $msg .= ": $!";
72 require Carp;
73 Carp::croak($msg);
74}
75
76{
7711µs my $_can_T_filehandle;
78
79 sub _istext {
80 local *FH = shift;
81 my $file = shift;
82
83 if (! defined $_can_T_filehandle) {
84 local $^W = 0;
85 my $istext = eval { -T FH };
86 $_can_T_filehandle = $@ ? 0 : 1;
87 return $_can_T_filehandle ? $istext : -T $file;
88 }
89 return $_can_T_filehandle ? -T FH : -T $file;
90 }
91}
92
9311µssub _addfile {
94 my ($self, $handle) = @_;
95
96 my $n;
97 my $buf = "";
98
99 while (($n = read($handle, $buf, 4096))) {
100 $self->add($buf);
101 }
102 _bail("Read failed") unless defined $n;
103
104 $self;
105}
106
107sub addfile {
108 my ($self, $file, $mode) = @_;
109
110 return(_addfile($self, $file)) unless ref(\$file) eq 'SCALAR';
111
112 $mode = defined($mode) ? $mode : "";
113 my ($binary, $UNIVERSAL, $BITS, $portable) =
114 map { $_ eq $mode } ("b", "U", "0", "p");
115
116 ## Always interpret "-" to mean STDIN; otherwise use
117 ## sysopen to handle full range of POSIX file names
118
119 local *FH;
120 $file eq '-' and open(FH, '< -')
121 or sysopen(FH, $file, O_RDONLY)
122 or _bail('Open failed');
123
124 if ($BITS) {
125 my ($n, $buf) = (0, "");
126 while (($n = read(FH, $buf, 4096))) {
127 $buf =~ s/[^01]//g;
128 $self->add_bits($buf);
129 }
130 _bail("Read failed") unless defined $n;
131 close(FH);
132 return($self);
133 }
134
135 binmode(FH) if $binary || $portable || $UNIVERSAL;
136 if ($UNIVERSAL && _istext(*FH, $file)) {
137 $self->_addfileuniv(*FH);
138 }
139 elsif ($portable && _istext(*FH, $file)) {
140 while (<FH>) {
141 s/\015?\015\012/\012/g;
142 s/\015/\012/g;
143 $self->add($_);
144 }
145 }
146 else { $self->_addfilebin(*FH) }
147 close(FH);
148
149 $self;
150}
151
152sub getstate {
153 my $self = shift;
154
155 my $alg = $self->algorithm or return;
156 my $state = $self->_getstate or return;
157 my $nD = $alg <= 256 ? 8 : 16;
158 my $nH = $alg <= 256 ? 32 : 64;
159 my $nB = $alg <= 256 ? 64 : 128;
160 my($H, $block, $blockcnt, $lenhh, $lenhl, $lenlh, $lenll) =
161 $state =~ /^(.{$nH})(.{$nB})(.{4})(.{4})(.{4})(.{4})(.{4})$/s;
162 for ($alg, $H, $block, $blockcnt, $lenhh, $lenhl, $lenlh, $lenll) {
163 return unless defined $_;
164 }
165
166 my @s = ();
167 push(@s, "alg:" . $alg);
168 push(@s, "H:" . join(":", unpack("H*", $H) =~ /.{$nD}/g));
169 push(@s, "block:" . join(":", unpack("H*", $block) =~ /.{2}/g));
170 push(@s, "blockcnt:" . unpack("N", $blockcnt));
171 push(@s, "lenhh:" . unpack("N", $lenhh));
172 push(@s, "lenhl:" . unpack("N", $lenhl));
173 push(@s, "lenlh:" . unpack("N", $lenlh));
174 push(@s, "lenll:" . unpack("N", $lenll));
175 join("\n", @s) . "\n";
176}
177
178sub putstate {
179 my($class, $state) = @_;
180
181 my %s = ();
182 for (split(/\n/, $state)) {
183 s/^\s+//;
184 s/\s+$//;
185 next if (/^(#|$)/);
186 my @f = split(/[:\s]+/);
187 my $tag = shift(@f);
188 $s{$tag} = join('', @f);
189 }
190
191 # H and block may contain arbitrary values, but check everything else
192 grep { $_ == $s{'alg'} } (1,224,256,384,512,512224,512256) or return;
193 length($s{'H'}) == ($s{'alg'} <= 256 ? 64 : 128) or return;
194 length($s{'block'}) == ($s{'alg'} <= 256 ? 128 : 256) or return;
195 {
1962434µs241µs
# spent 35µs (29+6) within Digest::SHA::BEGIN@196 which was called: # once (29µs+6µs) by CPAN::has_inst at line 196
no integer;
# spent 35µs making 1 call to Digest::SHA::BEGIN@196 # spent 6µs making 1 call to integer::unimport
197 for (qw(blockcnt lenhh lenhl lenlh lenll)) {
198 0 <= $s{$_} or return;
199 $s{$_} <= 4294967295 or return;
200 }
201 $s{'blockcnt'} < ($s{'alg'} <= 256 ? 512 : 1024) or return;
202 }
203
204 my $packed_state = (
205 pack("H*", $s{'H'}) .
206 pack("H*", $s{'block'}) .
207 pack("N", $s{'blockcnt'}) .
208 pack("N", $s{'lenhh'}) .
209 pack("N", $s{'lenhl'}) .
210 pack("N", $s{'lenlh'}) .
211 pack("N", $s{'lenll'})
212 );
213
214 return $class->new($s{'alg'})->_putstate($packed_state);
215}
216
217sub dump {
218 my $self = shift;
219 my $file = shift;
220
221 my $state = $self->getstate or return;
222 $file = "-" if (!defined($file) || $file eq "");
223
224 local *FH;
225 open(FH, "> $file") or return;
226 print FH $state;
227 close(FH);
228
229 return($self);
230}
231
232sub load {
233 my $class = shift;
234 my $file = shift;
235
236 $file = "-" if (!defined($file) || $file eq "");
237
238 local *FH;
239 open(FH, "< $file") or return;
240 my $str = join('', <FH>);
241 close(FH);
242
243 $class->putstate($str);
244}
245
246111µs12.39msDigest::SHA->bootstrap($VERSION);
# spent 2.39ms making 1 call to DynaLoader::bootstrap
247
248119µs1;
249__END__
 
# spent 3µs within Digest::SHA::CORE:subst which was called: # once (3µs+0s) by Digest::SHA::new at line 43
sub Digest::SHA::CORE:subst; # opcode
# spent 3µs within Digest::SHA::DESTROY which was called: # once (3µs+0s) by CPAN::Distribution::eq_CHECKSUM at line 1597 of CPAN/Distribution.pm
sub Digest::SHA::DESTROY; # xsub
# spent 3.01ms within Digest::SHA::add which was called 89 times, avg 34µs/call: # 89 times (3.01ms+0s) by CPAN::Distribution::eq_CHECKSUM at line 1593 of CPAN/Distribution.pm, avg 34µs/call
sub Digest::SHA::add; # xsub
# spent 810µs within Digest::SHA::bootstrap which was called: # once (810µs+0s) by DynaLoader::bootstrap at line 214 of DynaLoader.pm
sub Digest::SHA::bootstrap; # xsub
# spent 8µs within Digest::SHA::hexdigest which was called: # once (8µs+0s) by CPAN::Distribution::eq_CHECKSUM at line 1595 of CPAN/Distribution.pm
sub Digest::SHA::hexdigest; # xsub
# spent 46µs within Digest::SHA::newSHA which was called: # once (46µs+0s) by Digest::SHA::new at line 52
sub Digest::SHA::newSHA; # xsub