Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cbsspeke
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Charles Wright
Cbsspeke
Commits
519df62c
Commit
519df62c
authored
3 years ago
by
Charles Wright
Browse files
Options
Downloads
Patches
Plain Diff
More portable (linux compatible) random number generation
parent
de806e5d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bsspeke.c
+18
-4
18 additions, 4 deletions
bsspeke.c
with
18 additions
and
4 deletions
bsspeke.c
+
18
−
4
View file @
519df62c
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment