]> www.wagner.pp.ru Git - openssl-gost/engine.git/blob - tcl_tests/enc.try
tcl_tests: ca.try: Ignore openssl crl exit status for 'corrupted CRL' test
[openssl-gost/engine.git] / tcl_tests / enc.try
1 #!/usr/bin/tclsh/
2 lappend auto_path [file dirname [info script]] 
3 package require ossltest
4 set plain0 [getFile plain.enc]
5 file copy -force $::test::src/cfb0.enc $::test::dir
6 file copy -force $::test::src/cnt0.enc $::test::dir
7 file copy -force $::test::src/cbc0.enc $::test::dir
8 file copy -force $::test::src/aes0.enc $::test::dir
9 file copy -force $::test::src/plain.enc $::test::dir
10 file copy -force $::test::src/magma_plain.enc $::test::dir
11 file copy -force $::test::src/magma_acpkm_plain.enc $::test::dir
12 set cfb1 [getFile cfb1.enc]
13 set cbc1 [getFile cbc1.enc]
14 set cnt1 [getFile cnt1.enc]
15 set aes1 [getFile aes1.enc]
16 set magma1 [getFile magma1.enc]
17 set macpkm1 [getFile macpkm1.enc]
18 cd $::test::dir 
19 file delete cfb1.enc cbc1.enc cnt1.enc aes1.enc magma1.enc magma1.enc macpkm1.enc
20 start_tests "Тесты на команду enc" 
21
22 save_env2 {CRYPT_PARAMS}
23 if [info exists env(CRYPT_PARAMS)] {unset env(CRYPT_PARAMS)}
24
25 # Default CRYPT_PARAMS for the following tests.
26 set env(CRYPT_PARAMS) "id-tc26-gost-28147-param-Z"
27
28 test -createsfiles cfb0.dec "Decrypting etalon file with GOST89-(CFB)" {
29         openssl "enc -gost89 -d -md md5 -in cfb0.enc -out cfb0.dec -k 1234567890 -p"
30         getFile cfb0.dec 
31 } 0 $plain0
32
33 test -createsfiles cnt0.dec "Decrypting etalon file with GOST89-CNT" {
34         openssl "enc -gost89-cnt -d -md md5 -in cnt0.enc -out cnt0.dec -k 1234567890 -p"
35         getFile cnt0.dec 
36 } 0 $plain0
37
38 test -createsfiles cbc0.dec "Decrypting etalon file with GOST89-CBC" {
39         openssl "enc -gost89-cbc -d -md md5 -in cbc0.enc -out cbc0.dec -k 1234567890 -p"
40         getFile cbc0.dec 
41 } 0 $plain0
42
43 test -createsfiles aes0.dec "Decrypting etalon file encrypted with AES128-CBC" {
44         openssl "enc -aes-128-cbc -d -md md5 -in aes0.enc -out aes0.dec -k 1234567890"
45         getFile aes0.dec 
46 } 0 $plain0
47
48
49 test -createsfiles cfb1.enc "Encrypting etalon file with GOST89-(CFB)" {
50         openssl "enc -gost89 -in plain.enc -out cfb1.enc -K 0D6F24152DB4B18CC4B0EE62F55FAD0BEADC26E7992C5EDF039114EC3F44EB08 -iv 8EE68900818CD1F9 -p"
51         getFile cfb1.enc 
52 } 0 $cfb1
53
54 test -createsfiles cnt1.enc "Encrypting etalon file with GOST89-CNT mode" {
55         openssl "enc -gost89-cnt -in plain.enc -out cnt1.enc -K EF164FDF5B1128DE44AFCC00A0323DC1090EC99DE9C6B085B0D2550AB9F1AF47 -iv 9AF32B4E2FB1DF3D -p"
56         getFile cnt1.enc 
57 } 0 $cnt1
58
59 test -createsfiles cbc1.enc "Encrypting etalon file with GOST89-CBC mode" {
60         openssl "enc -gost89-cbc -in plain.enc -out cbc1.enc -K F6AF8D0EDF555D164E3DDFA20615D7DF602B99A5ED4BD4103C4CA622D4544636 -iv 8264BBB5A072CDB5 -p"
61         getFile cbc1.enc 
62 } 0 $cbc1
63
64 test -createsfiles aes1.enc "Encrypting etalon file with AES128-CBC" {
65         openssl "enc -aes-128-cbc -in plain.enc -out aes1.enc -K D45358C3C6E711392E9F2AFF46C444B1 -iv 78E88EFC8F44B9C27C45C5FCC61DCD94 -p"
66         getFile aes1.enc 
67 } 0 $aes1
68
69
70 set plain "Test data to encrypt "
71 makeFile enc.dat $plain binary
72 set plain2 [string repeat "Test data for encrypt of big string\n" 64]
73 makeFile enc2.dat $plain2 binary
74
75 test -createsfiles {cfb.enc} "Encrypting file with GOST89-(CFB)" {
76         openssl "enc -gost89 -out cfb.enc -in enc.dat -k 1234567890 -p"
77         file isfile cfb.enc
78 } 0 1
79
80 test -createsfiles {cnt.enc} "Encrypting file with GOST89-CNT" {
81         openssl "enc -gost89-cnt -out cnt.enc -in enc.dat -k 1234567890 -p"
82         file isfile cnt.enc
83 } 0 1
84
85 test -createsfiles {cbc.enc} "Encrypting file with GOST89-CBC" {
86         openssl "enc -gost89-cbc -out cbc.enc -in enc.dat -k 1234567890 -p"
87         file isfile cbc.enc
88 } 0 1
89
90 test -createsfiles aes.enc "Encrypting file using AES128-CBC" {
91         openssl "enc -aes-128-cbc -out aes.enc -in enc.dat -k 1234567890"
92         file isfile aes.enc     
93 } 0 1
94
95 test "Ciphered text with GOST89-CFB differs from plain text" {
96         set ciphered [getFile cfb.enc binary]
97         string first $ciphered $plain
98 } 0 -1
99
100 test "Ciphered text with GOST89-CNT differs from plain text" {
101         set ciphered [getFile cnt.enc binary]
102         string first $ciphered $plain
103 } 0 -1
104
105 test "Ciphered text with GOST89-CBC differs from plain text" {
106         set ciphered [getFile cbc.enc binary]
107         string first $ciphered $plain
108 } 0 -1
109
110 test "Ciphered with AES text differs from plain text" {
111         set ciphered [getFile aes.enc binary]
112         string first $ciphered $plain
113 } 0 -1
114
115 test -createsfiles cfb.dec "Decrypting file, encrypted with GOST89-CFB" {
116         openssl "enc -gost89 -d -in cfb.enc -out enc.dec -k 1234567890 -p"
117         getFile enc.dec 
118 } 0 $plain
119
120 test -createsfiles cnt.dec "Decrypting file, encrypted with GOST89-CNT" {
121         openssl "enc -gost89-cnt -d -in cnt.enc -out cnt.dec -k 1234567890 -p"
122         getFile cnt.dec 
123 } 0 $plain
124
125 test -createsfiles cbc.dec "Decrypting file, encrypted with GOST89-CBC" {
126         openssl "enc -gost89-cbc -d -in cbc.enc -out cbc.dec -k 1234567890 -p"
127         getFile cbc.dec 
128 } 0 $plain
129
130 test -createsfiles aes.dec "Decrypting file encrypted with AES" {
131         openssl "enc -aes-128-cbc -d -in aes.enc -out aes.dec -k 1234567890"
132         getFile aes.dec 
133 } 0 $plain
134
135
136 test -createsfiles {cfb2.enc} "Encrypting GOST89 more than 1KB" {
137         if [info exists env(CRYPT_PARAMS)] {unset env(CRYPT_PARAMS)}
138         openssl "enc -gost89 -out cfb2.enc -in enc2.dat -k 1234567890 -p"
139         file isfile cfb2.enc
140 } 0 1
141
142 test -createsfiles {cfb2.dec} "Decrypting GOST89 more than 1Kb" {
143         openssl "enc -d -gost89 -out cfb2.dec -in cfb2.enc -k 1234567890 -p"
144         getFile cfb2.dec
145 } 0 $plain2     
146
147 test -createsfiles {cnt2.enc} "Encrypting more than 1KB with GOST89-CNT" {
148         if [info exists env(CRYPT_PARAMS)] {unset env(CRYPT_PARAMS)}
149         openssl "enc -gost89-cnt -out cnt2.enc -in enc2.dat -k 1234567890 -p"
150         file isfile cnt2.enc
151 } 0 1
152
153 test -createsfiles {cnt2.dec} "Decrypting more than 1Kb with GOST89-CNT" {
154         openssl "enc -d -gost89-cnt -out cnt2.dec -in cnt2.enc -k 1234567890 -p"
155         getFile cnt2.dec
156 } 0 $plain2     
157
158 test -createsfiles {cnc2.enc} "Encrypting more than 1KB with GOST89-CBC" {
159         if [info exists env(CRYPT_PARAMS)] {unset env(CRYPT_PARAMS)}
160         openssl "enc -gost89-cbc -out cbc2.enc -in enc2.dat -k 1234567890 -p"
161         file isfile cbc2.enc
162 } 0 1
163
164 test -createsfiles {cbc2.dec} "Decrypting more than 1Kb with GOST89-CBC" {
165         openssl "enc -d -gost89-cbc -out cbc2.dec -in cbc2.enc -k 1234567890 -p"
166         getFile cbc2.dec
167 } 0 $plain2     
168
169 test -skip {![file exists enc2.dat]} -createsfiles {cfb3.enc} "Encrypting GOST89 with paramset TC26 (symbolic)" {
170         set env(CRYPT_PARAMS) "id-tc26-gost-28147-param-Z"
171         openssl "enc -gost89 -out cfb3.enc -in enc2.dat -k 1234567890 -p"
172         file isfile cfb3.enc
173 } 0 1
174
175 test -skip {![file exists cfb3.enc]} -createsfiles {cfb3.dec1} "Decrypting GOST89 with paramset TC26 (OID)" {
176         set env(CRYPT_PARAMS) "1.2.643.7.1.2.5.1.1"
177         openssl "enc -gost89 -d -in cfb3.enc -out cfb3.dec1 -k 1234567890 -p"
178         getFile cfb3.dec1       
179 } 0 $plain2
180
181 if {0} {
182 test -skip {![file exists enc2.dat]} -createsfiles {cbc3.enc} "Encrypting GOST89-CBC with paramset RIC 1 (symbolic)" {
183         set env(CRYPT_PARAMS) "id-Gost28147-89-CryptoPro-RIC-1-ParamSet"
184         openssl "enc -gost89-cbc -out cbc3.enc -in enc2.dat -k 1234567890 -p"
185         file isfile cbc3.enc
186 } 0 1
187
188 test -skip {![file exists cbc3.enc]} -createsfiles {cbc3.dec1} "Decrypting GOST89-CBC with paramset RIC 1 (OID)" {
189         set env(CRYPT_PARAMS) "1.2.643.2.2.31.7"
190         openssl "enc -gost89-cbc -d -in cbc3.enc -out cbc3.dec1 -k 1234567890 -p"
191         getFile cbc3.dec1       
192 } 0 $plain2
193 }
194 restore_env2 {CRYPT_PARAMS}
195
196 save_env2 {CRYPT_PARAMS OPENSSL_CONF}
197 test -skip {![file exists cfb3.enc]} -createsfiles {cfb3.dec2} "Decrypting GOST89 with default params" {
198         if [info exists env(CRYPT_PARAMS)] {unset env(CRYPT_PARAMS)}
199         makeFile enc1.cnf [regsub -all "\n\\s*CRYPT_PARAMS\\s*=\[\^\n]*" [getConfig] ""]
200         set ::env(OPENSSL_CONF) [file join [pwd] enc1.cnf]
201         openssl "enc -gost89 -d -in cfb3.enc -out cfb3.dec2 -k 1234567890 -p"
202         getFile cfb3.dec2       
203 } 0 $plain2
204 restore_env2 {CRYPT_PARAMS OPENSSL_CONF}
205
206 save_env2 {CRYPT_PARAMS}
207 test -skip {![file exists cfb3.enc]} -createsfiles {cfb3.dec3} "Decrypting GOST89 with wrong explicitely set" {
208         set env(CRYPT_PARAMS) "id-Gost28147-89-CryptoPro-B-ParamSet"
209         openssl "enc -gost89 -d -in cfb3.enc -out cfb3.dec3 -k 1234567890 -p"
210         string equal [getFile cfb3.dec3] $plain2        
211 } 0 0
212
213 restore_env2 {CRYPT_PARAMS}
214
215 test -createsfiles magma1.enc "Encrypting etalon file (Magma-CTR)" {
216         openssl "enc -magma-ctr -K ffeeddccbbaa99887766554433221100f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff -iv 1234567800000000 -in magma_plain.enc -out magma1.enc"
217         getFile magma1.enc 
218 } 0 $magma1
219
220 if {0} {
221 test -createsfiles macpkm1.enc "Encrypting etalon file (Magma-ACPKM)" {
222         openssl "enc -id-tc26-cipher-gostr3412-2015-magma-ctracpkm -K F797256845F36CF075603445CD322BACC3834032BC425E4D3C8495236F7B6CAF -iv 00000FFF00000000 -in magma_acpkm_plain.enc -out macpkm1.enc"
223         getFile macpkm1.enc 
224 } 0 $macpkm1
225 }
226
227 end_tests