HAVEGE on Spark Core

TropicSSL is included in Spark’s firmware, and it provides an implementation of the HAVEGE algorithm for generating pseudo-random numbers.

Does anyone know how effective one can expect this algorithm to be on the Spark Core? Can it provide decent entropy, or does it make more sense to use pre-computed random seeds with another PRNG algorithm?

1 Like

Hi, sorry for the very delayed response, I’ve only just seen this thread (oh, discourse!) :stuck_out_tongue:

Our distribution of TropicSSL isn’t a complete implementation - we only include the minimum necessary to support the cloud protocol. Consequently the HAVEGE PRNG isn’t included in our distribution.

However, you can always add the library/havege.c file in your own application. This is probably best rather than relying upon internal details, which may change between releases or different products.

PS: The random seed is set during handshake to a cryptographically secure random number from the cloud. Naturally, subsequent random numbers are only as strong as the PRNG used.

PPS: On the photon, we have access to a true RNG on the STM32F2 via uint32_t HAL_RNG_GetRandomNumber() in rng_hal.h. We are working to exposing this via a more friendlier interface - putting this here now in case it’s useful.

Hi @vace117,

Just wanted to jump in and say that you can ask for a chunk of random data from the cloud anytime using events!

void handler(const char *topic, const char *data) {
    Serial.println("received " + String(topic) + ": " + String(data));
void setup() {
    for(int i=0;i<5;i++) {
        Serial.println("waiting... " + String(5 - i));
    Spark.subscribe("spark/", handler);
void loop() {