Filename | /usr/local/perls/perl-5.26.1/lib/5.26.1/darwin-2level/Digest/SHA.pm |
Statements | Executed 31 statements in 3.99ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
89 | 1 | 1 | 3.01ms | 3.01ms | add (xsub) | Digest::SHA::
1 | 1 | 1 | 810µs | 810µs | bootstrap (xsub) | Digest::SHA::
1 | 1 | 1 | 526µs | 530µs | BEGIN@9 | Digest::SHA::
1 | 1 | 1 | 46µs | 46µs | newSHA (xsub) | Digest::SHA::
1 | 1 | 1 | 29µs | 35µs | BEGIN@196 | Digest::SHA::
1 | 1 | 1 | 28µs | 33µs | BEGIN@5 | Digest::SHA::
1 | 1 | 1 | 18µs | 67µs | new | Digest::SHA::
1 | 1 | 1 | 16µs | 31µs | BEGIN@6 | Digest::SHA::
1 | 1 | 1 | 14µs | 74µs | BEGIN@7 | Digest::SHA::
1 | 1 | 1 | 14µs | 62µs | BEGIN@8 | Digest::SHA::
1 | 1 | 1 | 8µs | 8µs | hexdigest (xsub) | Digest::SHA::
1 | 1 | 1 | 7µs | 7µs | BEGIN@55 | Digest::SHA::
1 | 1 | 1 | 3µs | 3µs | CORE:subst (opcode) | Digest::SHA::
1 | 1 | 1 | 3µs | 3µs | DESTROY (xsub) | Digest::SHA::
0 | 0 | 0 | 0s | 0s | _addfile | Digest::SHA::
0 | 0 | 0 | 0s | 0s | _bail | Digest::SHA::
0 | 0 | 0 | 0s | 0s | _istext | Digest::SHA::
0 | 0 | 0 | 0s | 0s | add_bits | Digest::SHA::
0 | 0 | 0 | 0s | 0s | addfile | Digest::SHA::
0 | 0 | 0 | 0s | 0s | dump | Digest::SHA::
0 | 0 | 0 | 0s | 0s | getstate | Digest::SHA::
0 | 0 | 0 | 0s | 0s | load | Digest::SHA::
0 | 0 | 0 | 0s | 0s | putstate | Digest::SHA::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Digest::SHA; | ||||
2 | |||||
3 | 1 | 23µs | require 5.003000; | ||
4 | |||||
5 | 2 | 74µs | 2 | 38µ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 # spent 33µs making 1 call to Digest::SHA::BEGIN@5
# spent 5µs making 1 call to strict::import |
6 | 2 | 42µs | 2 | 46µ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 # spent 31µs making 1 call to Digest::SHA::BEGIN@6
# spent 15µs making 1 call to warnings::import |
7 | 2 | 42µs | 2 | 134µ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 # spent 74µs making 1 call to Digest::SHA::BEGIN@7
# spent 60µs making 1 call to vars::import |
8 | 2 | 43µs | 2 | 110µ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 # spent 62µs making 1 call to Digest::SHA::BEGIN@8
# spent 48µs making 1 call to Exporter::import |
9 | 2 | 872µs | 2 | 534µ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 # spent 530µs making 1 call to Digest::SHA::BEGIN@9
# spent 4µs making 1 call to integer::import |
10 | |||||
11 | 1 | 1µs | $VERSION = '5.96'; | ||
12 | |||||
13 | 1 | 2µs | require Exporter; | ||
14 | 1 | 1µs | require DynaLoader; | ||
15 | 1 | 25µs | @ISA = qw(Exporter DynaLoader); | ||
16 | 1 | 5µ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 | |||||
34 | 1 | 3µs | eval { | ||
35 | 1 | 649µs | require Digest::base; | ||
36 | 1 | 19µ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 | ||||
42 | 1 | 1µs | my($class, $alg) = @_; | ||
43 | 1 | 10µs | 1 | 3µs | $alg =~ s/\D+//g if defined $alg; # spent 3µs making 1 call to Digest::SHA::CORE:subst |
44 | 1 | 0s | 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 | } | ||||
51 | 1 | 1µs | $alg = 1 unless defined $alg; | ||
52 | 1 | 56µs | 1 | 46µs | return $class->newSHA($alg); # spent 46µs making 1 call to Digest::SHA::newSHA |
53 | } | ||||
54 | |||||
55 | 1 | 1.65ms | 1 | 7µs | # spent 7µs within Digest::SHA::BEGIN@55 which was called:
# once (7µs+0s) by CPAN::has_inst at line 55 # spent 7µs making 1 call to Digest::SHA::BEGIN@55 |
56 | |||||
57 | sub 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 | |||||
68 | sub _bail { | ||||
69 | my $msg = shift; | ||||
70 | |||||
71 | $msg .= ": $!"; | ||||
72 | require Carp; | ||||
73 | Carp::croak($msg); | ||||
74 | } | ||||
75 | |||||
76 | { | ||||
77 | 1 | 1µ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 | |||||
93 | 1 | 1µs | sub _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 | |||||
107 | sub 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 | |||||
152 | sub 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 | |||||
178 | sub 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 | { | ||||
196 | 2 | 434µs | 2 | 41µ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 # 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 | |||||
217 | sub 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 | |||||
232 | sub 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 | |||||
246 | 1 | 11µs | 1 | 2.39ms | Digest::SHA->bootstrap($VERSION); # spent 2.39ms making 1 call to DynaLoader::bootstrap |
247 | |||||
248 | 1 | 19µs | 1; | ||
249 | __END__ | ||||
# spent 3µs within Digest::SHA::CORE:subst which was called:
# once (3µs+0s) by Digest::SHA::new at line 43 | |||||
# 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 | |||||
# 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 | |||||
# spent 810µs within Digest::SHA::bootstrap which was called:
# once (810µs+0s) by DynaLoader::bootstrap at line 214 of DynaLoader.pm | |||||
# 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 | |||||
# spent 46µs within Digest::SHA::newSHA which was called:
# once (46µs+0s) by Digest::SHA::new at line 52 |