mdc2_internal_test.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /* Internal tests for the mdc2 module */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <openssl/mdc2.h>
  13. #include "testutil.h"
  14. #include "internal/nelem.h"
  15. typedef struct {
  16. const char *input;
  17. const unsigned char expected[MDC2_DIGEST_LENGTH];
  18. } TESTDATA;
  19. /**********************************************************************
  20. *
  21. * Test driver
  22. *
  23. ***/
  24. static TESTDATA tests[] = {
  25. {
  26. "Now is the time for all ",
  27. {
  28. 0x42, 0xE5, 0x0C, 0xD2, 0x24, 0xBA, 0xCE, 0xBA,
  29. 0x76, 0x0B, 0xDD, 0x2B, 0xD4, 0x09, 0x28, 0x1A
  30. }
  31. }
  32. };
  33. /**********************************************************************
  34. *
  35. * Test of mdc2 internal functions
  36. *
  37. ***/
  38. static int test_mdc2(int idx)
  39. {
  40. unsigned char md[MDC2_DIGEST_LENGTH];
  41. MDC2_CTX c;
  42. const TESTDATA testdata = tests[idx];
  43. MDC2_Init(&c);
  44. MDC2_Update(&c, (const unsigned char *)testdata.input,
  45. strlen(testdata.input));
  46. MDC2_Final(&(md[0]), &c);
  47. if (!TEST_mem_eq(testdata.expected, MDC2_DIGEST_LENGTH,
  48. md, MDC2_DIGEST_LENGTH)) {
  49. TEST_info("mdc2 test %d: unexpected output", idx);
  50. return 0;
  51. }
  52. return 1;
  53. }
  54. int setup_tests(void)
  55. {
  56. ADD_ALL_TESTS(test_mdc2, OSSL_NELEM(tests));
  57. return 1;
  58. }