ADDED tests/test_vectors/Symetric_Block/SM4-CBC.test Index: tests/test_vectors/Symetric_Block/SM4-CBC.test ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4-CBC.test @@ -0,0 +1,43 @@ +# Auto generated from "SM4-CBC.txt" +lappend auto_path [file dirname [file dirname [file dirname [file dirname [file join [pwd] [info script]]]]]] +package require tls +package require tcltest + +catch {tls::provider legacy} +tcltest::testConstraint SM4_CBC [expr {[lsearch -nocase [tls::ciphers] SM4-CBC] > -1}] + +tcltest::test Symetric_Block_SM4-CBC-1.1 {Encrypt SM4-CBC} \ + -constraints SM4_CBC \ + -body {binary encode hex [tls::encrypt -cipher SM4-CBC -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB]]} \ + -match exact -result 78ebb11cc40b0a48312aaeb2040244cb4cb7016951909226979b0d15dc6a8f6d + +tcltest::test Symetric_Block_SM4-CBC-1.2 {Decrypt SM4-CBC} \ + -constraints SM4_CBC \ + -body {binary encode hex [tls::decrypt -cipher SM4-CBC -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex 78EBB11CC40B0A48312AAEB2040244CB4CB7016951909226979B0D15DC6A8F6D]]} \ + -match exact -result aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffaaaaaaaabbbbbbbb + +tcltest::test Symetric_Block_SM4-CBC-1.3 {Encrypt SM4-CBC} \ + -constraints SM4_CBC \ + -body {binary encode hex [tls::encrypt -cipher SM4-CBC -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB]]} \ + -match exact -result 0d3a6ddc2d21c698857215587b7bb59a91f2c147911a4144665e1fa1d40bae38 + +tcltest::test Symetric_Block_SM4-CBC-1.4 {Decrypt SM4-CBC} \ + -constraints SM4_CBC \ + -body {binary encode hex [tls::decrypt -cipher SM4-CBC -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex 0D3A6DDC2D21C698857215587B7BB59A91F2C147911A4144665E1FA1D40BAE38]]} \ + -match exact -result aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffaaaaaaaabbbbbbbb + +# Cleanup +::tcltest::cleanupTests +return ADDED tests/test_vectors/Symetric_Block/SM4-CBC.txt Index: tests/test_vectors/Symetric_Block/SM4-CBC.txt ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4-CBC.txt @@ -0,0 +1,15 @@ +# SM4-CBC cipher from: https://datatracker.ietf.org/doc/html/draft-ribose-cfrg-sm4-10 + +# A.2.2. SM4-CBC Examples + +# A.2.2.1. Example 1 +Plaintext = AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB +Key = 0123456789ABCDEFFEDCBA9876543210 +IV = 000102030405060708090A0B0C0D0E0F +Ciphertext = 78EBB11CC40B0A48312AAEB2040244CB4CB7016951909226979B0D15DC6A8F6D + +# A.2.2.2. Example 2 +Plaintext = AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB +Key = FEDCBA98765432100123456789ABCDEF +IV = 000102030405060708090A0B0C0D0E0F +Ciphertext = 0D3A6DDC2D21C698857215587B7BB59A91F2C147911A4144665E1FA1D40BAE38 ADDED tests/test_vectors/Symetric_Block/SM4-CFB.test Index: tests/test_vectors/Symetric_Block/SM4-CFB.test ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4-CFB.test @@ -0,0 +1,43 @@ +# Auto generated from "SM4-CFB.txt" +lappend auto_path [file dirname [file dirname [file dirname [file dirname [file join [pwd] [info script]]]]]] +package require tls +package require tcltest + +catch {tls::provider legacy} +tcltest::testConstraint SM4_CFB [expr {[lsearch -nocase [tls::ciphers] SM4-CFB] > -1}] + +tcltest::test Symetric_Block_SM4-CFB-1.1 {Encrypt SM4-CFB} \ + -constraints SM4_CFB \ + -body {binary encode hex [tls::encrypt -cipher SM4-CFB -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB]]} \ + -match exact -result ac3236cb861dd316e6413b4e3c7524b769d4c54ed433b9a0346009beb37b2b3f + +tcltest::test Symetric_Block_SM4-CFB-1.2 {Decrypt SM4-CFB} \ + -constraints SM4_CFB \ + -body {binary encode hex [tls::decrypt -cipher SM4-CFB -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex AC3236CB861DD316E6413B4E3C7524B769D4C54ED433B9A0346009BEB37B2B3F]]} \ + -match exact -result aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffaaaaaaaabbbbbbbb + +tcltest::test Symetric_Block_SM4-CFB-1.3 {Encrypt SM4-CFB} \ + -constraints SM4_CFB \ + -body {binary encode hex [tls::encrypt -cipher SM4-CFB -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB]]} \ + -match exact -result 5dcccd25a84ba16560d7f265887068490d9b86ff20c3bfe115ffa02ca6192cc5 + +tcltest::test Symetric_Block_SM4-CFB-1.4 {Decrypt SM4-CFB} \ + -constraints SM4_CFB \ + -body {binary encode hex [tls::decrypt -cipher SM4-CFB -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex 5DCCCD25A84BA16560D7F265887068490D9B86FF20C3BFE115FFA02CA6192CC5]]} \ + -match exact -result aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffaaaaaaaabbbbbbbb + +# Cleanup +::tcltest::cleanupTests +return ADDED tests/test_vectors/Symetric_Block/SM4-CFB.txt Index: tests/test_vectors/Symetric_Block/SM4-CFB.txt ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4-CFB.txt @@ -0,0 +1,15 @@ +# SM4-CFB cipher from: https://datatracker.ietf.org/doc/html/draft-ribose-cfrg-sm4-10 + +# A.2.4. SM4-CFB Examples + +# A.2.4.1. Example 1 +Plaintext = AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB +Key = 0123456789ABCDEFFEDCBA9876543210 +IV = 000102030405060708090A0B0C0D0E0F +Ciphertext = AC3236CB861DD316E6413B4E3C7524B769D4C54ED433B9A0346009BEB37B2B3F + +# A.2.4.2. Example 2 +Plaintext = AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB +Key = FEDCBA98765432100123456789ABCDEF +IV = 000102030405060708090A0B0C0D0E0F +Ciphertext = 5DCCCD25A84BA16560D7F265887068490D9B86FF20C3BFE115FFA02CA6192CC5 ADDED tests/test_vectors/Symetric_Block/SM4-CTR.test Index: tests/test_vectors/Symetric_Block/SM4-CTR.test ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4-CTR.test @@ -0,0 +1,43 @@ +# Auto generated from "SM4-CTR.txt" +lappend auto_path [file dirname [file dirname [file dirname [file dirname [file join [pwd] [info script]]]]]] +package require tls +package require tcltest + +catch {tls::provider legacy} +tcltest::testConstraint SM4_CTR [expr {[lsearch -nocase [tls::ciphers] SM4-CTR] > -1}] + +tcltest::test Symetric_Block_SM4-CTR-1.1 {Encrypt SM4-CTR} \ + -constraints SM4_CTR \ + -body {binary encode hex [tls::encrypt -cipher SM4-CTR -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFFFAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBB]]} \ + -match exact -result ac3236cb970cc20791364c395a1342d1a3cbc1878c6f30cd074cce385cdd70c7f234bc0e24c11980fd1286310ce37b926e02fcd0faa0baf38b2933851d824514 + +tcltest::test Symetric_Block_SM4-CTR-1.2 {Decrypt SM4-CTR} \ + -constraints SM4_CTR \ + -body {binary encode hex [tls::decrypt -cipher SM4-CTR -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex AC3236CB970CC20791364C395A1342D1A3CBC1878C6F30CD074CCE385CDD70C7F234BC0E24C11980FD1286310CE37B926E02FCD0FAA0BAF38B2933851D824514]]} \ + -match exact -result aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbccccccccccccccccddddddddddddddddeeeeeeeeeeeeeeeeffffffffffffffffaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbb + +tcltest::test Symetric_Block_SM4-CTR-1.3 {Encrypt SM4-CTR} \ + -constraints SM4_CTR \ + -body {binary encode hex [tls::encrypt -cipher SM4-CTR -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFFFAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBB]]} \ + -match exact -result 5dcccd25b95ab07417a08512ee160e2f8f661521cbbab44cc87138445bc29e5c0ae0297205d62704173b21239b887f6c8cb5b800917a2488284bde9e16ea2906 + +tcltest::test Symetric_Block_SM4-CTR-1.4 {Decrypt SM4-CTR} \ + -constraints SM4_CTR \ + -body {binary encode hex [tls::decrypt -cipher SM4-CTR -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex 5DCCCD25B95AB07417A08512EE160E2F8F661521CBBAB44CC87138445BC29E5C0AE0297205D62704173B21239B887F6C8CB5B800917A2488284BDE9E16EA2906]]} \ + -match exact -result aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbccccccccccccccccddddddddddddddddeeeeeeeeeeeeeeeeffffffffffffffffaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbb + +# Cleanup +::tcltest::cleanupTests +return ADDED tests/test_vectors/Symetric_Block/SM4-CTR.txt Index: tests/test_vectors/Symetric_Block/SM4-CTR.txt ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4-CTR.txt @@ -0,0 +1,15 @@ +# SM4-CTR cipher from: https://datatracker.ietf.org/doc/html/draft-ribose-cfrg-sm4-10 + +# A.2.5. SM4-CTR Examples + +# A.2.5.1. Example 1 +Plaintext = AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFFFAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBB +Key = 0123456789ABCDEFFEDCBA9876543210 +IV = 000102030405060708090A0B0C0D0E0F +Ciphertext = AC3236CB970CC20791364C395A1342D1A3CBC1878C6F30CD074CCE385CDD70C7F234BC0E24C11980FD1286310CE37B926E02FCD0FAA0BAF38B2933851D824514 + +# A.2.5.2. Example 2 +Plaintext = AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDDEEEEEEEEEEEEEEEEFFFFFFFFFFFFFFFFAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBB +Key = FEDCBA98765432100123456789ABCDEF +IV = 000102030405060708090A0B0C0D0E0F +Ciphertext = 5DCCCD25B95AB07417A08512EE160E2F8F661521CBBAB44CC87138445BC29E5C0AE0297205D62704173B21239B887F6C8CB5B800917A2488284BDE9E16EA2906 ADDED tests/test_vectors/Symetric_Block/SM4-ECB.test Index: tests/test_vectors/Symetric_Block/SM4-ECB.test ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4-ECB.test @@ -0,0 +1,39 @@ +# Auto generated from "SM4-ECB.txt" +lappend auto_path [file dirname [file dirname [file dirname [file dirname [file join [pwd] [info script]]]]]] +package require tls +package require tcltest + +catch {tls::provider legacy} +tcltest::testConstraint SM4_ECB [expr {[lsearch -nocase [tls::ciphers] SM4-ECB] > -1}] + +tcltest::test Symetric_Block_SM4-ECB-1.1 {Encrypt SM4-ECB} \ + -constraints SM4_ECB \ + -body {binary encode hex [tls::encrypt -cipher SM4-ECB -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -data [binary decode hex AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB]]} \ + -match exact -result 5ec8143de509cff7b5179f8f474b86192f1d305a7fb17df985f81c8482192304 + +tcltest::test Symetric_Block_SM4-ECB-1.2 {Decrypt SM4-ECB} \ + -constraints SM4_ECB \ + -body {binary encode hex [tls::decrypt -cipher SM4-ECB -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -data [binary decode hex 5EC8143DE509CFF7B5179F8F474B86192F1D305A7FB17DF985F81C8482192304]]} \ + -match exact -result aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffaaaaaaaabbbbbbbb + +tcltest::test Symetric_Block_SM4-ECB-1.3 {Encrypt SM4-ECB} \ + -constraints SM4_ECB \ + -body {binary encode hex [tls::encrypt -cipher SM4-ECB -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -data [binary decode hex AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB]]} \ + -match exact -result c5876897e4a59bbba72a10c83872245b12dd90bc2d200692b529a4155ac9e600 + +tcltest::test Symetric_Block_SM4-ECB-1.4 {Decrypt SM4-ECB} \ + -constraints SM4_ECB \ + -body {binary encode hex [tls::decrypt -cipher SM4-ECB -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -data [binary decode hex C5876897E4A59BBBA72A10C83872245B12DD90BC2D200692B529A4155AC9E600]]} \ + -match exact -result aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffaaaaaaaabbbbbbbb + +# Cleanup +::tcltest::cleanupTests +return ADDED tests/test_vectors/Symetric_Block/SM4-ECB.txt Index: tests/test_vectors/Symetric_Block/SM4-ECB.txt ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4-ECB.txt @@ -0,0 +1,13 @@ +# SM4-ECB cipher from https://datatracker.ietf.org/doc/html/draft-ribose-cfrg-sm4-10 + +# A.2.1. SM4-ECB Examples + +# A.2.1.1. Example 1 +Plaintext = AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB +Key = 0123456789ABCDEFFEDCBA9876543210 +Ciphertext = 5EC8143DE509CFF7B5179F8F474B86192F1D305A7FB17DF985F81C8482192304 + +# A.2.1.2. Example 2 +Plaintext = AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB +Key = FEDCBA98765432100123456789ABCDEF +Ciphertext = C5876897E4A59BBBA72A10C83872245B12DD90BC2D200692B529A4155AC9E600 ADDED tests/test_vectors/Symetric_Block/SM4-OFB.test Index: tests/test_vectors/Symetric_Block/SM4-OFB.test ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4-OFB.test @@ -0,0 +1,43 @@ +# Auto generated from "SM4-OFB.txt" +lappend auto_path [file dirname [file dirname [file dirname [file dirname [file join [pwd] [info script]]]]]] +package require tls +package require tcltest + +catch {tls::provider legacy} +tcltest::testConstraint SM4_OFB [expr {[lsearch -nocase [tls::ciphers] SM4-OFB] > -1}] + +tcltest::test Symetric_Block_SM4-OFB-1.1 {Encrypt SM4-OFB} \ + -constraints SM4_OFB \ + -body {binary encode hex [tls::encrypt -cipher SM4-OFB -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB]]} \ + -match exact -result ac3236cb861dd316e6413b4e3c7524b71d01aca2487ca582cbf5463e6698539b + +tcltest::test Symetric_Block_SM4-OFB-1.2 {Decrypt SM4-OFB} \ + -constraints SM4_OFB \ + -body {binary encode hex [tls::decrypt -cipher SM4-OFB -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex AC3236CB861DD316E6413B4E3C7524B71D01ACA2487CA582CBF5463E6698539B]]} \ + -match exact -result aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffaaaaaaaabbbbbbbb + +tcltest::test Symetric_Block_SM4-OFB-1.3 {Encrypt SM4-OFB} \ + -constraints SM4_OFB \ + -body {binary encode hex [tls::encrypt -cipher SM4-OFB -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB]]} \ + -match exact -result 5dcccd25a84ba16560d7f2658870684933fa16bd5cd9c856cacaa1e101897a97 + +tcltest::test Symetric_Block_SM4-OFB-1.4 {Decrypt SM4-OFB} \ + -constraints SM4_OFB \ + -body {binary encode hex [tls::decrypt -cipher SM4-OFB -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -iv [binary decode hex 000102030405060708090A0B0C0D0E0F] \ + -data [binary decode hex 5DCCCD25A84BA16560D7F2658870684933FA16BD5CD9C856CACAA1E101897A97]]} \ + -match exact -result aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffaaaaaaaabbbbbbbb + +# Cleanup +::tcltest::cleanupTests +return ADDED tests/test_vectors/Symetric_Block/SM4-OFB.txt Index: tests/test_vectors/Symetric_Block/SM4-OFB.txt ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4-OFB.txt @@ -0,0 +1,15 @@ +# SM4-OFB cipher from: https://datatracker.ietf.org/doc/html/draft-ribose-cfrg-sm4-10 + +# A.2.3. SM4-OFB Examples + +# A.2.3.1. Example 1 +Plaintext = AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB +Key = 0123456789ABCDEFFEDCBA9876543210 +IV = 000102030405060708090A0B0C0D0E0F +Ciphertext = AC3236CB861DD316E6413B4E3C7524B71D01ACA2487CA582CBF5463E6698539B + +# A.2.3.2. Example 2 +Plaintext = AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDDEEEEEEEEFFFFFFFFAAAAAAAABBBBBBBB +Key = FEDCBA98765432100123456789ABCDEF +IV = 000102030405060708090A0B0C0D0E0F +Ciphertext = 5DCCCD25A84BA16560D7F2658870684933FA16BD5CD9C856CACAA1E101897A97 ADDED tests/test_vectors/Symetric_Block/SM4.test Index: tests/test_vectors/Symetric_Block/SM4.test ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4.test @@ -0,0 +1,67 @@ +# Auto generated from "SM4.txt" +lappend auto_path [file dirname [file dirname [file dirname [file dirname [file join [pwd] [info script]]]]]] +package require tls +package require tcltest + +catch {tls::provider legacy} +tcltest::testConstraint SM4 [expr {[lsearch -nocase [tls::ciphers] SM4] > -1}] + +tcltest::test Symetric_Block_SM4-1.1 {Encrypt SM4} \ + -constraints SM4 \ + -body {binary encode hex [tls::encrypt -cipher SM4 -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -data [binary decode hex 0123456789ABCDEFFEDCBA9876543210]]} \ + -match exact -result 681edf34d206965e86b3e94f536e4246 + +tcltest::test Symetric_Block_SM4-1.2 {Decrypt SM4} \ + -constraints SM4 \ + -body {binary encode hex [tls::decrypt -cipher SM4 -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -data [binary decode hex 681EDF34D206965E86B3E94F536E4246]]} \ + -match exact -result 0123456789abcdeffedcba9876543210 + +tcltest::test Symetric_Block_SM4-1.3 {Encrypt SM4} \ + -constraints SM4 \ + -body {binary encode hex [set data [binary decode hex 0123456789ABCDEFFEDCBA9876543210];for {set i 0} {$i < 1000000} {incr i} {set data [tls::encrypt -cipher SM4 -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -data $data]};set data]} \ + -match exact -result 595298c7c6fd271f0402f804c33d3f66 + +tcltest::test Symetric_Block_SM4-1.4 {Decrypt SM4} \ + -constraints SM4 \ + -body {binary encode hex [set data [binary decode hex 595298C7C6FD271F0402F804C33D3F66];for {set i 0} {$i < 1000000} {incr i} {set data [tls::decrypt -cipher SM4 -padding 0 \ + -key [binary decode hex 0123456789ABCDEFFEDCBA9876543210] \ + -data $data]};set data]} \ + -match exact -result 0123456789abcdeffedcba9876543210 + +tcltest::test Symetric_Block_SM4-1.5 {Encrypt SM4} \ + -constraints SM4 \ + -body {binary encode hex [tls::encrypt -cipher SM4 -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -data [binary decode hex 000102030405060708090A0B0C0D0E0F]]} \ + -match exact -result f766678f13f01adeac1b3ea955adb594 + +tcltest::test Symetric_Block_SM4-1.6 {Decrypt SM4} \ + -constraints SM4 \ + -body {binary encode hex [tls::decrypt -cipher SM4 -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -data [binary decode hex F766678F13F01ADEAC1B3EA955ADB594]]} \ + -match exact -result 000102030405060708090a0b0c0d0e0f + +tcltest::test Symetric_Block_SM4-1.7 {Encrypt SM4} \ + -constraints SM4 \ + -body {binary encode hex [set data [binary decode hex 000102030405060708090A0B0C0D0E0F];for {set i 0} {$i < 1000000} {incr i} {set data [tls::encrypt -cipher SM4 -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -data $data]};set data]} \ + -match exact -result 379a96d0a6a5a5060fb460c75d1879ed + +tcltest::test Symetric_Block_SM4-1.8 {Decrypt SM4} \ + -constraints SM4 \ + -body {binary encode hex [set data [binary decode hex 379A96D0A6A5A5060FB460C75D1879ED];for {set i 0} {$i < 1000000} {incr i} {set data [tls::decrypt -cipher SM4 -padding 0 \ + -key [binary decode hex FEDCBA98765432100123456789ABCDEF] \ + -data $data]};set data]} \ + -match exact -result 000102030405060708090a0b0c0d0e0f + +# Cleanup +::tcltest::cleanupTests +return ADDED tests/test_vectors/Symetric_Block/SM4.txt Index: tests/test_vectors/Symetric_Block/SM4.txt ================================================================== --- /dev/null +++ tests/test_vectors/Symetric_Block/SM4.txt @@ -0,0 +1,23 @@ +# SM4 cipher from: https://datatracker.ietf.org/doc/html/draft-ribose-cfrg-sm4-10 + +# A.1. Example 1 (GB/T 32907-2016 Example 1) +Plaintext = 0123456789ABCDEFFEDCBA9876543210 +Key = 0123456789ABCDEFFEDCBA9876543210 +Ciphertext = 681EDF34D206965E86B3E94F536E4246 + +# A.1.3. Example 3 (GB/T 32907-2016 Example 2 Encryption) +Plaintext = 0123456789ABCDEFFEDCBA9876543210 +Key = 0123456789ABCDEFFEDCBA9876543210 +Iterations = 1000000 +Ciphertext = 595298C7C6FD271F0402F804C33D3F66 + +# A.1.4. Example 4 +Plaintext = 000102030405060708090A0B0C0D0E0F +Key = FEDCBA98765432100123456789ABCDEF +Ciphertext = F766678F13F01ADEAC1B3EA955ADB594 + +# A.1.6. Example 6 +Plaintext = 000102030405060708090A0B0C0D0E0F +Key = FEDCBA98765432100123456789ABCDEF +Iterations = 1000000 +Ciphertext = 379A96D0A6A5A5060FB460C75D1879ED Index: tests/test_vectors/Symetric_Block/make_test.tcl ================================================================== --- tests/test_vectors/Symetric_Block/make_test.tcl +++ tests/test_vectors/Symetric_Block/make_test.tcl @@ -18,11 +18,11 @@ # # Create test case and output to test file # proc do_test {group cipher test_num tc params fn} { - array set config [list repeat 1] + array set config [list iterations 1 repeat 1] array set config $params # Test info set line [format "tcltest::test %s-%d.%d {%s %s} \\\n\t" $group $test_num $tc [string totitle $fn] $cipher] @@ -44,11 +44,15 @@ foreach {param names type} [list -key [list key] s -iv [list iv nonce] s -data $list1 s] { foreach name $names { if {[info exists config($name)]} { set data [get_value $type $config($name)] if {$data ne ""} { - append cmd " " $param " " $data " \\\n\t\t" + if {$param ne "-data" || $config(iterations) == 1} { + append cmd " " $param " " $data " \\\n\t\t" + } else { + set cmd [string cat "set data " $data ";for \{set i 0\} \{\$i < " $config(iterations) "\} \{incr i\} \{set data \[" $cmd " " $param " \$data\]\};set data"] + } } break } } } @@ -156,14 +160,14 @@ set tail [file tail $filename] if {[string match -nocase "Readme.txt" $tail]} { continue } - set cipher [file rootname [file tail $filename]] + set cipher [string trim [file rootname [file tail $filename]]] set id [format "%s_%s" $group $cipher] set test_num [incr test_ids($id)] parse $id $filename $test_num $cipher } } main [pwd] exit