Currently, the library isn't considered ready for use, but it works.
Link in the library in your ARM7 code BEFORE all the devkitPro libraries you use.
LIBS := -lnds_getentropy7 -lnds7
In your ARM7 program:
#include <nds_getentropy.h>
int
main(void)
{
unsigned char entropy[20];
...
arm7_getentropy(entropy, sizeof(entropy);
/* entropy now contains a random sequence of bytes. */
...
}
Make sure you initialize the hardware properly like the default ARM7 program does.
The interface is almost the same as the BSD getentropy()
:
https://man.openbsd.org/getentropy.2
The only difference is that getentropy()
can be called from anywhere, whereas
arm7_getentropy()
may only be called from the ARM7.
While writing a previous version that was never commited to git, I used my example code to debug and saw that the result would only change once a second. It seems some entropy sources don't actually work, I need to write a separate program to print them and see what's wrong.
The example's output is wrong under DeSmuME:
Why does it print all zeroes? A SHA1 hash of a buffer full of zeroes isn't all zeroes, so even if the time of day or the temperature were 0, the returned entropy wouldn't be 0. As it currently stands, the library doesn't work under DeSmuME.