iPXE
md5_test.c
Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /** @file
27  *
28  * MD5 tests
29  *
30  * Test inputs borrowed from NIST SHA-1 tests, with results calculated
31  * using md5sum.
32  */
33 
34 /* Forcibly enable assertions */
35 #undef NDEBUG
36 
37 #include <ipxe/md5.h>
38 #include <ipxe/test.h>
39 #include "digest_test.h"
40 
41 /* Empty test vector (digest obtained from "md5sum /dev/null") */
43  DIGEST ( 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9,
44  0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e ) );
45 
46 /* NIST test vector "abc" (digest obtained from "md5sum <data>") */
47 DIGEST_TEST ( md5_nist_abc, &md5_algorithm, DIGEST_NIST_ABC,
48  DIGEST ( 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6,
49  0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 ) );
50 
51 /* NIST test vector "abc...opq" (digest obtained from "md5sum <data>") */
52 DIGEST_TEST ( md5_nist_abc_opq, &md5_algorithm, DIGEST_NIST_ABC_OPQ,
53  DIGEST ( 0x82, 0x15, 0xef, 0x07, 0x96, 0xa2, 0x0b, 0xca, 0xaa,
54  0xe1, 0x16, 0xd3, 0x87, 0x6c, 0x66, 0x4a ) );
55 
56 /**
57  * Perform MD5 self-test
58  *
59  */
60 static void md5_test_exec ( void ) {
61 
62  /* Correctness tests */
63  digest_ok ( &md5_empty );
64  digest_ok ( &md5_nist_abc );
65  digest_ok ( &md5_nist_abc_opq );
66 
67  /* Speed tests */
68  DBG ( "MD5 required %ld cycles per byte\n",
70 }
71 
72 /** MD5 self-test */
73 struct self_test md5_test __self_test = {
74  .name = "md5",
75  .exec = md5_test_exec,
76 };
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define DIGEST_NIST_ABC
Standard test vector: NIST string "abc".
Definition: digest_test.h:60
Self-test infrastructure.
const char * name
Test set name.
Definition: test.h:17
A self-test set.
Definition: test.h:15
#define DIGEST_NIST_ABC_OPQ
Standard test vector: NIST string "abc...opq".
Definition: digest_test.h:71
unsigned long digest_cost(struct digest_algorithm *digest)
Calculate digest algorithm cost.
Definition: digest_test.c:131
static void md5_test_exec(void)
Perform MD5 self-test.
Definition: md5_test.c:60
#define digest_ok(test)
Report a digest test result.
Definition: digest_test.h:109
#define DIGEST_EMPTY
Standard test vector: empty data.
Definition: digest_test.h:51
DIGEST_TEST(md5_empty, &md5_algorithm, DIGEST_EMPTY, DIGEST(0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e))
struct self_test md5_test __self_test
MD5 self-test.
Definition: md5_test.c:73
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define DIGEST(...)
Define inline expected digest.
Definition: der_test.c:45
MD5 algorithm.
struct digest_algorithm md5_algorithm
MD5 algorithm.
Definition: md5.c:286