credential icon indicating copy to clipboard operation
credential copied to clipboard

Inconsistent use of bytes length/encodings?

Open raxell opened this issue 6 years ago • 3 comments

createSalt generates keyLength bytes and then transform it in a base64 string. This string is passed to pbkdf2 as salt, but pbkdf2 treats strings as utf8, so the given salt is not the same random sequence of bytes generated early.
Can be assumed that the salt is still random even if has been expanded by the inconsistent use of the encodings? Are there any security implications? Usually in cryptography when you introduce some fixed points you open yourself to some kind of attacks.

raxell avatar Feb 12 '19 18:02 raxell

createSalt generates keyLength bytes and then transform it in a base64 string. This string is passed to pbkdf2 as salt, but pbkdf2 treats strings as utf8, so the given salt is not the same random sequence of bytes generated early.

I'm not sure I understand the question. Doesn't UTF8 deterministically encode all base64 strings? Where does the inconsistency arise?

ericelliott avatar Feb 13 '19 02:02 ericelliott

Where does the inconsistency arise?

The thing is that the lib is encoding the bytes with one encoding and decoding it with a different one. The decoding is not explicit in this lib, but is done by the pbkdf2 of the crypto module.
I don't know if this can be a problem, just asking if it is. The salt given to pbkdf is a 88 byte sequence, not the 66 bytes randomly generated

raxell avatar Feb 13 '19 08:02 raxell

So, I assume, with my newbie cryptography knowledge, that the entropy is by definition the same regardless of how you encode the bytes. If that is the only desirable property of the salt, it may be alright. I don't know if it can cause unintended side-effects though. I would also guess that the back and forth encoding would mean the bytes get a pattern (usually not good for randomness) even if compensated for by length. I chose not to coerce types in https://github.com/srcagency/credentials due to the above unknowns.

tjconcept avatar Feb 13 '19 09:02 tjconcept