Calling of HSM True Random Number Generation from Application is leading to the memory protection hook

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
ursurya007
Level 1
Level 1
10 sign-ins 5 replies posted 5 sign-ins

Hello,

I am currently working with TC234LP microcontroller.

I am basically using "HSM_TrueRandomGenerate" to generate random numbers and providing this random number to "ASK" library to generate the seed for security. 

When I am trying to  call "HSM_TrueRandomGenerate" from the Bootloader. It is able to properly generate the random numbers.

When i tried to call "HSM_TrueRandomGenerate", then it is invoking memory protection Hook. Can you please provide some solution or document  to properly invoke "HSM_TrueRandomGenerate" (or) "HSM_PseudoRandomGenerate" from the Application.

Regards,

Surya

0 Likes
1 Solution
13 Replies
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi Surya,

For HSM, you could apply access right for myICP and get some application notes there.

 

dw

0 Likes
ursurya007
Level 1
Level 1
10 sign-ins 5 replies posted 5 sign-ins

Hi Dw,

Thank you for reply.. i am able to interact HSM core from Host after properly initializing the "HSM Driver" and generating the "HSM_TrueRandomGenerate"

But, Is it possible to generate the Pseudo numbers from crypto library when HSM is disabled.

Thanks,

Surya

0 Likes
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

HI Surya,

True random number generator is in HSM Domain, for Pseudo Random Number Generator you could try srand() from C lib, furthermore you could write your own srand() for your application.
FYI.

https://www.geeksforgeeks.org/pseudo-random-number-generator-prng/#:~:text=Pseudo%20Random%20Number%....

0 Likes
ursurya007
Level 1
Level 1
10 sign-ins 5 replies posted 5 sign-ins

Hi Dw,

Thank you for reply.. Basically we are using "STM0 (0xF0000010u) TC23x" Timer to generate the random value (Please find below attachment), when HSM is disabled.

Now, We are looking for other "method which doesn’t generate duplicated random numbers until the generation count of 1,000,000".

Can you please confirm is it possible to meet the above requirement with "srand( )" (or) please suggest me different  approach to meet above criteria.

Thanks,

Surya

0 Likes
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi ursurya007,

The srand pseudo-random number gernerator is like a serie of differenct number,  which could be the integer in MAX_RANGE depending on differnce system. i.e. 32767 or much more.

The subsequence will jump randomly in the MAX_RANGE, so you will not get dublicated number unless in rare probablity. 

The problem is that the srand is a fake random number which depends on the seed. Suppose your seed is 0 or 1, then your subsequence will always be guessed.  The hacker could easily record your sequence and playback to attack.

If you use Timer as a seed, which still depends, because 1min =60s, that means there are only 60 sequences, stil ease to record. If you use ms(million second), it would be much better, that means you have 1000 seeds to choose from which is still much less than True random generator.

Note that the true random generator is based on hardware structure of much more chaotic and complex source, that means completedly unpredictable.

dw

0 Likes
ursurya007
Level 1
Level 1
10 sign-ins 5 replies posted 5 sign-ins

Hi Dw,

Thank you for the reply.. I have tried to call "Srand" and "Rand" from my application. After compilation and during the executio time, rand is generating same random number "1" everytime. 

I have tried with below code lines

srand(time(NULL)); // tried srand with srand(time(0)), srand(10000)
rand_seed_ASK = rand(); //"rand_seed_ASK " is always updating with 1

Can you please provide your comment

Note: I am using  "Tasking VX Toolset for Tricore V6.3r1". Srand and rand is included in stdlib.h
Regards,

Surya

0 Likes
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi Surya,

I used TriCore Eclipse IDE v6.3r1,  you can see rand() get a sequence of 5 random number as attached screenshot.

You should notice the sequence always the same, because srand(SEED) used the same SEED.

So SEED has to be random as you used Timer functions. Please debug your Timer function return value to check if it is randomed.

TASKING VX-toolset for TriCore: control program v6.3r1 Build 19041558
Copyright 2003-2019 TASKING BV
#include <stdio.h>

int main(void)
{
	int i,rNum[5];

	srand(2);

	for(i=0;i<5;i++){

		rNum[i] = rand();

		printf( "Random sequence (%d):[%d]\n",i,rNum[i] );
	}
	printf("\n");
	while(1){
		i++;
	}

}

dw_0-1645079864055.png

dw

0 Likes
ursurya007
Level 1
Level 1
10 sign-ins 5 replies posted 5 sign-ins

Hello Dw,

Thank you for the reply.. I have tried to call "Srand" and "Rand" from my application. It is able to generate the random value. But the problem is" it is limited to generate max 16bit random number (4 bytes)". But we are looking to generate atleast 32 bit random value. can you please suggest an approach to meet the criteria (method which doesn’t generate duplicated random numbers until the generation count of 1,000,000).

Thanks,

Surya

0 Likes
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi Surya,

You could try to generate a 32bit by 

rndNum = (rndNum1<<16) | ranNum2;

 

However, as prevous descripted, this is not a real random number, which is a sequence repeatedly by same SEED to generate. 

dw

0 Likes
ursurya007
Level 1
Level 1
10 sign-ins 5 replies posted 5 sign-ins

Hi dw,

Thank you.. I am able to get 32 bit random number. But there is 1 issue i am facing currently.

I am following below sequence to generate the random numbers

srand(time(NULL)); --> Calling from "EcuM_AL_DriverInitZero" during initalization time

Below 3 lines are calling from Cyclic task (25ms) to generate random numbers.

rand_seed1 = rand();
rand_seed2 = rand();
rand_seed = ((rand_seed1 << 16) | (rand_seed2));

But my main intention is to call above 3 lines of code in the security access, when i have requested for security unlock. If i am going to call above 3 lines at the "event based task", then everytime it is generating same random number.

Is there any restriction for rand() to generate different random numbers in the cyclic task?

Thanks,

Surya

0 Likes
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi ursurya,

1) Check srand() during initialization,  and record first random number and SEED after cold/warm Reset 

2) For the same SEED, all the following rand() will be same sequence as above code example I already provided, however, everytime you call rand() should give different number.

3) About debugging, first you should using main() to generate a random sequence after everytime reset. If it's fine, then move the rand() to task.

 

 

 

 

0 Likes
ursurya007
Level 1
Level 1
10 sign-ins 5 replies posted 5 sign-ins

Hello Dw,

Thank you for the reply

I have observed time() function is always returning maximum value 0xFFFFFFFF

I have used time(NULL), time(0) and time(&Var)..

But all the above functions are returning maximum value or 0xFFFFFFFF

Thanks,

Surya

0 Likes