2 use Test::More tests => 48;
6 # If this variable is set, engine would be loaded via configuration
7 # file. Otherwise - via command line
14 # Set OPENSSL_ENGINES environment variable to just build engine
15 $ENV{'OPENSSL_ENGINES'} = abs_path("../.libs");
17 $key='0123456789abcdef' x 2;
20 # You can redefine engine to use using ENGINE_NAME environment variable
22 $engine=$ENV{'ENGINE_NAME'}||"gost";
24 # Reopen STDERR to eliminate extra output
25 open STDERR, ">>","tests.err";
30 # parameters -paramset = oid of the parameters
31 # -cleartext - data to encrypt
32 # -ciphertext - expected ciphertext (hex-encoded)
33 # -key - key (hex-encoded)
34 # -iv - IV (hex-encoded)
37 open F,">","test.cnf";
38 if (defined($use_config) && $use_config) {
40 open F,">","test.cnf";
42 openssl_conf = openssl_def
48 default_algorithms = ALL
52 $eng_param = "-engine $engine"
55 $ENV{'OPENSSL_CONF'}=abs_path('test.cnf');
60 open my $f, ">", "test$count.clear";
61 print $f $p{-cleartext};
64 $ENV{'CRYPT_PARAMS'} = $p{-paramset} if exists $p{-paramset};
65 my $ctext = `openssl enc ${eng_param} -e -$p{-alg} -K $p{-key} -iv $p{-iv} -in test$count.clear`;
66 is($?,0,"$p{-name} - encrypt successful");
67 is(unpack("H*",$ctext),$p{-ciphertext},"$p{-name} - ciphertext expected");
68 open my $f, ">", "test$count.enc";
71 my $otext = `openssl enc ${eng_param} -d -$p{-alg} -K $p{-key} -iv $p{-iv} -in test$count.enc`;
72 is($?,0,"$p{-name} - decrypt successful");
73 is($otext,$p{-cleartext},"$p{-name} - decrypted correctly");
74 unlink "test$count.enc";
75 unlink "test$count.clear";
76 delete $ENV{'CRYPT_PARAMS'};
79 $key = '0123456789ABCDEF' x 4;
80 $iv = '0000000000000000';
81 $clear1 = "The quick brown fox jumps over the lazy dog\n";
83 crypt_test(-paramset=> "1.2.643.2.2.31.1", -key => $key, -iv => $iv,
84 -cleartext => $clear1,
85 -ciphertext => '07f4102c6185c4a09e676e269bfa4bc9c5df6575916b879bd13a893a2285ee6690107cdeef7a315d2eb54bfa',
87 -name=> 'CFB short text, paramset A');
89 crypt_test(-paramset=> "1.2.643.2.2.31.2", -key => $key, -iv => $iv,
90 -cleartext => $clear1,
91 -ciphertext => '11465c1c9708033e784fbb5536f2719c38353cb488b01f195c20d4c027022e8300d98bb66c138afbe878c88b',
93 -name=> 'CFB short text, paramset B');
95 crypt_test(-paramset=> "1.2.643.2.2.31.3", -key => $key, -iv => $iv,
96 -cleartext => $clear1,
97 -ciphertext => '2f213b390c9b6ceb18de479686d23f4f03c76644a0aab8894b50b71a3bbb3c027ec4c2d569ba0e6a873bd46e',
99 -name=> 'CFB short text, paramset C');
101 crypt_test(-paramset=> "1.2.643.2.2.31.4", -key => $key, -iv => $iv,
102 -cleartext => $clear1,
103 -ciphertext => 'e835f59a7fdfd84764efe1e987660327f5d0de187afea72f9cd040983a5e5bbeb4fe1aa5ff85d623ebc4d435',
105 -name=> 'CFB short text, paramset D');
108 crypt_test(-paramset=> "1.2.643.2.2.31.1", -key => $key, -iv => $iv,
109 -cleartext => $clear1,
110 -ciphertext => 'bcb821452e459f10f92019171e7c3b27b87f24b174306667f67704812c07b70b5e7420f74a9d54feb4897df8',
111 -alg => 'gost89-cnt',
112 -name=> 'CNT short text');
114 crypt_test(-paramset=> "1.2.643.2.2.31.2", -key => $key, -iv => $iv,
115 -cleartext => $clear1,
116 -ciphertext => 'bcb821452e459f10f92019171e7c3b27b87f24b174306667f67704812c07b70b5e7420f74a9d54feb4897df8',
117 -alg => 'gost89-cnt',
118 -name=> 'CNT short text, paramset param doesnt affect cnt');
121 crypt_test(-paramset=> "1.2.643.2.2.31.1", -key => $key, -iv => $iv,
122 -cleartext => $clear1,
123 -ciphertext => 'cf3f5f713b3d10abd0c6f7bafb6aaffe13dfc12ef5c844f84873aeaaf6eb443a9747c9311b86f97ba3cdb5c4',
124 -alg => 'gost89-cnt-12',
125 -name=> 'CNT-12 short text');
127 crypt_test(-paramset=> "1.2.643.2.2.31.2", -key => $key, -iv => $iv,
128 -cleartext => $clear1,
129 -ciphertext => 'cf3f5f713b3d10abd0c6f7bafb6aaffe13dfc12ef5c844f84873aeaaf6eb443a9747c9311b86f97ba3cdb5c4',
130 -alg => 'gost89-cnt-12',
131 -name=> 'CNT-12 short text, paramset param doesnt affect cnt');
134 crypt_test(-paramset=> "1.2.643.2.2.31.1", -key => $key, -iv => $iv,
135 -cleartext => $clear1,
136 -ciphertext => '3a3293e75089376572da44966cd1759c29d2f1e5e1c3fa9674909a63026da3dc51a4266bff37fb74a3a07155c9ca8fcf',
137 -alg => 'gost89-cbc',
138 -name=> 'CBC short text, paramset A');
141 crypt_test(-paramset=> "1.2.643.2.2.31.2", -key => $key, -iv => $iv,
142 -cleartext => $clear1,
143 -ciphertext => '11465c1c9708033e784fbb5536f2719c38353cb488b01f195c20d4c027022e8300d98bb66c138afbe878c88b',
145 -name=> 'CBC short text, paramset B');
147 crypt_test(-paramset=> "1.2.643.2.2.31.3", -key => $key, -iv => $iv,
148 -cleartext => $clear1,
149 -ciphertext => '987c0fb3d84530467a1973791e0a25e33c5d14591976f8c1573bdb9d056eb7b353f66fef3ffe2e3524583b3997123c8a',
150 -alg => 'gost89-cbc',
151 -name=> 'CBC short text, paramset C');
153 crypt_test(-paramset=> "1.2.643.2.2.31.4", -key => $key, -iv => $iv,
154 -cleartext => $clear1,
155 -ciphertext => 'e076b09822d4786a2863125d16594d765d8acd0f360e52df42e9d52c8e6c0e6595b5f6bbecb04a22c8ae5f4f87c1523b',
156 -alg => 'gost89-cbc',
157 -name=> 'CBC short text, paramset D');