You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

md4_test.c 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /** @file
  25. *
  26. * MD4 tests
  27. *
  28. * Test inputs borrowed from NIST SHA-1 tests, with results calculated
  29. * using "openssl dgst -md4"
  30. */
  31. /* Forcibly enable assertions */
  32. #undef NDEBUG
  33. #include <ipxe/md4.h>
  34. #include <ipxe/test.h>
  35. #include "digest_test.h"
  36. /* Empty test vector */
  37. DIGEST_TEST ( md4_empty, &md4_algorithm, DIGEST_EMPTY,
  38. DIGEST ( 0x31, 0xd6, 0xcf, 0xe0, 0xd1, 0x6a, 0xe9, 0x31, 0xb7,
  39. 0x3c, 0x59, 0xd7, 0xe0, 0xc0, 0x89, 0xc0 ) );
  40. /* NIST test vector "abc" */
  41. DIGEST_TEST ( md4_nist_abc, &md4_algorithm, DIGEST_NIST_ABC,
  42. DIGEST ( 0xa4, 0x48, 0x01, 0x7a, 0xaf, 0x21, 0xd8, 0x52, 0x5f,
  43. 0xc1, 0x0a, 0xe8, 0x7a, 0xa6, 0x72, 0x9d ) );
  44. /* NIST test vector "abc...opq" */
  45. DIGEST_TEST ( md4_nist_abc_opq, &md4_algorithm, DIGEST_NIST_ABC_OPQ,
  46. DIGEST ( 0x46, 0x91, 0xa9, 0xec, 0x81, 0xb1, 0xa6, 0xbd, 0x1a,
  47. 0xb8, 0x55, 0x72, 0x40, 0xb2, 0x45, 0xc5 ) );
  48. /**
  49. * Perform MD4 self-test
  50. *
  51. */
  52. static void md4_test_exec ( void ) {
  53. /* Correctness tests */
  54. digest_ok ( &md4_empty );
  55. digest_ok ( &md4_nist_abc );
  56. digest_ok ( &md4_nist_abc_opq );
  57. /* Speed tests */
  58. DBG ( "MD4 required %ld cycles per byte\n",
  59. digest_cost ( &md4_algorithm ) );
  60. }
  61. /** MD4 self-test */
  62. struct self_test md4_test __self_test = {
  63. .name = "md4",
  64. .exec = md4_test_exec,
  65. };