Conversation
So, that doesn't seem like a complete answer to that question. Sure, tweetnacl may use it, but we also are already using blake2 heavily in Shelter Protocol. So why should we add additional code to the codebase, thereby increasing the bundle size, and adding additional cognitive load through an extra decision added ("blake2 vs sha512?")? |
Mostly for things that are identifiers.
This looks like it's referring to two different things.
This part doesn't seem to deal with the choice of hash function. The reason for this is to be able to use these primitives for generating tokens, and that they can be handled like regular Shelter code. We do use blake2 in a few places in the codebase with ad-hoc constructions, but that's something that we probably should avoid, or at least not add more places of ad-hoc crypto. That makes things difficult to audit, difficult to write and difficult to maintain. Now, the purpose of this code in particular (HMAC primitives) is to make computing tokens (see the ephemeral messages doc):
Instead of having the app developer have to call SHA-256 (or blake2, or whatever), they can use this primitive, and instead of This would become something like:
The goal of this again is to reduce the cognitive load by just using HMAC can be applied to any hash function. However, besides it being what |
But we are not doing that. We are not "just using @chelonia/crypto" ourselves. We are using blake2 everywhere we use a hash function. Therefore it would make sense to me to continue to rely on blake2 for all of our hash/HMAC needs. This PR says, "No, let us use an additional hash function for this specific scenario". Again - why? Why not just continue to use blake2? We could add that to @chelonia/crypto, right? |
Yes, but mostly that's been for generating identifiers. And, fortunately, not in a lot of places (I say fortunately because there shouldn't be much need for raw hashes in the app, or that should be the goal)
That's not entirely true. We use:
If you feel strongly about this, I can switch it up to Blake. But it wouldn't be my first choice because:
|
|
Thanks, that's what I was looking for. I "feel strongly" about decisions being well-thought out and having reasons behind them. Your latest comment helps me understand those reasons better, thanks for taking the time to explain. I think we can go with this. 👍 |
|
Awesome. In any case, let's not make a release of this just yet. I'll try actually using it and see if it simplifies code the way I thought it would. |
This PR is part of the ephemeral messages series and adds a new key type,
HMACSHA512, along with correspondingverifySignatureandsignimplementations.Instead of having the app have low-level crypto code for implementing deletion tokens, we can use a new key type, which also has the advantage that deletion tokens can be handled as any other key (for example, for key rotations).
As for why choose
SHA-512and not some other algorithm (SHA-256, Blake, SHA-3 or a myriad of others), the main reason is that it's whattweetnaclprovides astweetnacl.hash.