diff options
author | Vitaly Chikunov <vt@altlinux.org> | 2018-10-30 07:02:42 +0300 |
---|---|---|
committer | Vitaly Chikunov <vt@altlinux.org> | 2018-10-30 12:34:35 +0300 |
commit | de4d2469aa223941f4ac1d171dedd9edd1d27381 (patch) | |
tree | f3456ee417fc6efd77a4028e65e94f09b34edefa /test-gensalt.c | |
parent | 8903971060d201a2be4549d53cac1c27e338f90b (diff) | |
download | libxcrypt-de4d2469aa223941f4ac1d171dedd9edd1d27381.tar.gz libxcrypt-de4d2469aa223941f4ac1d171dedd9edd1d27381.tar.bz2 libxcrypt-de4d2469aa223941f4ac1d171dedd9edd1d27381.zip |
Add generic test if crypt is accepting gensalt and crypt outputs
Some backends do not test if a hashed password is accepted properly as a
setting, this is a generic place to test it for all backends.
Only default rounds size is tested otherwise the test is taking too long.
Diffstat (limited to 'test-gensalt.c')
-rw-r--r-- | test-gensalt.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/test-gensalt.c b/test-gensalt.c index 8c13a16..5307b52 100644 --- a/test-gensalt.c +++ b/test-gensalt.c @@ -464,7 +464,37 @@ main (void) tcase->prefix, tcase->rounds, ent, salt); XCRYPT_STRCPY_OR_ABORT (prev_output, CRYPT_GENSALT_OUTPUT_SIZE, salt); - } + + /* Test if crypt works with this salt. */ + if (!tcase->rounds) + { +#define PASSW "alexander" + static struct crypt_data a, b; + if (!crypt_rn (PASSW, salt, &a, sizeof(a))) + { + fprintf (stderr, "ERROR: %s/%u -> crypt(gensalt) fail\n", + tcase->prefix, ent); + status = 1; + } + else if (!crypt_rn (PASSW, a.output, &b, sizeof(b))) + { + fprintf (stderr, "ERROR: %s/%u -> cryptn(crypt(gensalt)) fail\n", + tcase->prefix, ent); + status = 1; + } + else if (strcmp (a.output, b.output)) + { + fprintf (stderr, "ERROR: %s/%u -> crypt(gensalt) != crypt(crypt(gensalt))\n", + tcase->prefix, ent); + status = 1; + } + else + { + fprintf (stderr, " ok: %s/%u -> crypt works with this salt\n", + tcase->prefix, ent); + } + } + } } /* Currently, passing a null pointer as the prefix argument to |