forked from wolfSSL/wolfssl
PIC32MZ RNG
This commit is contained in:
@ -460,29 +460,78 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
|||||||
|
|
||||||
#elif defined(MICROCHIP_PIC32)
|
#elif defined(MICROCHIP_PIC32)
|
||||||
|
|
||||||
#ifdef MICROCHIP_MPLAB_HARMONY
|
#ifdef MICROCHIP_MPLAB_HARMONY
|
||||||
#define PIC32_SEED_COUNT _CP0_GET_COUNT
|
#define PIC32_SEED_COUNT _CP0_GET_COUNT
|
||||||
#else
|
#else
|
||||||
#if !defined(CYASSL_MICROCHIP_PIC32MZ)
|
#if !defined(CYASSL_MICROCHIP_PIC32MZ)
|
||||||
#include <peripheral/timer.h>
|
#include <peripheral/timer.h>
|
||||||
|
#endif
|
||||||
|
#define PIC32_SEED_COUNT ReadCoreTimer
|
||||||
#endif
|
#endif
|
||||||
#define PIC32_SEED_COUNT ReadCoreTimer
|
|
||||||
|
#ifdef CYASSL_MIC32MZ_RNG
|
||||||
|
#include "xc.h"
|
||||||
|
int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||||
|
{
|
||||||
|
int i ;
|
||||||
|
byte rnd[8] ;
|
||||||
|
word32 *rnd32 = (word32 *)rnd ;
|
||||||
|
word32 size = sz ;
|
||||||
|
byte* op = output ;
|
||||||
|
|
||||||
|
RNGNUMGEN1 = ReadCoreTimer();
|
||||||
|
RNGPOLY1 = 0x01020304;
|
||||||
|
RNGPOLY2 = 0x05060709;
|
||||||
|
RNGNUMGEN2 = ReadCoreTimer();
|
||||||
|
#ifdef DEBUG_CYASSL
|
||||||
|
printf("GenerateSeed::Seed=%08x, %08x\n", RNGNUMGEN1, RNGNUMGEN2) ;
|
||||||
#endif
|
#endif
|
||||||
|
RNGCONbits.PLEN = 0x40;
|
||||||
|
RNGCONbits.PRNGEN = 1;
|
||||||
|
for(i=0; i<3; i++) { /* wait for RNGNUMGEN ready */
|
||||||
|
volatile int x ;
|
||||||
|
x = RNGNUMGEN1 ;
|
||||||
|
x = RNGNUMGEN2 ;
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
rnd32[0] = RNGNUMGEN1;
|
||||||
|
rnd32[1] = RNGNUMGEN2;
|
||||||
|
|
||||||
/* uses the core timer, in nanoseconds to seed srand */
|
for(i=0; i<8; i++, op++) {
|
||||||
int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
*op = rnd[i] ;
|
||||||
{
|
size -- ;
|
||||||
int i;
|
if(size==0)break ;
|
||||||
srand(PIC32_SEED_COUNT() * 25);
|
}
|
||||||
|
} while(size) ;
|
||||||
|
|
||||||
for (i = 0; i < sz; i++ ) {
|
#ifdef DEBUG_CYASSL
|
||||||
output[i] = rand() % 256;
|
printf("\nReturn=") ;
|
||||||
if ( (i % 8) == 7)
|
for(i=0; i<sz; i++) {
|
||||||
|
printf("%02x", output[(i/4)*4 + (3-(i%4))]) ;
|
||||||
|
if((i+1)%4==0)putchar(',') ;
|
||||||
|
}
|
||||||
|
putchar('\n') ;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
srand(PIC32_SEED_COUNT() * 25);
|
srand(PIC32_SEED_COUNT() * 25);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
for (i = 0; i < sz; i++ ) {
|
||||||
}
|
output[i] = rand() % 256;
|
||||||
|
if ( (i % 8) == 7)
|
||||||
|
srand(PIC32_SEED_COUNT() * 25);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#elif defined(CYASSL_SAFERTOS) || defined(CYASSL_LEANPSK)
|
#elif defined(CYASSL_SAFERTOS) || defined(CYASSL_LEANPSK)
|
||||||
|
|
||||||
@ -573,7 +622,7 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#warning "write a real random seed!!!!, just for testing now"
|
#warning "write a real random seed!!!!, just for testing now"
|
||||||
|
|
||||||
int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||||
@ -584,7 +633,7 @@ int GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* FREESCALE_K70_RNGA */
|
#endif /* FREESCALE_K70_RNGA */
|
||||||
|
|
||||||
#elif defined(STM32F2_RNG)
|
#elif defined(STM32F2_RNG)
|
||||||
#undef RNG
|
#undef RNG
|
||||||
|
Reference in New Issue
Block a user