/*******************************************
函数名称:CardExterVali
函数功能:卡与ESAM之间外部认证
输入参数:cApplySerialNumber1[8]-卡公共应用信息文件中的序列号,
KeyNum2-外部认证密钥标识符
输出参数:无
描述:卡取随机数-ESAM用02密钥对序列号生成过程密钥-ESAM过程密钥内部认证
--卡82H外部认证
*******************************************/
void CardAndEsamExternVerify(unsigned char cApplySerialNumber1[8],unsigned char KeyNum2)
{
unsigned char *pcReceCardRand;
unsigned char *pcReceCardData;
unsigned char cReceCardData[8]={0};
unsigned char cReceCardRand[8]={0};
CardWorkFlag=CardORESAM|CardWorkFlag;
pcReceCardRand=Get_RandNum(); //从卡上取随机数
if(ErrorRWBIT&CardError) goto CardExterValiEnd;
memcpy(&cReceCardRand[0],pcReceCardRand,8);
CardWorkFlag=~CardORESAM&CardWorkFlag;
//ESAM用02密钥,将序列号生成过程密钥
GetProcessKey(cApplySerialNumber1,EsamInfoUpKey);
if(ErrorRWBIT&CardError) goto CardExterValiEnd;
CardWorkFlag=~CardORESAM&CardWorkFlag;
//ESAM用过程密钥对随机数做内部认证,生成数据D
pcReceCardData=EsamInsideVerify(cReceCardRand,EsamKEYVerify);
if(ErrorRWBIT&CardError) goto CardExterValiEnd;
memcpy(&cReceCardData[0],pcReceCardData,8);
//cpu卡使用外部验证指令对数据D进行外部验证
CardWorkFlag=CardORESAM|CardWorkFlag;
ExternVerify(cReceCardData,CardInfoUpKey);
CardExterValiEnd:
_NOP();
if(ErrorRWBIT&CardError)
CardError=ErrorCardExtAuthBIT|CardError;
}