| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Crypt::DES_EDE3; |
|
4
|
1
|
|
|
1
|
|
47
|
use strict; |
|
|
1
|
|
|
|
|
18
|
|
|
|
1
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
64
|
use Crypt::DES; |
|
|
1
|
|
|
|
|
10
|
|
|
|
1
|
|
|
|
|
19
|
|
|
7
|
1
|
|
|
1
|
|
18
|
use vars qw( $VERSION ); |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
|
|
$VERSION = '0.01'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
|
11
|
1
|
|
|
1
|
1
|
71
|
my $class = shift; |
|
12
|
1
|
|
|
|
|
15
|
my $ede3 = bless {}, $class; |
|
13
|
1
|
|
|
|
|
13
|
$ede3->init(@_); |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
1
|
960
|
sub keysize { 24 } |
|
17
|
0
|
|
|
0
|
1
|
0
|
sub blocksize { 8 } |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub init { |
|
20
|
1
|
|
|
1
|
0
|
9
|
my $ede3 = shift; |
|
21
|
1
|
|
|
|
|
11
|
my($key) = @_; |
|
22
|
1
|
|
|
|
|
12
|
for my $i (1..3) { |
|
23
|
3
|
|
|
|
|
98
|
$ede3->{"des$i"} = Crypt::DES->new(substr $key, 8*($i-1), 8); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
1
|
|
|
|
|
34
|
$ede3; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub encrypt { |
|
29
|
1
|
|
|
1
|
1
|
11
|
my($ede3, $block) = @_; |
|
30
|
1
|
|
|
|
|
18
|
$ede3->{des3}->encrypt( |
|
31
|
|
|
|
|
|
|
$ede3->{des2}->decrypt( |
|
32
|
|
|
|
|
|
|
$ede3->{des1}->encrypt($block) |
|
33
|
|
|
|
|
|
|
) |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub decrypt { |
|
38
|
1
|
|
|
1
|
1
|
1087
|
my($ede3, $block) = @_; |
|
39
|
1
|
|
|
|
|
18
|
$ede3->{des1}->decrypt( |
|
40
|
|
|
|
|
|
|
$ede3->{des2}->encrypt( |
|
41
|
|
|
|
|
|
|
$ede3->{des3}->decrypt($block) |
|
42
|
|
|
|
|
|
|
) |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
|
47
|
|
|
|
|
|
|
__END__ |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 NAME |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Crypt::DES_EDE3 - Triple-DES EDE encryption/decryption |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Crypt::DES_EDE3; |
|
56
|
|
|
|
|
|
|
my $ede3 = Crypt::DES_EDE3->new($key); |
|
57
|
|
|
|
|
|
|
$ede3->encrypt($block); |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
I<Crypt::DES_EDE3> implements DES-EDE3 encryption. This is triple-DES |
|
62
|
|
|
|
|
|
|
encryption where an encrypt operation is encrypt-decrypt-encrypt, and |
|
63
|
|
|
|
|
|
|
decrypt is decrypt-encrypt-decrypt. This implementation uses I<Crypt::DES> |
|
64
|
|
|
|
|
|
|
to do its dirty DES work, and simply provides a wrapper around that |
|
65
|
|
|
|
|
|
|
module: setting up the individual DES ciphers, initializing the keys, |
|
66
|
|
|
|
|
|
|
and performing the encryption/decryption steps. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
DES-EDE3 encryption requires a key size of 24 bytes. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
You're probably best off not using this module directly, as the I<encrypt> |
|
71
|
|
|
|
|
|
|
and I<decrypt> methods expect 8-octet blocks. You might want to use the |
|
72
|
|
|
|
|
|
|
module in conjunction with I<Crypt::CBC>, for example. This would be |
|
73
|
|
|
|
|
|
|
DES-EDE3-CBC, or triple-DES in outer CBC mode. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 USAGE |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 $ede3 = Crypt::DES_EDE3->new($key) |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Creates a new I<Crypt::DES_EDE3> object (really, a collection of three DES |
|
80
|
|
|
|
|
|
|
ciphers), and initializes each cipher with part of I<$key>, which should be |
|
81
|
|
|
|
|
|
|
at least 24 bytes. If it's longer than 24 bytes, the extra bytes will be |
|
82
|
|
|
|
|
|
|
ignored. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Returns the new object. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 $ede3->encrypt($block) |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Encrypts an 8-byte block of data I<$block> using the three DES ciphers in |
|
89
|
|
|
|
|
|
|
an encrypt-decrypt-encrypt operation. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Returns the encrypted block. |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 $ede3->decrypt($block) |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Decrypts an 8-byte block of data I<$block> using the three DES ciphers in |
|
96
|
|
|
|
|
|
|
a decrypt-encrypt-decrypt operation. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Returns the decrypted block. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 $ede3->blocksize |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Returns the block size (8). |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 $ede3->keysize |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Returns the key size (24). |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 LICENSE |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Crypt::DES_EDE3 is free software; you may redistribute it and/or modify |
|
111
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 AUTHOR & COPYRIGHTS |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Crypt::DES_EDE3 is Copyright 2001 Benjamin Trott, ben@rhumba.pair.com. All |
|
116
|
|
|
|
|
|
|
rights reserved. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
|
119
|
|
|
|
|
|
|
|