Hello,
How would I go about implementing a CSRPNG on the RP2040?
In MicroPython there is:In the SDK:Both implementations use the ROSC, however the RP2040 Datasheet clearly states that it shouldn't be used for crypto since it can be compromised (side-channel attacks?).
The idea is to keep it simple: just get a good enough entropy source to seed a Sponge (https://keccak.team/files/SpongePRNG.pdf).
Ideally, this wouldn't require any extra components, since portability is a goal here.
How would I go about implementing a CSRPNG on the RP2040?
In MicroPython there is:
Code:
uint8_t rosc_random_u8(size_t cycles) { static uint8_t r; for (size_t i = 0; i < cycles; ++i) { r = ((r << 1) | rosc_hw->randombit) ^ (r & 0x80 ? POLY : 0); mp_hal_delay_us_fast(1); } return r;}uint32_t rosc_random_u32(void) { uint32_t value = 0; for (size_t i = 0; i < 4; ++i) { value = value << 8 | rosc_random_u8(32); } return value;}
Code:
// we won the race (if any) for the bit, so we collect it locally samples <<= 1; samples |= rosc_hw->randombit & 1u; // use of relative time to now, rather than offset from before makes things // a bit less predictable at the cost of some speed. next_sample_time = make_timeout_time_us(PICO_RAND_MIN_ROSC_BIT_SAMPLE_TIME_US);
The idea is to keep it simple: just get a good enough entropy source to seed a Sponge (https://keccak.team/files/SpongePRNG.pdf).
Ideally, this wouldn't require any extra components, since portability is a goal here.
Statistics: Posted by 0x67757300 — Sat Dec 23, 2023 11:43 pm