Ejemplo n.º 1
0
int main(void)
{
    char       *str_out;
    char       *str_out2;
    char       *salt;
    const char *passwd = "Correct Horse Battery Staple";

    tv();
    tv2();
    salt = (char *) sodium_malloc(crypto_pwhash_SALTBYTES);
    str_out = (char *) sodium_malloc(crypto_pwhash_STRBYTES);
    str_out2 = (char *) sodium_malloc(crypto_pwhash_STRBYTES);
    memcpy(salt, ">A 16-bytes salt", crypto_pwhash_SALTBYTES);
    if (crypto_pwhash_str(str_out, passwd, strlen(passwd),
                          OPSLIMIT, MEMLIMIT) != 0) {
        printf("pwhash_str failure\n");
    }
    if (crypto_pwhash_str(str_out2, passwd, strlen(passwd),
                          OPSLIMIT, MEMLIMIT) != 0) {
        printf("pwhash_str(2) failure\n");
    }
    if (strcmp(str_out, str_out2) == 0) {
        printf("pwhash_str doesn't generate different salts\n");
    }
    if (crypto_pwhash_str_verify(str_out, passwd, strlen(passwd)) != 0) {
        printf("pwhash_str_verify failure\n");
    }
    if (crypto_pwhash_str_verify(str_out, passwd, strlen(passwd)) != 0) {
        printf("pwhash_str_verify failure\n");
    }
    str_out[14]++;
    if (crypto_pwhash_str_verify(str_out, passwd, strlen(passwd)) == 0) {
        printf("pwhash_str_verify(2) failure\n");
    }
    str_out[14]--;

    assert(str_out[crypto_pwhash_STRBYTES - 1U] == 0);
    assert(crypto_pwhash_saltbytes() > 0U);
    assert(crypto_pwhash_strbytes() > 1U);
    assert(crypto_pwhash_strbytes() > strlen(crypto_pwhash_strprefix()));
    assert(crypto_pwhash_opslimit_interactive() > 0U);
    assert(crypto_pwhash_memlimit_interactive() > 0U);
    assert(crypto_pwhash_opslimit_moderate() > 0U);
    assert(crypto_pwhash_memlimit_moderate() > 0U);
    assert(crypto_pwhash_opslimit_sensitive() > 0U);
    assert(crypto_pwhash_memlimit_sensitive() > 0U);

    sodium_free(salt);
    sodium_free(str_out);
    sodium_free(str_out2);

    printf("OK\n");

    return 0;
}
Ejemplo n.º 2
0
int
main(void)
{
    tv();
    tv2();
    tv3();
    str_tests();

    assert(crypto_pwhash_bytes_min() > 0U);
    assert(crypto_pwhash_bytes_max() > crypto_pwhash_bytes_min());
    assert(crypto_pwhash_passwd_max() > crypto_pwhash_passwd_min());
    assert(crypto_pwhash_saltbytes() > 0U);
    assert(crypto_pwhash_strbytes() > 1U);
    assert(crypto_pwhash_strbytes() > strlen(crypto_pwhash_strprefix()));

    assert(crypto_pwhash_opslimit_min() > 0U);
    assert(crypto_pwhash_opslimit_max() > 0U);
    assert(crypto_pwhash_memlimit_min() > 0U);
    assert(crypto_pwhash_memlimit_max() > 0U);
    assert(crypto_pwhash_opslimit_interactive() > 0U);
    assert(crypto_pwhash_memlimit_interactive() > 0U);
    assert(crypto_pwhash_opslimit_moderate() > 0U);
    assert(crypto_pwhash_memlimit_moderate() > 0U);
    assert(crypto_pwhash_opslimit_sensitive() > 0U);
    assert(crypto_pwhash_memlimit_sensitive() > 0U);
    assert(strcmp(crypto_pwhash_primitive(), "argon2i") == 0);

    assert(crypto_pwhash_bytes_min() == crypto_pwhash_BYTES_MIN);
    assert(crypto_pwhash_bytes_max() == crypto_pwhash_BYTES_MAX);
    assert(crypto_pwhash_passwd_min() == crypto_pwhash_PASSWD_MIN);
    assert(crypto_pwhash_passwd_max() == crypto_pwhash_PASSWD_MAX);
    assert(crypto_pwhash_saltbytes() == crypto_pwhash_SALTBYTES);
    assert(crypto_pwhash_strbytes() == crypto_pwhash_STRBYTES);

    assert(crypto_pwhash_opslimit_min() == crypto_pwhash_OPSLIMIT_MIN);
    assert(crypto_pwhash_opslimit_max() == crypto_pwhash_OPSLIMIT_MAX);
    assert(crypto_pwhash_memlimit_min() == crypto_pwhash_MEMLIMIT_MIN);
    assert(crypto_pwhash_memlimit_max() == crypto_pwhash_MEMLIMIT_MAX);
    assert(crypto_pwhash_opslimit_interactive() ==
           crypto_pwhash_OPSLIMIT_INTERACTIVE);
    assert(crypto_pwhash_memlimit_interactive() ==
           crypto_pwhash_MEMLIMIT_INTERACTIVE);
    assert(crypto_pwhash_opslimit_moderate() ==
           crypto_pwhash_OPSLIMIT_MODERATE);
    assert(crypto_pwhash_memlimit_moderate() ==
           crypto_pwhash_MEMLIMIT_MODERATE);
    assert(crypto_pwhash_opslimit_sensitive() ==
           crypto_pwhash_OPSLIMIT_SENSITIVE);
    assert(crypto_pwhash_memlimit_sensitive() ==
           crypto_pwhash_MEMLIMIT_SENSITIVE);

    assert(crypto_pwhash_argon2id_bytes_min() == crypto_pwhash_bytes_min());
    assert(crypto_pwhash_argon2id_bytes_max() == crypto_pwhash_bytes_max());
    assert(crypto_pwhash_argon2id_passwd_min() == crypto_pwhash_passwd_min());
    assert(crypto_pwhash_argon2id_passwd_max() == crypto_pwhash_passwd_max());
    assert(crypto_pwhash_argon2id_saltbytes() == crypto_pwhash_saltbytes());
    assert(crypto_pwhash_argon2id_strbytes() == crypto_pwhash_strbytes());
    assert(strcmp(crypto_pwhash_argon2id_strprefix(),
                  crypto_pwhash_strprefix()) == 0);
    assert(crypto_pwhash_argon2id_opslimit_min() ==
           crypto_pwhash_opslimit_min());
    assert(crypto_pwhash_argon2id_opslimit_max() ==
           crypto_pwhash_opslimit_max());
    assert(crypto_pwhash_argon2id_memlimit_min() ==
           crypto_pwhash_memlimit_min());
    assert(crypto_pwhash_argon2id_memlimit_max() ==
           crypto_pwhash_memlimit_max());
    assert(crypto_pwhash_argon2id_opslimit_interactive() ==
           crypto_pwhash_opslimit_interactive());
    assert(crypto_pwhash_argon2id_opslimit_moderate() ==
           crypto_pwhash_opslimit_moderate());
    assert(crypto_pwhash_argon2id_opslimit_sensitive() ==
           crypto_pwhash_opslimit_sensitive());
    assert(crypto_pwhash_argon2id_memlimit_interactive() ==
           crypto_pwhash_memlimit_interactive());
    assert(crypto_pwhash_argon2id_memlimit_moderate() ==
           crypto_pwhash_memlimit_moderate());
    assert(crypto_pwhash_argon2id_memlimit_sensitive() ==
           crypto_pwhash_memlimit_sensitive());
    assert(crypto_pwhash_alg_argon2id13() ==
           crypto_pwhash_argon2id_alg_argon2id13());
    assert(crypto_pwhash_alg_argon2i13() == crypto_pwhash_ALG_ARGON2I13);
    assert(crypto_pwhash_alg_argon2i13() != crypto_pwhash_alg_default());
    assert(crypto_pwhash_alg_argon2id13() == crypto_pwhash_ALG_ARGON2ID13);
    assert(crypto_pwhash_alg_argon2id13() != crypto_pwhash_alg_argon2i13());
    assert(crypto_pwhash_alg_argon2id13() == crypto_pwhash_alg_default());

    assert(crypto_pwhash_argon2id(guard_page, 0, (const char *) guard_page, 0, guard_page,
                                  crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
                                  crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
                                  0) == -1);
    assert(crypto_pwhash_argon2id(guard_page, 0, (const char *) guard_page, 0, guard_page,
                                 crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
                                 crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
                                 crypto_pwhash_ALG_ARGON2I13) == -1);
    assert(crypto_pwhash_argon2i(guard_page, 0, (const char *) guard_page, 0, guard_page,
                                 crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
                                 crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
                                 0) == -1);
    assert(crypto_pwhash_argon2i(guard_page, 0, (const char *) guard_page, 0, guard_page,
                                 crypto_pwhash_argon2id_OPSLIMIT_INTERACTIVE,
                                 crypto_pwhash_argon2id_MEMLIMIT_INTERACTIVE,
                                 crypto_pwhash_ALG_ARGON2ID13) == -1);

    printf("OK\n");

    return 0;
}