>From a26c38096e74efdab48a159e34f288d356b5aac5 Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Sat, 31 May 2014 15:01:12 +0200 Subject: [PATCH 2/2] TESTS: Add test for s3crypt_sha512 --- src/tests/crypto-tests.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/tests/crypto-tests.c b/src/tests/crypto-tests.c index 87184594e2fb7cedc234350b56aa341d9de62713..1f145bfb05a1d4c551a5ff3839aaa5dc0aa73e53 100644 --- a/src/tests/crypto-tests.c +++ b/src/tests/crypto-tests.c @@ -122,6 +122,83 @@ START_TEST(test_hmac_sha1) } END_TEST +#define SALT1 "super.salt" +#define SALT2 "Loremipsumdolors" +#define SALT3 "$6$rounds=10000$Loremipsumdolors$" + +#define PREFIX1 "$6$"SALT1"$" +#define PREFIX2 "$6$"SALT2"$" +#define PREFIX3 SALT3 + +START_TEST(test_crypt_sha512) +{ + const char *message[] = { + "short", + "proper6789012345678901234567890123456789012345678901234567890123", + "longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong", + NULL }; + const char *results_salt1[] = { + PREFIX1"EHCvLEO9BgT8ObsacnLX6cn8.g.KWQdkoE2QGRGHQuC2qSY7pj47SlsiWtsi2" + "SL0GB25rgeZfaIrVWeiMdPK..", + PREFIX1"ZeJDjANbC3bAD0KkHdbrcjXGudhAF7VtxE6YVIDtoDQR8aBT4ixYbunZ1Pbxx" + "ejkapQYqEu4rvJrPybbvo1/6.", + PREFIX1"0iY1uLvQBdYJs4CnZaTcALpZ3B2Bc2jT3WEmxLrE89mAQfgGBlog9aG/Y9/ry" + "QroLEDutCtpiJyHBsf.yJ/uP1", + NULL }; + const char *results_salt2[] = { + PREFIX2"Mpwr..dRHfhEt8VQ6EiU2/o75agqGFrxxaqARbb6I9QbsEv7WoEesyYKo35C." + "ZRviQIbIsm/kiTVlTotKJm5e/", + PREFIX2"/I1VnfwFWUDMhG5s.NEs2Kq2dNjDDXyjmhogfWJaHEAkRv.E.SP4p5lfIdYWq" + "b39GBIJGffSSno1DLX.NP9Ed0", + PREFIX2"DY9R5CD3QQt9UwoduerLHtjHC0YezO/v37.O0qqqXr4cTwoQHUaXlR7oKdet3" + "DfWPAxsTys0Nkwl65gU./99v0", + NULL }; + const char *results_salt3[] = { + PREFIX3"5vkWlXWA/fJT0GVEo8GH4H/UaPnV2iSUjZu06kKOXyMBqaTrQ9CCLboOuyFYl" + "RX6N3M.RVPsoc50PbM8OCXnc.", + PREFIX3"v1SUGuleIb6RMnacA4x9ro3x8vbPCaO9uCy8gboNU2gT3j.LphSAT4a7hbJ2I" + "/VVp/EEWrjiZb8BIhrJ4rmmq1", + PREFIX3"uBqJ/JfPZYiuqaGCJcSxgBlvWJjg5LvSDiWGIYO4ijNuYPC9Xn0A9BVnRYpW0" + "32S3V07X4Q1b5g73kCjOGABG/", + NULL }; + char *hash = NULL; + int ret; + int i; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(NULL); + fail_if(tmp_ctx == NULL); + ck_leaks_push(tmp_ctx); + + for (i = 0; message[i]; i++) { + ret = s3crypt_sha512(tmp_ctx, message[i], SALT1, &hash); + fail_if(ret != EOK); + fail_if(hash == NULL); + fail_if(strcmp(hash, results_salt1[i]) != 0); + + talloc_zfree(hash); + + ret = s3crypt_sha512(tmp_ctx, message[i], SALT2, &hash); + fail_if(ret != EOK); + fail_if(hash == NULL); + fail_if(strcmp(hash, results_salt2[i]) != 0); + + talloc_zfree(hash); + + ret = s3crypt_sha512(tmp_ctx, message[i], SALT3, &hash); + fail_if(ret != EOK); + fail_if(hash == NULL); + fail_if(strcmp(hash, results_salt3[i]) != 0); + + talloc_zfree(hash); + } + + ck_leaks_pop(tmp_ctx); + talloc_free(tmp_ctx); +} +END_TEST + + START_TEST(test_base64_encode) { const unsigned char obfbuf[] = "test"; @@ -170,6 +247,7 @@ Suite *crypto_suite(void) #endif tcase_add_test(tc, test_encrypt_decrypt); tcase_add_test(tc, test_hmac_sha1); + tcase_add_test(tc, test_crypt_sha512); tcase_add_test(tc, test_base64_encode); tcase_add_test(tc, test_base64_decode); /* Add all test cases to the test suite */ -- 1.9.3