line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Crypt::PBE; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1434
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
59
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
63
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
13
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
138
|
|
7
|
2
|
|
|
2
|
|
914
|
use Crypt::PBE::PBES1; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
109
|
|
8
|
2
|
|
|
2
|
|
916
|
use Crypt::PBE::PBES2; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
117
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.101'; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
13
|
use Exporter qw(import); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
395
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my @JCE_PBE_ALGORITHMS = qw( |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
PBEWithMD5AndDES |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
PBEWithHmacSHA1AndAES_128 |
19
|
|
|
|
|
|
|
PBEWithHmacSHA1AndAES_192 |
20
|
|
|
|
|
|
|
PBEWithHmacSHA1AndAES_256 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
PBEWithHmacSHA224AndAES_128 |
23
|
|
|
|
|
|
|
PBEWithHmacSHA224AndAES_192 |
24
|
|
|
|
|
|
|
PBEWithHmacSHA224AndAES_256 |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
PBEWithHmacSHA256AndAES_128 |
27
|
|
|
|
|
|
|
PBEWithHmacSHA256AndAES_192 |
28
|
|
|
|
|
|
|
PBEWithHmacSHA256AndAES_256 |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
PBEWithHmacSHA384AndAES_128 |
31
|
|
|
|
|
|
|
PBEWithHmacSHA384AndAES_192 |
32
|
|
|
|
|
|
|
PBEWithHmacSHA384AndAES_256 |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
PBEWithHmacSHA512AndAES_128 |
35
|
|
|
|
|
|
|
PBEWithHmacSHA512AndAES_192 |
36
|
|
|
|
|
|
|
PBEWithHmacSHA512AndAES_256 |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
our @EXPORT_OK = @JCE_PBE_ALGORITHMS; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'jce' => \@JCE_PBE_ALGORITHMS ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# JCE algorithm PBEWithAnd |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $pbes1_map = { |
46
|
|
|
|
|
|
|
'PBEWithMD2AndDES' => { hash => 'md2', encryption => 'des' }, |
47
|
|
|
|
|
|
|
'PBEWithMD5AndDES' => { hash => 'md5', encryption => 'des' }, |
48
|
|
|
|
|
|
|
'PBEWithSHA1AndDES' => { hash => 'sha1', encryption => 'des' }, |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $pbes2_map = { |
52
|
|
|
|
|
|
|
'PBEWithHmacSHA1AndAES_128' => { hmac => 'hmac-sha1', encryption => 'aes-128' }, |
53
|
|
|
|
|
|
|
'PBEWithHmacSHA1AndAES_192' => { hmac => 'hmac-sha1', encryption => 'aes-192' }, |
54
|
|
|
|
|
|
|
'PBEWithHmacSHA1AndAES_256' => { hmac => 'hmac-sha1', encryption => 'aes-256' }, |
55
|
|
|
|
|
|
|
'PBEWithHmacSHA224AndAES_128' => { hmac => 'hmac-sha224', encryption => 'aes-128' }, |
56
|
|
|
|
|
|
|
'PBEWithHmacSHA224AndAES_192' => { hmac => 'hmac-sha224', encryption => 'aes-192' }, |
57
|
|
|
|
|
|
|
'PBEWithHmacSHA224AndAES_256' => { hmac => 'hmac-sha224', encryption => 'aes-256' }, |
58
|
|
|
|
|
|
|
'PBEWithHmacSHA256AndAES_128' => { hmac => 'hmac-sha256', encryption => 'aes-128' }, |
59
|
|
|
|
|
|
|
'PBEWithHmacSHA256AndAES_192' => { hmac => 'hmac-sha256', encryption => 'aes-192' }, |
60
|
|
|
|
|
|
|
'PBEWithHmacSHA256AndAES_256' => { hmac => 'hmac-sha256', encryption => 'aes-256' }, |
61
|
|
|
|
|
|
|
'PBEWithHmacSHA384AndAES_128' => { hmac => 'hmac-sha384', encryption => 'aes-128' }, |
62
|
|
|
|
|
|
|
'PBEWithHmacSHA384AndAES_192' => { hmac => 'hmac-sha384', encryption => 'aes-192' }, |
63
|
|
|
|
|
|
|
'PBEWithHmacSHA384AndAES_256' => { hmac => 'hmac-sha384', encryption => 'aes-256' }, |
64
|
|
|
|
|
|
|
'PBEWithHmacSHA512AndAES_128' => { hmac => 'hmac-sha512', encryption => 'aes-128' }, |
65
|
|
|
|
|
|
|
'PBEWithHmacSHA512AndAES_192' => { hmac => 'hmac-sha512', encryption => 'aes-192' }, |
66
|
|
|
|
|
|
|
'PBEWithHmacSHA512AndAES_256' => { hmac => 'hmac-sha512', encryption => 'aes-256' }, |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# PBES1 + PBDKF1 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
foreach ( keys %{$pbes1_map} ) { |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $params = $pbes1_map->{$_}; |
74
|
|
|
|
|
|
|
my $sub_name = $_; |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
2
|
|
15
|
no strict 'refs'; ## no critic |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
320
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
*{$sub_name} = sub { |
79
|
1
|
|
|
1
|
|
580
|
my ( $password, $count ) = @_; |
80
|
|
|
|
|
|
|
my $pbes1 = Crypt::PBE::PBES1->new( |
81
|
|
|
|
|
|
|
password => $password, |
82
|
|
|
|
|
|
|
count => $count || 1_000, |
83
|
|
|
|
|
|
|
hash => $params->{hash}, |
84
|
|
|
|
|
|
|
encryption => $params->{encryption}, |
85
|
1
|
|
50
|
|
|
12
|
); |
86
|
1
|
|
|
|
|
3
|
return $pbes1; |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# PBES2 + PBDKF2 |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
foreach ( keys %{$pbes2_map} ) { |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $params = $pbes2_map->{$_}; |
96
|
|
|
|
|
|
|
my $sub_name = $_; |
97
|
|
|
|
|
|
|
|
98
|
2
|
|
|
2
|
|
15
|
no strict 'refs'; ## no critic |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
298
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
*{$sub_name} = sub { |
101
|
15
|
|
|
15
|
|
51
|
my ( $password, $count ) = @_; |
102
|
|
|
|
|
|
|
my $pbes2 = Crypt::PBE::PBES2->new( |
103
|
|
|
|
|
|
|
password => $password, |
104
|
|
|
|
|
|
|
count => $count || 1_000, |
105
|
|
|
|
|
|
|
hmac => $params->{hmac}, |
106
|
|
|
|
|
|
|
encryption => $params->{encryption}, |
107
|
15
|
|
50
|
|
|
51
|
); |
108
|
15
|
|
|
|
|
25
|
return $pbes2; |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
__END__ |