Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to set the RNG function? #205

Open
ZahidKamil opened this issue Feb 28, 2023 · 2 comments
Open

how to set the RNG function? #205

ZahidKamil opened this issue Feb 28, 2023 · 2 comments

Comments

@ZahidKamil
Copy link

Hi, I would like to know how to set the RNG function.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void generate_random_bytes(unsigned char *buffer, size_t size) {
    // Set the seed value
    srand(time(0));

    // Generate random bytes
    for (size_t i = 0; i < size; i++) {
        buffer[i] = (unsigned char) rand();
    }
}

int main() {
    // Generate 10 random bytes
    size_t size = 10;
    unsigned char buffer[size];

    generate_random_bytes(buffer, size);

    // Output the generated random bytes
    printf("Random bytes: ");
    for (size_t i = 0; i < size; i++) {
        printf("%02x", buffer[i]);
    }
    printf("\n");

    return 0;
}

How would I set this code as my RNG function in uECC_set_rng?

@uc-mani
Copy link

uc-mani commented Mar 16, 2023

I guess you can check the line where the default_RNG function is defined.
#if default_RNG_defined
static uECC_RNG_Function g_rng_function = &default_RNG;
#else
static uECC_RNG_Function g_rng_function = 0;
#endif

probably replacing it with your function in "platform-specific.h"

@yasmineantille
Copy link

You can just set it in your main function. If generate_random_bytes is the random function you want to use do it as follows:

int main() {
     uECC_set_rng((uECC_RNG_Function)generate_random_bytes);
     // rest of your code
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants