diff options
author | Andrew Bartlett <abartlet@samba.org> | 2006-09-11 04:18:16 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:18:17 -0500 |
commit | 2059aa0949b831c362b30d82ccba8a7c8cb1c601 (patch) | |
tree | 2eee5696a515497a9af8bda7a849be4f6505525e | |
parent | bfe8de694950e6988fcbdfd5617c44c3e5c4999d (diff) | |
download | samba-2059aa0949b831c362b30d82ccba8a7c8cb1c601.tar.gz samba-2059aa0949b831c362b30d82ccba8a7c8cb1c601.tar.bz2 samba-2059aa0949b831c362b30d82ccba8a7c8cb1c601.zip |
r18357: Convert more crypto tests from using function results as initialisers.
(Fails on older Unix C compilers)
Andrew Bartlett
(This used to be commit a4cc13a93fc2f18bfb266603617e14d1cc7ceecf)
-rw-r--r-- | source4/lib/crypto/hmacmd5test.c | 66 | ||||
-rw-r--r-- | source4/lib/crypto/hmacsha1test.c | 66 | ||||
-rw-r--r-- | source4/lib/crypto/md4test.c | 1 | ||||
-rw-r--r-- | source4/lib/crypto/md5test.c | 53 |
4 files changed, 97 insertions, 89 deletions
diff --git a/source4/lib/crypto/hmacmd5test.c b/source4/lib/crypto/hmacmd5test.c index a1d3ff0ee1..2c0db14762 100644 --- a/source4/lib/crypto/hmacmd5test.c +++ b/source4/lib/crypto/hmacmd5test.c @@ -40,40 +40,40 @@ BOOL torture_local_crypto_hmacmd5(struct torture_context *torture) DATA_BLOB key; DATA_BLOB data; DATA_BLOB md5; - } testarray[] = { - { - .key = data_blob_repeat_byte(0x0b, 16), - .data = data_blob_string_const("Hi There"), - .md5 = strhex_to_data_blob("9294727a3638bb1c13f48ef8158bfc9d") - },{ - .key = data_blob_string_const("Jefe"), - .data = data_blob_string_const("what do ya want for nothing?"), - .md5 = strhex_to_data_blob("750c783e6ab0b503eaa86e310a5db738") - },{ - .key = data_blob_repeat_byte(0xaa, 16), - .data = data_blob_repeat_byte(0xdd, 50), - .md5 = strhex_to_data_blob("56be34521d144c88dbb8c733f0e8b3f6") - },{ - .key = strhex_to_data_blob("0102030405060708090a0b0c0d0e0f10111213141516171819"), - .data = data_blob_repeat_byte(0xcd, 50), - .md5 = strhex_to_data_blob("697eaf0aca3a3aea3a75164746ffaa79") - },{ - .key = data_blob_repeat_byte(0x0c, 16), - .data = data_blob_string_const("Test With Truncation"), - .md5 = strhex_to_data_blob("56461ef2342edc00f9bab995690efd4c") - },{ - .key = data_blob_repeat_byte(0xaa, 80), - .data = data_blob_string_const("Test Using Larger Than Block-Size Key - Hash Key First"), - .md5 = strhex_to_data_blob("6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd") - },{ - .key = data_blob_repeat_byte(0xaa, 80), - .data = data_blob_string_const("Test Using Larger Than Block-Size Key " - "and Larger Than One Block-Size Data"), - .md5 = strhex_to_data_blob("6f630fad67cda0ee1fb1f562db3aa53e") - } - }; + } testarray[8]; + + testarray[0].key = data_blob_repeat_byte(0x0b, 16); + testarray[0].data = data_blob_string_const("Hi There"); + testarray[0].md5 = strhex_to_data_blob("9294727a3638bb1c13f48ef8158bfc9d"); + + testarray[1].key = data_blob_string_const("Jefe"); + testarray[1].data = data_blob_string_const("what do ya want for nothing?"); + testarray[1].md5 = strhex_to_data_blob("750c783e6ab0b503eaa86e310a5db738"); + + testarray[2].key = data_blob_repeat_byte(0xaa, 16); + testarray[2].data = data_blob_repeat_byte(0xdd, 50); + testarray[2].md5 = strhex_to_data_blob("56be34521d144c88dbb8c733f0e8b3f6"); + + testarray[3].key = strhex_to_data_blob("0102030405060708090a0b0c0d0e0f10111213141516171819"); + testarray[3].data = data_blob_repeat_byte(0xcd, 50); + testarray[3].md5 = strhex_to_data_blob("697eaf0aca3a3aea3a75164746ffaa79"); + + testarray[4].key = data_blob_repeat_byte(0x0c, 16); + testarray[4].data = data_blob_string_const("Test With Truncation"); + testarray[4].md5 = strhex_to_data_blob("56461ef2342edc00f9bab995690efd4c"); + + testarray[5].key = data_blob_repeat_byte(0xaa, 80); + testarray[5].data = data_blob_string_const("Test Using Larger Than Block-Size Key - Hash Key First"); + testarray[5].md5 = strhex_to_data_blob("6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"); + + testarray[6].key = data_blob_repeat_byte(0xaa, 80); + testarray[6].data = data_blob_string_const("Test Using Larger Than Block-Size Key " + "and Larger Than One Block-Size Data"); + testarray[6].md5 = strhex_to_data_blob("6f630fad67cda0ee1fb1f562db3aa53e"); + + testarray[7].key = data_blob(NULL, 0); - for (i=0; i < ARRAY_SIZE(testarray); i++) { + for (i=0; testarray[i].key.data; i++) { HMACMD5Context ctx; uint8_t md5[16]; int e; diff --git a/source4/lib/crypto/hmacsha1test.c b/source4/lib/crypto/hmacsha1test.c index 92a50ed933..7b8bd20707 100644 --- a/source4/lib/crypto/hmacsha1test.c +++ b/source4/lib/crypto/hmacsha1test.c @@ -40,39 +40,39 @@ BOOL torture_local_crypto_hmacsha1(struct torture_context *torture) DATA_BLOB key; DATA_BLOB data; DATA_BLOB sha1; - } testarray[] = { - { - .key = data_blob_repeat_byte(0x0b, 20), - .data = data_blob_string_const("Hi There"), - .sha1 = strhex_to_data_blob("b617318655057264e28bc0b6fb378c8ef146be00") - },{ - .key = data_blob_string_const("Jefe"), - .data = data_blob_string_const("what do ya want for nothing?"), - .sha1 = strhex_to_data_blob("effcdf6ae5eb2fa2d27416d5f184df9c259a7c79") - },{ - .key = data_blob_repeat_byte(0xaa, 20), - .data = data_blob_repeat_byte(0xdd, 50), - .sha1 = strhex_to_data_blob("125d7342b9ac11cd91a39af48aa17b4f63f175d3") - },{ - .key = strhex_to_data_blob("0102030405060708090a0b0c0d0e0f10111213141516171819"), - .data = data_blob_repeat_byte(0xcd, 50), - .sha1 = strhex_to_data_blob("4c9007f4026250c6bc8414f9bf50c86c2d7235da") - },{ - .key = data_blob_repeat_byte(0x0c, 20), - .data = data_blob_string_const("Test With Truncation"), - .sha1 = strhex_to_data_blob("4c1a03424b55e07fe7f27be1d58bb9324a9a5a04") - /* sha1-96 = 0x4c1a03424b55e07fe7f27be1 */ - },{ - .key = data_blob_repeat_byte(0xaa, 80), - .data = data_blob_string_const("Test Using Larger Than Block-Size Key - Hash Key First"), - .sha1 = strhex_to_data_blob("aa4ae5e15272d00e95705637ce8a3b55ed402112") - },{ - .key = data_blob_repeat_byte(0xaa, 80), - .data = data_blob_string_const("Test Using Larger Than Block-Size Key " - "and Larger Than One Block-Size Data"), - .sha1 = strhex_to_data_blob("e8e99d0f45237d786d6bbaa7965c7808bbff1a91") - } - }; + } testarray[7]; + + testarray[0].key = data_blob_repeat_byte(0x0b, 20); + testarray[0].data = data_blob_string_const("Hi There"); + testarray[0].sha1 = strhex_to_data_blob("b617318655057264e28bc0b6fb378c8ef146be00"); + + testarray[1].key = data_blob_string_const("Jefe"); + testarray[1].data = data_blob_string_const("what do ya want for nothing?"); + testarray[1].sha1 = strhex_to_data_blob("effcdf6ae5eb2fa2d27416d5f184df9c259a7c79"); + + testarray[2].key = data_blob_repeat_byte(0xaa, 20); + testarray[2].data = data_blob_repeat_byte(0xdd, 50); + testarray[2].sha1 = strhex_to_data_blob("125d7342b9ac11cd91a39af48aa17b4f63f175d3"); + + testarray[3].key = strhex_to_data_blob("0102030405060708090a0b0c0d0e0f10111213141516171819"); + testarray[3].data = data_blob_repeat_byte(0xcd, 50); + testarray[3].sha1 = strhex_to_data_blob("4c9007f4026250c6bc8414f9bf50c86c2d7235da"); + + testarray[4].key = data_blob_repeat_byte(0x0c, 20); + testarray[4].data = data_blob_string_const("Test With Truncation"); + testarray[4].sha1 = strhex_to_data_blob("4c1a03424b55e07fe7f27be1d58bb9324a9a5a04"); + /* sha1-96 = 0x4c1a03424b55e07fe7f27be1 */ + + testarray[5].key = data_blob_repeat_byte(0xaa, 80); + testarray[5].data = data_blob_string_const("Test Using Larger Than Block-Size Key - Hash Key First"); + testarray[5].sha1 = strhex_to_data_blob("aa4ae5e15272d00e95705637ce8a3b55ed402112"); + + testarray[6].key = data_blob_repeat_byte(0xaa, 80); + testarray[6].data = data_blob_string_const("Test Using Larger Than Block-Size Key " + "and Larger Than One Block-Size Data"); + testarray[6].sha1 = strhex_to_data_blob("e8e99d0f45237d786d6bbaa7965c7808bbff1a91"); + + testarray[7].key = data_blob(NULL, 0); for (i=0; i < ARRAY_SIZE(testarray); i++) { struct HMACSHA1Context ctx; diff --git a/source4/lib/crypto/md4test.c b/source4/lib/crypto/md4test.c index 747d374396..1c98fe0846 100644 --- a/source4/lib/crypto/md4test.c +++ b/source4/lib/crypto/md4test.c @@ -77,6 +77,7 @@ BOOL torture_local_crypto_md4(struct torture_context *torture) dump_data(0, md4, sizeof(md4)); ret = False; } + talloc_free(md4blob.data); } return ret; diff --git a/source4/lib/crypto/md5test.c b/source4/lib/crypto/md5test.c index 89b0e55876..f16eabf75c 100644 --- a/source4/lib/crypto/md5test.c +++ b/source4/lib/crypto/md5test.c @@ -31,34 +31,34 @@ BOOL torture_local_crypto_md5(struct torture_context *torture) BOOL ret = True; uint32_t i; struct { - DATA_BLOB data; - DATA_BLOB md5; + const char *data; + const char *md5; } testarray[] = { { - .data = data_blob_string_const(""), - .md5 = strhex_to_data_blob("d41d8cd98f00b204e9800998ecf8427e") + .data = "", + .md5 = "d41d8cd98f00b204e9800998ecf8427e" },{ - .data = data_blob_string_const("a"), - .md5 = strhex_to_data_blob("0cc175b9c0f1b6a831c399e269772661") + .data = "a", + .md5 = "0cc175b9c0f1b6a831c399e269772661" },{ - .data = data_blob_string_const("abc"), - .md5 = strhex_to_data_blob("900150983cd24fb0d6963f7d28e17f72") + .data = "abc", + .md5 = "900150983cd24fb0d6963f7d28e17f72" },{ - .data = data_blob_string_const("message digest"), - .md5 = strhex_to_data_blob("f96b697d7cb7938d525a2f31aaf161d0") + .data = "message digest", + .md5 = "f96b697d7cb7938d525a2f31aaf161d0" },{ - .data = data_blob_string_const("abcdefghijklmnopqrstuvwxyz"), - .md5 = strhex_to_data_blob("c3fcd3d76192e4007dfb496cca67e13b") + .data = "abcdefghijklmnopqrstuvwxyz", + .md5 = "c3fcd3d76192e4007dfb496cca67e13b" },{ - .data = data_blob_string_const("ABCDEFGHIJKLMNOPQRSTUVWXYZ" + .data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" - "0123456789"), - .md5 = strhex_to_data_blob("d174ab98d277d9f5a5611c2c9f419d9f") + "0123456789", + .md5 = "d174ab98d277d9f5a5611c2c9f419d9f" },{ - .data = data_blob_string_const("123456789012345678901234567890" + .data = "123456789012345678901234567890" "123456789012345678901234567890" - "12345678901234567890"), - .md5 = strhex_to_data_blob("57edf4a22be3c955ac49da2e2107b67a") + "12345678901234567890", + .md5 = "57edf4a22be3c955ac49da2e2107b67a" } }; @@ -67,20 +67,27 @@ BOOL torture_local_crypto_md5(struct torture_context *torture) uint8_t md5[16]; int e; + DATA_BLOB data; + DATA_BLOB md5blob; + + data = data_blob_string_const(testarray[i].data); + md5blob = strhex_to_data_blob(testarray[i].md5); + MD5Init(&ctx); - MD5Update(&ctx, testarray[i].data.data, testarray[i].data.length); + MD5Update(&ctx, data.data, data.length); MD5Final(md5, &ctx); - e = memcmp(testarray[i].md5.data, + e = memcmp(md5blob.data, md5, - MIN(testarray[i].md5.length, sizeof(md5))); + MIN(md5blob.length, sizeof(md5))); if (e != 0) { printf("md5 test[%u]: failed\n", i); - dump_data(0, testarray[i].data.data, testarray[i].data.length); - dump_data(0, testarray[i].md5.data, testarray[i].md5.length); + dump_data(0, data.data, data.length); + dump_data(0, md5blob.data, md5blob.length); dump_data(0, md5, sizeof(md5)); ret = False; } + talloc_free(md5blob.data); } return ret; |