@@ -14323,6 +14323,137 @@ static const struct cipher_testvec serpent_xts_dec_tv_template[] = {
1432314323 },
1432414324};
1432514325
14326+ /*
14327+ * SM4 test vector taken from the draft RFC
14328+ * https://tools.ietf.org/html/draft-crypto-sm4-00#ref-GBT.32907-2016
14329+ */
14330+
14331+ static const struct cipher_testvec sm4_enc_tv_template[] = {
14332+ { /* SM4 Appendix A: Example Calculations. Example 1. */
14333+ .key = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
14334+ "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
14335+ .klen = 16,
14336+ .input = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
14337+ "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
14338+ .ilen = 16,
14339+ .result = "\x68\x1E\xDF\x34\xD2\x06\x96\x5E"
14340+ "\x86\xB3\xE9\x4F\x53\x6E\x42\x46",
14341+ .rlen = 16,
14342+ }, { /*
14343+ * SM4 Appendix A: Example Calculations.
14344+ * Last 10 iterations of Example 2.
14345+ */
14346+ .key = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
14347+ "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
14348+ .klen = 16,
14349+ .input = "\x99\x4a\xc3\xe7\xc3\x57\x89\x6a"
14350+ "\x81\xfc\xa8\xe\x38\x3e\xef\x80"
14351+ "\xb1\x98\xf2\xde\x3f\x4b\xae\xd1"
14352+ "\xf0\xf1\x30\x4c\x1\x27\x5a\x8f"
14353+ "\x45\xe1\x39\xb7\xae\xff\x1f\x27"
14354+ "\xad\x57\x15\xab\x31\x5d\xc\xef"
14355+ "\x8c\xc8\x80\xbd\x11\x98\xf3\x7b"
14356+ "\xa2\xdd\x14\x20\xf9\xe8\xbb\x82"
14357+ "\xf7\x32\xca\x4b\xa8\xf7\xb3\x4d"
14358+ "\x27\xd1\xcd\xe6\xb6\x65\x5a\x23"
14359+ "\xc2\xf3\x54\x84\x53\xe3\xb9\x20"
14360+ "\xa5\x37\x0\xbe\xe7\x7b\x48\xfb"
14361+ "\x21\x3d\x9e\x48\x1d\x9e\xf5\xbf"
14362+ "\x77\xd5\xb4\x4a\x53\x71\x94\x7a"
14363+ "\x88\xa6\x6e\x6\x93\xca\x43\xa5"
14364+ "\xc4\xf6\xcd\x53\x4b\x7b\x8e\xfe"
14365+ "\xb4\x28\x7c\x42\x29\x32\x5d\x88"
14366+ "\xed\xce\x0\x19\xe\x16\x2\x6e"
14367+ "\x87\xff\x2c\xac\xe8\xe7\xe9\xbf"
14368+ "\x31\x51\xec\x47\xc3\x51\x83\xc1",
14369+ .ilen = 160,
14370+ .result = "\xb1\x98\xf2\xde\x3f\x4b\xae\xd1"
14371+ "\xf0\xf1\x30\x4c\x1\x27\x5a\x8f"
14372+ "\x45\xe1\x39\xb7\xae\xff\x1f\x27"
14373+ "\xad\x57\x15\xab\x31\x5d\xc\xef"
14374+ "\x8c\xc8\x80\xbd\x11\x98\xf3\x7b"
14375+ "\xa2\xdd\x14\x20\xf9\xe8\xbb\x82"
14376+ "\xf7\x32\xca\x4b\xa8\xf7\xb3\x4d"
14377+ "\x27\xd1\xcd\xe6\xb6\x65\x5a\x23"
14378+ "\xc2\xf3\x54\x84\x53\xe3\xb9\x20"
14379+ "\xa5\x37\x0\xbe\xe7\x7b\x48\xfb"
14380+ "\x21\x3d\x9e\x48\x1d\x9e\xf5\xbf"
14381+ "\x77\xd5\xb4\x4a\x53\x71\x94\x7a"
14382+ "\x88\xa6\x6e\x6\x93\xca\x43\xa5"
14383+ "\xc4\xf6\xcd\x53\x4b\x7b\x8e\xfe"
14384+ "\xb4\x28\x7c\x42\x29\x32\x5d\x88"
14385+ "\xed\xce\x0\x19\xe\x16\x2\x6e"
14386+ "\x87\xff\x2c\xac\xe8\xe7\xe9\xbf"
14387+ "\x31\x51\xec\x47\xc3\x51\x83\xc1"
14388+ "\x59\x52\x98\xc7\xc6\xfd\x27\x1f"
14389+ "\x4\x2\xf8\x4\xc3\x3d\x3f\x66",
14390+ .rlen = 160
14391+ }
14392+ };
14393+
14394+ static const struct cipher_testvec sm4_dec_tv_template[] = {
14395+ { /* SM4 Appendix A: Example Calculations. Example 1. */
14396+ .key = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
14397+ "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
14398+ .klen = 16,
14399+ .input = "\x68\x1E\xDF\x34\xD2\x06\x96\x5E"
14400+ "\x86\xB3\xE9\x4F\x53\x6E\x42\x46",
14401+ .ilen = 16,
14402+ .result = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
14403+ "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
14404+ .rlen = 16,
14405+ }, { /*
14406+ * SM4 Appendix A: Example Calculations.
14407+ * Last 10 iterations of Example 2.
14408+ */
14409+ .key = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"
14410+ "\xFE\xDC\xBA\x98\x76\x54\x32\x10",
14411+ .klen = 16,
14412+ .input = "\xb1\x98\xf2\xde\x3f\x4b\xae\xd1"
14413+ "\xf0\xf1\x30\x4c\x1\x27\x5a\x8f"
14414+ "\x45\xe1\x39\xb7\xae\xff\x1f\x27"
14415+ "\xad\x57\x15\xab\x31\x5d\xc\xef"
14416+ "\x8c\xc8\x80\xbd\x11\x98\xf3\x7b"
14417+ "\xa2\xdd\x14\x20\xf9\xe8\xbb\x82"
14418+ "\xf7\x32\xca\x4b\xa8\xf7\xb3\x4d"
14419+ "\x27\xd1\xcd\xe6\xb6\x65\x5a\x23"
14420+ "\xc2\xf3\x54\x84\x53\xe3\xb9\x20"
14421+ "\xa5\x37\x0\xbe\xe7\x7b\x48\xfb"
14422+ "\x21\x3d\x9e\x48\x1d\x9e\xf5\xbf"
14423+ "\x77\xd5\xb4\x4a\x53\x71\x94\x7a"
14424+ "\x88\xa6\x6e\x6\x93\xca\x43\xa5"
14425+ "\xc4\xf6\xcd\x53\x4b\x7b\x8e\xfe"
14426+ "\xb4\x28\x7c\x42\x29\x32\x5d\x88"
14427+ "\xed\xce\x0\x19\xe\x16\x2\x6e"
14428+ "\x87\xff\x2c\xac\xe8\xe7\xe9\xbf"
14429+ "\x31\x51\xec\x47\xc3\x51\x83\xc1"
14430+ "\x59\x52\x98\xc7\xc6\xfd\x27\x1f"
14431+ "\x4\x2\xf8\x4\xc3\x3d\x3f\x66",
14432+ .ilen = 160,
14433+ .result = "\x99\x4a\xc3\xe7\xc3\x57\x89\x6a"
14434+ "\x81\xfc\xa8\xe\x38\x3e\xef\x80"
14435+ "\xb1\x98\xf2\xde\x3f\x4b\xae\xd1"
14436+ "\xf0\xf1\x30\x4c\x1\x27\x5a\x8f"
14437+ "\x45\xe1\x39\xb7\xae\xff\x1f\x27"
14438+ "\xad\x57\x15\xab\x31\x5d\xc\xef"
14439+ "\x8c\xc8\x80\xbd\x11\x98\xf3\x7b"
14440+ "\xa2\xdd\x14\x20\xf9\xe8\xbb\x82"
14441+ "\xf7\x32\xca\x4b\xa8\xf7\xb3\x4d"
14442+ "\x27\xd1\xcd\xe6\xb6\x65\x5a\x23"
14443+ "\xc2\xf3\x54\x84\x53\xe3\xb9\x20"
14444+ "\xa5\x37\x0\xbe\xe7\x7b\x48\xfb"
14445+ "\x21\x3d\x9e\x48\x1d\x9e\xf5\xbf"
14446+ "\x77\xd5\xb4\x4a\x53\x71\x94\x7a"
14447+ "\x88\xa6\x6e\x6\x93\xca\x43\xa5"
14448+ "\xc4\xf6\xcd\x53\x4b\x7b\x8e\xfe"
14449+ "\xb4\x28\x7c\x42\x29\x32\x5d\x88"
14450+ "\xed\xce\x0\x19\xe\x16\x2\x6e"
14451+ "\x87\xff\x2c\xac\xe8\xe7\xe9\xbf"
14452+ "\x31\x51\xec\x47\xc3\x51\x83\xc1",
14453+ .rlen = 160
14454+ }
14455+ };
14456+
1432614457/*
1432714458 * Speck test vectors taken from the original paper:
1432814459 * "The Simon and Speck Families of Lightweight Block Ciphers"
0 commit comments