/* Wrapper for argon Ruby bindings * lolware.net * Much of this code is based on run.c from the reference implementation */ #include #include #include #include #include #include #include #include "argon2.h" #define OUT_LEN 32 #define SALT_LEN 16 /** * Hashes a password with Argon2i, producing a raw hash * @param t_cost Number of iterations * @param m_cost Sets memory usage to 2^m_cost kibibytes * @param parallelism Number of threads and compute lanes * @param pwd Pointer to password * @param pwdlen Password size in bytes * @param salt Pointer to salt * @param saltlen Salt size in bytes * @param hash Buffer where to write the raw hash * @param hashlen Desired length of the hash in bytes * @pre Different parallelism levels will give different results * @pre Returns ARGON2_OK if successful int argon2i_hash_raw(const uint32_t t_cost, const uint32_t m_cost, const uint32_t parallelism, const void *pwd, const size_t pwdlen, const void *salt, const size_t saltlen, void *hash, const size_t hashlen); */ unsigned int argon2_wrap(char *out, const char *pwd, size_t pwd_length, uint8_t *salt, uint32_t saltlen, uint32_t t_cost, uint32_t m_cost, uint32_t lanes, uint8_t *secret, size_t secretlen); int wrap_argon2_verify(const char *encoded, const char *pwd, const size_t pwdlen, uint8_t *secret, size_t secretlen); int main() { unsigned char out[OUT_LEN]; unsigned char hex_out[OUT_LEN*2 + 4]; /* Allow space for NULL byute */ char out2[300]; char *pwd = NULL; uint8_t salt[SALT_LEN]; int i, ret; memset(salt, 0x00, SALT_LEN); /* pad with null bytes */ memcpy(salt, "somesalt", 8); #define RAWTEST(T, M, P, PWD, REF) \ pwd = strdup(PWD); \ assert(pwd); \ ret = argon2i_hash_raw(T, 1<