Khady / ocaml-argon2

Ocaml bindings to Argon2
MIT License
29 stars 8 forks source link

Don't return the NUL-terminator in hash_encoded #5

Closed dra27 closed 4 years ago

dra27 commented 4 years ago

On further use, I noticed that examples/examples.ml was printing the output of hash_encoded as though it was binary, which it's not! So I changed the example - then I noticed that hash_encoded is accidentally returning the NUL terminator from the C string.

I've double-checked the C code in the reference implementation - argon2_encodedlen definitely requires the space for the terminator to be included and it definitely writes the final NUL. hashlen definitely doesn't include a NUL terminator (and one is never written).

I've fixed this by subtracting 1 when the string is extracted, so that Argon2.encoded_len still returns the same value as the underlying C function (so it will necessarily be 1 more than the length of the OCaml string actually returned).

Khady commented 4 years ago

thanks!