From b895f134844990d733c3db8fe0921dec913e3c2a Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 30 Apr 2014 01:10:22 +0200 Subject: [PATCH] minor changes/clean-up sources --- .gitignore | 9 +-- demos/test.c | 2 +- src/headers/tomcrypt_custom.h | 6 +- src/mac/hmac/hmac_test.c | 20 ++++++ src/misc/crypt/crypt.c | 130 +++++++++++++++++++--------------- src/misc/hkdf/hkdf_test.c | 4 ++ src/misc/pkcs5/pkcs_5_test.c | 2 + 7 files changed, 109 insertions(+), 64 deletions(-) diff --git a/.gitignore b/.gitignore index 4c10b12..002a2d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ # suppress compiler/linker output *.[oa] *.obj -*.gcno [Dd]ebug/ [Rr]elease/ @@ -39,6 +38,8 @@ timing.exe *.patch *.diff *.orig -*.out -*.ll -*.gcda +*.out +*.ll +*.gcda +*.gcno +*.gcov diff --git a/demos/test.c b/demos/test.c index e9c9a90..b19b887 100644 --- a/demos/test.c +++ b/demos/test.c @@ -18,7 +18,7 @@ int main(void) printf("build == \n%s\n", crypt_build_settings); printf("\nstore_test...."); fflush(stdout); x = store_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); - printf("\nmisc_test...."); fflush(stdout); x = misc_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); + printf("\nmisc_test....."); fflush(stdout); x = misc_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\ncipher_test..."); fflush(stdout); x = cipher_hash_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\nmac_test......"); fflush(stdout); x = mac_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); printf("\nmodes_test...."); fflush(stdout); x = modes_test(); printf(x ? "failed" : "passed");if (x) exit(EXIT_FAILURE); diff --git a/src/headers/tomcrypt_custom.h b/src/headers/tomcrypt_custom.h index 6518b2a..b87700a 100644 --- a/src/headers/tomcrypt_custom.h +++ b/src/headers/tomcrypt_custom.h @@ -121,6 +121,8 @@ #ifndef LTC_NO_TEST #define LTC_TEST #endif +/* Enable extended self-tests */ +/* #define LTC_TEST_EXT */ /* Use small code where possible */ /* #define LTC_SMALL_CODE */ @@ -170,7 +172,7 @@ #define LTC_TWOFISH_SMALL #endif /* #define LTC_TWOFISH_SMALL */ -/* LTC_DES includes EDE triple-LTC_DES */ +/* LTC_DES includes EDE triple-DES */ #define LTC_DES #define LTC_CAST5 #define LTC_NOEKEON @@ -378,7 +380,7 @@ /* Keep LTC_NO_HKDF for compatibility reasons * superseeded by LTC_NO_MISC*/ #ifndef LTC_NO_HKDF -/* LTC_HKDF Key Derivation/Expansion stuff */ +/* HKDF Key Derivation/Expansion stuff */ #define LTC_HKDF #endif /* LTC_NO_HKDF */ diff --git a/src/mac/hmac/hmac_test.c b/src/mac/hmac/hmac_test.c index 3573b50..adec517 100644 --- a/src/mac/hmac/hmac_test.c +++ b/src/mac/hmac/hmac_test.c @@ -66,6 +66,7 @@ int hmac_test(void) 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b }, +#ifdef LTC_TEST_EXT { // 2 0x4a, 0x65, 0x66, 0x65 }, @@ -101,6 +102,7 @@ int hmac_test(void) 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa } +#endif /* LTC_TEST_EXT */ }; @@ -108,6 +110,7 @@ int hmac_test(void) { "Hi There" }, +#ifdef LTC_TEST_EXT { "what do ya want for nothing?" }, @@ -137,6 +140,7 @@ int hmac_test(void) { "This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm." } +#endif /* LTC_TEST_EXT */ }; static const struct hmac_test_case { @@ -158,6 +162,7 @@ int hmac_test(void) 0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e, 0xf1, 0x46, 0xbe, 0x00} }, +#ifdef LTC_TEST_EXT { "rfc2202 3.2", "sha1", hmac_test_case_keys[1], 4, hmac_test_case_data[1], 28, @@ -197,6 +202,7 @@ int hmac_test(void) hmac_test_case_data[6], 73, {0xe8, 0xe9, 0x9d, 0x0f, 0x45, 0x23, 0x7d, 0x78, 0x6d, 0x6b, 0xba, 0xa7, 0x96, 0x5c, 0x78, 0x08, 0xbb, 0xff, 0x1a, 0x91} }, +#endif /* LTC_TEST_EXT */ /* RFC 2202 2. Test Cases for HMAC-MD5 @@ -207,6 +213,7 @@ int hmac_test(void) {0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c, 0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d} }, +#ifdef LTC_TEST_EXT { "rfc2202 2.2", "md5", hmac_test_case_keys[1], 4, hmac_test_case_data[1], 28, @@ -242,6 +249,7 @@ int hmac_test(void) hmac_test_case_data[6], 73, {0x6f, 0x63, 0x0f, 0xad, 0x67, 0xcd, 0xa0, 0xee, 0x1f, 0xb1, 0xf5, 0x62, 0xdb, 0x3a, 0xa5, 0x3e} }, +#endif /* LTC_TEST_EXT */ /* RFC 2286 2. Test Cases for HMAC-RIPEMD160 @@ -253,6 +261,7 @@ int hmac_test(void) 0x5d, 0x2e, 0xd7, 0x73, 0x2d, 0xcc, 0x39, 0x37, 0x7f, 0x0a, 0x56, 0x68} }, +#ifdef LTC_TEST_EXT { "rfc2286 2.2", "rmd160", hmac_test_case_keys[1], 4, hmac_test_case_data[1], 28, @@ -294,6 +303,7 @@ int hmac_test(void) {0x69, 0xea, 0x60, 0x79, 0x8d, 0x71, 0x61, 0x6c, 0xce, 0x5f, 0xd0, 0x87, 0x1e, 0x23, 0x75, 0x4c, 0xd7, 0x5d, 0x5a, 0x0a} }, +#endif /* LTC_TEST_EXT */ /* RFC 2286 3. Test Cases for HMAC-RIPEMD128 @@ -304,6 +314,7 @@ int hmac_test(void) {0xfb, 0xf6, 0x1f, 0x94, 0x92, 0xaa, 0x4b, 0xbf, 0x81, 0xc1, 0x72, 0xe8, 0x4e, 0x07, 0x34, 0xdb} }, +#ifdef LTC_TEST_EXT { "rfc2286 3.2", "rmd128", hmac_test_case_keys[1], 4, hmac_test_case_data[1], 28, @@ -339,6 +350,7 @@ int hmac_test(void) hmac_test_case_data[6], 73, {0x5c, 0x6b, 0xec, 0x96, 0x79, 0x3e, 0x16, 0xd4, 0x06, 0x90, 0xc2, 0x37, 0x63, 0x5f, 0x30, 0xc5} }, +#endif /* LTC_TEST_EXT */ /* RFC 4231 4. Test Vectors @@ -352,6 +364,7 @@ int hmac_test(void) 0x47, 0xb4, 0xb1, 0x16, 0x99, 0x12, 0xba, 0x4f, 0x53, 0x68, 0x4b, 0x22} }, +#ifdef LTC_TEST_EXT { "rfc4231 4.3", "sha224", hmac_test_case_keys[1], 4, hmac_test_case_data[1], 28, @@ -391,6 +404,7 @@ int hmac_test(void) 0x3f, 0x54, 0xd5, 0x17, 0xd0, 0xb3, 0x9d, 0xbd, 0x94, 0x67, 0x70, 0xdb, 0x9c, 0x2b, 0x95, 0xc9, 0xf6, 0xf5, 0x65, 0xd1} }, +#endif /* LTC_TEST_EXT */ { "rfc4231 4.2", "sha256", hmac_test_case_keys[0], 20, @@ -400,6 +414,7 @@ int hmac_test(void) 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7, 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7} }, +#ifdef LTC_TEST_EXT { "rfc4231 4.3", "sha256", hmac_test_case_keys[1], 4, hmac_test_case_data[1], 28, @@ -439,6 +454,7 @@ int hmac_test(void) 0x27, 0x63, 0x5f, 0xbc, 0xd5, 0xb0, 0xe9, 0x44, 0xbf, 0xdc, 0x63, 0x64, 0x4f, 0x07, 0x13, 0x93, 0x8a, 0x7f, 0x51, 0x53, 0x5c, 0x3a, 0x35, 0xe2} }, +#endif /* LTC_TEST_EXT */ { "rfc4231 4.2", "sha384", hmac_test_case_keys[0], 20, @@ -450,6 +466,7 @@ int hmac_test(void) 0xfa, 0xea, 0x9e, 0xa9, 0x07, 0x6e, 0xde, 0x7f, 0x4a, 0xf1, 0x52, 0xe8, 0xb2, 0xfa, 0x9c, 0xb6} }, +#ifdef LTC_TEST_EXT { "rfc4231 4.3", "sha384", hmac_test_case_keys[1], 4, hmac_test_case_data[1], 28, @@ -499,6 +516,7 @@ int hmac_test(void) 0xdc, 0xce, 0xbb, 0x82, 0x46, 0x1e, 0x99, 0xc5, 0xa6, 0x78, 0xcc, 0x31, 0xe7, 0x99, 0x17, 0x6d, 0x38, 0x60, 0xe6, 0x11, 0x0c, 0x46, 0x52, 0x3e} }, +#endif /* LTC_TEST_EXT */ { "rfc4231 4.2", "sha512", hmac_test_case_keys[0], 20, @@ -512,6 +530,7 @@ int hmac_test(void) 0xbe, 0x9d, 0x91, 0x4e, 0xeb, 0x61, 0xf1, 0x70, 0x2e, 0x69, 0x6c, 0x20, 0x3a, 0x12, 0x68, 0x54} }, +#ifdef LTC_TEST_EXT { "rfc4231 4.3", "sha512", hmac_test_case_keys[1], 4, hmac_test_case_data[1], 28, @@ -571,6 +590,7 @@ int hmac_test(void) 0x0d, 0x5e, 0xeb, 0x55, 0xc3, 0xe4, 0xde, 0x15, 0x13, 0x46, 0x76, 0xfb, 0x6d, 0xe0, 0x44, 0x60, 0x65, 0xc9, 0x74, 0x40, 0xfa, 0x8c, 0x6a, 0x58} }, +#endif /* LTC_TEST_EXT */ }; diff --git a/src/misc/crypt/crypt.c b/src/misc/crypt/crypt.c index fdfe13e..e6bbeaa 100644 --- a/src/misc/crypt/crypt.c +++ b/src/misc/crypt/crypt.c @@ -48,13 +48,13 @@ const char *crypt_build_settings = " Blowfish\n" #endif #if defined(LTC_RC2) - " LTC_RC2\n" + " RC2\n" #endif #if defined(LTC_RC5) - " LTC_RC5\n" + " RC5\n" #endif #if defined(LTC_RC6) - " LTC_RC6\n" + " RC6\n" #endif #if defined(LTC_SAFERP) " Safer+\n" @@ -66,7 +66,7 @@ const char *crypt_build_settings = " Rijndael\n" #endif #if defined(LTC_XTEA) - " LTC_XTEA\n" + " XTEA\n" #endif #if defined(LTC_TWOFISH) " Twofish " @@ -89,10 +89,10 @@ const char *crypt_build_settings = #endif #endif #if defined(LTC_DES) - " LTC_DES\n" + " DES\n" #endif #if defined(LTC_CAST5) - " LTC_CAST5\n" + " CAST5\n" #endif #if defined(LTC_NOEKEON) " Noekeon\n" @@ -111,7 +111,7 @@ const char *crypt_build_settings = #endif "\n" #if defined(LTC_KSEED) - " LTC_KSEED\n" + " KSEED\n" #endif #if defined(LTC_KASUMI) " KASUMI\n" @@ -125,49 +125,49 @@ const char *crypt_build_settings = "\nHashes built-in:\n" #if defined(LTC_SHA512) - " LTC_SHA-512\n" + " SHA-512\n" #endif #if defined(LTC_SHA384) - " LTC_SHA-384\n" + " SHA-384\n" #endif #if defined(LTC_SHA256) - " LTC_SHA-256\n" + " SHA-256\n" #endif #if defined(LTC_SHA224) - " LTC_SHA-224\n" + " SHA-224\n" #endif #if defined(LTC_TIGER) - " LTC_TIGER\n" + " TIGER\n" #endif #if defined(LTC_SHA1) - " LTC_SHA1\n" + " SHA1\n" #endif #if defined(LTC_MD5) - " LTC_MD5\n" + " MD5\n" #endif #if defined(LTC_MD4) - " LTC_MD4\n" + " MD4\n" #endif #if defined(LTC_MD2) - " LTC_MD2\n" + " MD2\n" #endif #if defined(LTC_RIPEMD128) - " LTC_RIPEMD128\n" + " RIPEMD128\n" #endif #if defined(LTC_RIPEMD160) - " LTC_RIPEMD160\n" + " RIPEMD160\n" #endif #if defined(LTC_RIPEMD256) - " LTC_RIPEMD256\n" + " RIPEMD256\n" #endif #if defined(LTC_RIPEMD320) - " LTC_RIPEMD320\n" + " RIPEMD320\n" #endif #if defined(LTC_WHIRLPOOL) - " LTC_WHIRLPOOL\n" + " WHIRLPOOL\n" #endif #if defined(LTC_CHC_HASH) - " LTC_CHC_HASH \n" + " CHC_HASH\n" #endif "\nBlock Chaining Modes:\n" @@ -190,81 +190,91 @@ const char *crypt_build_settings = " (CTR_OLD) " #endif "\n" -#if defined(LRW_MODE) - " LRW_MODE" +#if defined(LTC_LRW_MODE) + " LRW" #if defined(LRW_TABLES) - " (LRW_TABLES) " + " (tables) " #endif "\n" #endif #if defined(LTC_F8_MODE) - " F8 MODE\n" + " F8\n" #endif #if defined(LTC_XTS_MODE) - " LTC_XTS_MODE\n" + " XTS\n" #endif "\nMACs:\n" #if defined(LTC_HMAC) - " LTC_HMAC\n" + " HMAC\n" #endif #if defined(LTC_OMAC) - " LTC_OMAC\n" + " OMAC\n" #endif #if defined(LTC_PMAC) " PMAC\n" #endif #if defined(LTC_PELICAN) - " LTC_PELICAN\n" + " PELICAN\n" #endif #if defined(LTC_XCBC) - " XCBC-MAC\n" + " XCBC\n" #endif #if defined(LTC_F9_MODE) - " F9-MAC\n" + " F9\n" #endif "\nENC + AUTH modes:\n" #if defined(LTC_EAX_MODE) - " LTC_EAX_MODE\n" + " EAX\n" #endif #if defined(LTC_OCB_MODE) - " LTC_OCB_MODE\n" + " OCB\n" #endif #if defined(LTC_OCB3_MODE) - " LTC_OCB3_MODE\n" + " OCB3\n" #endif #if defined(LTC_CCM_MODE) - " LTC_CCM_MODE\n" + " CCM\n" #endif #if defined(LTC_GCM_MODE) - " LTC_GCM_MODE " -#endif + " GCM" #if defined(LTC_GCM_TABLES) - " (LTC_GCM_TABLES) " + " (tables) " +#endif +#if defined(LTC_GCM_TABLES_SSE2) + " (SSE2) " #endif "\n" +#endif "\nPRNG:\n" #if defined(LTC_YARROW) " Yarrow\n" #endif #if defined(LTC_SPRNG) - " LTC_SPRNG\n" + " SPRNG\n" #endif #if defined(LTC_RC4) - " LTC_RC4\n" + " RC4\n" #endif #if defined(LTC_FORTUNA) " Fortuna\n" #endif #if defined(LTC_SOBER128) - " LTC_SOBER128\n" + " SOBER128\n" #endif "\nPK Algs:\n" #if defined(LTC_MRSA) - " RSA \n" + " RSA" +#if defined(LTC_RSA_BLINDING) + " (with blinding)" +#endif + "\n" +#endif +#if defined(LTC_MDH) + " DH\n" #endif #if defined(LTC_MECC) " ECC\n" @@ -301,37 +311,43 @@ const char *crypt_build_settings = " x86-64 detected.\n" #endif #if defined(LTC_PPC32) - " LTC_PPC32 defined \n" + " PPC32 defined \n" #endif "\nVarious others: " #if defined(LTC_BASE64) - " LTC_BASE64 " + " BASE64 " +#endif +#if defined(LTC_BASE64_URL) + " BASE64-URL-SAFE " +#endif +#if defined(LTC_DER) + " DER " +#endif +#if defined(LTC_PKCS_1) + " PKCS#1 " +#endif +#if defined(LTC_PKCS_5) + " PKCS#5 " +#endif +#if defined(LTC_HKDF) + " HKDF " #endif #if defined(MPI) " MPI " #endif -#if defined(TRY_UNRANDOM_FIRST) - " TRY_UNRANDOM_FIRST " +#if defined(TRY_URANDOM_FIRST) + " TRY_URANDOM_FIRST " #endif #if defined(LTC_TEST) " LTC_TEST " #endif -#if defined(LTC_PKCS_1) - " LTC_PKCS#1 " -#endif -#if defined(LTC_PKCS_5) - " LTC_PKCS#5 " -#endif #if defined(LTC_SMALL_CODE) " LTC_SMALL_CODE " #endif #if defined(LTC_NO_FILE) " LTC_NO_FILE " #endif -#if defined(LTC_DER) - " LTC_DER " -#endif #if defined(LTC_FAST) " LTC_FAST " #endif @@ -366,7 +382,7 @@ const char *crypt_build_settings = " GMP_DESC " #endif #if defined(LTC_EASY) - " (easy) " + " LTC_EASY " #endif #if defined(LTC_MECC_FP) " LTC_MECC_FP " diff --git a/src/misc/hkdf/hkdf_test.c b/src/misc/hkdf/hkdf_test.c index 70bb008..0447d28 100644 --- a/src/misc/hkdf/hkdf_test.c +++ b/src/misc/hkdf/hkdf_test.c @@ -86,6 +86,7 @@ int hkdf_test(void) 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf, 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18, 0x58, 0x65}, 42}, +#ifdef LTC_TEST_EXT /* Test with SHA-256 and longer inputs/outputs */ {2, "sha256", {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, @@ -150,6 +151,7 @@ int hkdf_test(void) 0xc3, 0x45, 0x4e, 0x5f, 0x3c, 0x73, 0x8d, 0x2d, 0x9d, 0x20, 0x13, 0x95, 0xfa, 0xa4, 0xb6, 0x1a, 0x96, 0xc8}, 42}, +#endif /* LTC_TEST_EXT */ #endif /* LTC_SHA256 */ #ifdef LTC_SHA1 /* Basic test case with SHA-1 */ @@ -169,6 +171,7 @@ int hkdf_test(void) 0x68, 0xa9, 0xcd, 0xd4, 0xf1, 0x55, 0xfd, 0xa2, 0xc2, 0x2e, 0x42, 0x24, 0x78, 0xd3, 0x05, 0xf3, 0xf8, 0x96}, 42}, +#ifdef LTC_TEST_EXT /* Test with SHA-1 and longer inputs/outputs */ {5, "sha1", {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, @@ -248,6 +251,7 @@ int hkdf_test(void) 0xb0, 0xd1, 0xf2, 0x7e, 0xbb, 0xa6, 0xf5, 0xe5, 0x67, 0x3a, 0x08, 0x1d, 0x70, 0xcc, 0xe7, 0xac, 0xfc, 0x48}, 42}, +#endif /* LTC_TEST_EXT */ #endif /* LTC_SHA1 */ }; diff --git a/src/misc/pkcs5/pkcs_5_test.c b/src/misc/pkcs5/pkcs_5_test.c index 21f4b58..85ccdfa 100644 --- a/src/misc/pkcs5/pkcs_5_test.c +++ b/src/misc/pkcs5/pkcs_5_test.c @@ -65,6 +65,7 @@ int pkcs_5_test (void) 0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0, 0xd8, 0xde, 0x89, 0x57 } }, +#ifdef LTC_TEST_EXT { "password", 8, @@ -109,6 +110,7 @@ int pkcs_5_test (void) { 0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d, 0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3 } }, +#endif /* LTC_TEST_EXT */ }; unsigned char DK[25];