aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/test/blowfish.pl
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:50 -0500
committerJacek Antonelli2008-08-15 23:44:50 -0500
commit89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 (patch)
treebcff14b7888d04a2fec799c59369f6095224bd08 /linden/indra/test/blowfish.pl
parentSecond Life viewer sources 1.13.3.2 (diff)
downloadmeta-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-xlinden/indra/test/blowfish.pl74
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
2use strict;
3use warnings;
4
5# *TODO: specify test count here
6use Test::More qw(no_plan);
7
8use Crypt::CBC;
9use MIME::Base64;
10
11my $init_vector = "\x00" x 8;
12# my $key = pack("H*", "ef5a8376eb0c99fe0dafa487d15bec19cae63d1e25fe31d8d92f7ab0398246d70ee733108e47360e16359654571cf5bab6c3375b42cee4fa");
13# my $key = "d263eb8a78034e40";
14 #"8d082918aa369174";
15my $key = "\x00" x 16;
16
17my $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
28my $len;
29my $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);
32is ($len, 36, "input length");
33
34$len = length($key);
35is ($len, 16, "key length");
36
37
38my $encrypted = $cipher->encrypt($input);
39is (length($encrypted), 40, "encrypted length");
40
41open(FH, "blowfish.1.bin");
42my $bin = scalar <FH>;
43is ($encrypted, $bin, "matches openssl");
44close(FH);
45
46my $base64 = encode_base64($encrypted);
47is ($base64, "LkGExDOMTNxFIGBg8gP43UvbQLz7xztNWwYF2kLrtwT4hD7LykOXJw==\n",
48 "base64 output");
49
50my $unbase64 = decode_base64($base64);
51is( $encrypted, $unbase64, "reverse base64" );
52
53my $output = $cipher->decrypt($unbase64);
54is ($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);
65is (length($encrypted), 40, "uuid encrypted length");
66$output = $cipher->decrypt($encrypted);
67is ($input, $output, "uuid reverse encrypt");
68
69open(FH, "blowfish.2.bin");
70$bin = scalar <FH>;
71close(FH);
72is( $encrypted, $bin, "uuid matches openssl" );
73
74print encode_base64($encrypted);