HASH RSA

mail@pastecode.io avatar
unknown
c_cpp
20 days ago
3.1 kB
8
Indexable
Never
	//Hash RSA
	if(LlaveOpenpay==FALSE)
	{
		if(FindKey)
		{
			char buffer_in[256], buffer_out[256];
			char pucKeyInfoOut[128] = { 0 };
			memset(buffer_in, '0', sizeof(buffer_in));
			memset(buffer_out, 0, sizeof(buffer_out));
			iRet = PedRsaRecover(RsaIndex, (uchar*)buffer_in, (uchar*)buffer_out, (uchar*)pucKeyInfoOut);
			//sprintf(msg, "SHA1 ret %d Mod len %d", iRet, RsakeyOut.iModulusLen/8);paintMessage(msg);getkey();
			if (iRet != PED_RET_OK) 
			{
				LLaveCorrecta = FALSE;
			}
			else
			{
				LLaveCorrecta = TRUE;
				memcpy(blockCIPHERbcd, buffer_out, 4);
			}

			//leer KCV de llave
			if(KeyType!=PED_TAESK)
			{

				memset(&kcv_info, 0, sizeof(ST_KCV_INFO));
				kcv_info.iCheckMode=0x00;
				if(KeyType==PED_TIK)
					kcv_info.aucCheckBuf[0]=0x04;
				else
					kcv_info.aucCheckBuf[0]=0x08;
				iRet= PedGetKcv(KeyType, KeyIndex, &kcv_info);
				if (iRet != PED_RET_OK) 
				{
					LLaveCorrecta = FALSE;
				}
			}
			else if(KeyType==PED_TAESK)
			{
				uchar Data[16]={0};

				iRet = PedCalcAes(KeyIndex,NULL,Data,16,DataOut,PED_ENCRYPT);
				if (iRet != PED_RET_OK) 
				{
					LLaveCorrecta = FALSE;
				}
			}
		}
		else
		{
			char buffer_in[256], buffer_out[256];
			char pucKeyInfoOut[128] = { 0 };
			memset(buffer_in, '0', sizeof(buffer_in));
			memset(buffer_out, 0, sizeof(buffer_out));
			iRet = PedRsaRecover(RsaIndex, (uchar*)buffer_in, (uchar*)buffer_out, (uchar*)pucKeyInfoOut);
			if (iRet != PED_RET_OK)
			{
				LLaveCorrecta = FALSE;
			}
		}
	}
	else
	{
		//char msg[50]={0};
		char buffer_in[256], buffer_out[256];
		char pucKeyInfoOut[128] = {0};

		if(FindKey)
		{
			if (memcmp(Key_Name, LLAVE_001, 10) == 0)
				RsaIndex = IDX_LLAVE_001;
			/*else if (memcmp(Key_Name, LLAVE_002, 10) == 0)
				RsaIndex = IDX_LLAVE_002;
			else if (memcmp(Key_Name, LLAVE_003, 10) == 0)
				RsaIndex = IDX_LLAVE_003;*/
			else if (memcmp(Key_Name, LLAVE_004, 10) == 0)
				RsaIndex = IDX_LLAVE_004;
			memset(buffer_in, '0', sizeof(buffer_in));
			memset(buffer_out, 0, sizeof(buffer_out));
			iRet = PedRsaRecover(RsaIndex, (uchar*)buffer_in, (uchar*)buffer_out, (uchar*)pucKeyInfoOut);
			if (iRet == PED_RET_OK)
			{
				memcpy(blockCIPHERbcd, buffer_out, 4);
			}
		}
		if (RsaIndex == IDX_LLAVE_001)
		{
			memset(buffer_in, '0', sizeof(buffer_in));
			memset(buffer_out, 0, sizeof(buffer_out));
			RsaIndex = IDX_LLAVE_004;
			iRet = PedRsaRecover(RsaIndex, (uchar*)buffer_in, (uchar*)buffer_out, (uchar*)pucKeyInfoOut);
			if (iRet != PED_RET_OK)
			{
				//ScrCls();Lcdprintf("SHA2 %d", iRet);getkey();
				LLaveCorrecta = FALSE;
			}
			else //if(memcmp(pucKeyInfoOut, LLAVE_PRIVADA_OP, 10)==0)
			{
				FindKey2 = TRUE;
				memcpy(blockCIPHERbcd2, buffer_out, 4);
				//sprintf(msg, "PedRsaRecover ret %d %s", iRet, pucKeyInfoOut);paintMessage(msg);getkey();
			}
		}
	}
	//envia respuesta del Z13
	cleanBuff(SendBuf, sizeof(SendBuf));
	SendBuf[offset++] = STX;
	SendBuf[offset++] = _Z1XB1;
	SendBuf[offset++] = _Z1XB2;
	SendBuf[offset++] = _Z13B3;
Leave a Comment