| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Digest::QuickXor; |
|
2
|
3
|
|
|
3
|
|
215735
|
use parent qw|DynaLoader|; |
|
|
3
|
|
|
|
|
966
|
|
|
|
3
|
|
|
|
|
18
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
167
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
53
|
|
|
5
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
70
|
|
|
6
|
3
|
|
|
3
|
|
12
|
use utf8; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
17
|
|
|
7
|
3
|
|
|
3
|
|
100
|
use v5.24; |
|
|
3
|
|
|
|
|
13
|
|
|
8
|
3
|
|
|
3
|
|
17
|
use feature 'signatures'; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
437
|
|
|
9
|
3
|
|
|
3
|
|
21
|
no warnings 'experimental::signatures'; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
125
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
17
|
use Carp 'croak'; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
1735
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
__PACKAGE__->bootstrap($VERSION); |
|
16
|
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
1
|
2389
|
sub new ($class) { |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
4
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
3
|
|
|
|
|
27
|
my $qx = Digest::QuickXor::HashPtr->new(); |
|
20
|
3
|
|
|
|
|
10
|
my $self = {_qx => $qx}; |
|
21
|
|
|
|
|
|
|
|
|
22
|
3
|
|
|
|
|
17
|
return bless $self, $class; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
13
|
|
|
13
|
1
|
24
|
sub add ($self, @data) { |
|
|
13
|
|
|
|
|
17
|
|
|
|
13
|
|
|
|
|
156
|
|
|
|
13
|
|
|
|
|
19
|
|
|
26
|
13
|
|
|
|
|
29
|
for (@data) { |
|
27
|
15
|
|
|
|
|
996
|
$self->{_qx}->add($_, length $_); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
13
|
|
|
|
|
59
|
return $self; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
8
|
|
|
8
|
1
|
13
|
sub addfile ($self, $file) { |
|
|
8
|
|
|
|
|
13
|
|
|
|
8
|
|
|
|
|
12
|
|
|
|
8
|
|
|
|
|
9
|
|
|
34
|
8
|
|
|
|
|
14
|
my $fh; |
|
35
|
8
|
100
|
|
|
|
22
|
if (ref($file) eq 'GLOB') { |
|
36
|
4
|
|
|
|
|
7
|
$fh = $file; |
|
37
|
|
|
|
|
|
|
} else { |
|
38
|
4
|
50
|
|
|
|
177
|
CORE::open $fh, '<', $file or croak qq|Can't open file "$file": $!|; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
8
|
|
|
|
|
18
|
my $ret = ''; |
|
42
|
8
|
|
|
|
|
93
|
while ($ret = $fh->sysread(my $buffer, 131072, 0)) { |
|
43
|
8
|
|
|
|
|
9136
|
$self->add($buffer); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
8
|
50
|
|
|
|
113
|
croak qq|Can't read from file: $!| unless defined $ret; |
|
46
|
|
|
|
|
|
|
|
|
47
|
8
|
|
|
|
|
64
|
return $self; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
11
|
|
|
11
|
1
|
20
|
sub b64digest ($self) { |
|
|
11
|
|
|
|
|
16
|
|
|
|
11
|
|
|
|
|
14
|
|
|
51
|
11
|
|
|
|
|
57
|
my $rv = $self->{_qx}->b64digest; |
|
52
|
11
|
|
|
|
|
30
|
$self->reset; |
|
53
|
|
|
|
|
|
|
|
|
54
|
11
|
|
|
|
|
52
|
return $rv; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
11
|
|
|
11
|
1
|
14
|
sub reset ($self) { |
|
|
11
|
|
|
|
|
14
|
|
|
|
11
|
|
|
|
|
15
|
|
|
58
|
11
|
|
|
|
|
30
|
$self->{_qx}->reset; |
|
59
|
|
|
|
|
|
|
|
|
60
|
11
|
|
|
|
|
15
|
return $self; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=encoding utf8 |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 NAME |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Digest::QuickXor - The QuickXorHash |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use Digest::QuickXor; |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $qx = Digest::QuickXor->new; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$qx->add(@data); |
|
78
|
|
|
|
|
|
|
$qx->b64digest; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$qx->addfile($file); |
|
81
|
|
|
|
|
|
|
$qx->b64digest; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$qx->add($wrong_data); |
|
84
|
|
|
|
|
|
|
$qx->reset; |
|
85
|
|
|
|
|
|
|
$qx->add($correct_data); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
L implements the QuickXorHash. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
The QuickXorHash is the digest used by Microsoft on Office 365 OneDrive for Business and Sharepoint. |
|
92
|
|
|
|
|
|
|
It was published by Microsoft in 2016 in form of a C# script. The explanation describes it as a |
|
93
|
|
|
|
|
|
|
"quick, simple non-cryptographic hash algorithm that works by XORing the bytes in a circular-shifting fashion". |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 new |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$qx = Digest::QuickXor->new; |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 METHODS |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 add |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$qx = $qx->add($data); |
|
106
|
|
|
|
|
|
|
$qx = $qx->add(@data); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Adds new blocks of data. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 addfile |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$qx = $qx->addfile($path); |
|
113
|
|
|
|
|
|
|
$qx = $qx->addfile($filehandle); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Adds data from a file path or from a file handle. |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 b64digest |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$string = $qx->b64digest; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Returns the digest and resets the object. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 reset |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$qx = $qx->reset; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Resets the object so it is ready to accept new data. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR & COPYRIGHT |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
© 2019 by Tekki (Rolf Stöckli). |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
© for the original algorithm 2016 by Microsoft. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Explanation of the |
|
140
|
|
|
|
|
|
|
L |
|
141
|
|
|
|
|
|
|
in the OneDrive Dev Center. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
L |
|
144
|
|
|
|
|
|
|
by Ryan Gregg. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L, C implementation of the hash, base code for this module. |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |