diff options
author | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:50 -0500 |
commit | 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch) | |
tree | bcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/test/blowfish.pl | |
parent | Second Life viewer sources 1.13.3.2 (diff) | |
download | meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.zip meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.gz meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.bz2 meta-impy-89fe5dab825a62a0e3fd8d248cbc91c65eb2a426.tar.xz |
Second Life viewer sources 1.14.0.0
Diffstat (limited to 'linden/indra/test/blowfish.pl')
-rwxr-xr-x | linden/indra/test/blowfish.pl | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/linden/indra/test/blowfish.pl b/linden/indra/test/blowfish.pl new file mode 100755 index 0000000..7940d87 --- /dev/null +++ b/linden/indra/test/blowfish.pl | |||
@@ -0,0 +1,74 @@ | |||
1 | #!/usr/bin/perl | ||
2 | use strict; | ||
3 | use warnings; | ||
4 | |||
5 | # *TODO: specify test count here | ||
6 | use Test::More qw(no_plan); | ||
7 | |||
8 | use Crypt::CBC; | ||
9 | use MIME::Base64; | ||
10 | |||
11 | my $init_vector = "\x00" x 8; | ||
12 | # my $key = pack("H*", "ef5a8376eb0c99fe0dafa487d15bec19cae63d1e25fe31d8d92f7ab0398246d70ee733108e47360e16359654571cf5bab6c3375b42cee4fa"); | ||
13 | # my $key = "d263eb8a78034e40"; | ||
14 | #"8d082918aa369174"; | ||
15 | my $key = "\x00" x 16; | ||
16 | |||
17 | my $cipher = Crypt::CBC->new( { cipher => 'Blowfish', | ||
18 | regenerate_key => 0, | ||
19 | key => $key, | ||
20 | iv => $init_vector, | ||
21 | header => 'none', | ||
22 | prepend_iv => 0, | ||
23 | keysize => 16 } ); | ||
24 | |||
25 | #my $blocks = $cipher->blocksize(); | ||
26 | #print "blocksize $blocks\n"; | ||
27 | |||
28 | my $len; | ||
29 | my $input = "01234567890123456789012345678901234\n"; | ||
30 | #my $input = "a whale of a tale I tell you lad, a whale of a tale for me, a whale of a tale and the fiddlers three"; | ||
31 | $len = length($input); | ||
32 | is ($len, 36, "input length"); | ||
33 | |||
34 | $len = length($key); | ||
35 | is ($len, 16, "key length"); | ||
36 | |||
37 | |||
38 | my $encrypted = $cipher->encrypt($input); | ||
39 | is (length($encrypted), 40, "encrypted length"); | ||
40 | |||
41 | open(FH, "blowfish.1.bin"); | ||
42 | my $bin = scalar <FH>; | ||
43 | is ($encrypted, $bin, "matches openssl"); | ||
44 | close(FH); | ||
45 | |||
46 | my $base64 = encode_base64($encrypted); | ||
47 | is ($base64, "LkGExDOMTNxFIGBg8gP43UvbQLz7xztNWwYF2kLrtwT4hD7LykOXJw==\n", | ||
48 | "base64 output"); | ||
49 | |||
50 | my $unbase64 = decode_base64($base64); | ||
51 | is( $encrypted, $unbase64, "reverse base64" ); | ||
52 | |||
53 | my $output = $cipher->decrypt($unbase64); | ||
54 | is ($input, $output, "reverse encrypt"); | ||
55 | |||
56 | $key = pack("H[32]", "526a1e07a19dbaed84c4ff08a488d15e"); | ||
57 | $cipher = Crypt::CBC->new( { cipher => 'Blowfish', | ||
58 | regenerate_key => 0, | ||
59 | key => $key, | ||
60 | iv => $init_vector, | ||
61 | header => 'none', | ||
62 | prepend_iv => 0, | ||
63 | keysize => 16 } ); | ||
64 | $encrypted = $cipher->encrypt($input); | ||
65 | is (length($encrypted), 40, "uuid encrypted length"); | ||
66 | $output = $cipher->decrypt($encrypted); | ||
67 | is ($input, $output, "uuid reverse encrypt"); | ||
68 | |||
69 | open(FH, "blowfish.2.bin"); | ||
70 | $bin = scalar <FH>; | ||
71 | close(FH); | ||
72 | is( $encrypted, $bin, "uuid matches openssl" ); | ||
73 | |||
74 | print encode_base64($encrypted); | ||