Arduino Mega 2560操作SMEC98SP加密芯片的事例代码,如果需要完整代码(包括加密芯片代码),请到中巨伟业 http://www.sinormous.com/download.html下载
#include “smec98sp.h”
#include “iic_smec98sp.h”
void PrintHex(unsigned char *str,unsigned int len)
{
unsigned int i;
for(i=0;i<len;i++)
{
Serial.print(*str++,HEX);
}
Serial.print("\r\n");
}
/*
1.获取SMEC98SP的UID号, 获取STM32的ID, 获取STM32随机数
2.验证PIN
3.内外部认证
4.SHA1=>前置数据^随机数
5.密文读
6.读数据
7.写数据
8.构造算法(PA口数据->密文送加密芯片, 密文返回)
如果直接引用,请将print的调试信息去除
*/
void SMEC_Test(void)
{
/*各种密钥,不会在I2C线路上传输,可以使用同一组.应该将密钥分散存储,防止主控芯片被破解后,被攻击者在二进制码中找到密钥 */
unsigned char InternalKey[16] = {
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F };//内部认证密钥,必须和SMEC98SP一致
unsigned char ExternalKey[16] = {
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F };//外部认证密钥,必须和SMEC98SP一致
unsigned char SHA1_Key[16] = {
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F }; //哈希算法认证密钥,必须和SMEC98SP一致
unsigned char MKey[16] = {
<