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