Skip to content
Snippets Groups Projects
Commit 519df62c authored by Charles Wright's avatar Charles Wright
Browse files

More portable (linux compatible) random number generation

parent de806e5d
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,16 @@ void print_point(const char *label,
printf("]\n");
}
void
generate_random_bytes(uint8_t *buf, size_t len)
{
#ifdef linux
getrandom(buf, len, 0);
#else
arc4random_buf(buf, len);
#endif
}
void
bsspeke_client_init(bsspeke_client_ctx *ctx,
const char* client_id, const size_t client_id_len,
......@@ -116,7 +126,8 @@ bsspeke_client_generate_message1
// * Then use the inverse of 1/r as `r`
// FIXME: On second thought, monocypher seems to handle all of this complexity for us. Let's see what happens if we just do things the straightforward way for now...
debug(DEBUG, "Generating random blind `r`");
arc4random_buf(client->r, 32);
//arc4random_buf(client->r, 32);
generate_random_bytes(client->r, 32);
print_point("r", client->r);
debug(DEBUG, "Clamping r");
crypto_x25519_clamp(client->r);
......@@ -155,7 +166,8 @@ bsspeke_server_setup_generate_message2
// So we have to create a new random salt for the user
debug(DEBUG, "Generating new salt");
user_info->salt_len = 32;
arc4random_buf(user_info->salt, user_info->salt_len);
//arc4random_buf(user_info->salt, user_info->salt_len);
generate_random_bytes(user_info->salt, user_info->salt_len);
print_point("salt", user_info->salt);
// Hash the salt
......@@ -313,7 +325,8 @@ bsspeke_server_login_generate_message2(bsspeke_login_msg2_t *msg2,
// Generate random ephemeral private key b, save it in ctx->b
debug(DEBUG, "Generating ephemeral private key b");
arc4random_buf(server->b, 32);
//arc4random_buf(server->b, 32);
generate_random_bytes(server->b, 32);
crypto_x25519_clamp(server->b);
print_point("b", server->b);
......@@ -406,7 +419,8 @@ bsspeke_client_login_generate_message3(bsspeke_login_msg3_t *msg3,
// Generate a random ephemeral private key a, store it in ctx->a
debug(DEBUG, "Generating ephemeral private key a");
arc4random_buf(client->a, 32);
//arc4random_buf(client->a, 32);
generate_random_bytes(client->a, 32);
crypto_x25519_clamp(client->a);
print_point("a", client->a);
// Generate the ephemeral public key A = a * P, store it in msg3->A
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment