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).
On further use, I noticed that
examples/examples.ml
was printing the output ofhash_encoded
as though it was binary, which it's not! So I changed the example - then I noticed thathash_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).