//分组密码算法的测试向量, 如CBC, CMAC等
typedef struct block_cipher_test_vector_st
{
char * inf; //测试向量的附加信息说明
int alg; //密码算法
int mod; //工作模式
int klen; //密钥字节长度
char * key; //密钥
int ivlen; // IV 字节长度
char * iv; // IV
int ptlen; //明文字节长度
char * pt; //明文
int ctlen; //密文字节长度
char * ct; //密文
int maclen; //MAC 字节长度
char * mac; //MAC
}BCTV;//分组密码算法的测试向量
BCTV sm4mactv[] =
{
{/*测试向量0 */
/*inf*/ (char*)"XX中心提供", SM4, CBC_MAC_PAD_0000,
/*Key*/ 16, (char*)"EEF3C9888129755F 2C769DBC459448CE",
/*IV */ 16, (char*)"FBD7B7AB0793F814 B28A970F9E859C05",
/*pt */ 16, (char*)"99C9D02D03F2CD39 4A680DC51B112322",
/*ct */ 0, (char*)NULL,
/*mac*/ 16, (char*)"530EDF0605A302F3 0096AE46BD6316AF",
},
{/*测试向量1 */
/*inf*/ (char*)"XX中心提供", SM4, CBC_MAC_PAD_0000,
/*Key*/ 16, (char*)"973270DF92EFF5EC 1E170A1566098CB3",
/*IV */ 16, (char*)"2C2A98AF53A684F1 9DF3C39B721FA27E",
/*pt */ 32, (char*)"AADA15E99FE95171 B6F15FD3E427976E"
/* */ "B1B595FCA82A23AC 00C7AC7CEF9DDED7",
/*ct */ 0, (char*)NULL,
/*mac*/ 16, (char*)"CF505945E5C135BC 2BB4588D17E404D4",
},
{/*测试向量2 */
/*inf*/ (char*)"XX中心提供", SM4, CBC_MAC_PAD_0000,
/*Key*/ 16, (char*)"F82B569F5D3DCB61 D0BE8778BF05D1B0",
/*IV */ 16, (char*)"791004096432F985 F7BE6B5CDAC79EB8",
/*pt */ 48, (char*)"F76C0ADA8374F1D0 C4B7EC5CC5047E03"
/* */ "CF83B7A9ECE3777C FAEEC940ECE815CA"
/* */ "E2FAA69EFAAC61A1 42C882CCC772E653",
/*ct */ 0, (char*)NULL,
/*mac*/ 16, (char*)"651AF0AA9D73D2C6 460DAEC83738AE3C",
},
{/*测试向量3 */
/*inf*/ (char*)"XX中心提供", SM4, CBC_MAC_PAD_0000,
/*Key*/ 16, (char*)"ABC854B48BD5811E 22DDBB513313C858",
/*IV */ 16, (char*)"500D6DD1001962FE 4727C117ACDE2C4E",
/*pt */ 64, (char*)"E0D1F45DB6C3DB00 F954062DB748162F"
/* */ "5FF589645686F615 92A98574334BE914"
/* */ "42B8BCDB331887D7 D3873EDB63EFA4E4"
/* */ "1FA3BC66BA9BDBD9 F02A6CF6D6116044",
/*ct */ 0, (char*)NULL,
/*mac*/ 16, (char*)"AA54E04FC85B56C2 CEB1D58E122ADB79",
},
{/*测试向量4 中心提供数据 */
/*inf*/ (char*)"中心提供", SM4, CBC_MAC_PAD_0000,
/*Key*/ 16, (char*)"3CA7EF836755B8D4 A1F981A596DB17E8",
/*IV */ 16, (char*)"607B652B1E129F69 00FDF21D833AED4B",
/*pt */ 80, (char*)"DF8C24D34145C12B 335852E9F23468A9"
/* */ "EA01C3A356FD0701 7F55706BF403D4A4"
/* */ "B1C0E4C9448D18F6 2FFEB58DACC857F2"
/* */ "73ABFC4C064E05B4 B2DBA149E1CBA7DE"
/* */ "C6A3809AD916306C 48A5F564B1378356",
/*ct */ 0, NULL,
/*mac*/ 16, (char*)"C5C98AC7CD492D41 92706C7CCC6C9F79",
},
{/*测试向量5 GB/T 15852.1 B.2节 MAC算法1(CBC-MAC) TV1 */
/*inf*/ (char*)"GB/T 15852.1 B.2节 CBC-MAC TV1", SM4, CBC_MAC_PAD_0000,
/*Key*/ 16, (char*)"0123456789ABCDEF FEDCBA9876543210",
/*IV */ 0, NULL,
/*pt */ 32, (char*)"5468697320697320 7468652074657374"
/* */ "206D657373616765 20666F72206D6163",
/*ct */ 0, NULL,
/*mac*/ 8, (char*)"16E02904EFB765B7",
},
{/*测试向量6 GB/T 15852.1 B.2节 MAC算法1(CBC-MAC) TV2 */
/*inf*/ (char*)"GB/T 15852.1 B.2节 CBC-MAC TV2", SM4, CBC_MAC_PAD_1000,
/*Key*/ 16, (char*)"0123456789ABCDEF FEDCBA9876543210",
/*IV */ 0, NULL,
/*pt */ 32, (char*)"5468697320697320 7468652074657374"
/* */ "206D657373616765 20666F72206D6163",
/*ct */ 0, NULL,
/*mac*/ 8, (char*)"4B6553AF3C4E2744",
},
{/*测试向量7 GB/T 15852.1 B.2节 MAC算法1(CBC-MAC) TV3 */
/*说明: 代码中无标准规定的第3种填充方式:
* 最左边填一个分组表示长度,最右边填最少的0比特
* 所以这里将模式和pt做了对应性调整 */
/*inf*/ (char*)"GB/T 15852.1 B.2节 CBC-MAC TV3", SM4, CBC_MAC_PAD_0000,
/*Key*/ 16, (char*)"0123456789ABCDEF FEDCBA9876543210",
/*IV */ 0, NULL,
/*pt */ 48, (char*)"0000000000000000 0000000000000100"
/* */ "5468697320697320 7468652074657374"
/* */ "206D657373616765 20666F72206D6163",
/*ct */ 0, NULL,
/*mac*/ 8, (char*)"71AF7E4553404CBC",
},
{/*测试向量8 GB/T 15852.1 B.2节 MAC算法1(CBC-MAC) TV4 */
/*inf*/ (char*)"GB/T 15852.1 B.2节 CBC-MAC TV4", SM4, CBC_MAC_PAD_0000,
/*Key*/ 16, (char*)"0123456789ABCDEF FEDCBA9876543210",
/*IV */ 0, NULL,
/*pt */ 25, (char*)"5468697320697320 7468652074657374"
/* */ "206D657373616765 20",
/*ct */ 0, NULL,
/*mac*/ 8, (char*)"BA89E45FE8ABF242",
},
{/*测试向量9 GB/T 15852.1 B.2节 MAC算法1(CBC-MAC) TV5 */
/*inf*/ (char*)"GB/T 15852.1 B.2节 CBC-MAC TV5", SM4, CBC_MAC_PAD_1000,
/*Key*/ 16, (char*)"0123456789ABCDEF FEDCBA9876543210",
/*IV */ 0, NULL,
/*pt */ 25, (char*)"5468697320697320 7468652074657374"
/* */ "206D657373616765 20",
/*ct */ 0, NULL,
/*mac*/ 8, (char*)"421AD1690AA152E2",
},
{/*测试向量10 GB/T 15852.1 B.2节 MAC算法1(CBC-MAC) TV6 */
/*说明: 代码中无标准规定的第3种填充方式:
* 最左边填一个分组表示长度,最右边填最少的0比特
* 所以这里将模式和pt做了对应性调整 */
/*inf*/ (char*)"GB/T 15852.1 B.2节 CBC-MAC TV6", SM4, CBC_MAC_PAD_0000,
/*Key*/ 16, (char*)"0123456789ABCDEF FEDCBA9876543210",
/*IV */ 0, NULL,
/*pt */ 48, (char*)"0000000000000000 00000000000000C8"
/* */ "5468697320697320 7468652074657374"
/* */ "206D657373616765 2000000000000000",
/*ct */ 0, NULL,
/*mac*/ 8, (char*)"6A4A86F5B5E468DA",
},
{/*测试向量11 GB/T 15852.1 B.6节 MAC算法5(CMAC) TV1 */
/*说明: 代码中无标准规定的第3种填充方式:
* 最左边填一个分组表示长度,最右边填最少的0比特
* 所以这里将模式和pt做了对应性调整 */
/*inf*/ (char*)"GB/T 15852.1 B.6节 CMAC TV1", SM4, CMAC,
/*Key*/ 16, (char*)"0123456789ABCDEF FEDCBA9876543210",
/*IV */ 0, NULL,
/*pt */ 32, (char*)"5468697320697320 7468652074657374"
/* */ "206D657373616765 20666F72206D6163",
/*ct */ 0, NULL,
/*mac*/ 8, (char*)"692C437100F3B5EE",
},
{/*测试向量12 GB/T 15852.1 B.6节 MAC算法6(CMAC) TV2 */
/*说明: 代码中无标准规定的第3种填充方式:
* 最左边填一个分组表示长度,最右边填最少的0比特
* 所以这里将模式和pt做了对应性调整 */
/*inf*/ (char*)"GB/T 15852.1 B.6节 CMAC TV2", SM4, CMAC,
/*Key*/ 16, (char*)"0123456789ABCDEF FEDCBA9876543210",
/*IV */ 0, NULL,
/*pt */ 25, (char*)"5468697320697320 7468652074657374"
/* */ "206D657373616765 20",
/*ct */ 0, NULL,
/*mac*/ 8, (char*)"4738A6C760B280FC",
},
};