line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Scrypt; |
2
|
1
|
|
|
1
|
|
1077
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
3
|
1
|
|
|
1
|
|
1127
|
use Crypt::ScryptKDF qw/scrypt_hash scrypt_hash_verify/; |
|
1
|
|
|
|
|
2391
|
|
|
1
|
|
|
|
|
295
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub register { |
8
|
1
|
|
|
1
|
1
|
42
|
my ( $self, $app, $conf ) = @_; |
9
|
1
|
|
50
|
|
|
7
|
my $salt_len = $conf->{salt_length} || 32; |
10
|
1
|
|
50
|
|
|
4
|
my $N = $conf->{cost} || 16384; |
11
|
1
|
|
50
|
|
|
5
|
my $r = $conf->{block_size} || 8; |
12
|
1
|
|
50
|
|
|
4
|
my $p = $conf->{parallelism} || 1; |
13
|
1
|
|
50
|
|
|
5
|
my $len = $conf->{derived_length} || 32; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$app->helper( |
16
|
|
|
|
|
|
|
scrypt => sub { |
17
|
10
|
|
|
10
|
|
1206178
|
my $c = shift; |
18
|
10
|
|
|
|
|
28
|
my ( $secret, $salt ) = @_; |
19
|
10
|
100
|
|
|
|
45
|
unless ($salt) { |
20
|
4
|
|
|
|
|
20
|
return scrypt_hash( $secret, \$salt_len, $N, $r, $p, $len ); |
21
|
|
|
|
|
|
|
} |
22
|
6
|
|
|
|
|
33
|
return scrypt_hash( $secret, $salt, $N, $r, $p, $len ); |
23
|
|
|
|
|
|
|
} |
24
|
1
|
|
|
|
|
10
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$app->helper( |
27
|
|
|
|
|
|
|
scrypt_verify => sub { |
28
|
6
|
|
|
6
|
|
795410
|
my $c = shift; |
29
|
6
|
|
|
|
|
14
|
my ( $plain, $encoded ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#returns: 1 (ok) or 0 (fail) |
32
|
6
|
|
|
|
|
24
|
return scrypt_hash_verify( $plain, $encoded ); |
33
|
|
|
|
|
|
|
} |
34
|
1
|
|
|
|
|
35
|
); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
__END__ |