| 1 | package Crypt::Passphrase::SaltedHash; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use v5.6; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 2 | ▶ | use parent 'Crypt::Passphrase::Validator'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 2 | ▶ | use Digest 1.19 (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use MIME::Base64 (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | # ABSTRACT: Validate against Crypt::SaltedHash hashes with Crypt::Passphrase | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 2 | my %DIGESTS = ( | |||||||||||||||||||
| 19 | GOST => [ 256, "GOST" ], | ||||||||||||||||||||
| 20 | HMACMD5 => [ 128, "HMAC-MD5" ], # Note: Digest::HMAC does not work with Crypt::SaltedHash | ||||||||||||||||||||
| 21 | HMACSHA => [ 160, "HMAC-SHA-1" ], | ||||||||||||||||||||
| 22 | MD2 => [128], | ||||||||||||||||||||
| 23 | MD4 => [128], | ||||||||||||||||||||
| 24 | MD5 => [128], | ||||||||||||||||||||
| 25 | MD6 => [256], | ||||||||||||||||||||
| 26 | SHA => [ 160, "SHA-1" ], | ||||||||||||||||||||
| 27 | SHA224 => [ 224, "SHA-224" ], | ||||||||||||||||||||
| 28 | SHA256 => [ 256, "SHA-256" ], | ||||||||||||||||||||
| 29 | SHA384 => [ 384, "SHA-384" ], | ||||||||||||||||||||
| 30 | SHA512 => [ 512, "SHA-512" ], | ||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 2 | my $ALGS = join( "|", keys %DIGESTS ); | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 2 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 37 | 2 | my $class = shift; | |||||||||||||||||||
| 38 | 2 | return bless {}, $class; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 8 | ▶ | sub accepts_hash { | ||||||||||||||||||
|
Subroutine
accepts_hash: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 42 | 8 | my ( $self, $hash ) = @_; | |||||||||||||||||||
| 43 | 8 | ▶ | my ( $has_salt, $alg ) = $hash =~ /^\{(S)?(${ALGS})\}/ or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 8 | return exists $DIGESTS{ uc $alg }; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 8 | ▶ | sub verify_password { | ||||||||||||||||||
|
Subroutine
verify_password: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||
| 48 | 8 | my ( $self, $password, $hash ) = @_; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 8 | ▶ | my ( $has_salt, $alg ) = $hash =~ /^\{(S)?(${ALGS})\}/ or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 8 | ▶ | my $meta = $DIGESTS{ uc $alg } or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 8 | ▶ | my $name = $meta->[1] || $alg; | ||||||||||||||||||
|
Condition66%2/3
$meta->[1] || $alg
MC/DC0%0/2
$meta->[1] || $alg
$meta->[1]
$alg
Truth table66%2/3
A || B
A= $meta->[1]B= $alg
| |||||||||||||||||||||
| 54 | 8 | my $bytes = $meta->[0] / 8; | |||||||||||||||||||
| 55 | 8 | my $digest = Digest->new($name); | |||||||||||||||||||
| 56 | 8 | ▶ | my $bin = MIME::Base64::decode_base64( substr( $hash, length($alg) + 2 + ( $has_salt ? 1 : 0 ) ) ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 8 | ▶ | my $salt = $has_salt ? substr( $bin, $bytes ) : ""; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 8 | my $maybe = $digest->add( $password . $salt )->digest; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 8 | return $self->secure_compare( $maybe, substr( $bin, 0, $bytes ) ); | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 2 | 1; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||