iPXE
md4_test.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 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
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26/** @file
27 *
28 * MD4 tests
29 *
30 * Test inputs borrowed from NIST SHA-1 tests, with results calculated
31 * using "openssl dgst -md4"
32 */
33
34/* Forcibly enable assertions */
35#undef NDEBUG
36
37#include <ipxe/md4.h>
38#include <ipxe/test.h>
39#include "digest_test.h"
40
41/* Empty test vector */
43 DIGEST ( 0x31, 0xd6, 0xcf, 0xe0, 0xd1, 0x6a, 0xe9, 0x31, 0xb7,
44 0x3c, 0x59, 0xd7, 0xe0, 0xc0, 0x89, 0xc0 ) );
45
46/* NIST test vector "abc" */
48 DIGEST ( 0xa4, 0x48, 0x01, 0x7a, 0xaf, 0x21, 0xd8, 0x52, 0x5f,
49 0xc1, 0x0a, 0xe8, 0x7a, 0xa6, 0x72, 0x9d ) );
50
51/* NIST test vector "abc...opq" */
53 DIGEST ( 0x46, 0x91, 0xa9, 0xec, 0x81, 0xb1, 0xa6, 0xbd, 0x1a,
54 0xb8, 0x55, 0x72, 0x40, 0xb2, 0x45, 0xc5 ) );
55
56/**
57 * Perform MD4 self-test
58 *
59 */
60static void md4_test_exec ( void ) {
61
62 /* Correctness tests */
63 digest_ok ( &md4_empty );
64 digest_ok ( &md4_nist_abc );
65 digest_ok ( &md4_nist_abc_opq );
66
67 /* Speed tests */
68 DBG ( "MD4 required %ld cycles per byte\n",
70}
71
72/** MD4 self-test */
73struct self_test md4_test __self_test = {
74 .name = "md4",
75 .exec = md4_test_exec,
76};
#define DIGEST(...)
Define inline expected digest.
Definition der_test.c:45
unsigned long digest_cost(struct digest_algorithm *digest)
Calculate digest algorithm cost.
#define DIGEST_TEST(name, DIGEST, DATA, EXPECTED)
Define a digest test.
Definition digest_test.h:39
#define digest_ok(test)
Report a digest test result.
#define DIGEST_NIST_ABC_OPQ
Standard test vector: NIST string "abc...opq".
Definition digest_test.h:71
#define DIGEST_NIST_ABC
Standard test vector: NIST string "abc".
Definition digest_test.h:60
#define DIGEST_EMPTY
Standard test vector: empty data.
Definition digest_test.h:51
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
struct digest_algorithm md4_algorithm
MD4 algorithm.
Definition md4.c:262
MD4 algorithm.
static void md4_test_exec(void)
Perform MD4 self-test.
Definition md4_test.c:60
A self-test set.
Definition test.h:15
Self-test infrastructure.
#define __self_test
Declare a self-test.
Definition test.h:32