我正在尝试使用 DiagStartGenerateKeyFromSeed 从 ECU 发送的种子生成密钥,但我得到的结果是“缓冲区太小”
on diagResponse ECU.SecurityAccess_Process
{
long result ;
result = diagGetParameterRaw (this, "securitySeed", gSeedArray, elcount(gSeedArray));
if (result == 0 )
{
write("Seed is (hex) %X %X %X",gSeedArray[0],gSeedArray[1],gSeedArray[2]);
result=DiagStartGenerateKeyFromSeed("ECU",gSeedArray,elcount(gSeedArray),1,"Common","");
if (result == 0)
{
write(" Key computation for security Level 1 was started ") ;
}
else
{
write("Error code %ld during key calculation",result);
if(result==-84)
write("invalid security level");
if(result==-86)
write("buffer too small");
}
}
else
{
write("Could not retrieve parameter");
}
}
Diag_GenerateKeyResult( long result, BYTE computedKey[])
{
int i;
long ret;
char keyBuffer[3], stringBuffer[10];
if(result==0) // if key has been calculated
{
write("callback started ");
// To output the key in one line, a composite string has to be build
snprintf(stringBuffer, elCount(stringBuffer),""); // Clear the string buffer
strncat(stringBuffer, "Key is (hex): ",
elCount(stringBuffer)); // Begin to build composite string
for(i=0;i<elCount(computedKey);i++)
{
snprintf(keyBuffer, elCount(keyBuffer), "%02X ",
computedKey[i]); // Print current key byte into key buffer
strncat(stringBuffer, keyBuffer,
elCount(stringBuffer)); // Add current key byte to the string buffer
}
write(stringBuffer); // Output the string buffer (the key) in one line
}
else
{
write("Error code %ld during key calculation",result);
if(result==-84)
write("invalid security level");
if(result==-86)
write("buffer too small");
}
}
如果一旦 ECU 发送种子回调函数 _Diag_GenerateKeyResult 事件 OndiagResponse 处于活动状态,则 DiagStartGenerateKeyFromSeed 正常工作我得到“安全级别 1 的密钥计算已启动”