iPXE
md5_test.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012 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  * MD5 tests
00029  *
00030  * Test inputs borrowed from NIST SHA-1 tests, with results calculated
00031  * using md5sum.
00032  */
00033 
00034 /* Forcibly enable assertions */
00035 #undef NDEBUG
00036 
00037 #include <ipxe/md5.h>
00038 #include <ipxe/test.h>
00039 #include "digest_test.h"
00040 
00041 /* Empty test vector (digest obtained from "md5sum /dev/null") */
00042 DIGEST_TEST ( md5_empty, &md5_algorithm, DIGEST_EMPTY,
00043               DIGEST ( 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9,
00044                        0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e ) );
00045 
00046 /* NIST test vector "abc" (digest obtained from "md5sum <data>") */
00047 DIGEST_TEST ( md5_nist_abc, &md5_algorithm, DIGEST_NIST_ABC,
00048               DIGEST ( 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6,
00049                        0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 ) );
00050 
00051 /* NIST test vector "abc...opq" (digest obtained from "md5sum <data>") */
00052 DIGEST_TEST ( md5_nist_abc_opq, &md5_algorithm, DIGEST_NIST_ABC_OPQ,
00053               DIGEST ( 0x82, 0x15, 0xef, 0x07, 0x96, 0xa2, 0x0b, 0xca, 0xaa,
00054                        0xe1, 0x16, 0xd3, 0x87, 0x6c, 0x66, 0x4a ) );
00055 
00056 /**
00057  * Perform MD5 self-test
00058  *
00059  */
00060 static void md5_test_exec ( void ) {
00061 
00062         /* Correctness tests */
00063         digest_ok ( &md5_empty );
00064         digest_ok ( &md5_nist_abc );
00065         digest_ok ( &md5_nist_abc_opq );
00066 
00067         /* Speed tests */
00068         DBG ( "MD5 required %ld cycles per byte\n",
00069               digest_cost ( &md5_algorithm ) );
00070 }
00071 
00072 /** MD5 self-test */
00073 struct self_test md5_test __self_test = {
00074         .name = "md5",
00075         .exec = md5_test_exec,
00076 };