From e07a94a66985b674c5df11ca466792902164c4e2 Mon Sep 17 00:00:00 2001 From: George McCollister Date: Tue, 19 Jun 2012 12:36:28 -0500 Subject: libcrypto fully implemented Implemented working versions of the following functions for libcrypto: sss_base64_encode sss_base64_decode sss_hmac_sha1 sss_password_encrypt sss_password_decrypt test_encrypt_decrypt now expects EOK from libcrypto. test_hmac_sha1 now expects EOK from libcrypto. Added test_base64_encode to test base64 encoding implementation. Added test_base64_decode to test base64 decoding implementation. Signed-off-by: George McCollister --- src/tests/crypto-tests.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'src/tests/crypto-tests.c') diff --git a/src/tests/crypto-tests.c b/src/tests/crypto-tests.c index 045f4262..0492a384 100644 --- a/src/tests/crypto-tests.c +++ b/src/tests/crypto-tests.c @@ -60,10 +60,8 @@ START_TEST(test_encrypt_decrypt) int ret; int expected; -#ifdef HAVE_NSS +#if defined(HAVE_NSS) || defined(HAVE_LIBCRYPTO) expected = EOK; -#elif HAVE_LIBCRYPTO - expected = ENOSYS; #else #error Unknown crypto back end #endif @@ -108,10 +106,8 @@ START_TEST(test_hmac_sha1) int ret, expected; int i; -#ifdef HAVE_NSS +#if defined(HAVE_NSS) || defined(HAVE_LIBCRYPTO) expected = EOK; -#elif HAVE_LIBCRYPTO - expected = ENOSYS; #else #error Unknown crypto back end #endif @@ -126,6 +122,42 @@ START_TEST(test_hmac_sha1) } END_TEST +START_TEST(test_base64_encode) +{ + const unsigned char obfbuf[] = "test"; + const char expected[] = "dGVzdA=="; + char *obfpwd = NULL; + + test_ctx = talloc_new(NULL); + fail_if(test_ctx == NULL); + /* Base64 encode the buffer */ + obfpwd = sss_base64_encode(test_ctx, obfbuf, strlen((const char*)obfbuf)); + fail_if(obfpwd == NULL); + fail_if(strcmp(obfpwd,expected) != 0); + + talloc_free(test_ctx); +} +END_TEST + +START_TEST(test_base64_decode) +{ + unsigned char *obfbuf = NULL; + size_t obflen; + const char b64encoded[] = "dGVzdA=="; + const unsigned char expected[] = "test"; + + test_ctx = talloc_new(NULL); + fail_if(test_ctx == NULL); + /* Base64 decode the buffer */ + obfbuf = sss_base64_decode(test_ctx, b64encoded, &obflen); + fail_if(!obfbuf); + fail_if(obflen != strlen((const char*)expected)); + fail_if(memcmp(obfbuf, expected, obflen) != 0); + + talloc_free(test_ctx); +} +END_TEST + Suite *crypto_suite(void) { Suite *s = suite_create("sss_crypto"); @@ -138,6 +170,8 @@ Suite *crypto_suite(void) #endif tcase_add_test(tc, test_encrypt_decrypt); tcase_add_test(tc, test_hmac_sha1); + tcase_add_test(tc, test_base64_encode); + tcase_add_test(tc, test_base64_decode); /* Add all test cases to the test suite */ suite_add_tcase(s, tc); -- cgit