1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-27 14:04:05 +03:00

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)
This commit is contained in:
Andrew Bartlett 2006-09-11 04:18:16 +00:00 committed by Gerald (Jerry) Carter
parent bfe8de6949
commit 2059aa0949
4 changed files with 97 additions and 89 deletions

View File

@ -40,40 +40,40 @@ BOOL torture_local_crypto_hmacmd5(struct torture_context *torture)
DATA_BLOB key; DATA_BLOB key;
DATA_BLOB data; DATA_BLOB data;
DATA_BLOB md5; DATA_BLOB md5;
} testarray[] = { } testarray[8];
{
.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")
}
};
for (i=0; i < ARRAY_SIZE(testarray); i++) { 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; testarray[i].key.data; i++) {
HMACMD5Context ctx; HMACMD5Context ctx;
uint8_t md5[16]; uint8_t md5[16];
int e; int e;

View File

@ -40,39 +40,39 @@ BOOL torture_local_crypto_hmacsha1(struct torture_context *torture)
DATA_BLOB key; DATA_BLOB key;
DATA_BLOB data; DATA_BLOB data;
DATA_BLOB sha1; DATA_BLOB sha1;
} testarray[] = { } testarray[7];
{
.key = data_blob_repeat_byte(0x0b, 20), testarray[0].key = data_blob_repeat_byte(0x0b, 20);
.data = data_blob_string_const("Hi There"), testarray[0].data = data_blob_string_const("Hi There");
.sha1 = strhex_to_data_blob("b617318655057264e28bc0b6fb378c8ef146be00") testarray[0].sha1 = strhex_to_data_blob("b617318655057264e28bc0b6fb378c8ef146be00");
},{
.key = data_blob_string_const("Jefe"), testarray[1].key = data_blob_string_const("Jefe");
.data = data_blob_string_const("what do ya want for nothing?"), testarray[1].data = data_blob_string_const("what do ya want for nothing?");
.sha1 = strhex_to_data_blob("effcdf6ae5eb2fa2d27416d5f184df9c259a7c79") testarray[1].sha1 = strhex_to_data_blob("effcdf6ae5eb2fa2d27416d5f184df9c259a7c79");
},{
.key = data_blob_repeat_byte(0xaa, 20), testarray[2].key = data_blob_repeat_byte(0xaa, 20);
.data = data_blob_repeat_byte(0xdd, 50), testarray[2].data = data_blob_repeat_byte(0xdd, 50);
.sha1 = strhex_to_data_blob("125d7342b9ac11cd91a39af48aa17b4f63f175d3") testarray[2].sha1 = strhex_to_data_blob("125d7342b9ac11cd91a39af48aa17b4f63f175d3");
},{
.key = strhex_to_data_blob("0102030405060708090a0b0c0d0e0f10111213141516171819"), testarray[3].key = strhex_to_data_blob("0102030405060708090a0b0c0d0e0f10111213141516171819");
.data = data_blob_repeat_byte(0xcd, 50), testarray[3].data = data_blob_repeat_byte(0xcd, 50);
.sha1 = strhex_to_data_blob("4c9007f4026250c6bc8414f9bf50c86c2d7235da") testarray[3].sha1 = strhex_to_data_blob("4c9007f4026250c6bc8414f9bf50c86c2d7235da");
},{
.key = data_blob_repeat_byte(0x0c, 20), testarray[4].key = data_blob_repeat_byte(0x0c, 20);
.data = data_blob_string_const("Test With Truncation"), testarray[4].data = data_blob_string_const("Test With Truncation");
.sha1 = strhex_to_data_blob("4c1a03424b55e07fe7f27be1d58bb9324a9a5a04") testarray[4].sha1 = strhex_to_data_blob("4c1a03424b55e07fe7f27be1d58bb9324a9a5a04");
/* sha1-96 = 0x4c1a03424b55e07fe7f27be1 */ /* sha1-96 = 0x4c1a03424b55e07fe7f27be1 */
},{
.key = data_blob_repeat_byte(0xaa, 80), testarray[5].key = data_blob_repeat_byte(0xaa, 80);
.data = data_blob_string_const("Test Using Larger Than Block-Size Key - Hash Key First"), testarray[5].data = data_blob_string_const("Test Using Larger Than Block-Size Key - Hash Key First");
.sha1 = strhex_to_data_blob("aa4ae5e15272d00e95705637ce8a3b55ed402112") testarray[5].sha1 = strhex_to_data_blob("aa4ae5e15272d00e95705637ce8a3b55ed402112");
},{
.key = data_blob_repeat_byte(0xaa, 80), testarray[6].key = data_blob_repeat_byte(0xaa, 80);
.data = data_blob_string_const("Test Using Larger Than Block-Size Key " testarray[6].data = data_blob_string_const("Test Using Larger Than Block-Size Key "
"and Larger Than One Block-Size Data"), "and Larger Than One Block-Size Data");
.sha1 = strhex_to_data_blob("e8e99d0f45237d786d6bbaa7965c7808bbff1a91") testarray[6].sha1 = strhex_to_data_blob("e8e99d0f45237d786d6bbaa7965c7808bbff1a91");
}
}; testarray[7].key = data_blob(NULL, 0);
for (i=0; i < ARRAY_SIZE(testarray); i++) { for (i=0; i < ARRAY_SIZE(testarray); i++) {
struct HMACSHA1Context ctx; struct HMACSHA1Context ctx;

View File

@ -77,6 +77,7 @@ BOOL torture_local_crypto_md4(struct torture_context *torture)
dump_data(0, md4, sizeof(md4)); dump_data(0, md4, sizeof(md4));
ret = False; ret = False;
} }
talloc_free(md4blob.data);
} }
return ret; return ret;

View File

@ -31,34 +31,34 @@ BOOL torture_local_crypto_md5(struct torture_context *torture)
BOOL ret = True; BOOL ret = True;
uint32_t i; uint32_t i;
struct { struct {
DATA_BLOB data; const char *data;
DATA_BLOB md5; const char *md5;
} testarray[] = { } testarray[] = {
{ {
.data = data_blob_string_const(""), .data = "",
.md5 = strhex_to_data_blob("d41d8cd98f00b204e9800998ecf8427e") .md5 = "d41d8cd98f00b204e9800998ecf8427e"
},{ },{
.data = data_blob_string_const("a"), .data = "a",
.md5 = strhex_to_data_blob("0cc175b9c0f1b6a831c399e269772661") .md5 = "0cc175b9c0f1b6a831c399e269772661"
},{ },{
.data = data_blob_string_const("abc"), .data = "abc",
.md5 = strhex_to_data_blob("900150983cd24fb0d6963f7d28e17f72") .md5 = "900150983cd24fb0d6963f7d28e17f72"
},{ },{
.data = data_blob_string_const("message digest"), .data = "message digest",
.md5 = strhex_to_data_blob("f96b697d7cb7938d525a2f31aaf161d0") .md5 = "f96b697d7cb7938d525a2f31aaf161d0"
},{ },{
.data = data_blob_string_const("abcdefghijklmnopqrstuvwxyz"), .data = "abcdefghijklmnopqrstuvwxyz",
.md5 = strhex_to_data_blob("c3fcd3d76192e4007dfb496cca67e13b") .md5 = "c3fcd3d76192e4007dfb496cca67e13b"
},{ },{
.data = data_blob_string_const("ABCDEFGHIJKLMNOPQRSTUVWXYZ" .data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz"
"0123456789"), "0123456789",
.md5 = strhex_to_data_blob("d174ab98d277d9f5a5611c2c9f419d9f") .md5 = "d174ab98d277d9f5a5611c2c9f419d9f"
},{ },{
.data = data_blob_string_const("123456789012345678901234567890" .data = "123456789012345678901234567890"
"123456789012345678901234567890" "123456789012345678901234567890"
"12345678901234567890"), "12345678901234567890",
.md5 = strhex_to_data_blob("57edf4a22be3c955ac49da2e2107b67a") .md5 = "57edf4a22be3c955ac49da2e2107b67a"
} }
}; };
@ -67,20 +67,27 @@ BOOL torture_local_crypto_md5(struct torture_context *torture)
uint8_t md5[16]; uint8_t md5[16];
int e; 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); MD5Init(&ctx);
MD5Update(&ctx, testarray[i].data.data, testarray[i].data.length); MD5Update(&ctx, data.data, data.length);
MD5Final(md5, &ctx); MD5Final(md5, &ctx);
e = memcmp(testarray[i].md5.data, e = memcmp(md5blob.data,
md5, md5,
MIN(testarray[i].md5.length, sizeof(md5))); MIN(md5blob.length, sizeof(md5)));
if (e != 0) { if (e != 0) {
printf("md5 test[%u]: failed\n", i); printf("md5 test[%u]: failed\n", i);
dump_data(0, testarray[i].data.data, testarray[i].data.length); dump_data(0, data.data, data.length);
dump_data(0, testarray[i].md5.data, testarray[i].md5.length); dump_data(0, md5blob.data, md5blob.length);
dump_data(0, md5, sizeof(md5)); dump_data(0, md5, sizeof(md5));
ret = False; ret = False;
} }
talloc_free(md5blob.data);
} }
return ret; return ret;