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