|
@@ -0,0 +1,93 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
|
|
3
|
+ *
|
|
4
|
+ * This program is free software; you can redistribute it and/or
|
|
5
|
+ * modify it under the terms of the GNU General Public License as
|
|
6
|
+ * published by the Free Software Foundation; either version 2 of the
|
|
7
|
+ * License, or any later version.
|
|
8
|
+ *
|
|
9
|
+ * This program is distributed in the hope that it will be useful, but
|
|
10
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+ * General Public License for more details.
|
|
13
|
+ *
|
|
14
|
+ * You should have received a copy of the GNU General Public License
|
|
15
|
+ * along with this program; if not, write to the Free Software
|
|
16
|
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
+ */
|
|
18
|
+
|
|
19
|
+FILE_LICENCE ( GPL2_OR_LATER );
|
|
20
|
+
|
|
21
|
+/** @file
|
|
22
|
+ *
|
|
23
|
+ * MD5 tests
|
|
24
|
+ *
|
|
25
|
+ */
|
|
26
|
+
|
|
27
|
+#include <stdint.h>
|
|
28
|
+#include <ipxe/md5.h>
|
|
29
|
+#include <ipxe/test.h>
|
|
30
|
+#include "digest_test.h"
|
|
31
|
+
|
|
32
|
+/** An MD5 test vector */
|
|
33
|
+struct md5_test_vector {
|
|
34
|
+ /** Test data */
|
|
35
|
+ void *data;
|
|
36
|
+ /** Test data length */
|
|
37
|
+ size_t len;
|
|
38
|
+ /** Expected digest */
|
|
39
|
+ uint8_t digest[MD5_DIGEST_SIZE];
|
|
40
|
+};
|
|
41
|
+
|
|
42
|
+/** MD5 test vectors */
|
|
43
|
+static struct md5_test_vector md5_test_vectors[] = {
|
|
44
|
+ /* Test inputs borrowed from SHA-1 tests, with results
|
|
45
|
+ * calculated using md5sum.
|
|
46
|
+ */
|
|
47
|
+ { NULL, 0,
|
|
48
|
+ { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04,
|
|
49
|
+ 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e } },
|
|
50
|
+ { "abc", 3,
|
|
51
|
+ { 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0,
|
|
52
|
+ 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 } },
|
|
53
|
+ { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56,
|
|
54
|
+ { 0x82, 0x15, 0xef, 0x07, 0x96, 0xa2, 0x0b, 0xca,
|
|
55
|
+ 0xaa, 0xe1, 0x16, 0xd3, 0x87, 0x6c, 0x66, 0x4a } },
|
|
56
|
+};
|
|
57
|
+
|
|
58
|
+/** MD5 test fragment lists */
|
|
59
|
+static struct digest_test_fragments md5_test_fragments[] = {
|
|
60
|
+ { { 0, -1UL, } },
|
|
61
|
+ { { 1, 1, 1, 1, 1, 1, 1, 1 } },
|
|
62
|
+ { { 2, 0, 23, 4, 6, 1, 0 } },
|
|
63
|
+};
|
|
64
|
+
|
|
65
|
+/**
|
|
66
|
+ * Perform MD5 self-test
|
|
67
|
+ *
|
|
68
|
+ */
|
|
69
|
+static void md5_test_exec ( void ) {
|
|
70
|
+ struct digest_algorithm *digest = &md5_algorithm;
|
|
71
|
+ struct md5_test_vector *test;
|
|
72
|
+ unsigned int i;
|
|
73
|
+ unsigned int j;
|
|
74
|
+
|
|
75
|
+ for ( i = 0 ; i < ( sizeof ( md5_test_vectors ) /
|
|
76
|
+ sizeof ( md5_test_vectors[0] ) ) ; i++ ) {
|
|
77
|
+ test = &md5_test_vectors[i];
|
|
78
|
+ /* Test with a single pass */
|
|
79
|
+ digest_ok ( digest, NULL, test->data, test->len, test->digest );
|
|
80
|
+ /* Test with fragment lists */
|
|
81
|
+ for ( j = 0 ; j < ( sizeof ( md5_test_fragments ) /
|
|
82
|
+ sizeof ( md5_test_fragments[0] ) ) ; j++ ){
|
|
83
|
+ digest_ok ( digest, &md5_test_fragments[j],
|
|
84
|
+ test->data, test->len, test->digest );
|
|
85
|
+ }
|
|
86
|
+ }
|
|
87
|
+}
|
|
88
|
+
|
|
89
|
+/** MD5 self-test */
|
|
90
|
+struct self_test md5_test __self_test = {
|
|
91
|
+ .name = "md5",
|
|
92
|
+ .exec = md5_test_exec,
|
|
93
|
+};
|