#include #include #include #include static std::string base64(const unsigned char *data, size_t length) { std::array output{}; sodium_bin2base64(output.data(), output.size(), data, length, sodium_base64_VARIANT_ORIGINAL_NO_PADDING); return output.data(); } int main(int argc, char **argv) { if (argc != 2 || sodium_init() < 0) return 1; std::ofstream output(argv[1]); output << "{\"hashes\":["; const std::array passwords{"voicecat test", "caf\xc3\xa9", std::string("a\0b", 3)}; std::array salt{}; for (size_t i = 0; i < salt.size(); ++i) salt[i] = static_cast(i); for (size_t i = 0; i < passwords.size(); ++i) { std::array hash{}; if (crypto_pwhash(hash.data(), hash.size(), passwords[i].data(), passwords[i].size(), salt.data(), 2, 64 * 1024 * 1024, crypto_pwhash_ALG_ARGON2ID13) != 0) return 1; if (i) output << ','; output << "{\"passwordBase64\":\"" << base64(reinterpret_cast(passwords[i].data()), passwords[i].size()) << "\",\"hash\":\"$argon2id$v=19$m=65536,t=2,p=1$" << base64(salt.data(), salt.size()) << '$' << base64(hash.data(), hash.size()) << "\"}"; } output << "]}\n"; return output ? 0 : 1; }