Crypto_Ipw_encrypt func problem

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Crypto_Ipw_encrypt func problem

跳至解决方案
1,310 次查看
Kanaqw
Contributor III

Hello, can anybody explain to me this thing? In Crypto_Ipw_Encrypt function there's a next check:

if ( (Std_ReturnType)E_OK == sVerifyKey.eFound )
{
sVerifyKeyElement = Crypto_Ipw_VerifyKeyElementId ( sVerifyKey.u32Counter, 5U );
}

Here notice the 5 that function passes as parameter. Inside the Crypto_Ipw_VerifyKeyElementId this condition:


if ( u32keyElementId == Crypto_aKeyElementList[Crypto_aKeyList[u32KeyIndex]->pCryptoKeyElementList->u32CryptoKeyElements[u32Counter]]->u32CryptoKeyElementId )
{
sVerifyKeyElement.eFound = (Std_ReturnType)E_OK;
sVerifyKeyElement.u32Counter = Crypto_aKeyList[u32KeyIndex]->pCryptoKeyElementList->u32CryptoKeyElements[u32Counter];
}

which sends error if you dont have Crypto_aKeyElementList[] with id=5, but what to do if I have only two keys or one? I still have to do 5 id's in config? Since Im writing my own configs this is really confusing

0 项奖励
回复
1 解答
1,276 次查看
namnguyenviet
NXP Employee
NXP Employee

Hello @Kanaqw,

I supposed you're doing the CBC encryption. This algorithm requires an initial value, or an initialization vector (https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation). As a result, the key used for CBC encryption requires two key elements: one is the key material (key element ID =1) and the other is the init vector (key element ID = 5). 

namnguyenviet_0-1642176997814.png

(Source: AUTOSAR_SWS_CryptoServiceManager.pdf)

In order to configure the key for CBC encryption, you can configure one key with two key elements. For example, let's say that you want to configure KEY_8 as the CBC encryption key. You can do as follow:

1. In CryptoKeyElement, add two elements

- One is the keyElement for key material, CryptoKeyElementID must be 1

- The other is the keyElement for initial vector, CryptoKeyElementID must be 5. You can also configure the value for this initial vector in CryptoKeyElementInitValue - if it's blank then the initial vector is 0

2. In CryptoKeyType, add a KeyType, contains two above KeyElements

3. In CryptoKey, add a new key, with CryptoKeyId = 11 (KEY_8).and refer to the above KeyType

MicrosoftTeams-image (8).png

Best Regards,

Nam

在原帖中查看解决方案

0 项奖励
回复
1 回复
1,277 次查看
namnguyenviet
NXP Employee
NXP Employee

Hello @Kanaqw,

I supposed you're doing the CBC encryption. This algorithm requires an initial value, or an initialization vector (https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation). As a result, the key used for CBC encryption requires two key elements: one is the key material (key element ID =1) and the other is the init vector (key element ID = 5). 

namnguyenviet_0-1642176997814.png

(Source: AUTOSAR_SWS_CryptoServiceManager.pdf)

In order to configure the key for CBC encryption, you can configure one key with two key elements. For example, let's say that you want to configure KEY_8 as the CBC encryption key. You can do as follow:

1. In CryptoKeyElement, add two elements

- One is the keyElement for key material, CryptoKeyElementID must be 1

- The other is the keyElement for initial vector, CryptoKeyElementID must be 5. You can also configure the value for this initial vector in CryptoKeyElementInitValue - if it's blank then the initial vector is 0

2. In CryptoKeyType, add a KeyType, contains two above KeyElements

3. In CryptoKey, add a new key, with CryptoKeyId = 11 (KEY_8).and refer to the above KeyType

MicrosoftTeams-image (8).png

Best Regards,

Nam

0 项奖励
回复