1 (edited by jesussotofan 2016-11-02 04:45:07)

Topic: [SOLVED] using rsa, "undefined reference to `wc_GenerateSeed'" error

Hi, I'm trying to test RSA encryption arduino.
Libs have imported correctly, but when I try to run the example I get the error:

"C: \ Users \ Eugenio \ AppData \ Local \ Temp \ ccDlIFnm.ltrans0.ltrans.o: In function` loop ':

: ( ccDlIFnm.ltrans0.o text + 0xc6c.): undefined reference to `wc_GenerateSeed '

collect2.exe: error: ld returned 1 exit status"

This is my code:

#include <wolfssl.h>
#include <wolfssl/wolfcrypt/rsa.h>

void setup(void){

  while(!Serial);
  Serial.begin(9600);
}
 
void loop(void){

RsaKey rsaPublicKey;
byte publicKeyBuffer[]  = {"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL+pEyWGAfj8NRW03Ox55IXMCLwCm1EjQ0mwonOjazvAkkwLSthUPmaCq2/A01843K3zqN40dslDUwYlfAg9hC8CAwEAAQ=="}; // holds the raw data from the key, maybe from a file like RsaPublicKey.der 
word32 idx = 0;             //  where to start reading into the buffer
byte in[] = {"hola mundohola mundohola mundoho"};
byte out[128];
RNG rng;
wc_InitRng(&rng);


wc_RsaPublicKeyDecode(publicKeyBuffer, &idx, &rsaPublicKey, sizeof(publicKeyBuffer));
word32 outLen = wc_RsaPublicEncrypt(in, sizeof(in), out, sizeof(out), &rsaPublicKey, &rng);

delay(3000);
}

Can you give me a hand?

Share

Re: [SOLVED] using rsa, "undefined reference to `wc_GenerateSeed'" error

Hi Jesussotofan,

Your platform must not have a random number seed function defined in random.c (starting at line 1133).

Either you can:
1. Locate a reference implementation in random.c and make sure you have the right define set for your hardware platform / OS.

2. Define CUSTOM_RAND_GENERATE_SEED and use your own implementation:

int rand_gen_seed(byte* output, word32 sz);
#define CUSTOM_RAND_GENERATE_SEED  rand_gen_seed

In your example above, I also recommend:
including:
#include <wolfssl/wolfcrypt/random.h>

Using WC_RNG for the rng global:
WC_RNG rng;

Let me know if you have anymore questions,

Thanks,
David Garske, wolfSSL

Share

Re: [SOLVED] using rsa, "undefined reference to `wc_GenerateSeed'" error

I am somewhat newbie and do not know how to carry out the second solution. Regarding the first solution I think placed correctly references, this since I am able to make the call to "wc_InitRng". I have included "random.h", but the result is the same.

Can you be more specific about how to define my own "CUSTOM_RAND_GENERATE_SEED" with an example?

Share

Re: [SOLVED] using rsa, "undefined reference to `wc_GenerateSeed'" error

Hi Jesussotofan,

I did a search for Arduino RNG and came up with this good result:
https://www.arduino.cc/en/Reference/Random

To implement option #2 you need to add the following to your settings.h or user_settins.h (if WOLFSSL_USER_SETTINGS is defined).

int rand_gen_seed(byte* output, word32 sz);
#define CUSTOM_RAND_GENERATE_SEED  rand_gen_seed

Then the function can be put into any .c file in your project (wherever it makes sense to you).

The function would look like:

int rand_gen_seed(byte* output, word32 sz)
{
    int i;
    for (i = 0; i < sz; i++ ) {
        output[i] = analogRead(0);
    }

    return 0;
}

Its important to have a good random seed, so if your micro controller has an RNG peripheral you should find example code for it and use it. The above example uses analog source 0 noise to seed the P-RNG, which is from the reference to website provided above.

Our random.c file has many references to RNG hardware implementations, so check and see if your micro-controller is already listed in there. If so you can define the value needed to enable it.

Let me know if you have any other questions.

Thanks,
David Garske, wolfSSL

Share

Re: [SOLVED] using rsa, "undefined reference to `wc_GenerateSeed'" error

Thanks for the reply.
The problem persists, and I think is because it is still makes the call to wc_generateSeed. The problem I don't know where the call occurs because I do not do directly. Besides, I can not quite fully understand the complex structure of wolfssl.
I know it sounds silly, but could you tell me where in my code makes the call to wc_generateSeed and try to change that part of the library?

Share

Re: [SOLVED] using rsa, "undefined reference to `wc_GenerateSeed'" error

Hi Jesussotofan,

All calls to wc_GenerateSeed are in wolfcrypt/src/random.c. There are multiple places where this function exists depending on the hardware platform. Those start at line 1133.

If you are defining CUSTOM_RAND_GENERATE_SEED then it will use the function used in that define. I'd also make sure you don't have NO_DEV_RANDOM defined.

The function wc_InitRng calls wc_GenerateSeed. Make sure the wolfcrypt/src/random.c is being included with the build. Make sure you have a wc_GenerateSeed function in your random.c or use the CUSTOM_RAND_GENERATE_SEED define to remap it to your own function.

Have you seen our Arduino example for wolfSSL?
https://github.com/wolfSSL/wolfssl/tree … DE/ARDUINO

Thanks,
David Garske, wolfSSL

Share