SM1算法是分组密码算法,分组长度为128位,密钥长度都为 128 比特。SM1算法与国际标准中的AES对称加密算法类似,且加密强度相当。SM1算法不公开,无软件实现,仅以IP核的形式存在于芯片中。如果要使用SM1算法,只能通过采购带SM1算法的密码芯片、密码卡、密码机等方式实现。
SM1算法的常用模式包括ECB模式和CBC模式。用户在使用SM1算法时,为了验证密码硬件实现与API用法正确性,一般将API生成的加密数据与SM1算法的标准数据进行对比。
国密SM1算法标准数据
SM1_ECB模式
SM1_ECB:
密钥:
unsigned char pbKeyValue[16] = {0x40,0xbb,0x12,0xdd,0x6a,0x82,0x73,0x86,0x7f,0x35,0x29,0xd3,0x54,0xb4,0xa0,0x26};
明文:
unsigned char pbPlainText[16] = {0xff,0xee,0xdd,0xcc,0xbb,0xaa,0x99,0x88,0x77,0x66,0x55,0x44,0x33,0x22,0x11,0x00};
密文:
unsigned char pbCipherText[16] = {0x6d,0x7f,0x45,0xb0,0x8b,0xc4,0xd9,0x66,0x44,0x4c,0x86,0xc2,0xb0,0x7d,0x29,0x93};
SM1_CBC模式
SM1_CBC:
密钥:
unsigned char pbKeyValue[16] = {0x40,0xbb,0x12,0xdd,0x6a,0x82,0x73,0x86,0x7f,0x35,0x29,0xd3,0x54,0xb4,0xa0,0x26};
初始化向量:
unsigned char pbIV[16] = {0xe8,0x3d,0x17,0x15,0xac,0xf3,0x48,0x63,0xac,0xeb,0x93,0xe0,0xe5,0xab,0x8b,0x90};
明文:
unsigned char pbPlainText[32] = {0xff,0xee,0xdd,0xcc,0xbb,0xaa,0x99,0x88,0x77,0x66,0x55,0x44,0x33,0x22,0x11,0x00,0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xaa,0xbb,0xcc,0xdd,0xee,0xff};
密文:
unsigned char pbCipherText[32] = {0x3a,0x70,0xb5,0xd4,0x9a,0x78,0x2c,0x07,0x2d,0xe1,0x13,0x43,0x81,0x9e,0xc6,0x59,0xf8,0xfc,0x7a,0xf0,0x5e,0x7c,0x6d,0xfb,0x5f,0x81,0x09,0x0f,0x0d,0x87,0x91,0xb2};
对于需要使用SM1算法的用户,需要结合实际项目的算法功能、性能需求,选择合适的密码硬件。成本从低到高,可考虑依次选择:国密Ukey、USB密码卡、mini-PCIE密码卡、PCIE密码卡、服务器密码机等多种形式。