Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UUID loses 2 bits of entropy #559

Closed
dchest opened this issue Aug 10, 2019 · 0 comments · Fixed by #580
Closed

UUID loses 2 bits of entropy #559

dchest opened this issue Aug 10, 2019 · 0 comments · Fixed by #580

Comments

@dchest
Copy link

dchest commented Aug 10, 2019

UUIDv4 includes 4 bits as version number and 2 or 3 bits as variant. This code:

export default function generate(): string {
  return "00000000-0000-4000-8000-000000000000".replace(
    /[0]/g,
    (): string =>
      // random integer from 0 to 15 as a hex digit.
      (crypto.getRandomValues(new Uint8Array(1))[0] % 16).toString(16)
  );
}

takes 4 bits for variant instead (8 is hard-coded), so it can generate only 2^120 uuids instead of 2^122.

@ry ry closed this as completed in #580 Sep 11, 2019
inverted-capital pushed a commit to dreamcatcher-tech/napps that referenced this issue Oct 24, 2024
…d#559)

fixes denoland#472 

@iuioiua this is as simple as I got, without being too intrusive; I
personally like it; the problem was a bug regarding the state change of
the variable `isLoadingSig`, I was able to avoid it by initializing the
variable as `undefined` and bypassing it with the conditional rendering
not sure if is worth taking another look at it some other time.

Note: The simplicity of this PR does not reflect at all the time that
took me to get there — just for the record.

---------

Co-authored-by: Asher Gomez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant