| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | MD4 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 |
|
|---|
| 20 | #include "replace.h"
|
|---|
| 21 | #include "../lib/util/util.h"
|
|---|
| 22 | #include "../lib/crypto/crypto.h"
|
|---|
| 23 |
|
|---|
| 24 | struct torture_context;
|
|---|
| 25 |
|
|---|
| 26 | /*
|
|---|
| 27 | This uses the test values from rfc1320
|
|---|
| 28 | */
|
|---|
| 29 | bool torture_local_crypto_md4(struct torture_context *torture)
|
|---|
| 30 | {
|
|---|
| 31 | bool ret = true;
|
|---|
| 32 | uint32_t i;
|
|---|
| 33 | struct {
|
|---|
| 34 | const char *data;
|
|---|
| 35 | const char *md4;
|
|---|
| 36 | } testarray[] = {
|
|---|
| 37 | {
|
|---|
| 38 | .data = "",
|
|---|
| 39 | .md4 = "31d6cfe0d16ae931b73c59d7e0c089c0"
|
|---|
| 40 | },{
|
|---|
| 41 | .data = "a",
|
|---|
| 42 | .md4 = "bde52cb31de33e46245e05fbdbd6fb24"
|
|---|
| 43 | },{
|
|---|
| 44 | .data = "abc",
|
|---|
| 45 | .md4 = "a448017aaf21d8525fc10ae87aa6729d"
|
|---|
| 46 | },{
|
|---|
| 47 | .data = "message digest",
|
|---|
| 48 | .md4 = "d9130a8164549fe818874806e1c7014b"
|
|---|
| 49 | },{
|
|---|
| 50 | .data = "abcdefghijklmnopqrstuvwxyz",
|
|---|
| 51 | .md4 = "d79e1c308aa5bbcdeea8ed63df412da9"
|
|---|
| 52 | },{
|
|---|
| 53 | .data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
|---|
| 54 | .md4 = "043f8582f241db351ce627e153e7f0e4"
|
|---|
| 55 | },{
|
|---|
| 56 | .data = "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
|---|
| 57 | .md4 = "e33b4ddc9c38f2199c3e7b164fcc0536"
|
|---|
| 58 | }
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | for (i=0; i < ARRAY_SIZE(testarray); i++) {
|
|---|
| 62 | uint8_t md4[16];
|
|---|
| 63 | int e;
|
|---|
| 64 | DATA_BLOB data;
|
|---|
| 65 | DATA_BLOB md4blob;
|
|---|
| 66 |
|
|---|
| 67 | data = data_blob_string_const(testarray[i].data);
|
|---|
| 68 | md4blob = strhex_to_data_blob(NULL, testarray[i].md4);
|
|---|
| 69 |
|
|---|
| 70 | mdfour(md4, data.data, data.length);
|
|---|
| 71 |
|
|---|
| 72 | e = memcmp(md4blob.data, md4, MIN(md4blob.length, sizeof(md4)));
|
|---|
| 73 | if (e != 0) {
|
|---|
| 74 | printf("md4 test[%u]: failed\n", i);
|
|---|
| 75 | dump_data(0, data.data, data.length);
|
|---|
| 76 | dump_data(0, md4blob.data, md4blob.length);
|
|---|
| 77 | dump_data(0, md4, sizeof(md4));
|
|---|
| 78 | ret = false;
|
|---|
| 79 | }
|
|---|
| 80 | talloc_free(md4blob.data);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | return ret;
|
|---|
| 84 | }
|
|---|