2 lappend auto_path [file dirname [info script]]
3 package require ossltest
4 set plain0 [getFile plain.enc]
5 file copy -force cfb0.enc $::test::dir
6 file copy -force cnt0.enc $::test::dir
7 file copy -force cbc0.enc $::test::dir
8 file copy -force aes0.enc $::test::dir
9 file copy -force plain.enc $::test::dir
10 file copy -force magma_plain.enc $::test::dir
11 file copy -force 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]
19 file delete cfb1.enc cbc1.enc cnt1.enc aes1.enc magma1.enc magma1.enc macpkm1.enc
20 start_tests "Тесты на команду enc"
22 save_env2 {CRYPT_PARAMS}
23 if [info exists env(CRYPT_PARAMS)] {unset env(CRYPT_PARAMS)}
25 # Default CRYPT_PARAMS for the following tests.
26 set env(CRYPT_PARAMS) "id-tc26-gost-28147-param-Z"
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"
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"
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"
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"
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"
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"
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"
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"
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
75 test -createsfiles {cfb.enc} "Encrypting file with GOST89-(CFB)" {
76 openssl "enc -gost89 -out cfb.enc -in enc.dat -k 1234567890 -p"
80 test -createsfiles {cnt.enc} "Encrypting file with GOST89-CNT" {
81 openssl "enc -gost89-cnt -out cnt.enc -in enc.dat -k 1234567890 -p"
85 test -createsfiles {cbc.enc} "Encrypting file with GOST89-CBC" {
86 openssl "enc -gost89-cbc -out cbc.enc -in enc.dat -k 1234567890 -p"
90 test -createsfiles aes.enc "Encrypting file using AES128-CBC" {
91 openssl "enc -aes-128-cbc -out aes.enc -in enc.dat -k 1234567890"
95 test "Ciphered text with GOST89-CFB differs from plain text" {
96 set ciphered [getFile cfb.enc binary]
97 string first $ciphered $plain
100 test "Ciphered text with GOST89-CNT differs from plain text" {
101 set ciphered [getFile cnt.enc binary]
102 string first $ciphered $plain
105 test "Ciphered text with GOST89-CBC differs from plain text" {
106 set ciphered [getFile cbc.enc binary]
107 string first $ciphered $plain
110 test "Ciphered with AES text differs from plain text" {
111 set ciphered [getFile aes.enc binary]
112 string first $ciphered $plain
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"
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"
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"
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"
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"
142 test -createsfiles {cfb2.dec} "Decrypting GOST89 more than 1Kb" {
143 openssl "enc -d -gost89 -out cfb2.dec -in cfb2.enc -k 1234567890 -p"
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"
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"
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"
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"
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"
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"
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"
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"
194 restore_env2 {CRYPT_PARAMS}
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"
204 restore_env2 {CRYPT_PARAMS OPENSSL_CONF}
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
213 restore_env2 {CRYPT_PARAMS}
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"
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"