📄 ic.c.bak
字号:
/*本函数用于从IC卡的指定地址读取指定长度的数据*/
int IC_read()
{
extern int r_IC(),peek();
extern void poke();
int status;
unsigned int IC_addr,IC_len,tmp;
unsigned char temp;
/* tmp=peek(0x8000BFFC,2); //操作员权限
if (tmp!=0)
{
temp=(unsigned char)(tmp>>24);
if(temp!=0)
{
status=0x0a;
poke(0x80008800,0x0a,2);
goto label1;
}
}*/
IC_addr=peek(0x80008804,2); /*读出IC卡地址*/
IC_len=peek(0x80008808,2); /*读出数据长度*/
status=r_IC(IC_addr,0x80008804,IC_len); /*从IC卡读出指定长度的数据*/
if (status==0x30)
{
status=0x3;
poke(0x80008800,0x3,2);
goto label1;
}
if (status==0x32)
{
status=0x7;
poke(0x80008800,0x7,2);
goto label1;
} /*若读IC卡失败,进行相应处理*/
status=0;
poke(0x80008800,0,2);
label1: return status;
}
/*本函数用于向IC卡的指定地址写入指定长度的数据*/
int IC_write()
{
extern int w_IC(),peek();
extern void poke();
unsigned int IC_addr,IC_len,tmp;
unsigned char temp;
int status;
/* tmp=peek(0x8000BFFC,2); //操作员权限
if (tmp!=0)
{
temp=(unsigned char)(tmp>>24);
if(temp!=0)
{
status=0x0a;
poke(0x80008800,0x0a,2);
goto label2;
}
}*/
IC_addr=peek(0x80008804,2); /*读出IC卡地址*/
IC_len=peek(0x80008808,2); /*读出数据长度*/
status=w_IC(0x8000880C,IC_addr,IC_len); /*向IC卡写入指定长度的数据*/
if (status==0x30)
{
status=0x3;
poke(0x80008800,0x3,2);
goto label2;
}
if (status==0x32)
{
status=0x7;
poke(0x80008800,0x7,2);
goto label2;
} /*若写IC卡失败,进行相应处理*/
status=0;
poke(0x80008800,0,2);
label2: return status;
}
/*本函数用于清除IC卡中的内容*/
int IC_clean()
{
extern int w_IC();
extern void poke();
int i,status;
unsigned int data[64],tmp;
unsigned char temp;
/* tmp=peek(0x8000BFFC,2); //操作员权限
if (tmp!=0)
{
temp=(unsigned char)(tmp>>24);
if(temp!=0)
{
status=0x0a;
poke(0x80008800,0x0a,2);
goto label2;
}
}
*/
for (i=0;i<64;i++)
{
data[i]=0xFFFFFFFF;
}
for (i=0;i<32;i++)
{
status=w_IC(data,0+i*256,256);
if (status==0x30)
{
status=0x3;
poke(0x80008800,0x3,2);
goto label2;
}
if (status==0x32)
{
status=0x7;
poke(0x80008800,0x7,2);
goto label2;
} /*若写IC卡失败,进行相应处理*/
}
status=0;
poke(0x80008800,0,2);
label2: return status;
}
/*本函数用于制操作员IC卡*/
int operatorIC_create()
{
extern int w_IC(),peek(),inputkey();
extern void poke(),flash_w(),secerase(),memcopy();
int status,i;
unsigned int u_num,addr,new_ICID,tmp;
unsigned char temp;
/* tmp=peek(0x8000BFFC,2); //操作员权限
if (tmp!=0)
{
temp=(unsigned char)(tmp>>24);
if(temp!=0)
{
status=0x0a;
poke(0x80008800,0x0a,2);
goto label2;
}
}
*/
u_num=peek(0x8000BFFE,2); /*确定现在已经存在的用户数目*/
addr=0x8000C800+u_num*20; /*确定新的用户信息应写入的地址*/
new_ICID=peek(0x80008B24,1);
if((u_num+1)>50)
{
status=0x09;
poke(0x80008800,0x09,2);
goto label2;
}
for(i=0;i<u_num;i++)
{
if(peek(0x8000C800+i*20,1)==new_ICID)
{
status=0x32;
poke(0x80008800,0x32,2);
goto label2;
}
}
memcopy(0x80008B24,addr,1,1); /*将ICID移到内存的相应位置*/
memcopy(0x80008B44,addr+4,4,2); /*将认证随机串移到内存相应位置*/
secerase(0x01480000); /*擦除用户信息所在的flash扇区*/
flash_w(0x8000C800,0x01480000,5*(u_num+1)); /*更新flash中的用户信息区*/
status=w_IC(0x80008804,0,800); /*将头信息写入IC卡*/
if (status==0x30)
{
status=0x3;
poke(0x80008800,0x3,2);
goto label2;
}
if (status==0x32)
{
status=0x7;
poke(0x80008800,0x7,2);
goto label2;
} /*若写IC卡失败,进行相应处理*/
memcopy(0x8000880C,0x8000e000,4,2); /*将主密钥移到DSP内存位置*/
memcopy(0x80008B24,0x80008808,12,2); /*将用户信息移到加密位置*/
poke(0x80008804,3,2); /*输入加密数据的组数*/
inputkey(0x80008804,0x8000E000,0x80008808,0x80008808,0); /*用主密钥加密用户信息*/
poke(0x80008804,3,2); /*输入加密数据的组数*/
inputkey(0x80008804,0x8000E010,0x80008808,0x80008808,0); /*用PASSWORD加密用户信息*/
status=w_IC(0x80008804,0x320,48); /*将加密后的用户信息存入IC卡*/
if (status==0x30)
{
status=0x3;
poke(0x80008800,0x3,2);
goto label2;
}
if (status==0x32)
{
status=0x7;
poke(0x80008800,0x7,2);
goto label2;
} /*若写IC卡失败,进行相应处理*/
memcopy(0x8000E000,0x80008808,4,2); /*将主密钥移到DSP内存位置*/
poke(0x80008804,1,2);
inputkey(0x80008804,0x8000E010,0x80008808,0x80008804,0); /*用PASSWORD加密KP1*/
status=w_IC(0x80008804,0x08,16); /*将加密后的KP1存入IC卡*/
if (status==0x30)
{
status=0x3;
poke(0x80008800,0x3,2);
goto label2;
}
if (status==0x32)
{
status=0x7;
poke(0x80008800,0x7,2);
goto label2;
} /*若写IC卡失败,进行相应处理*/
memcopy(0x8000E020,0x80008808,4,2); /*将主密钥移到DSP内存位置*/
poke(0x80008804,1,2);
inputkey(0x80008804,0x8000E010,0x80008808,0x80008804,0); /*用PASSWORD加密确认串*/
status=w_IC(0x80008804,0x350,16); /*将加密后的确认串存入IC卡*/
if (status==0x30)
{
status=0x3;
poke(0x80008800,0x3,2);
goto label2;
}
if (status==0x32)
{
status=0x7;
poke(0x80008800,0x7,2);
goto label2;
} /*若写IC卡失败,进行相应处理*/
u_num=u_num+1; /*密码卡增加了一个用户*/
poke(0x8000BFFE,u_num,1); /*更新用户状态字*/
status=0;
poke(0x80008800,0,2);
label2: return status;
}
/*本函数用于验证用户身份*/
int login()
{
extern int r_IC(),w_IC(),peek(),inputkey(),erandx();
extern void poke(),memcopy(),flash_w(),secerase();
int i,j,status;
unsigned short ICID,u_num;
poke(0x80008800,0x1,2);
inputkey(0x80008800,0x80008804,0x8000E020,0x80008814,0);
status=r_IC(0x350,0x80008824,16); /*从IC卡中读出确认串的密文*/
if (status==0x30)
{
status=0x3;
poke(0x80008800,0x3,2);
goto label1;
}
if (status==0x32)
{
status=0x7;
poke(0x80008800,0x7,2);
goto label1;
}
for (j=0;j<4;j++)
{
if(peek(0x80008824+j*4,2)!=peek(0x80008814+j*4,2))
{
poke(0x80008800,0xa,2);
status=0xa;
goto label1; /*若操作员非法,则做相应处理*/
}
}
memcopy(0x80008804,0x8000E010,4,2);
status=r_IC(0x320,0x80008818,48); /*将用户信息读到内存中,准备解密*/
if (status==0x30)
{
status=0x3;
poke(0x80008800,0x3,2);
goto label1;
}
if (status==0x32)
{
status=0x7;
poke(0x80008800,0x7,2);
goto label1;
} /*若读IC卡失败,进行相应处理*/
poke(0x80008804,3,2);
inputkey(0x80008804,0x8000E010,0x80008818,0x80008818,1); /*用PASSWORD解密用户信息*/
status=r_IC(0x08,0x80008808,16); /*将主密钥的密文读到内存中,准备解密*/
if (status==0x30)
{
status=0x3;
poke(0x80008800,0x3,2);
goto label1;
}
if (status==0x32)
{
status=0x7;
poke(0x80008800,0x7,2);
goto label1;
} /*若读IC卡失败,进行相应处理*/
poke(0x80008804,1,2);
inputkey(0x80008804,0x8000E010,0x80008808,0x80008808,1); /*用PASSWORD解密KP1*/
memcopy(0x80008808,0x8000E000,4,2); /*存贮KP1*/
poke(0x80008804,3,2); /*输入要解密数据的组数*/
inputkey(0x80008804,0x80008808,0x80008818,0x80008804,1); /*用主密钥解密用户信息*/
ICID=peek(0x80008804,1); /*要验证用户的ICID*/
u_num=peek(0x8000BFFE,1);
for (i=0;i<u_num;i++)
{
if(ICID==peek(0x8000C800+i*20,1))
break;
}
if(i>=u_num)
{
poke(0x80008800,0xa,2);
status=0x0f; /*若操作员非法,则做相应处理*/
goto label1;
}
for (j=0;j<4;j++)
{
if(peek(0x80008824+j*4,2)!=peek(0x8000C800+i*20+4+j*4,2))
{
poke(0x80008800,0xa,2);
status=0x0f;
goto label1; /*若操作员非法,则做相应处理*/
}
}
for (j=0;j<4;j++)
{
poke(0x80008824+j*4,erandx(),2); /*产生16字节的随机数作为新的认证随机串*/
}
memcopy(0x80008824,0x8000C800+i*20+4,4,2); /*将新的认证随机串移到指定位置*/
memcopy(0x80008824,0x80008838,4,2);
memcopy(0x80008814,0x80008828,4,2);
memcopy(0x80008804,0x80008818,4,2); /*将新的用户信息移到加密位置*/
poke(0x80008804,3,2); /*输入要加密的数据的组数*/
inputkey(0x80008804,0x8000E000,0x80008818,0x80008808,0); /*用主密钥加密用户信息*/
inputkey(0x80008804,0x8000E010,0x80008808,0x80008804,0); /*用PASSWORD加密用户信息*/
status=w_IC(0x80008804,0x320,48); /*新的用户信息密文写入IC卡*/
if (status==0x30)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -