iPXE
md4_test.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2017 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 /** @file
00027  *
00028  * MD4 tests
00029  *
00030  * Test inputs borrowed from NIST SHA-1 tests, with results calculated
00031  * using "openssl dgst -md4"
00032  */
00033 
00034 /* Forcibly enable assertions */
00035 #undef NDEBUG
00036 
00037 #include <ipxe/md4.h>
00038 #include <ipxe/test.h>
00039 #include "digest_test.h"
00040 
00041 /* Empty test vector */
00042 DIGEST_TEST ( md4_empty, &md4_algorithm, DIGEST_EMPTY,
00043               DIGEST ( 0x31, 0xd6, 0xcf, 0xe0, 0xd1, 0x6a, 0xe9, 0x31, 0xb7,
00044                        0x3c, 0x59, 0xd7, 0xe0, 0xc0, 0x89, 0xc0 ) );
00045 
00046 /* NIST test vector "abc" */
00047 DIGEST_TEST ( md4_nist_abc, &md4_algorithm, DIGEST_NIST_ABC,
00048               DIGEST ( 0xa4, 0x48, 0x01, 0x7a, 0xaf, 0x21, 0xd8, 0x52, 0x5f,
00049                        0xc1, 0x0a, 0xe8, 0x7a, 0xa6, 0x72, 0x9d ) );
00050 
00051 /* NIST test vector "abc...opq" */
00052 DIGEST_TEST ( md4_nist_abc_opq, &md4_algorithm, DIGEST_NIST_ABC_OPQ,
00053               DIGEST ( 0x46, 0x91, 0xa9, 0xec, 0x81, 0xb1, 0xa6, 0xbd, 0x1a,
00054                        0xb8, 0x55, 0x72, 0x40, 0xb2, 0x45, 0xc5 ) );
00055 
00056 /**
00057  * Perform MD4 self-test
00058  *
00059  */
00060 static void md4_test_exec ( void ) {
00061 
00062         /* Correctness tests */
00063         digest_ok ( &md4_empty );
00064         digest_ok ( &md4_nist_abc );
00065         digest_ok ( &md4_nist_abc_opq );
00066 
00067         /* Speed tests */
00068         DBG ( "MD4 required %ld cycles per byte\n",
00069               digest_cost ( &md4_algorithm ) );
00070 }
00071 
00072 /** MD4 self-test */
00073 struct self_test md4_test __self_test = {
00074         .name = "md4",
00075         .exec = md4_test_exec,
00076 };