Passphrase/DESCrypt.pm

filter: Statementstmt 98.2% 111 / 113 Branchbran 72.3% 68 / 94 Conditioncond 45.4% 15 / 33 MC/DCmcdc 10.5% 2 / 19 Subroutinesub 100% 23 / 23 Podpod 100% 14 / 14 totaltotal 78.7% 233 / 296 CC 59 SCAR 39.4
CC
59
Cov
81%
new
86.8
as_crypt
7.3
from_crypt
5.3
CRAP 51.6
↑ Summary Passphrase/VMSPurdy.pm »
1 =head1 NAME
2  
3 Authen::Passphrase::DESCrypt - passphrases using the DES-based Unix
4 crypt()
5  
6 =head1 SYNOPSIS
7  
8 use Authen::Passphrase::DESCrypt;
9  
10 $ppr = Authen::Passphrase::DESCrypt->new(
11 salt_base64 => "my",
12 hash_base64 => "TYK.j.88/9s");
13  
14 $ppr = Authen::Passphrase::DESCrypt->new(
15 salt_random => 12,
16 passphrase => "passphrase");
17  
18 $ppr = Authen::Passphrase::DESCrypt
19 ->from_crypt('myTYK.j.88/9s');
20  
21 $ppr = Authen::Passphrase::DESCrypt->new(
22 fold => 1,
23 initial => "xyzzy!!!",
24 nrounds => 500,
25 salt_base64 => "quux",
26 hash_base64 => "QCKcHlgVsRY");
27  
28 $fold = $ppr->fold;
29 $initial = $ppr->initial;
30 $initial_base64 = $ppr->initial_base64;
31 $nrounds = $ppr->nrounds;
32 $nrounds_base64 = $ppr->nrounds_base64_4;
33 $salt = $ppr->salt;
34 $salt_base64 = $ppr->salt_base64_2;
35 $salt_base64 = $ppr->salt_base64_4;
36 $hash = $ppr->hash;
37 $hash_base64 = $ppr->hash_base64;
38  
39 if($ppr->match($passphrase)) { ...
40  
41 $passwd = $ppr->as_crypt;
42 $userPassword = $ppr->as_rfc2307;
43  
44 =head1 DESCRIPTION
45  
46 An object of this class encapsulates a passphrase hashed using some
47 form of the DES-based Unix crypt() hash function. This is a subclass
48 of L<Authen::Passphrase>, and this document assumes that the reader is
49 familiar with the documentation for that class.
50  
51 The crypt() function in a modern Unix actually supports several different
52 passphrase schemes. That is not what this class is about. This class
53 is concerned only with one family of schemes, variants of the DES-based
54 scheme that crypt() originally implemented, which confusingly is usually
55 referred to merely as "crypt()". To handle the whole range of passphrase
56 schemes supported by the modern crypt(), see the
57 L<from_crypt|Authen::Passphrase/from_crypt> constructor and the
58 L<as_crypt|Authen::Passphrase/as_crypt> method in L<Authen::Passphrase>.
59  
60 I<Warning:> this password scheme is weak by modern standards, and in
61 any case does not support a large password space. Cracking crypt()ed
62 passwords has been a routine activity since the early 1990s. This scheme
63 is supported for compatibility reasons only, and should not be used
64 except when compatibility is required. Do not use this in the design of
65 any new system or for new passwords in any system that supports better
66 passphrase schemes.
67  
68 =head2 The traditional DES-based Unix crypt() password scheme
69  
70 The traditional Unix crypt() password scheme is based on the DES block
71 encryption algorithm. Using the password as a 56-bit key, it passes a
72 64-bit data block, initialised to zero, through the encryption function
73 25 times, and the hash is the 64-bit output of this process. A 12-bit
74 salt is used to tweak the encryption algorithm.
75  
76 The 56-bit key is extracted from the password in a very poor way.
77 Only the first eight bytes of the password are used, and any remainder
78 is ignored. This makes it impossible to use a passphrase, rather than
79 a password, hence the terminology in this section. Of the eight bytes
80 used, the top bit is also ignored; this function hails from the days of
81 pure ASCII.
82  
83 A password hash of this scheme is conventionally represented in ASCII as
84 a 13-character string using a base 64 encoding. The base 64 digits are
85 "B<.>", "B</>", "B<0>" to "B<9>", "B<A>" to "B<Z>", "B<a>" to "B<z>"
86 (in ASCII order). The first two characters give the 12-bit salt.
87 The remaining eleven characters give the 64-bit hash. Because the base
88 64 encoding can represent 66 bits in eleven digits, more than the 64
89 required, the last character of the string can only take sixteen of the
90 base 64 digit values.
91  
92 =head2 Variant DES-based Unix crypt() passphrase schemes
93  
94 To make password cracking more difficult, historically some Unix sites
95 modified the crypt() function to be incompatible with the standard one.
96 This was easily achieved by initialising the data block to something
97 other than the standard all-bits-zero. Another variation used was to
98 increase the number of encryption rounds, which makes cracking take
99 longer in addition to being non-standard. Password hashes on such a
100 system looked normal but were not interoperable with standard crypt()
101 implementations. To interpret them properly it is necessary to know
102 the modified parameters.
103  
104 BSDi standardised an extended DES-based scheme. The salt is extended to
105 24 bits, and the number of encryption rounds is variable. Passphrases
106 longer than 8 characters are handled by an additional step that folds
107 (hashes) them down to 8 characters, rather than just throwing away
108 the characters after the eighth. Passphrase hashes in this scheme
109 are conventionally represented in ASCII as a "B<_>" followed by 19
110 characters of base 64. The first four base 64 digits give the number
111 of encryption rounds, the next four give the salt, and the remaining
112 eleven give the hash.
113  
114 =cut
115  
116 package Authen::Passphrase::DESCrypt;
117  
118 7 ▶{ use 5.006; }
Subroutine BEGIN: called CC=1 SCAR=0.0
119 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
120 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
121  
122 7 ▶use Authen::Passphrase 0.003;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
124 7 ▶use Crypt::UnixCrypt_XS 0.08 qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
125 fold_password crypt_rounds
126 base64_to_block block_to_base64
127 base64_to_int24 int24_to_base64
128 base64_to_int12 int12_to_base64
129 7 );
130 7 ▶use Crypt::SysRandom 'random_bytes';
Subroutine BEGIN: called CC=1 SCAR=0.0
131  
132 7 our $VERSION = "0.009";
133  
134 7 ▶use parent "Authen::Passphrase";
Subroutine BEGIN: called CC=1 SCAR=0.0
135  
136 =head1 CONSTRUCTORS
137  
138 =over
139  
140 =item Authen::Passphrase::DESCrypt->new(ATTR => VALUE, ...)
141  
142 Generates a new passphrase recogniser object using the generalised
143 DES-based crypt() algorithm. The following attributes may be given:
144  
145 =over
146  
147 =item B<fold>
148  
149 Truth value indicating whether the BSDi passphrase folding scheme should be
150 used for long passphrases. Default false, for compatibility with the
151 original DES-based scheme.
152  
153 =item B<initial>
154  
155 The initial data block to encrypt, as a string of exactly eight bytes.
156 Default all bits zero, for compatibility with the original DES-based
157 scheme.
158  
159 =item B<initial_base64>
160  
161 The initial data block to encrypt, as a string of eleven base 64 digits.
162  
163 =item B<nrounds>
164  
165 The number of encryption rounds to use, as a Perl integer. Default 25,
166 for compatibility with the original DES-based scheme.
167  
168 =item B<nrounds_base64>
169  
170 The number of encryption rounds to use, as a string of four base 64
171 digits.
172  
173 =item B<salt>
174  
175 The salt, as an integer in the range [0, 16777216).
176  
177 =item B<salt_base64>
178  
179 The salt, as a string of two or four base 64 digits.
180  
181 =item B<salt_random>
182  
183 Causes salt to be generated randomly. The value given for this attribute
184 must be either 12 or 24, giving the number of bits of salt to generate.
185  
186 =item B<hash>
187  
188 The hash (output of encryption), as a string of exactly eight bytes.
189  
190 =item B<hash_base64>
191  
192 The hash, as a string of eleven base 64 digits.
193  
194 =item B<passphrase>
195  
196 A passphrase that will be accepted.
197  
198 =back
199  
200 The salt must be given, and either the hash or the passphrase. The other
201 parameters default to those used in the original DES-based crypt().
202  
203 =cut
204  
205 67 ▶sub new {
Subroutine new: called CC=47 SCAR=44.6
Pod documented
206 67 my $class = shift;
207 67 my $self = bless({}, $class);
208 67 my $passphrase;
209 67 ▶ while(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 185 67 252
210 185 my $attr = shift;
211 185 my $value = shift;
212 185 ▶ if($attr eq "fold") {
Branch: 11 branches
BranchTrueFalseTotal
if ($attr eq 'fold') { } 13 172 185
elsif ($attr eq 'initial') { } 1 171 172
elsif ($attr eq 'initial_base64') { } 6 165 171
elsif ($attr eq 'nrounds') { } 19 146 165
elsif ($attr eq 'nrounds_base64') { } 12 134 146
elsif ($attr eq 'salt') { } 47 87 134
elsif ($attr eq 'salt_base64') { } 19 68 87
elsif ($attr eq 'salt_random') { } 1 67 68
elsif ($attr eq 'hash') { } 33 34 67
elsif ($attr eq 'hash_base64') { } 18 16 34
elsif ($attr eq 'passphrase') { } 16 0 16
213 croak "foldness specified redundantly"
214 13 ▶ if exists $self->{fold};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"fold"} 0 13 13
215 13 $self->{fold} = !!$value;
216 } elsif($attr eq "initial") {
217 croak "initial block specified redundantly"
218 1 ▶ if exists $self->{initial};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"initial"} 0 1 1
219 1 ▶ $value =~ m#\A[\x00-\xff]{8}\z#
Branch: 1 branch
BranchTrueFalseTotal
$value =~ /\A[\x00-\xff]{8}\z/ or croak("not a valid raw block") 1 0 1
220 or croak "not a valid raw block";
221 1 $self->{initial} = "$value";
222 } elsif($attr eq "initial_base64") {
223 croak "initial block specified redundantly"
224 6 ▶ if exists $self->{initial};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"initial"} 0 6 6
225 6 ▶ $value =~ m#\A[./0-9A-Za-z]{10}[.26AEIMQUYcgkosw]\z#
Branch: 1 branch
BranchTrueFalseTotal
$value =~ m[\A[./0-9A-Za-z]{10}[.26AEIMQUYcgkosw]\z] or croak(qq["$value" is not a valid ] . 'encoded block') 6 0 6
226 or croak "\"$value\" is not a valid ".
227 "encoded block";
228 6 $self->{initial} = base64_to_block($value);
229 } elsif($attr eq "nrounds") {
230 croak "number of rounds specified redundantly"
231 19 ▶ if exists $self->{nrounds};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"nrounds"} 0 19 19
232 19 ▶ croak "\"$value\" is not a valid number of rounds"
Branch: 1 branch
BranchTrueFalseTotal
unless $value == int $value and $value >= 0 0 19 19
Condition33%1/3
$value == int $value and $value >= 0
!ll&&!rl&&r
0019
MC/DC0%0/2
$value == int $value and $value >= 0
$value == int $value $value >= 0
Truth table33%1/3
A and B
A= $value == int $valueB= $value >= 0
ABresult
0X0
100
111
233 unless $value == int($value) && $value >= 0;
234 19 $self->{nrounds} = 0+$value;
235 } elsif($attr eq "nrounds_base64") {
236 croak "number of rounds specified redundantly"
237 12 ▶ if exists $self->{nrounds};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"nrounds"} 0 12 12
238 12 ▶ croak "\"$value\" is not a valid number of rounds"
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ m[\A[./0-9A-Za-z]{4}\z] 0 12 12
239 unless $value =~ m#\A[./0-9A-Za-z]{4}\z#;
240 12 $self->{nrounds} = base64_to_int24($value);
241 } elsif($attr eq "salt") {
242 croak "salt specified redundantly"
243 47 ▶ if exists $self->{salt};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"salt"} 0 47 47
244 47 ▶ croak "\"$value\" is not a valid salt"
Branch: 1 branch
BranchTrueFalseTotal
unless $value == int $value and $value >= 0 and $value < 16777216 0 47 47
Condition33%2/6
$value == int $value and $value >= 0 and $value < 16777216
!ll&&!rl&&r
0047
$value == int $value and $value >= 0
!ll&&!rl&&r
0047
MC/DC0%0/3
$value == int $value and $value >= 0 and $value < 16777216
$value == int $value $value >= 0 $value < 16777216
Truth table25%1/4
A and B and C
A= $value == int $valueB= $value >= 0C= $value < 16777216
ABCresult
0XX0
10X0
1100
1111
245 unless $value == int($value) &&
246 $value >= 0 && $value < 16777216;
247 47 $self->{salt} = 0+$value;
248 } elsif($attr eq "salt_base64") {
249 croak "salt specified redundantly"
250 19 ▶ if exists $self->{salt};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"salt"} 0 19 19
251 19 ▶ $value =~ m#\A(?:[./0-9A-Za-z]{2}|[./0-9A-Za-z]{4})\z#
Branch: 1 branch
BranchTrueFalseTotal
$value =~ m[\A(?:[./0-9A-Za-z]{2}|[./0-9A-Za-z]{4})\z] or croak(qq["$value" is not a valid salt]) 19 0 19
252 or croak "\"$value\" is not a valid salt";
253 19 ▶ $self->{salt} = length($value) == 2 ?
Branch: 1 branch
BranchTrueFalseTotal
length $value == 2 ? : 7 12 19
254 base64_to_int12($value) :
255 base64_to_int24($value);
256 } elsif($attr eq "salt_random") {
257 croak "salt specified redundantly"
258 1 ▶ if exists $self->{salt};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"salt"} 0 1 1
259 1 ▶ croak "\"$value\" is not a valid salt size"
Branch: 1 branch
BranchTrueFalseTotal
unless $value == 12 or $value == 24 0 1 1
Condition33%1/3
$value == 12 or $value == 24
l!l&&r!l&&!r
100
MC/DC0%0/2
$value == 12 or $value == 24
$value == 12 $value == 24
Truth table33%1/3
A or B
A= $value == 12B= $value == 24
ABresult
1X1
011
000
260 unless $value == 12 || $value == 24;
261 1 $self->{salt} = unpack("I", random_bytes(4)) % (1 << $value);
262 } elsif($attr eq "hash") {
263 croak "hash specified redundantly"
264 33 ▶ if exists($self->{hash}) ||
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"hash"} or defined $passphrase 0 33 33
Condition33%1/3
exists $self->{"hash"} or defined $passphrase
l!l&&r!l&&!r
0033
MC/DC0%0/2
exists $self->{"hash"} or defined $passphrase
exists $self->{"hash"} defined $passphrase
Truth table33%1/3
A or B
A= exists $self->{"hash"}B= defined $passphrase
ABresult
1X1
011
000
265 defined($passphrase);
266 33 ▶ $value =~ m#\A[\x00-\xff]{8}\z#
Branch: 1 branch
BranchTrueFalseTotal
$value =~ /\A[\x00-\xff]{8}\z/ or croak("not a valid raw hash") 33 0 33
267 or croak "not a valid raw hash";
268 33 $self->{hash} = "$value";
269 } elsif($attr eq "hash_base64") {
270 croak "hash specified redundantly"
271 18 ▶ if exists($self->{hash}) ||
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"hash"} or defined $passphrase 0 18 18
Condition33%1/3
exists $self->{"hash"} or defined $passphrase
l!l&&r!l&&!r
0018
MC/DC0%0/2
exists $self->{"hash"} or defined $passphrase
exists $self->{"hash"} defined $passphrase
Truth table33%1/3
A or B
A= exists $self->{"hash"}B= defined $passphrase
ABresult
1X1
011
000
272 defined($passphrase);
273 18 ▶ $value =~ m#\A[./0-9A-Za-z]{10}[.26AEIMQUYcgkosw]\z#
Branch: 1 branch
BranchTrueFalseTotal
$value =~ m[\A[./0-9A-Za-z]{10}[.26AEIMQUYcgkosw]\z] or croak(qq["$value" is not a valid ] . 'encoded hash') 18 0 18
274 or croak "\"$value\" is not a valid ".
275 "encoded hash";
276 18 $self->{hash} = base64_to_block($value);
277 } elsif($attr eq "passphrase") {
278 croak "passphrase specified redundantly"
279 16 ▶ if exists($self->{hash}) ||
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"hash"} or defined $passphrase 0 16 16
Condition33%1/3
exists $self->{"hash"} or defined $passphrase
l!l&&r!l&&!r
0016
MC/DC0%0/2
exists $self->{"hash"} or defined $passphrase
exists $self->{"hash"} defined $passphrase
Truth table33%1/3
A or B
A= exists $self->{"hash"}B= defined $passphrase
ABresult
1X1
011
000
280 defined($passphrase);
281 16 $passphrase = $value;
282 } else {
283 0 croak "unrecognised attribute `$attr'";
284 }
285 }
286 67 ▶ $self->{fold} = !!0 unless exists $self->{fold};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"fold"} 54 13 67
287 67 ▶ $self->{initial} = "\0\0\0\0\0\0\0\0" unless exists $self->{initial};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"initial"} 60 7 67
288 67 ▶ $self->{nrounds} = 25 unless exists $self->{nrounds};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"nrounds"} 36 31 67
289 67 ▶ croak "salt not specified" unless exists $self->{salt};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"salt"} 0 67 67
290 67 ▶ $self->{hash} = $self->_hash_of($passphrase) if defined $passphrase;
Branch: 1 branch
BranchTrueFalseTotal
if defined $passphrase 16 51 67
291 67 ▶ croak "hash not specified" unless exists $self->{hash};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"hash"} 0 67 67
292 67 return $self;
293 }
294  
295 =item Authen::Passphrase::DESCrypt->from_crypt(PASSWD)
296  
297 Generates a new passphrase recogniser object using the DES-based crypt()
298 algorithm, from a crypt string. Two forms of crypt string are supported.
299  
300 The first form of crypt string must consist of 13 base 64 digits.
301 The first two give the salt, and the next eleven give the hash.
302 Long passphrases are not folded, the initial block is all bits zero,
303 and 25 encryption rounds are performed.
304  
305 The second form of crypt string must consist of an "B<_>" followed
306 by 19 base 64 digits. The first four give the number of encryption
307 rounds, the next four give the salt, and the next eleven give the hash.
308 Long passphrases are folded, and the initial block is all bits zero.
309  
310 =cut
311  
312 2 ▶sub from_crypt {
Subroutine from_crypt: called CC=5 SCAR=16.7
Pod documented
313 2 my($class, $passwd) = @_;
314 2 ▶ if($passwd =~ /\A[^\$].{12}\z/s) {
Branch: 2 branches
BranchTrueFalseTotal
if ($passwd =~ /\A[^\$].{12}\z/s) { } 1 1 2
elsif ($passwd =~ /\A_.{19}\z/s) { } 1 0 1
315 1 ▶ $passwd =~ m#\A([./0-9A-Za-z]{2})([./0-9A-Za-z]{11})\z#
Branch: 1 branch
BranchTrueFalseTotal
$passwd =~ m[\A([./0-9A-Za-z]{2})([./0-9A-Za-z]{11})\z] or croak("malformed DES crypt data") 1 0 1
316 or croak "malformed DES crypt data";
317 1 my($salt, $hash) = ($1, $2);
318 1 return $class->new(salt_base64 => $salt, hash_base64 => $hash);
319 } elsif($passwd =~ /\A_.{19}\z/s) {
320 1 ▶ $passwd =~ m#\A_([./0-9A-Za-z]{4})([./0-9A-Za-z]{4})
Branch: 1 branch
BranchTrueFalseTotal
$passwd =~ m[\A_([./0-9A-Za-z]{4})([./0-9A-Za-z]{4}) ([./0-9A-Za-z]{11})\z]x or croak("malformed _ data") 1 0 1
321 ([./0-9A-Za-z]{11})\z#x
322 or croak "malformed _ data";
323 1 my($nr, $salt, $hash) = ($1, $2, $3);
324 1 return $class->new(fold => 1, nrounds_base64 => $nr,
325 salt_base64 => $salt, hash_base64 => $hash);
326 }
327 0 return $class->SUPER::from_crypt($passwd);
328 }
329  
330 =item Authen::Passphrase::DESCrypt->from_rfc2307(USERPASSWORD)
331  
332 Generates a new passphrase recogniser object using the DES-based
333 crypt() algorithm, from an RFC 2307 string. The string must consist of
334 "B<{CRYPT}>" (case insensitive) followed by an acceptable crypt string.
335  
336 =back
337  
338 =head1 METHODS
339  
340 =over
341  
342 =item $ppr->fold
343  
344 Returns a truth value indicating whether passphrase folding is used.
345  
346 =cut
347  
348 27 ▶sub fold {
Subroutine fold: called CC=1 SCAR=0.0
Pod documented
349 27 my($self) = @_;
350 27 return $self->{fold};
351 }
352  
353 =item $ppr->initial
354  
355 Returns the initial block, as a string of eight bytes.
356  
357 =cut
358  
359 8 ▶sub initial {
Subroutine initial: called CC=1 SCAR=0.0
Pod documented
360 8 my($self) = @_;
361 8 return $self->{initial};
362 }
363  
364 =item $ppr->initial_base64
365  
366 Returns the initial block, as a string of eleven base 64 digits.
367  
368 =cut
369  
370 23 ▶sub initial_base64 {
Subroutine initial_base64: called CC=1 SCAR=0.0
Pod documented
371 23 my($self) = @_;
372 23 return block_to_base64($self->{initial});
373 }
374  
375 =item $ppr->nrounds
376  
377 Returns the number of encryption rounds, as a Perl integer.
378  
379 =cut
380  
381 15 ▶sub nrounds {
Subroutine nrounds: called CC=1 SCAR=0.0
Pod documented
382 15 my($self) = @_;
383 15 return $self->{nrounds};
384 }
385  
386 =item $ppr->nrounds_base64_4
387  
388 Returns the number of encryption rounds, as a string of four base
389 64 digits.
390  
391 =cut
392  
393 26 ▶sub nrounds_base64_4 {
Subroutine nrounds_base64_4: called CC=1 SCAR=0.0
Pod documented
394 26 my($self) = @_;
395 26 return int24_to_base64($self->{nrounds});
396 }
397  
398 =item $ppr->salt
399  
400 Returns the salt, as a Perl integer.
401  
402 =cut
403  
404 14 ▶sub salt {
Subroutine salt: called CC=1 SCAR=0.0
Pod documented
405 14 my($self) = @_;
406 14 return $self->{salt};
407 }
408  
409 =item $ppr->salt_base64_2
410  
411 Returns the salt, as a string of two base 64 digits. C<die>s if it
412 doesn't fit into two digits.
413  
414 =cut
415  
416 45 ▶sub salt_base64_2 {
Subroutine salt_base64_2: called CC=2 SCAR=6.9
Pod documented
417 45 my($self) = @_;
418 45 my $salt = $self->{salt};
419 45 ▶ croak "salt $salt doesn't fit into two digits" if $salt >= 4096;
Branch: 1 branch
BranchTrueFalseTotal
if $salt >= 4096 2 43 45
420 43 return int12_to_base64($salt);
421 }
422  
423 =item $ppr->salt_base64_4
424  
425 Returns the salt, as a string of four base 64 digits.
426  
427 =cut
428  
429 27 ▶sub salt_base64_4 {
Subroutine salt_base64_4: called CC=1 SCAR=0.0
Pod documented
430 27 my($self) = @_;
431 27 return int24_to_base64($self->{salt});
432 }
433  
434 =item $ppr->hash
435  
436 Returns the hash value, as a string of eight bytes.
437  
438 =cut
439  
440 13 ▶sub hash {
Subroutine hash: called CC=1 SCAR=0.0
Pod documented
441 13 my($self) = @_;
442 13 return $self->{hash};
443 }
444  
445 =item $ppr->hash_base64
446  
447 Returns the hash value, as a string of eleven base 64 digits.
448  
449 =cut
450  
451 118 ▶sub hash_base64 {
Subroutine hash_base64: called CC=1 SCAR=0.0
Pod documented
452 118 my($self) = @_;
453 118 return block_to_base64($self->{hash});
454 }
455  
456 =item $ppr->match(PASSPHRASE)
457  
458 =item $ppr->as_crypt
459  
460 =item $ppr->as_rfc2307
461  
462 These methods are part of the standard L<Authen::Passphrase> interface.
463  
464 =cut
465  
466  
467  
468 170 ▶sub _hash_of {
Subroutine _hash_of: called CC=2 SCAR=6.9
469 170 my($self, $passphrase) = @_;
470 170 ▶ $passphrase = fold_password($passphrase) if $self->{fold};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"fold"} 50 120 170
471 return crypt_rounds($passphrase, $self->{nrounds}, $self->{salt},
472 170 $self->{initial});
473 }
474  
475 154 ▶sub match {
Subroutine match: called CC=1 SCAR=0.0
Pod documented
476 154 my($self, $passphrase) = @_;
477 154 return $self->_hash_of($passphrase) eq $self->{hash};
478 }
479  
480 36 ▶sub as_crypt {
Subroutine as_crypt: called CC=7 SCAR=19.9
Pod documented
481 36 my($self) = @_;
482 36 ▶ if(!$self->{fold} && $self->{initial} eq "\0\0\0\0\0\0\0\0" &&
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->{'fold'} and $self->{'initial'} eq "\000\000\000\000\000\000\000\000" and $self->{'nrounds'} == 25 and $self->{'salt'} < 4096) { } 16 20 36
elsif ($self->{'fold'} and $self->{'initial'} eq "\000\000\000\000\000\000\000\000") { } 10 10 20
Condition66%6/9
not $self->{"fold"} and $self->{"initial"} eq "\0\0\0\0\0\0\0\0" and $self->{"nrounds"} == 25 and $self->{"salt"} < 4096
!ll&&!rl&&r
20016
not $self->{"fold"} and $self->{"initial"} eq "\0\0\0\0\0\0\0\0" and $self->{"nrounds"} == 25
!ll&&!rl&&r
20016
not $self->{"fold"} and $self->{"initial"} eq "\0\0\0\0\0\0\0\0"
!ll&&!rl&&r
20016
MC/DC25%1/4
not $self->{"fold"} and $self->{"initial"} eq "\0\0\0\0\0\0\0\0" and $self->{"nrounds"} == 25 and $self->{"salt"} < 4096
not $self->{"fold"} $self->{"initial"} eq "\0\0\0\0\0\0\0\0" $self->{"nrounds"} == 25 $self->{"salt"} < 4096
Truth table40%2/5
not(A) and B and C and D
A= not $self->{"fold"}B= $self->{"initial"} eq "\0\0\0\0\0\0\0\0"C= $self->{"nrounds"} == 25D= $self->{"salt"} < 4096
ABCDresult
0XXX0
10XX0
110X0
11100
11111
483 $self->{nrounds} == 25 && $self->{salt} < 4096) {
484 16 return $self->salt_base64_2.$self->hash_base64;
485 ▶ } elsif($self->{fold} && $self->{initial} eq "\0\0\0\0\0\0\0\0") {
Condition66%2/3
$self->{"fold"} and $self->{"initial"} eq "\0\0\0\0\0\0\0\0"
!ll&&!rl&&r
01010
MC/DC50%1/2
$self->{"fold"} and $self->{"initial"} eq "\0\0\0\0\0\0\0\0"
$self->{"fold"} $self->{"initial"} eq "\0\0\0\0\0\0\0\0"
Truth table66%2/3
A and B
A= $self->{"fold"}B= $self->{"initial"} eq "\0\0\0\0\0\0\0\0"
ABresult
0X0
100
111
486 10 return "_".$self->nrounds_base64_4.$self->salt_base64_4.
487 $self->hash_base64;
488 } else {
489 10 croak "passphrase can't be expressed as a crypt string";
490 }
491 }
492  
493 =back
494  
495 =head1 SEE ALSO
496  
497 L<Authen::Passphrase>,
498 L<Crypt::UnixCrypt_XS>
499  
500 =head1 AUTHOR
501  
502 Andrew Main (Zefram) <zefram@fysh.org>
503  
504 =head1 COPYRIGHT
505  
506 Copyright (C) 2006, 2007, 2009, 2010, 2012
507 Andrew Main (Zefram) <zefram@fysh.org>
508  
509 =head1 LICENSE
510  
511 This module is free software; you can redistribute it and/or modify it
512 under the same terms as Perl itself.
513  
514 =cut
515  
516 7 1;
↑ Summary Passphrase/VMSPurdy.pm »