Skip to content

Commit

Permalink
Updated Soft_RNG library - v1.1 with Dual-Timer Entropy enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
mbedsyst committed Nov 8, 2024
1 parent c2cc3b6 commit c08629d
Show file tree
Hide file tree
Showing 10 changed files with 742 additions and 747 deletions.
Binary file modified Debug/Soft_RNG.elf
Binary file not shown.
1,104 changes: 549 additions & 555 deletions Debug/Soft_RNG.list

Large diffs are not rendered by default.

341 changes: 170 additions & 171 deletions Debug/Soft_RNG.map

Large diffs are not rendered by default.

Binary file modified Debug/Src/Soft_RNG.o
Binary file not shown.
2 changes: 1 addition & 1 deletion Debug/Src/main.cyclo
Original file line number Diff line number Diff line change
@@ -1 +1 @@
../Src/main.c:9:5:main 2
../Src/main.c:11:5:main 2
Binary file modified Debug/Src/main.o
Binary file not shown.
2 changes: 1 addition & 1 deletion Debug/Src/main.su
Original file line number Diff line number Diff line change
@@ -1 +1 @@
../Src/main.c:9:5:main 16 static
../Src/main.c:11:5:main 16 static
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Software Random Number Generator
A Software library to generate 32-bit Random Numbers using an onboard 32-bit Timer
A Software library to generate 32-bit Random Numbers using onboard 32-bit Timers
and a combination of LFSR, XOR Shift and the FNV hash function on an STM32F401
Nucleo Development Board
10 changes: 5 additions & 5 deletions Src/Soft_RNG.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ static void TIM2_Init(void)
static void TIM3_Init(void)
{
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
TIM2->CR1 |= TIM_CR1_DIR;
TIM2->PSC = 479;
TIM2->ARR = 0xFFFFFFFF;
TIM2->CR1 |= TIM_CR1_CEN;
TIM3->CR1 |= TIM_CR1_DIR;
TIM3->PSC = 479;
TIM3->ARR = 0xFFFFFFFF;
TIM3->CR1 |= TIM_CR1_CEN;
}

static uint32_t GetHardwareSeed(void)
Expand Down Expand Up @@ -69,7 +69,7 @@ uint32_t SoftRNG_Generate(void)
uint16_t seed16 = seedValue & 0xFFFF;
uint16_t lfsrVal = GetLFSR(seed16);
uint32_t xorVal = GetXORShift(seedValue);
uint32_t combined = (lfsrVal ^ xorVal) * 1664525 + 1013904223 ;
uint32_t combined = (lfsrVal & xorVal);
uint32_t randomVal = GetFNVHash(combined);
return randomVal;
}
28 changes: 15 additions & 13 deletions Src/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <stdio.h>
#include <stdint.h>

#include "LED.h"
#include "SYSTICK.h"
#include "W25Qxx.h"
Expand All @@ -8,21 +10,21 @@ uint32_t count = 0;

int main()
{
uint32_t random;
uint32_t random;

LED_Init();
W25Q_Init();
SoftRNG_Init();
LED_Init();
W25Q_Init();
SoftRNG_Init();

for(int i = 0; i < 100000; i++)
{
random = SoftRNG_Generate();
W25Q_WriteData(i, 0, 4, (uint8_t *)&random);
count++;
}
for(int i = 0; i < 10000; i++)
{
random = SoftRNG_Generate();
W25Q_WriteData(i, 0, 4, (uint8_t *)&random);
count++;
}

while(1)
{
while(1)
{

}
}
}

0 comments on commit c08629d

Please sign in to comment.