]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - test/00-engine.t
Hopefully merge tests from object_db branch
[openssl-gost/engine.git] / test / 00-engine.t
1 #!/usr/bin/perl
2 use Test::More tests => 5;
3 use Cwd 'abs_path';
4
5 # prepare data for 
6
7 open F,">","testdata.dat";
8 print F "12345670" x 128;
9 close F;
10
11 # Set OPENSSL_ENGINES environment variable to just build engine
12 $ENV{'OPENSSL_ENGINES'} = abs_path("../.libs");
13
14 $key='0123456789abcdef' x 2;
15
16 #
17 # You can redefine engine to use using ENGINE_NAME environment variable
18
19 $engine=$ENV{'ENGINE_NAME'}||"gost";
20
21 # Reopen STDERR to eliminate extra output
22 open STDERR, ">>","tests.err";
23
24 if (exists $ENV{'OPENSSL_CONF'}) {
25         delete $ENV{'OPENSSL_CONF'}
26 }
27 #
28 # This test needs output of openssl engine -c command.
29 # Default one  is hardcoded below, but you can place file
30 # ${ENGINE_NAME}.info into this directory if you use this test suite
31 # to test other engine implementing GOST cryptography.
32 #
33 if ( -f $engine . ".info") {
34         diag("Reading $engine.info");
35         open F, "<", $engine . ".info";
36         read F,$engine_info,1024;
37 } else {
38
39 $engine_info= <<EOINF;
40 (gost) Reference implementation of GOST engine
41  [gost89, gost89-cnt, gost89-cnt-12, gost89-cbc, md_gost94, gost-mac, md_gost12_256, md_gost12_512, gost-mac-12, gost2001, gost-mac, gost2012_256, gost2012_512, gost-mac-12]
42 EOINF
43 }
44
45 $ENV{'OPENSSL_CONF'}=abs_path("no_such_file.cfg");
46 is(`openssl engine -c $engine`,
47 $engine_info,
48 "load engine without any config");
49
50 is(`openssl dgst -engine $engine -md_gost94 testdata.dat`,
51 "md_gost94(testdata.dat)= f7fc6d16a6a5c12ac4f7d320e0fd0d8354908699125e09727a4ef929122b1cae\n",
52 "compute digest without config");
53
54
55 open F,">","test.cnf";
56 print F <<EOCFG;
57 openssl_conf = openssl_def
58 [openssl_def]
59 engines = engines
60 [engines]
61 ${engine}=gost_conf
62 [gost_conf]
63 default_algorithms = ALL
64
65 EOCFG
66 close F;
67 $ENV{'OPENSSL_CONF'}=abs_path('test.cnf');
68
69 is(`openssl engine -c $engine`,
70 $engine_info,
71 "load engine with config");
72
73 is(`openssl dgst -md_gost94 testdata.dat`,
74 "md_gost94(testdata.dat)= f7fc6d16a6a5c12ac4f7d320e0fd0d8354908699125e09727a4ef929122b1cae\n",
75 "compute digest with config without explicit engine param");
76
77 is(`openssl dgst -engine $engine -md_gost94 testdata.dat`,
78 "md_gost94(testdata.dat)= f7fc6d16a6a5c12ac4f7d320e0fd0d8354908699125e09727a4ef929122b1cae\n",
79 "compute digest with both config and explicit engine param");
80
81 unlink('testdata.dat');
82 unlink('test.cnf');