crypto,uuid: use a native UUIDv4 implementation#357
Merged
Conversation
Owner
Author
|
I still need to fixup the uuid4 library:
|
Contributor
|
I don't know what security properties you're aiming for but that library uses xorshift128+, which is not a CSPRNG. Maybe easiest is to obtain 16 bytes of randomness from libuv, patch in the 6 uuidv4 marker bits, and format it. |
Contributor
|
I suppose I should put my money where my mouth is. :-) What I mean is this: // usage:
// char s[37];
// int err = uuidv4(&s);
int uuidv4(char (*s)[37]) {
unsigned char u[16];
int err;
err = uv_random(NULL, NULL, u, sizeof(u), 0, NULL);
if (err)
return err;
u[6] &= 15;
u[6] |= 64; // '4x'
u[8] &= 63;
u[8] |= 128; // 0b10xxxxxx
snprintf(*s, sizeof(*s),
"%02x%02x%02x%02x-%02x%02x-%02x%02x-"
"%02x%02x-%02x%02x%02x%02x%02x%02x",
u[0], u[1], u[2], u[3], u[4], u[5], u[6], u[7],
u[8], u[9], u[10], u[11], u[12], u[13], u[14], u[15]);
return 0;
} |
Owner
Author
|
Ha, even simpler! I ended up replacing the seed material with uv_random. But I like yours better :-) |
Thanks @bnoordhuis for the nice and small uuid v4 implementation!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.