[745] | 1 | /*
|
---|
| 2 | Unix SMB/CIFS implementation.
|
---|
| 3 | HMAC MD5 tests
|
---|
| 4 | Copyright (C) Stefan Metzmacher 2006
|
---|
| 5 |
|
---|
| 6 | This program is free software; you can redistribute it and/or modify
|
---|
| 7 | it under the terms of the GNU General Public License as published by
|
---|
| 8 | the Free Software Foundation; either version 3 of the License, or
|
---|
| 9 | (at your option) any later version.
|
---|
| 10 |
|
---|
| 11 | This program is distributed in the hope that it will be useful,
|
---|
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | GNU General Public License for more details.
|
---|
| 15 |
|
---|
| 16 | You should have received a copy of the GNU General Public License
|
---|
| 17 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 18 | */
|
---|
| 19 | #include "replace.h"
|
---|
| 20 | #include "../lib/util/util.h"
|
---|
| 21 | #include "../lib/crypto/crypto.h"
|
---|
| 22 |
|
---|
| 23 | struct torture_context;
|
---|
| 24 |
|
---|
| 25 | static DATA_BLOB data_blob_repeat_byte(uint8_t byte, size_t length)
|
---|
| 26 | {
|
---|
| 27 | DATA_BLOB b = data_blob(NULL, length);
|
---|
| 28 | memset(b.data, byte, length);
|
---|
| 29 | return b;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | /*
|
---|
| 33 | This uses the test values from rfc 2104, 2202
|
---|
| 34 | */
|
---|
| 35 | bool torture_local_crypto_hmacmd5(struct torture_context *torture)
|
---|
| 36 | {
|
---|
| 37 | bool ret = true;
|
---|
| 38 | uint32_t i;
|
---|
| 39 | struct {
|
---|
| 40 | DATA_BLOB key;
|
---|
| 41 | DATA_BLOB data;
|
---|
| 42 | DATA_BLOB md5;
|
---|
| 43 | } testarray[8];
|
---|
| 44 |
|
---|
| 45 | TALLOC_CTX *tctx = talloc_new(torture);
|
---|
| 46 | if (!tctx) { return false; };
|
---|
| 47 |
|
---|
| 48 | testarray[0].key = data_blob_repeat_byte(0x0b, 16);
|
---|
| 49 | testarray[0].data = data_blob_string_const("Hi There");
|
---|
| 50 | testarray[0].md5 = strhex_to_data_blob(tctx, "9294727a3638bb1c13f48ef8158bfc9d");
|
---|
| 51 |
|
---|
| 52 | testarray[1].key = data_blob_string_const("Jefe");
|
---|
| 53 | testarray[1].data = data_blob_string_const("what do ya want for nothing?");
|
---|
| 54 | testarray[1].md5 = strhex_to_data_blob(tctx, "750c783e6ab0b503eaa86e310a5db738");
|
---|
| 55 |
|
---|
| 56 | testarray[2].key = data_blob_repeat_byte(0xaa, 16);
|
---|
| 57 | testarray[2].data = data_blob_repeat_byte(0xdd, 50);
|
---|
| 58 | testarray[2].md5 = strhex_to_data_blob(tctx, "56be34521d144c88dbb8c733f0e8b3f6");
|
---|
| 59 |
|
---|
| 60 | testarray[3].key = strhex_to_data_blob(tctx, "0102030405060708090a0b0c0d0e0f10111213141516171819");
|
---|
| 61 | testarray[3].data = data_blob_repeat_byte(0xcd, 50);
|
---|
| 62 | testarray[3].md5 = strhex_to_data_blob(tctx, "697eaf0aca3a3aea3a75164746ffaa79");
|
---|
| 63 |
|
---|
| 64 | testarray[4].key = data_blob_repeat_byte(0x0c, 16);
|
---|
| 65 | testarray[4].data = data_blob_string_const("Test With Truncation");
|
---|
| 66 | testarray[4].md5 = strhex_to_data_blob(tctx, "56461ef2342edc00f9bab995690efd4c");
|
---|
| 67 |
|
---|
| 68 | testarray[5].key = data_blob_repeat_byte(0xaa, 80);
|
---|
| 69 | testarray[5].data = data_blob_string_const("Test Using Larger Than Block-Size Key - Hash Key First");
|
---|
| 70 | testarray[5].md5 = strhex_to_data_blob(tctx, "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd");
|
---|
| 71 |
|
---|
| 72 | testarray[6].key = data_blob_repeat_byte(0xaa, 80);
|
---|
| 73 | testarray[6].data = data_blob_string_const("Test Using Larger Than Block-Size Key "
|
---|
| 74 | "and Larger Than One Block-Size Data");
|
---|
| 75 | testarray[6].md5 = strhex_to_data_blob(tctx, "6f630fad67cda0ee1fb1f562db3aa53e");
|
---|
| 76 |
|
---|
| 77 | testarray[7].key = data_blob(NULL, 0);
|
---|
| 78 |
|
---|
| 79 | for (i=0; testarray[i].key.data; i++) {
|
---|
| 80 | HMACMD5Context ctx;
|
---|
| 81 | uint8_t md5[16];
|
---|
| 82 | int e;
|
---|
| 83 |
|
---|
| 84 | hmac_md5_init_rfc2104(testarray[i].key.data, testarray[i].key.length, &ctx);
|
---|
| 85 | hmac_md5_update(testarray[i].data.data, testarray[i].data.length, &ctx);
|
---|
| 86 | hmac_md5_final(md5, &ctx);
|
---|
| 87 |
|
---|
| 88 | e = memcmp(testarray[i].md5.data,
|
---|
| 89 | md5,
|
---|
| 90 | MIN(testarray[i].md5.length, sizeof(md5)));
|
---|
| 91 | if (e != 0) {
|
---|
| 92 | printf("hmacmd5 test[%u]: failed\n", i);
|
---|
| 93 | dump_data(0, testarray[i].key.data, testarray[i].key.length);
|
---|
| 94 | dump_data(0, testarray[i].data.data, testarray[i].data.length);
|
---|
| 95 | dump_data(0, testarray[i].md5.data, testarray[i].md5.length);
|
---|
| 96 | dump_data(0, md5, sizeof(md5));
|
---|
| 97 | ret = false;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | talloc_free(tctx);
|
---|
| 101 | return ret;
|
---|
| 102 | }
|
---|