I have a pair of board, which includes the Bearssl library to do some encryption.
I use the br_rsa_i15_keygen
to sucessfully generate a pair of the RSA key, which includes the public key and the private key.
And I want to sent the key to the client board which are the same model.
I originally write some code like below to send the key to the client:
bool trans_pk(WiFiClient &client, br_rsa_public_key &t_pk)
{
char t_pkn[t_pk.nlen] = {0};
for (int i = 0; i < t_pk.nlen; i++)
{
t_pkn[i] = (char)t_pk.n[i];
}
// The function to do Socket Transfer
// transfer_sock(WiFiClient &client, const char *data, uint8_t dsize)
transfer_sock(client, t_pkn, t_pk.nlen);
//...the "e" part of the code same as the "n” part, only changes some variable name
return true;
}
But I assumes maybe to prevent some time attack so the "n" array will change after few time so it not works, which method can I use to sucessfully transfer key?
Edit 1:
I also tried to add this code into the trans_pk
and before transfer_sock
to see the data and I observed the data of the array seems like changes constantly:
for (int i = 0; i < t_pk.nlen; i++)
{
Serial.printf("%02x ", t_pk.n[i]);
}
Serial.printf("\n");
delay(1000);
for (int i = 0; i < t_pk.nlen; i++)
{
Serial.printf("%02x ", t_pk.n[i]);
}
Serial.printf("\n");