Fast cryptographically safe GUID generator for Go
1–10 of 43 posts
Re: Fast cryptographically safe GUID generator for Go
#2I'm interested in feedback from the HN community.
Re: Fast cryptographically safe GUID generator for Go
#3Much faster (~10x) than standard github.com/google/uuid package I'm interested in feedback from the HN community.
Re: Fast cryptographically safe GUID generator for Go
#4- This uses global state under the hood. Surprise! Is it thread safe? I’m not a Go expert, but it looks non-thread-safe.
- The copying code reminds me of old-school awful C buffer handling code. Maybe it’s right. Maybe it’s wrong. But it’s not obviously right.
- The actual meat is a cryptographic randomness cache. This is a subtle thing, and all the best practices are missing. Where’s the backtracking protection? What if the program forks? vDSO getrandom() knows how to do this correctly — something high-level should use it, not reimplement it incorrectly.
Re: Fast cryptographically safe GUID generator for Go
#5Much faster (~10x) than standard github.com/google/uuid package I'm interested in feedback from the HN community.
Why is it so much faster than `uuid`?
Re: Fast cryptographically safe GUID generator for Go
#6On an extremely quick review: - This uses global state under the hood. Surprise! Is it thread safe? I’m not a Go expert, but it looks non-thread-safe. - The copying code reminds me of old-school awful C buffer handling code. Maybe it’s right. Maybe it’s wrong. But it’s not obviously right. - The actual meat is a cryptographic randomness cache. This is a subtle thing, and all the best practices are missing. Where’s th…
Re: Fast cryptographically safe GUID generator for Go
#7If it isn't meant to follow the RFC, … just find a new word. (There are plenty of alternate schemes out there, too.)
Re: Fast cryptographically safe GUID generator for Go
#8Re: Fast cryptographically safe GUID generator for Go
#9Earlier quoted context omitted.
Why is it so much faster than `uuid`?
It generates entropy 4kb-at-a-time (instead of on each call), and uses a cache-pool instead of single cache behind a lock (which is what standard uuid does in "RandPool=ON" mode).
The Linux kernel now has an optimization that makes it safe: https://lwn.net/Articles/983186/
Go should automatically benefit from this, if they use the vDSO getrandom().
Re: Fast cryptographically safe GUID generator for Go
#10On an extremely quick review: - This uses global state under the hood. Surprise! Is it thread safe? I’m not a Go expert, but it looks non-thread-safe. - The copying code reminds me of old-school awful C buffer handling code. Maybe it’s right. Maybe it’s wrong. But it’s not obviously right. - The actual meat is a cryptographic randomness cache. This is a subtle thing, and all the best practices are missing. Where’s th…
Unsafe use also looks fine, values either don't escape the function (a type string->byte type cast for function signature reasons) or they do but they're new temporary data (the byte->string cast, which is fine because there's no risk of reusing or modifying the original bytes).
I'm going to intentionally not make any claims to "cryptographic security" or "is this a GUID" as I'm not super clear on the details there. The code looks pretty normal to me though, with the possible exception of the base64 encoding (why not base64.URLEncoding? https://pkg.go.dev/encoding/base64#pkg-variables).