Skip to content

Commit 3f10496

Browse files
add weak source of entropy on microblaze to test with
1 parent 3901fa6 commit 3f10496

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

wolfcrypt/src/random.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,26 @@ static WC_INLINE word64 Entropy_TimeHiRes(void)
809809
);
810810
return cnt;
811811
}
812+
#elif !defined(ENTROPY_MEMUSE_THREAD) && defined(__MICROBLAZE__)
813+
814+
#define LPD_SCNTR_BASE_ADDRESS 0xFF250000
815+
816+
/* Get the high resolution time counter.
817+
* Collect ticks from LPD_SCNTR
818+
* @return 64-bit tick count.
819+
*/
820+
static WC_INLINE word64 Entropy_TimeHiRes(void)
821+
{
822+
word64 cnt;
823+
word32 *ptr;
824+
825+
ptr = (word32*)LPD_SCNTR_BASE_ADDRESS;
826+
cnt = *(ptr+1);
827+
cnt = cnt << 32;
828+
cnt |= *ptr;
829+
830+
return cnt;
831+
}
812832
#elif !defined(ENTROPY_MEMUSE_THREAD) && (_POSIX_C_SOURCE >= 199309L)
813833
/* Get the high resolution time counter.
814834
*
@@ -3515,6 +3535,26 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
35153535
* extern int myRngFunc(byte* output, word32 sz);
35163536
*/
35173537

3538+
#elif defined(__MICROBLAZE__)
3539+
#warning weak source of entropy
3540+
#define LPD_SCNTR_BASE_ADDRESS 0xFF250000
3541+
3542+
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
3543+
{
3544+
word32* cnt;
3545+
word32 i;
3546+
3547+
/* using current time with srand */
3548+
cnt = (word32*)LPD_SCNTR_BASE_ADDRESS;
3549+
srand(*cnt | *(cnt+1));
3550+
3551+
for (i = 0; i < sz; i++)
3552+
output[i] = rand();
3553+
3554+
(void)os;
3555+
return 0;
3556+
}
3557+
35183558
#elif defined(WOLFSSL_ZEPHYR)
35193559

35203560
#include <version.h>

0 commit comments

Comments
 (0)