Crypto_Ipw_encrypt func problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Crypto_Ipw_encrypt func problem

Jump to solution
1,299 Views
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 Kudos
Reply
1 Solution
1,265 Views
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

View solution in original post

0 Kudos
Reply
1 Reply
1,266 Views
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 Kudos
Reply