2
0

mdc2_internal_test.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2016-2020 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. /*
  11. * MDC2 low level APIs are deprecated for public use, but still ok for
  12. * internal use.
  13. */
  14. #include "internal/deprecated.h"
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <openssl/mdc2.h>
  18. #include "testutil.h"
  19. #include "internal/nelem.h"
  20. typedef struct {
  21. const char *input;
  22. const unsigned char expected[MDC2_DIGEST_LENGTH];
  23. } TESTDATA;
  24. /**********************************************************************
  25. *
  26. * Test driver
  27. *
  28. ***/
  29. static TESTDATA tests[] = {
  30. {
  31. "Now is the time for all ",
  32. {
  33. 0x42, 0xE5, 0x0C, 0xD2, 0x24, 0xBA, 0xCE, 0xBA,
  34. 0x76, 0x0B, 0xDD, 0x2B, 0xD4, 0x09, 0x28, 0x1A
  35. }
  36. }
  37. };
  38. /**********************************************************************
  39. *
  40. * Test of mdc2 internal functions
  41. *
  42. ***/
  43. static int test_mdc2(int idx)
  44. {
  45. unsigned char md[MDC2_DIGEST_LENGTH];
  46. MDC2_CTX c;
  47. const TESTDATA testdata = tests[idx];
  48. MDC2_Init(&c);
  49. MDC2_Update(&c, (const unsigned char *)testdata.input,
  50. strlen(testdata.input));
  51. MDC2_Final(&(md[0]), &c);
  52. if (!TEST_mem_eq(testdata.expected, MDC2_DIGEST_LENGTH,
  53. md, MDC2_DIGEST_LENGTH)) {
  54. TEST_info("mdc2 test %d: unexpected output", idx);
  55. return 0;
  56. }
  57. return 1;
  58. }
  59. int setup_tests(void)
  60. {
  61. ADD_ALL_TESTS(test_mdc2, OSSL_NELEM(tests));
  62. return 1;
  63. }