/opensource.apple.com/source/OpenSSL096/OpenSSL096-15/openssl/crypto/md2/md2test.c

# · C · 162 lines · 98 code · 10 blank · 54 comment · 2 complexity · af9d649fa71e58573e4105537da49849 MD5 · raw file

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>md2test.c</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">md2test.c&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. <span class="enscript-comment">/* crypto/md2/md2test.c */</span>
  24. <span class="enscript-comment">/* Copyright (C) 1995-1998 Eric Young (<a href="mailto:eay@cryptsoft.com">eay@cryptsoft.com</a>)
  25. * All rights reserved.
  26. *
  27. * This package is an SSL implementation written
  28. * by Eric Young (<a href="mailto:eay@cryptsoft.com">eay@cryptsoft.com</a>).
  29. * The implementation was written so as to conform with Netscapes SSL.
  30. *
  31. * This library is free for commercial and non-commercial use as long as
  32. * the following conditions are aheared to. The following conditions
  33. * apply to all code found in this distribution, be it the RC4, RSA,
  34. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  35. * included with this distribution is covered by the same copyright terms
  36. * except that the holder is Tim Hudson (<a href="mailto:tjh@cryptsoft.com">tjh@cryptsoft.com</a>).
  37. *
  38. * Copyright remains Eric Young's, and as such any Copyright notices in
  39. * the code are not to be removed.
  40. * If this package is used in a product, Eric Young should be given attribution
  41. * as the author of the parts of the library used.
  42. * This can be in the form of a textual message at program startup or
  43. * in documentation (online or textual) provided with the package.
  44. *
  45. * Redistribution and use in source and binary forms, with or without
  46. * modification, are permitted provided that the following conditions
  47. * are met:
  48. * 1. Redistributions of source code must retain the copyright
  49. * notice, this list of conditions and the following disclaimer.
  50. * 2. Redistributions in binary form must reproduce the above copyright
  51. * notice, this list of conditions and the following disclaimer in the
  52. * documentation and/or other materials provided with the distribution.
  53. * 3. All advertising materials mentioning features or use of this software
  54. * must display the following acknowledgement:
  55. * &quot;This product includes cryptographic software written by
  56. * Eric Young (<a href="mailto:eay@cryptsoft.com">eay@cryptsoft.com</a>)&quot;
  57. * The word 'cryptographic' can be left out if the rouines from the library
  58. * being used are not cryptographic related :-).
  59. * 4. If you include any Windows specific code (or a derivative thereof) from
  60. * the apps directory (application code) you must include an acknowledgement:
  61. * &quot;This product includes software written by Tim Hudson (<a href="mailto:tjh@cryptsoft.com">tjh@cryptsoft.com</a>)&quot;
  62. *
  63. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  64. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  65. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  67. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  68. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  69. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  70. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  71. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  72. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  73. * SUCH DAMAGE.
  74. *
  75. * The licence and distribution terms for any publically available version or
  76. * derivative of this code cannot be changed. i.e. this code cannot simply be
  77. * copied and put under another distribution licence
  78. * [including the GNU Public Licence.]
  79. */</span>
  80. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;stdio.h&gt;</span>
  81. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;stdlib.h&gt;</span>
  82. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;string.h&gt;</span>
  83. #<span class="enscript-reference">include</span> <span class="enscript-string">&quot;../e_os.h&quot;</span>
  84. #<span class="enscript-reference">ifdef</span> <span class="enscript-variable-name">NO_MD2</span>
  85. <span class="enscript-type">int</span> <span class="enscript-function-name">main</span>(<span class="enscript-type">int</span> argc, <span class="enscript-type">char</span> *argv[])
  86. {
  87. printf(<span class="enscript-string">&quot;No MD2 support\n&quot;</span>);
  88. <span class="enscript-keyword">return</span>(0);
  89. }
  90. #<span class="enscript-reference">else</span>
  91. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;openssl/md2.h&gt;</span>
  92. #<span class="enscript-reference">ifdef</span> <span class="enscript-variable-name">CHARSET_EBCDIC</span>
  93. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;openssl/ebcdic.h&gt;</span>
  94. #<span class="enscript-reference">endif</span>
  95. <span class="enscript-type">static</span> <span class="enscript-type">char</span> *test[]={
  96. <span class="enscript-string">&quot;&quot;</span>,
  97. <span class="enscript-string">&quot;a&quot;</span>,
  98. <span class="enscript-string">&quot;abc&quot;</span>,
  99. <span class="enscript-string">&quot;message digest&quot;</span>,
  100. <span class="enscript-string">&quot;abcdefghijklmnopqrstuvwxyz&quot;</span>,
  101. <span class="enscript-string">&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&quot;</span>,
  102. <span class="enscript-string">&quot;12345678901234567890123456789012345678901234567890123456789012345678901234567890&quot;</span>,
  103. NULL,
  104. };
  105. <span class="enscript-type">static</span> <span class="enscript-type">char</span> *ret[]={
  106. <span class="enscript-string">&quot;8350e5a3e24c153df2275c9f80692773&quot;</span>,
  107. <span class="enscript-string">&quot;32ec01ec4a6dac72c0ab96fb34c0b5d1&quot;</span>,
  108. <span class="enscript-string">&quot;da853b0d3f88d99b30283a69e6ded6bb&quot;</span>,
  109. <span class="enscript-string">&quot;ab4f496bfb2a530b219ff33031fe06b0&quot;</span>,
  110. <span class="enscript-string">&quot;4e8ddff3650292ab5a4108c3aa47940b&quot;</span>,
  111. <span class="enscript-string">&quot;da33def2a42df13975352846c30338cd&quot;</span>,
  112. <span class="enscript-string">&quot;d5976f79d83d3a0dc9806c3c66f3efd8&quot;</span>,
  113. };
  114. <span class="enscript-type">static</span> <span class="enscript-type">char</span> *<span class="enscript-function-name">pt</span>(<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> *md);
  115. <span class="enscript-type">int</span> <span class="enscript-function-name">main</span>(<span class="enscript-type">int</span> argc, <span class="enscript-type">char</span> *argv[])
  116. {
  117. <span class="enscript-type">int</span> i,err=0;
  118. <span class="enscript-type">char</span> **P,**R;
  119. <span class="enscript-type">char</span> *p;
  120. P=test;
  121. R=ret;
  122. i=1;
  123. <span class="enscript-keyword">while</span> (*P != NULL)
  124. {
  125. p=pt(MD2((<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> *)*P,(<span class="enscript-type">unsigned</span> <span class="enscript-type">long</span>)strlen(*P),NULL));
  126. <span class="enscript-keyword">if</span> (strcmp(p,*R) != 0)
  127. {
  128. printf(<span class="enscript-string">&quot;error calculating MD2 on '%s'\n&quot;</span>,*P);
  129. printf(<span class="enscript-string">&quot;got %s instead of %s\n&quot;</span>,p,*R);
  130. err++;
  131. }
  132. <span class="enscript-keyword">else</span>
  133. printf(<span class="enscript-string">&quot;test %d ok\n&quot;</span>,i);
  134. i++;
  135. R++;
  136. P++;
  137. }
  138. EXIT(err);
  139. <span class="enscript-keyword">return</span>(0);
  140. }
  141. <span class="enscript-type">static</span> <span class="enscript-type">char</span> *<span class="enscript-function-name">pt</span>(<span class="enscript-type">unsigned</span> <span class="enscript-type">char</span> *md)
  142. {
  143. <span class="enscript-type">int</span> i;
  144. <span class="enscript-type">static</span> <span class="enscript-type">char</span> buf[80];
  145. <span class="enscript-keyword">for</span> (i=0; i&lt;MD2_DIGEST_LENGTH; i++)
  146. sprintf(&amp;(buf[i*2]),<span class="enscript-string">&quot;%02x&quot;</span>,md[i]);
  147. <span class="enscript-keyword">return</span>(buf);
  148. }
  149. #<span class="enscript-reference">endif</span>
  150. </pre>
  151. <hr />
  152. </body></html>