/*******************************************
函数名称:EsamExternVerify
函数功能:ESAM外部认证
输入参数:
输出参数:
描述:ESAM取随机数-卡用对应密钥对随机数进行内部认证,获得数据D
-ESAM对用相应密钥数据D进行外部认证
*****************************************/
void EsamExternVerify(unsigned char EsamKEYID,unsigned char CardKEYID)
{
unsigned char *pcReceEsamRand,*pcReceCardData1;
unsigned char cReceEsamRand[8]={0},cReceCardData1[8]={0};
icflag1=~ICSAM&icflag1;
pcReceEsamRand=Get_RandNum(); //从ESAM模块取随机数
if(ErrorReadWriteBIT&iErrorRWrCard) goto EsamExterValiEnd;
memcpy(&cReceEsamRand[0],pcReceEsamRand,8);
icflag1=ICSAM|icflag1;
//随机数送卡做内部认证,生成数据d1
pcReceCardData1=CardInsideVerify(cReceEsamRand,CardKEYID);
if(ErrorReadWriteBIT&iErrorRWrCard) goto EsamExterValiEnd;
memcpy(&cReceCardData1[0],pcReceCardData1,8);
icflag1=~ICSAM&icflag1;
//d1送ESAM模块做外部认证
ExternVerify(cReceCardData1,EsamKEYID);
EsamExterValiEnd:
if(ErrorReadWriteBIT&iErrorRWrCard)
iErrorRWrCard=ErrorEsamExtAuthBIT|iErrorRWrCard;
}