コード例 #1
1
ファイル: run.c プロジェクト: PlasmaPower/phc-winner-argon2
/*
Runs Argon2 with certain inputs and parameters, inputs not cleared. Prints the
Base64-encoded hash string
@out output array with at least 32 bytes allocated
@pwd NULL-terminated string, presumably from argv[]
@salt salt array
@t_cost number of iterations
@m_cost amount of requested memory in KB
@lanes amount of requested parallelism
@threads actual parallelism
@type String, only "d" and "i" are accepted
@encoded_only display only the encoded hash
@raw_only display only the hexadecimal of the hash
*/
static void run(uint32_t outlen, char *pwd, char *salt, uint32_t t_cost,
                uint32_t m_cost, uint32_t lanes, uint32_t threads,
                argon2_type type, int encoded_only, int raw_only) {
    clock_t start_time, stop_time;
    size_t pwdlen, saltlen, encodedlen;
    int result;

    start_time = clock();

    if (!pwd) {
        fatal("password missing");
    }

    if (!salt) {
        secure_wipe_memory(pwd, strlen(pwd));
        fatal("salt missing");
    }

    pwdlen = strlen(pwd);
    saltlen = strlen(salt);
    if(UINT32_MAX < saltlen) {
        fatal("salt is too long");
    }

    UNUSED_PARAMETER(lanes);

    unsigned char* out = malloc(outlen + 1);
    if (!out) {
        secure_wipe_memory(pwd, strlen(pwd));
        fatal("could not allocate memory for output");
    }

    encodedlen = argon2_encodedlen(t_cost, m_cost, lanes, (uint32_t)saltlen, outlen);
    char* encoded = malloc(encodedlen + 1);
    if (!encoded) {
        secure_wipe_memory(pwd, strlen(pwd));
        fatal("could not allocate memory for hash");
    }

    result = argon2_hash(t_cost, m_cost, threads, pwd, pwdlen, salt, saltlen,
                         out, outlen, encoded, encodedlen, type,
                         ARGON2_VERSION_NUMBER);
    if (result != ARGON2_OK)
        fatal(argon2_error_message(result));

    stop_time = clock();

    if (encoded_only)
        puts(encoded);

    if (raw_only)
        print_hex(out, outlen);

    if (encoded_only || raw_only) {
        free(out);
        free(encoded);
        return;
    }

    printf("Hash:\t\t");
    print_hex(out, outlen);
    free(out);

    printf("Encoded:\t%s\n", encoded);

    printf("%2.3f seconds\n",
           ((double)stop_time - start_time) / (CLOCKS_PER_SEC));

    result = argon2_verify(encoded, pwd, pwdlen, type);
    if (result != ARGON2_OK)
        fatal(argon2_error_message(result));
    printf("Verification ok\n");
    free(encoded);
}
コード例 #2
0
ファイル: argon2.c プロジェクト: DarkDare/phc-winner-argon2
int argon2i_verify(const char *encoded, const void *pwd, const size_t pwdlen) {

    return argon2_verify(encoded, pwd, pwdlen, Argon2_i);
}
コード例 #3
0
ファイル: libargon2.c プロジェクト: alipha/csharp-argon2
int crypto_argon2_verify(const char *encoded, const void *pwd,
	const size_t pwdlen, argon2_type type)
{
	return argon2_verify(encoded, pwd, pwdlen, type);
}
コード例 #4
0
ファイル: run.c プロジェクト: jedisct1/phc-winner-argon2
/*
Runs Argon2 with certain inputs and parameters, inputs not cleared. Prints the
Base64-encoded hash string
@out output array with at least 32 bytes allocated
@pwd NULL-terminated string, presumably from argv[]
@salt salt array with at least SALTLEN_DEF bytes allocated
@t_cost number of iterations
@m_cost amount of requested memory in KB
@lanes amount of requested parallelism
@threads actual parallelism
@type String, only "d" and "i" are accepted
*/
static void run(uint32_t outlen, char *pwd, char *salt, uint32_t t_cost,
                uint32_t m_cost, uint32_t lanes, uint32_t threads,
                argon2_type type) {
    clock_t start_time, stop_time;
    size_t pwdlen, saltlen, encodedlen;
    uint32_t i;
    int result;

    start_time = clock();

    if (!pwd) {
        fatal("password missing");
    }

    if (!salt) {
        secure_wipe_memory(pwd, strlen(pwd));
        fatal("salt missing");
    }

    pwdlen = strlen(pwd);
    saltlen = strlen(salt);

    UNUSED_PARAMETER(lanes);

    unsigned char* out = malloc(outlen + 1);
    if (!out) {
        secure_wipe_memory(pwd, strlen(pwd));
        fatal("could not allocate memory for output");
    }

    encodedlen = enclen(outlen, saltlen, t_cost, m_cost, lanes);
    char* encoded = malloc(encodedlen + 1);
    if (!encoded) {
        secure_wipe_memory(pwd, strlen(pwd));
        fatal("could not allocate memory for hash");
    }

    result = argon2_hash(t_cost, m_cost, threads, pwd, pwdlen, salt, saltlen,
                         out, outlen, encoded, encodedlen, type);
    if (result != ARGON2_OK)
        fatal(argon2_error_message(result));

    stop_time = clock();

    printf("Hash:\t\t");
    for (i = 0; i < outlen; ++i) {
        printf("%02x", out[i]);
    }
    free(out);
    printf("\n");
    printf("Encoded:\t%s\n", encoded);

    printf("%2.3f seconds\n",
           ((double)stop_time - start_time) / (CLOCKS_PER_SEC));

    result = argon2_verify(encoded, pwd, pwdlen, type);
    if (result != ARGON2_OK)
        fatal(argon2_error_message(result));
    printf("Verification ok\n");
    free(encoded);
}