line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright 2001 Abhijit Menon-Sen |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Crypt::Twofish; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
13181
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
359
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
52
|
|
7
|
1
|
|
|
1
|
|
5
|
use DynaLoader; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
8
|
1
|
|
|
1
|
|
6
|
use vars qw( @ISA $VERSION ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
486
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
@ISA = qw( DynaLoader ); |
11
|
|
|
|
|
|
|
$VERSION = '2.18'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
bootstrap Crypt::Twofish $VERSION; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub keysize () { 16 } |
16
|
|
|
|
|
|
|
sub blocksize () { 16 } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new |
19
|
|
|
|
|
|
|
{ |
20
|
20297
|
|
|
20297
|
1
|
80980
|
my ($class, $key) = @_; |
21
|
|
|
|
|
|
|
|
22
|
20297
|
50
|
|
|
|
32770
|
croak "Usage: ".__PACKAGE__."->new(\$key)" unless $key; |
23
|
20297
|
|
|
|
|
208354
|
return Crypt::Twofish::setup($key); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub encrypt |
27
|
|
|
|
|
|
|
{ |
28
|
20148
|
|
|
20148
|
1
|
62985
|
my ($self, $data) = @_; |
29
|
|
|
|
|
|
|
|
30
|
20148
|
50
|
33
|
|
|
56362
|
croak "Usage: \$cipher->encrypt(\$data)" unless ref($self) && $data; |
31
|
20148
|
|
|
|
|
65681
|
$self->crypt($data, $data, 0); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub decrypt |
35
|
|
|
|
|
|
|
{ |
36
|
20148
|
|
|
20148
|
1
|
63881
|
my ($self, $data) = @_; |
37
|
|
|
|
|
|
|
|
38
|
20148
|
50
|
33
|
|
|
55864
|
croak "Usage: \$cipher->decrypt(\$data)" unless ref($self) && $data; |
39
|
20148
|
|
|
|
|
65737
|
$self->crypt($data, $data, 1); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# The functions below provide an interface that is call-compatible with |
43
|
|
|
|
|
|
|
# the Crypt::Twofish 1.0 module. They do not, however, behave in exactly |
44
|
|
|
|
|
|
|
# the same way: they don't pad keys, and cannot decrypt ciphertext which |
45
|
|
|
|
|
|
|
# was written by the old module. |
46
|
|
|
|
|
|
|
# |
47
|
|
|
|
|
|
|
# (This interface is deprecated. Please use the documented interface |
48
|
|
|
|
|
|
|
# instead). |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub Encipher |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
0
|
0
|
|
my ($key, $keylength, $plaintext) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
require Crypt::CBC; |
55
|
0
|
|
|
|
|
|
my $cipher = Crypt::CBC->new($key, "Twofish"); |
56
|
0
|
|
|
|
|
|
return $cipher->encrypt($plaintext); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub Decipher |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
0
|
0
|
|
my ($key, $keylength, $ciphertext, $cipherlength) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
require Crypt::CBC; |
64
|
0
|
|
|
|
|
|
my $cipher = Crypt::CBC->new($key, "Twofish"); |
65
|
0
|
|
|
|
|
|
return $cipher->decrypt($ciphertext); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
0
|
0
|
|
sub LastError { ""; } |
69
|
0
|
|
|
0
|
0
|
|
sub CheckTwofish { undef; } |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |