Closed OTP-Maintainer closed 3 years ago
starbelly
said:
Firstly let me state that I appreciate the time put into all this. Despite the PRs being rejected I learned a lot, in particularly around the ERTS, and that in and of itself made the attempt worth it. The commentary by members of the OTP team on the PRs were also very educational.
- I did offer to do an erlang implementation as an alternative to the C implementation in the PRs FWIW. In testing I
found more variance in the erlang implementation vs in C. Though, I think that should be checked by another party, as perhaps my tests were flawed or perhaps the code could be re-written to eliminate said variance. It also may be the
variance is acceptable. After all, a little variance is better than returning early on the first difference between two binaries or lists.
- One of the possible problems with having to go through a NIF implementation for such a function is a realloc that can
occur in the face of unaligned sub binaries, AFAIK. Is there a way to avoid this currently in the context of a NIF? Could a way be made available?
- An alternative to such a function existing in either crypto or binary might be a new module : crypto_lib. Functions written in erlang (possibly other langs) could live here and be made available even if you compile without openssl (or a compat lib).
- Cases that live outside the context of ssl and ssh is any scenario where authentication must be performed using tokens. Said tokens might not be hashes (thus the name hash_equals I do not believe makes sense). Web applications are one such area where tokens must be verified securely as possible on each request.
john
said:
{quote}I did offer to do an erlang implementation as an alternative to the C implementation in the PRs FWIW. In testing I
found more variance in the erlang implementation vs in C. Though, I think that should be checked by another party, as perhaps my tests were flawed or perhaps the code could be re-written to eliminate said variance. It also may be the
variance is acceptable. After all, a little variance is better than returning early on the first difference between two binaries or lists.
{quote}
Variance is not a problem per se, the important thing is that it never varies depending on how the terms compare.
{quote}One of the possible problems with having to go through a NIF implementation for such a function is a realloc that can occur in the face of unaligned sub binaries, AFAIK. Is there a way to avoid this currently in the context of a NIF? Could a way be made available?
{quote}
Even if you avoid reallocation, unaligned accesses are more expensive than aligned ones on all but the most exotic hardware, so you'll leak that either way.
Knowing whether it's byte-aligned in memory doesn't say anything about the secret itself though, so I think we can leave that alone.
{quote}An alternative to such a function existing in either crypto or binary might be a new module : crypto_lib. Functions written in erlang (possibly other langs) could live here and be made available even if you compile without openssl (or a compat lib).
{quote}
I don't think this is useful without {{crypto}}. You need encryption to begin with if you care about keeping things secret, and if you're using a different library for that then said library can expose a similar function.
{quote}Cases that live outside the context of ssl and ssh is any scenario where authentication must be performed using tokens. Said tokens might not be hashes (thus the name hash_equals I do not believe makes sense). Web applications are one such area where tokens must be verified securely as possible on each request.
{quote}
We're open to suggestions, but we'd like to avoid anything that implies that it's suitable for iffy uses like comparing passwords.
starbelly
said:
I think those are all fair points (y)
Original reporter:
hans
Affected version:OTP-24.0
Component:crypto
Migrated from: https://bugs.erlang.org/browse/ERL-1385