md2test.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "../e_os.h"
  13. #ifdef OPENSSL_NO_MD2
  14. int main(int argc, char *argv[])
  15. {
  16. printf("No MD2 support\n");
  17. return (0);
  18. }
  19. #else
  20. # include <openssl/evp.h>
  21. # include <openssl/md2.h>
  22. # ifdef CHARSET_EBCDIC
  23. # include <openssl/ebcdic.h>
  24. # endif
  25. static char *test[] = {
  26. "",
  27. "a",
  28. "abc",
  29. "message digest",
  30. "abcdefghijklmnopqrstuvwxyz",
  31. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
  32. "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
  33. NULL,
  34. };
  35. static char *ret[] = {
  36. "8350e5a3e24c153df2275c9f80692773",
  37. "32ec01ec4a6dac72c0ab96fb34c0b5d1",
  38. "da853b0d3f88d99b30283a69e6ded6bb",
  39. "ab4f496bfb2a530b219ff33031fe06b0",
  40. "4e8ddff3650292ab5a4108c3aa47940b",
  41. "da33def2a42df13975352846c30338cd",
  42. "d5976f79d83d3a0dc9806c3c66f3efd8",
  43. };
  44. static char *pt(unsigned char *md);
  45. int main(int argc, char *argv[])
  46. {
  47. int i, err = 0;
  48. char **P, **R;
  49. char *p;
  50. unsigned char md[MD2_DIGEST_LENGTH];
  51. P = test;
  52. R = ret;
  53. i = 1;
  54. while (*P != NULL) {
  55. if (!EVP_Digest((unsigned char *)*P, strlen(*P), md, NULL, EVP_md2(),
  56. NULL)) {
  57. printf("EVP Digest error.\n");
  58. EXIT(1);
  59. }
  60. p = pt(md);
  61. if (strcmp(p, *R) != 0) {
  62. printf("error calculating MD2 on '%s'\n", *P);
  63. printf("got %s instead of %s\n", p, *R);
  64. err++;
  65. } else
  66. printf("test %d ok\n", i);
  67. i++;
  68. R++;
  69. P++;
  70. }
  71. EXIT(err);
  72. return err;
  73. }
  74. static char *pt(unsigned char *md)
  75. {
  76. int i;
  77. static char buf[80];
  78. for (i = 0; i < MD2_DIGEST_LENGTH; i++)
  79. sprintf(&(buf[i * 2]), "%02x", md[i]);
  80. return (buf);
  81. }
  82. #endif