Some small fixes and improvements on the digest testcase: - multipart digest update now really breaks down the data into junks of DIGEST_UPDATE_JUNK_SIZE (currently 32 bytes) size. - fix in regress.h: macro testcase_pass prints out timev differences but start time was nowhere set (causing to print just some kind of random time). Now the testcase_begin* macros set start time and thus the time values printed out make sense.
Signed-off-by: Harald Freudenberger <[email protected]> --- testcases/crypto/digest.h | 1 + testcases/crypto/digest_func.c | 41 ++++++++++++++++++++++++---------------- testcases/include/regress.h | 2 ++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/testcases/crypto/digest.h b/testcases/crypto/digest.h index dff3e12..0ab98a9 100644 --- a/testcases/crypto/digest.h +++ b/testcases/crypto/digest.h @@ -3,6 +3,7 @@ #define MAX_KEY_SIZE 150 #define MAX_DATA_SIZE 512 #define MAX_HASH_SIZE 64 +#define DIGEST_UPDATE_JUNK_SIZE 32 CK_ULONG four = 4; CK_ULONG ten = 10; diff --git a/testcases/crypto/digest_func.c b/testcases/crypto/digest_func.c index 156c238..cfa4427 100644 --- a/testcases/crypto/digest_func.c +++ b/testcases/crypto/digest_func.c @@ -46,6 +46,10 @@ CK_RV do_Digest(struct digest_test_suite_info *tsuite) /** iterate over test vectors **/ for(i = 0; i < tsuite->tvcount; i++){ + /** begin test **/ + testcase_begin("Starting %s Digest with test vector %d.", + tsuite->name, i); + rc = CKR_OK; // set rc /** clear buffers **/ @@ -82,8 +86,9 @@ CK_RV do_Digest(struct digest_test_suite_info *tsuite) testcase_new_assertion(); if (actual_len != expected_len) { - testcase_fail("hashed data length does not match test vector's" " hashed data length.\nexpected length=%ld, found " - "length=%ld.", expected_len, actual_len); + testcase_fail("hashed data length does not match test vector's" + " hashed data length.\nexpected length=%ld, found " + "length=%ld.", expected_len, actual_len); } else if (memcmp(actual, expected, expected_len)){ @@ -110,7 +115,7 @@ CK_RV do_DigestUpdate(struct digest_test_suite_info *tsuite) { int i; CK_BYTE data[MAX_DATA_SIZE]; - CK_ULONG data_len; + CK_ULONG data_len, data_done; CK_BYTE actual[MAX_HASH_SIZE]; CK_ULONG actual_len; CK_BYTE expected[MAX_HASH_SIZE]; @@ -118,9 +123,9 @@ CK_RV do_DigestUpdate(struct digest_test_suite_info *tsuite) CK_MECHANISM mech; CK_SESSION_HANDLE session; - CK_SLOT_ID slot_id = SLOT_ID; + CK_SLOT_ID slot_id = SLOT_ID; CK_ULONG flags; - CK_RV rc; + CK_RV rc; /** begin test **/ testsuite_begin("Starting %s Multipart Digest.", tsuite->name); @@ -149,6 +154,7 @@ CK_RV do_DigestUpdate(struct digest_test_suite_info *tsuite) memset(expected, 0, sizeof(expected)); /** get test vector info **/ + data_done = 0; data_len = tsuite->tv[i].data_len; expected_len = tsuite->tv[i].hash_len; memcpy(data, tsuite->tv[i].data, data_len); @@ -167,13 +173,16 @@ CK_RV do_DigestUpdate(struct digest_test_suite_info *tsuite) actual_len = sizeof(actual); /** do multipart digest **/ - if (data_len > 0) { - rc = funcs->C_DigestUpdate(session, &data[0], data_len); + while (data_done < data_len) { + CK_ULONG len = data_len - data_done; + if (len >= DIGEST_UPDATE_JUNK_SIZE) + len = DIGEST_UPDATE_JUNK_SIZE; + rc = funcs->C_DigestUpdate(session, data + data_done, len); if (rc != CKR_OK) { - testcase_error("C_DigestUpdate rc=%s", - p11_get_ckr(rc)); + testcase_error("C_DigestUpdate rc=%s", p11_get_ckr(rc)); goto testcase_cleanup; } + data_done += len; } /** finalize multipart digest **/ @@ -258,7 +267,7 @@ CK_RV do_SignVerify_HMAC(struct HMAC_TEST_SUITE_INFO *tsuite){ /** get mechanism **/ mech = tsuite->mech; - + /* for ep11, check if key len is supported */ key_len = tsuite->tv[i].key_len; @@ -416,7 +425,7 @@ CK_RV do_SignVerify_HMAC_Update(struct HMAC_TEST_SUITE_INFO *tsuite) /** get mechanism **/ mech = tsuite->mech; - + /* for ep11, check if key len is supported */ key_len = tsuite->tv[i].key_len; @@ -461,20 +470,20 @@ CK_RV do_SignVerify_HMAC_Update(struct HMAC_TEST_SUITE_INFO *tsuite) len1 = 0; len2 = 0; /* do in 2 parts */ - if (data_len < 20) + if (data_len < 20) len1 = data_len; else { len1 = data_len - 20; len2 = 20; } - + rc = funcs->C_SignUpdate(session, data, len1); if (rc != CKR_OK) { testcase_error("C_SignUpdate rc=%s", p11_get_ckr(rc)); goto error; } - + if (len2) { rc = funcs->C_SignUpdate(session, data + len1, len2); @@ -516,7 +525,7 @@ CK_RV do_SignVerify_HMAC_Update(struct HMAC_TEST_SUITE_INFO *tsuite) goto error; } } - } + } rc = funcs->C_VerifyFinal(session, actual, actual_len); if (rc != CKR_OK) { testcase_error("C_VerifyFinal rc=%s", p11_get_ckr(rc)); @@ -601,7 +610,7 @@ CK_RV digest_funcs() { } } } - + return rc; } diff --git a/testcases/include/regress.h b/testcases/include/regress.h index 301aa56..0df5dea 100755 --- a/testcases/include/regress.h +++ b/testcases/include/regress.h @@ -121,12 +121,14 @@ int get_user_pin(CK_BYTE_PTR); do { \ printf("------\n* TESTCASE %s BEGIN " _fmt "\n", \ __func__, ## __VA_ARGS__); \ + gettimeofday(&timev1, NULL); \ } while (0) #define testcase_begin_f(_func, _fmt, ...) \ do { \ printf("------\n* TESTCASE %s BEGIN " _fmt "\n", \ _func, ## __VA_ARGS__); \ + gettimeofday(&timev1, NULL); \ } while (0) #define testcase_new_assertion() \ -- 1.7.9.5 ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk _______________________________________________ Opencryptoki-tech mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opencryptoki-tech
