← Index
NYTProf Performance Profile   « line view »
For t/bug-md-11.t
  Run on Fri Mar 8 13:27:24 2024
Reported on Fri Mar 8 13:30:23 2024

Filename/home/micha/Projekt/spreadsheet-parsexlsx/lib/Spreadsheet/ParseXLSX/Decryptor/Standard.pm
StatementsExecuted 7 statements in 338µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11112µs13µsSpreadsheet::ParseXLSX::Decryptor::Standard::::BEGIN@3Spreadsheet::ParseXLSX::Decryptor::Standard::BEGIN@3
1115µs52µsSpreadsheet::ParseXLSX::Decryptor::Standard::::BEGIN@10Spreadsheet::ParseXLSX::Decryptor::Standard::BEGIN@10
1113µs18µsSpreadsheet::ParseXLSX::Decryptor::Standard::::BEGIN@4Spreadsheet::ParseXLSX::Decryptor::Standard::BEGIN@4
0000s0sSpreadsheet::ParseXLSX::Decryptor::Standard::::_generateDecryptionKeySpreadsheet::ParseXLSX::Decryptor::Standard::_generateDecryptionKey
0000s0sSpreadsheet::ParseXLSX::Decryptor::Standard::::decryptSpreadsheet::ParseXLSX::Decryptor::Standard::decrypt
0000s0sSpreadsheet::ParseXLSX::Decryptor::Standard::::decryptFileSpreadsheet::ParseXLSX::Decryptor::Standard::decryptFile
0000s0sSpreadsheet::ParseXLSX::Decryptor::Standard::::verifyPasswordSpreadsheet::ParseXLSX::Decryptor::Standard::verifyPassword
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Spreadsheet::ParseXLSX::Decryptor::Standard;
2
3217µs214µs
# spent 13µs (12+1) within Spreadsheet::ParseXLSX::Decryptor::Standard::BEGIN@3 which was called: # once (12µs+1µs) by Spreadsheet::ParseXLSX::Decryptor::BEGIN@18 at line 3
use strict;
# spent 13µs making 1 call to Spreadsheet::ParseXLSX::Decryptor::Standard::BEGIN@3 # spent 1µs making 1 call to strict::import
4216µs233µs
# spent 18µs (3+15) within Spreadsheet::ParseXLSX::Decryptor::Standard::BEGIN@4 which was called: # once (3µs+15µs) by Spreadsheet::ParseXLSX::Decryptor::BEGIN@18 at line 4
use warnings;
# spent 18µs making 1 call to Spreadsheet::ParseXLSX::Decryptor::Standard::BEGIN@4 # spent 15µs making 1 call to warnings::import
5
6# VERSION
7
8# ABSTRACT: standard decryption
9
102304µs299µs
# spent 52µs (5+47) within Spreadsheet::ParseXLSX::Decryptor::Standard::BEGIN@10 which was called: # once (5µs+47µs) by Spreadsheet::ParseXLSX::Decryptor::BEGIN@18 at line 10
use base 'Spreadsheet::ParseXLSX::Decryptor';
# spent 52µs making 1 call to Spreadsheet::ParseXLSX::Decryptor::Standard::BEGIN@10 # spent 47µs making 1 call to base::import
11
12sub decrypt {
13 my $self = shift;
14 my ($encryptedValue) = @_;
15
16 my $key = $self->_generateDecryptionKey("\x00" x 4);
17 my $ecb = Crypt::Mode::ECB->new($self->{cipherAlgorithm}, 0);
18 return $ecb->decrypt($encryptedValue, $key);
19}
20
21sub decryptFile {
22 my $self = shift;
23 my ($inFile, $outFile, $bufferLength, $fileSize) = @_;
24
25 my $key = $self->_generateDecryptionKey("\x00" x 4);
26 my $ecb = Crypt::Mode::ECB->new($self->{cipherAlgorithm}, 0);
27
28 my $inbuf;
29 my $i = 0;
30
31 while (($fileSize > 0) && (my $inlen = $inFile->read($inbuf, $bufferLength))) {
32 if ($inlen < $bufferLength) {
33 $inbuf .= "\x00" x ($bufferLength - $inlen);
34 }
35
36 my $outbuf = $ecb->decrypt($inbuf, $key);
37 if ($fileSize < $inlen) {
38 $inlen = $fileSize;
39 }
40
41 $outFile->write($outbuf, $inlen);
42 $i++;
43 $fileSize -= $inlen;
44 }
45}
46
47sub _generateDecryptionKey {
48 my $self = shift;
49 my ($blockKey) = @_;
50
51 my $hash;
52 unless ($self->{pregeneratedKey}) {
53 $hash = $self->{hashProc}->($self->{salt} . Encode::encode('UTF-16LE', $self->{password}));
54 for (my $i = 0 ; $i < $self->{spinCount} ; $i++) {
55 $hash = $self->{hashProc}->(pack('L<', $i) . $hash);
56 }
57 $self->{pregeneratedKey} = $hash;
58 }
59
60 $hash = $self->{hashProc}->($self->{pregeneratedKey} . $blockKey);
61
62 my $x1 = $self->{hashProc}->(("\x36" x 64) ^ $hash);
63 if (length($x1) >= $self->{keyLength}) {
64 $hash = substr($x1, 0, $self->{keyLength});
65 } else {
66 my $x2 = $self->{hashProc}->(("\x5C" x 64) ^ $hash);
67 $hash = substr($x1 . $x2, 0, $self->{keyLength});
68 }
69
70 return $hash;
71}
72
73sub verifyPassword {
74 my $self = shift;
75 my ($encryptedVerifier, $encryptedVerifierHash) = @_;
76
77 my $verifier = $self->decrypt($encryptedVerifier);
78 my $verifierHash = $self->decrypt($encryptedVerifierHash);
79
80 my $verifierHash0 = $self->{hashProc}->($verifier);
81
82 die "Wrong password: $self" unless ($verifierHash0 eq substr($verifierHash, 0, length($verifierHash0)));
83}
84
85=begin Pod::Coverage
86
87 decrypt
88 decryptFile
89 verifyPassword
90
91=end Pod::Coverage
92
93=cut
94
9512µs1;