Current File : //usr/share/doc/net-snmp/html/md5_8c_source.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>net-snmp: md5.c Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">net-snmp
   &#160;<span id="projectnumber">5.4.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="examples.html"><span>Examples</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">md5.c</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * ** **************************************************************************</span>
<a name="l00003"></a>00003 <span class="comment"> * ** md5.c -- Implementation of MD5 Message Digest Algorithm                 **</span>
<a name="l00004"></a>00004 <span class="comment"> * ** Updated: 2/16/90 by Ronald L. Rivest                                    **</span>
<a name="l00005"></a>00005 <span class="comment"> * ** (C) 1990 RSA Data Security, Inc.                                        **</span>
<a name="l00006"></a>00006 <span class="comment"> * ** **************************************************************************</span>
<a name="l00007"></a>00007 <span class="comment"> */</span>
<a name="l00008"></a>00008 
<a name="l00009"></a>00009 <span class="comment">/*</span>
<a name="l00010"></a>00010 <span class="comment"> * ** To use MD5:</span>
<a name="l00011"></a>00011 <span class="comment"> * **   -- Include md5.h in your program</span>
<a name="l00012"></a>00012 <span class="comment"> * **   -- Declare an MDstruct MD to hold the state of the digest computation.</span>
<a name="l00013"></a>00013 <span class="comment"> * **   -- Initialize MD using MDbegin(&amp;MD)</span>
<a name="l00014"></a>00014 <span class="comment"> * **   -- For each full block (64 bytes) X you wish to process, call</span>
<a name="l00015"></a>00015 <span class="comment"> * **          MDupdate(&amp;MD,X,512)</span>
<a name="l00016"></a>00016 <span class="comment"> * **      (512 is the number of bits in a full block.)</span>
<a name="l00017"></a>00017 <span class="comment"> * **   -- For the last block (less than 64 bytes) you wish to process,</span>
<a name="l00018"></a>00018 <span class="comment"> * **          MDupdate(&amp;MD,X,n)</span>
<a name="l00019"></a>00019 <span class="comment"> * **      where n is the number of bits in the partial block. A partial</span>
<a name="l00020"></a>00020 <span class="comment"> * **      block terminates the computation, so every MD computation should</span>
<a name="l00021"></a>00021 <span class="comment"> * **      terminate by processing a partial block, even if it has n = 0.</span>
<a name="l00022"></a>00022 <span class="comment"> * **   -- The message digest is available in MD.buffer[0] ... MD.buffer[3].</span>
<a name="l00023"></a>00023 <span class="comment"> * **      (Least-significant byte of each word should be output first.)</span>
<a name="l00024"></a>00024 <span class="comment"> * **   -- You can print out the digest using MDprint(&amp;MD)</span>
<a name="l00025"></a>00025 <span class="comment"> */</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="comment">/*</span>
<a name="l00028"></a>00028 <span class="comment"> * Implementation notes:</span>
<a name="l00029"></a>00029 <span class="comment"> * ** This implementation assumes that ints are 32-bit quantities.</span>
<a name="l00030"></a>00030 <span class="comment"> * ** If the machine stores the least-significant byte of an int in the</span>
<a name="l00031"></a>00031 <span class="comment"> * ** least-addressed byte (eg., VAX and 8086), then LOWBYTEFIRST should be</span>
<a name="l00032"></a>00032 <span class="comment"> * ** set to TRUE.  Otherwise (eg., SUNS), LOWBYTEFIRST should be set to</span>
<a name="l00033"></a>00033 <span class="comment"> * ** FALSE.  Note that on machines with LOWBYTEFIRST FALSE the routine</span>
<a name="l00034"></a>00034 <span class="comment"> * ** MDupdate modifies has a side-effect on its input array (the order of bytes</span>
<a name="l00035"></a>00035 <span class="comment"> * ** in each word are reversed).  If this is undesired a call to MDreverse(X) can</span>
<a name="l00036"></a>00036 <span class="comment"> * ** reverse the bytes of X back into order after each call to MDupdate.</span>
<a name="l00037"></a>00037 <span class="comment"> */</span>
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 <span class="comment">/*</span>
<a name="l00040"></a>00040 <span class="comment"> * code uses WORDS_BIGENDIAN defined by configure now  -- WH 9/27/95 </span>
<a name="l00041"></a>00041 <span class="comment"> */</span>
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="comment">/*</span>
<a name="l00044"></a>00044 <span class="comment"> * Compile-time includes </span>
<a name="l00045"></a>00045 <span class="comment"> */</span>
<a name="l00046"></a>00046 
<a name="l00047"></a>00047 <span class="preprocessor">#include &lt;net-snmp/net-snmp-config.h&gt;</span>
<a name="l00048"></a>00048 
<a name="l00049"></a>00049 <span class="preprocessor">#ifndef NETSNMP_DISABLE_MD5</span>
<a name="l00050"></a>00050 <span class="preprocessor"></span>
<a name="l00051"></a>00051 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00052"></a>00052 <span class="preprocessor">#include &lt;sys/types.h&gt;</span>
<a name="l00053"></a>00053 <span class="preprocessor">#if HAVE_STRING_H</span>
<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00055"></a>00055 <span class="preprocessor">#else</span>
<a name="l00056"></a>00056 <span class="preprocessor"></span><span class="preprocessor">#include &lt;strings.h&gt;</span>
<a name="l00057"></a>00057 <span class="preprocessor">#endif</span>
<a name="l00058"></a>00058 <span class="preprocessor"></span><span class="preprocessor">#if HAVE_WINSOCK_H</span>
<a name="l00059"></a>00059 <span class="preprocessor"></span><span class="preprocessor">#include &lt;winsock.h&gt;</span>
<a name="l00060"></a>00060 <span class="preprocessor">#endif</span>
<a name="l00061"></a>00061 <span class="preprocessor"></span>
<a name="l00062"></a>00062 <span class="preprocessor">#if HAVE_STDLIB_H</span>
<a name="l00063"></a>00063 <span class="preprocessor"></span><span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00064"></a>00064 <span class="preprocessor">#endif</span>
<a name="l00065"></a>00065 <span class="preprocessor"></span>
<a name="l00066"></a>00066 <span class="preprocessor">#include &lt;net-snmp/utilities.h&gt;</span>
<a name="l00067"></a>00067 <span class="preprocessor">#include &lt;net-snmp/library/md5.h&gt;</span>
<a name="l00068"></a>00068 
<a name="l00069"></a>00069 <span class="comment">/*</span>
<a name="l00070"></a>00070 <span class="comment"> * Compile-time declarations of MD5 ``magic constants&#39;&#39;.</span>
<a name="l00071"></a>00071 <span class="comment"> */</span>
<a name="l00072"></a>00072 <span class="preprocessor">#define I0  0x67452301          </span><span class="comment">/* Initial values for MD buffer */</span>
<a name="l00073"></a>00073 <span class="preprocessor">#define I1  0xefcdab89</span>
<a name="l00074"></a>00074 <span class="preprocessor"></span><span class="preprocessor">#define I2  0x98badcfe</span>
<a name="l00075"></a>00075 <span class="preprocessor"></span><span class="preprocessor">#define I3  0x10325476</span>
<a name="l00076"></a>00076 <span class="preprocessor"></span><span class="preprocessor">#define fs1  7                  </span><span class="comment">/* round 1 shift amounts */</span>
<a name="l00077"></a>00077 <span class="preprocessor">#define fs2 12</span>
<a name="l00078"></a>00078 <span class="preprocessor"></span><span class="preprocessor">#define fs3 17</span>
<a name="l00079"></a>00079 <span class="preprocessor"></span><span class="preprocessor">#define fs4 22</span>
<a name="l00080"></a>00080 <span class="preprocessor"></span><span class="preprocessor">#define gs1  5                  </span><span class="comment">/* round 2 shift amounts */</span>
<a name="l00081"></a>00081 <span class="preprocessor">#define gs2  9</span>
<a name="l00082"></a>00082 <span class="preprocessor"></span><span class="preprocessor">#define gs3 14</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="preprocessor">#define gs4 20</span>
<a name="l00084"></a>00084 <span class="preprocessor"></span><span class="preprocessor">#define hs1  4                  </span><span class="comment">/* round 3 shift amounts */</span>
<a name="l00085"></a>00085 <span class="preprocessor">#define hs2 11</span>
<a name="l00086"></a>00086 <span class="preprocessor"></span><span class="preprocessor">#define hs3 16</span>
<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#define hs4 23</span>
<a name="l00088"></a>00088 <span class="preprocessor"></span><span class="preprocessor">#define is1  6                  </span><span class="comment">/* round 4 shift amounts */</span>
<a name="l00089"></a>00089 <span class="preprocessor">#define is2 10</span>
<a name="l00090"></a>00090 <span class="preprocessor"></span><span class="preprocessor">#define is3 15</span>
<a name="l00091"></a>00091 <span class="preprocessor"></span><span class="preprocessor">#define is4 21</span>
<a name="l00092"></a>00092 <span class="preprocessor"></span>
<a name="l00093"></a>00093 
<a name="l00094"></a>00094 <span class="comment">/*</span>
<a name="l00095"></a>00095 <span class="comment"> * Compile-time macro declarations for MD5.</span>
<a name="l00096"></a>00096 <span class="comment"> * ** Note: The ``rot&#39;&#39; operator uses the variable ``tmp&#39;&#39;.</span>
<a name="l00097"></a>00097 <span class="comment"> * ** It assumes tmp is declared as unsigned int, so that the &gt;&gt;</span>
<a name="l00098"></a>00098 <span class="comment"> * ** operator will shift in zeros rather than extending the sign bit.</span>
<a name="l00099"></a>00099 <span class="comment"> */</span>
<a name="l00100"></a>00100 <span class="preprocessor">#define f(X,Y,Z)             ((X&amp;Y) | ((~X)&amp;Z))</span>
<a name="l00101"></a>00101 <span class="preprocessor"></span><span class="preprocessor">#define g(X,Y,Z)             ((X&amp;Z) | (Y&amp;(~Z)))</span>
<a name="l00102"></a>00102 <span class="preprocessor"></span><span class="preprocessor">#define h(X,Y,Z)             (X^Y^Z)</span>
<a name="l00103"></a>00103 <span class="preprocessor"></span><span class="preprocessor">#define i_(X,Y,Z)            (Y ^ ((X) | (~Z)))</span>
<a name="l00104"></a>00104 <span class="preprocessor"></span><span class="preprocessor">#define rot(X,S)             (tmp=X,(tmp&lt;&lt;S) | (tmp&gt;&gt;(32-S)))</span>
<a name="l00105"></a>00105 <span class="preprocessor"></span><span class="preprocessor">#define ff(A,B,C,D,i,s,lp)   A = rot((A + f(B,C,D) + X[i] + lp),s) + B</span>
<a name="l00106"></a>00106 <span class="preprocessor"></span><span class="preprocessor">#define gg(A,B,C,D,i,s,lp)   A = rot((A + g(B,C,D) + X[i] + lp),s) + B</span>
<a name="l00107"></a>00107 <span class="preprocessor"></span><span class="preprocessor">#define hh(A,B,C,D,i,s,lp)   A = rot((A + h(B,C,D) + X[i] + lp),s) + B</span>
<a name="l00108"></a>00108 <span class="preprocessor"></span><span class="preprocessor">#define ii(A,B,C,D,i,s,lp)   A = rot((A + i_(B,C,D) + X[i] + lp),s) + B</span>
<a name="l00109"></a>00109 <span class="preprocessor"></span>
<a name="l00110"></a>00110 <span class="preprocessor">#ifdef STDC_HEADERS</span>
<a name="l00111"></a>00111 <span class="preprocessor"></span><span class="preprocessor">#define Uns(num) num##U</span>
<a name="l00112"></a>00112 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00113"></a>00113 <span class="preprocessor"></span><span class="preprocessor">#define Uns(num) num</span>
<a name="l00114"></a>00114 <span class="preprocessor"></span><span class="preprocessor">#endif                          </span><span class="comment">/* STDC_HEADERS */</span>
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 <span class="keywordtype">void</span>            MDreverse(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *);
<a name="l00117"></a>00117 <span class="keyword">static</span> <span class="keywordtype">void</span>     MDblock(<a class="code" href="structMDstruct.html">MDptr</a>, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *);
<a name="l00118"></a>00118 
<a name="l00119"></a>00119 <span class="preprocessor">#ifdef NETSNMP_ENABLE_TESTING_CODE</span>
<a name="l00120"></a>00120 <span class="preprocessor"></span><span class="comment">/*</span>
<a name="l00121"></a>00121 <span class="comment"> * MDprint(MDp)</span>
<a name="l00122"></a>00122 <span class="comment"> * ** Print message digest buffer MDp as 32 hexadecimal digits.</span>
<a name="l00123"></a>00123 <span class="comment"> * ** Order is from low-order byte of buffer[0] to high-order byte of buffer[3].</span>
<a name="l00124"></a>00124 <span class="comment"> * ** Each byte is printed with high-order hexadecimal digit first.</span>
<a name="l00125"></a>00125 <span class="comment"> * ** This is a user-callable routine.</span>
<a name="l00126"></a>00126 <span class="comment"> */</span>
<a name="l00127"></a>00127 <span class="keywordtype">void</span>
<a name="l00128"></a>00128 MDprint(<a class="code" href="structMDstruct.html">MDptr</a> MDp)
<a name="l00129"></a>00129 {
<a name="l00130"></a>00130     <span class="keywordtype">int</span>             i, j;
<a name="l00131"></a>00131     <span class="keywordflow">for</span> (i = 0; i &lt; 4; i++)
<a name="l00132"></a>00132         <span class="keywordflow">for</span> (j = 0; j &lt; 32; j = j + 8)
<a name="l00133"></a>00133             printf(<span class="stringliteral">&quot;%02x&quot;</span>, (MDp-&gt;buffer[i] &gt;&gt; j) &amp; 0xFF);
<a name="l00134"></a>00134     printf(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00135"></a>00135     fflush(stdout);
<a name="l00136"></a>00136 }
<a name="l00137"></a>00137 <span class="preprocessor">#endif                          </span><span class="comment">/* NETSNMP_ENABLE_TESTING_CODE */</span>
<a name="l00138"></a>00138 
<a name="l00139"></a>00139 <span class="comment">/*</span>
<a name="l00140"></a>00140 <span class="comment"> * MDbegin(MDp)</span>
<a name="l00141"></a>00141 <span class="comment"> * ** Initialize message digest buffer MDp. </span>
<a name="l00142"></a>00142 <span class="comment"> * ** This is a user-callable routine.</span>
<a name="l00143"></a>00143 <span class="comment"> */</span>
<a name="l00144"></a>00144 <span class="keywordtype">void</span>
<a name="l00145"></a>00145 MDbegin(<a class="code" href="structMDstruct.html">MDptr</a> MDp)
<a name="l00146"></a>00146 {
<a name="l00147"></a>00147     <span class="keywordtype">int</span>             i;
<a name="l00148"></a>00148     MDp-&gt;buffer[0] = I0;
<a name="l00149"></a>00149     MDp-&gt;buffer[1] = I1;
<a name="l00150"></a>00150     MDp-&gt;buffer[2] = I2;
<a name="l00151"></a>00151     MDp-&gt;buffer[3] = I3;
<a name="l00152"></a>00152     <span class="keywordflow">for</span> (i = 0; i &lt; 8; i++)
<a name="l00153"></a>00153         MDp-&gt;count[i] = 0;
<a name="l00154"></a>00154     MDp-&gt;done = 0;
<a name="l00155"></a>00155 }
<a name="l00156"></a>00156 
<a name="l00157"></a>00157 <span class="comment">/*</span>
<a name="l00158"></a>00158 <span class="comment"> * MDreverse(X)</span>
<a name="l00159"></a>00159 <span class="comment"> * ** Reverse the byte-ordering of every int in X.</span>
<a name="l00160"></a>00160 <span class="comment"> * ** Assumes X is an array of 16 ints.</span>
<a name="l00161"></a>00161 <span class="comment"> * ** The macro revx reverses the byte-ordering of the next word of X.</span>
<a name="l00162"></a>00162 <span class="comment"> */</span>
<a name="l00163"></a>00163 <span class="preprocessor">#define revx { t = (*X &lt;&lt; 16) | (*X &gt;&gt; 16); \</span>
<a name="l00164"></a>00164 <span class="preprocessor">               *X++ = ((t &amp; 0xFF00FF00) &gt;&gt; 8) | ((t &amp; 0x00FF00FF) &lt;&lt; 8); }</span>
<a name="l00165"></a>00165 <span class="preprocessor"></span>
<a name="l00166"></a>00166 <span class="keywordtype">void</span>
<a name="l00167"></a>00167 MDreverse(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *X)
<a name="l00168"></a>00168 {
<a name="l00169"></a>00169     <span class="keyword">register</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> t;
<a name="l00170"></a>00170     revx;
<a name="l00171"></a>00171     revx;
<a name="l00172"></a>00172     revx;
<a name="l00173"></a>00173     revx;
<a name="l00174"></a>00174     revx;
<a name="l00175"></a>00175     revx;
<a name="l00176"></a>00176     revx;
<a name="l00177"></a>00177     revx;
<a name="l00178"></a>00178     revx;
<a name="l00179"></a>00179     revx;
<a name="l00180"></a>00180     revx;
<a name="l00181"></a>00181     revx;
<a name="l00182"></a>00182     revx;
<a name="l00183"></a>00183     revx;
<a name="l00184"></a>00184     revx;
<a name="l00185"></a>00185     revx;
<a name="l00186"></a>00186 }
<a name="l00187"></a>00187 
<a name="l00188"></a>00188 <span class="comment">/*</span>
<a name="l00189"></a>00189 <span class="comment"> * MDblock(MDp,X)</span>
<a name="l00190"></a>00190 <span class="comment"> * ** Update message digest buffer MDp-&gt;buffer using 16-word data block X.</span>
<a name="l00191"></a>00191 <span class="comment"> * ** Assumes all 16 words of X are full of data.</span>
<a name="l00192"></a>00192 <span class="comment"> * ** Does not update MDp-&gt;count.</span>
<a name="l00193"></a>00193 <span class="comment"> * ** This routine is not user-callable. </span>
<a name="l00194"></a>00194 <span class="comment"> */</span>
<a name="l00195"></a>00195 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00196"></a>00196 MDblock(<a class="code" href="structMDstruct.html">MDptr</a> MDp, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *X)
<a name="l00197"></a>00197 {
<a name="l00198"></a>00198     <span class="keyword">register</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> tmp, A, B, C, D;      <span class="comment">/* hpux sysv sun */</span>
<a name="l00199"></a>00199 <span class="preprocessor">#ifdef WORDS_BIGENDIAN</span>
<a name="l00200"></a>00200 <span class="preprocessor"></span>    MDreverse(X);
<a name="l00201"></a>00201 <span class="preprocessor">#endif</span>
<a name="l00202"></a>00202 <span class="preprocessor"></span>    A = MDp-&gt;buffer[0];
<a name="l00203"></a>00203     B = MDp-&gt;buffer[1];
<a name="l00204"></a>00204     C = MDp-&gt;buffer[2];
<a name="l00205"></a>00205     D = MDp-&gt;buffer[3];
<a name="l00206"></a>00206 
<a name="l00207"></a>00207     <span class="comment">/*</span>
<a name="l00208"></a>00208 <span class="comment">     * Update the message digest buffer </span>
<a name="l00209"></a>00209 <span class="comment">     */</span>
<a name="l00210"></a>00210     ff(A, B, C, D, 0, fs1, Uns(3614090360));    <span class="comment">/* Round 1 */</span>
<a name="l00211"></a>00211     ff(D, A, B, C, 1, fs2, Uns(3905402710));
<a name="l00212"></a>00212     ff(C, D, A, B, 2, fs3, Uns(606105819));
<a name="l00213"></a>00213     ff(B, C, D, A, 3, fs4, Uns(3250441966));
<a name="l00214"></a>00214     ff(A, B, C, D, 4, fs1, Uns(4118548399));
<a name="l00215"></a>00215     ff(D, A, B, C, 5, fs2, Uns(1200080426));
<a name="l00216"></a>00216     ff(C, D, A, B, 6, fs3, Uns(2821735955));
<a name="l00217"></a>00217     ff(B, C, D, A, 7, fs4, Uns(4249261313));
<a name="l00218"></a>00218     ff(A, B, C, D, 8, fs1, Uns(1770035416));
<a name="l00219"></a>00219     ff(D, A, B, C, 9, fs2, Uns(2336552879));
<a name="l00220"></a>00220     ff(C, D, A, B, 10, fs3, Uns(4294925233));
<a name="l00221"></a>00221     ff(B, C, D, A, 11, fs4, Uns(2304563134));
<a name="l00222"></a>00222     ff(A, B, C, D, 12, fs1, Uns(1804603682));
<a name="l00223"></a>00223     ff(D, A, B, C, 13, fs2, Uns(4254626195));
<a name="l00224"></a>00224     ff(C, D, A, B, 14, fs3, Uns(2792965006));
<a name="l00225"></a>00225     ff(B, C, D, A, 15, fs4, Uns(1236535329));
<a name="l00226"></a>00226     gg(A, B, C, D, 1, gs1, Uns(4129170786));    <span class="comment">/* Round 2 */</span>
<a name="l00227"></a>00227     gg(D, A, B, C, 6, gs2, Uns(3225465664));
<a name="l00228"></a>00228     gg(C, D, A, B, 11, gs3, Uns(643717713));
<a name="l00229"></a>00229     gg(B, C, D, A, 0, gs4, Uns(3921069994));
<a name="l00230"></a>00230     gg(A, B, C, D, 5, gs1, Uns(3593408605));
<a name="l00231"></a>00231     gg(D, A, B, C, 10, gs2, Uns(38016083));
<a name="l00232"></a>00232     gg(C, D, A, B, 15, gs3, Uns(3634488961));
<a name="l00233"></a>00233     gg(B, C, D, A, 4, gs4, Uns(3889429448));
<a name="l00234"></a>00234     gg(A, B, C, D, 9, gs1, Uns(568446438));
<a name="l00235"></a>00235     gg(D, A, B, C, 14, gs2, Uns(3275163606));
<a name="l00236"></a>00236     gg(C, D, A, B, 3, gs3, Uns(4107603335));
<a name="l00237"></a>00237     gg(B, C, D, A, 8, gs4, Uns(1163531501));
<a name="l00238"></a>00238     gg(A, B, C, D, 13, gs1, Uns(2850285829));
<a name="l00239"></a>00239     gg(D, A, B, C, 2, gs2, Uns(4243563512));
<a name="l00240"></a>00240     gg(C, D, A, B, 7, gs3, Uns(1735328473));
<a name="l00241"></a>00241     gg(B, C, D, A, 12, gs4, Uns(2368359562));
<a name="l00242"></a>00242     hh(A, B, C, D, 5, hs1, Uns(4294588738));    <span class="comment">/* Round 3 */</span>
<a name="l00243"></a>00243     hh(D, A, B, C, 8, hs2, Uns(2272392833));
<a name="l00244"></a>00244     hh(C, D, A, B, 11, hs3, Uns(1839030562));
<a name="l00245"></a>00245     hh(B, C, D, A, 14, hs4, Uns(4259657740));
<a name="l00246"></a>00246     hh(A, B, C, D, 1, hs1, Uns(2763975236));
<a name="l00247"></a>00247     hh(D, A, B, C, 4, hs2, Uns(1272893353));
<a name="l00248"></a>00248     hh(C, D, A, B, 7, hs3, Uns(4139469664));
<a name="l00249"></a>00249     hh(B, C, D, A, 10, hs4, Uns(3200236656));
<a name="l00250"></a>00250     hh(A, B, C, D, 13, hs1, Uns(681279174));
<a name="l00251"></a>00251     hh(D, A, B, C, 0, hs2, Uns(3936430074));
<a name="l00252"></a>00252     hh(C, D, A, B, 3, hs3, Uns(3572445317));
<a name="l00253"></a>00253     hh(B, C, D, A, 6, hs4, Uns(76029189));
<a name="l00254"></a>00254     hh(A, B, C, D, 9, hs1, Uns(3654602809));
<a name="l00255"></a>00255     hh(D, A, B, C, 12, hs2, Uns(3873151461));
<a name="l00256"></a>00256     hh(C, D, A, B, 15, hs3, Uns(530742520));
<a name="l00257"></a>00257     hh(B, C, D, A, 2, hs4, Uns(3299628645));
<a name="l00258"></a>00258     ii(A, B, C, D, 0, is1, Uns(4096336452));    <span class="comment">/* Round 4 */</span>
<a name="l00259"></a>00259     ii(D, A, B, C, 7, is2, Uns(1126891415));
<a name="l00260"></a>00260     ii(C, D, A, B, 14, is3, Uns(2878612391));
<a name="l00261"></a>00261     ii(B, C, D, A, 5, is4, Uns(4237533241));
<a name="l00262"></a>00262     ii(A, B, C, D, 12, is1, Uns(1700485571));
<a name="l00263"></a>00263     ii(D, A, B, C, 3, is2, Uns(2399980690));
<a name="l00264"></a>00264     ii(C, D, A, B, 10, is3, Uns(4293915773));
<a name="l00265"></a>00265     ii(B, C, D, A, 1, is4, Uns(2240044497));
<a name="l00266"></a>00266     ii(A, B, C, D, 8, is1, Uns(1873313359));
<a name="l00267"></a>00267     ii(D, A, B, C, 15, is2, Uns(4264355552));
<a name="l00268"></a>00268     ii(C, D, A, B, 6, is3, Uns(2734768916));
<a name="l00269"></a>00269     ii(B, C, D, A, 13, is4, Uns(1309151649));
<a name="l00270"></a>00270     ii(A, B, C, D, 4, is1, Uns(4149444226));
<a name="l00271"></a>00271     ii(D, A, B, C, 11, is2, Uns(3174756917));
<a name="l00272"></a>00272     ii(C, D, A, B, 2, is3, Uns(718787259));
<a name="l00273"></a>00273     ii(B, C, D, A, 9, is4, Uns(3951481745));
<a name="l00274"></a>00274 
<a name="l00275"></a>00275     MDp-&gt;buffer[0] += A;
<a name="l00276"></a>00276     MDp-&gt;buffer[1] += B;
<a name="l00277"></a>00277     MDp-&gt;buffer[2] += C;
<a name="l00278"></a>00278     MDp-&gt;buffer[3] += D;
<a name="l00279"></a>00279 <span class="preprocessor">#ifdef WORDS_BIGENDIAN</span>
<a name="l00280"></a>00280 <span class="preprocessor"></span>    MDreverse(X);
<a name="l00281"></a>00281 <span class="preprocessor">#endif</span>
<a name="l00282"></a>00282 <span class="preprocessor"></span>}
<a name="l00283"></a>00283 
<a name="l00284"></a>00284 <span class="comment">/*</span>
<a name="l00285"></a>00285 <span class="comment"> * MDupdate(MDp,X,count)</span>
<a name="l00286"></a>00286 <span class="comment"> * ** Input: MDp -- an MDptr</span>
<a name="l00287"></a>00287 <span class="comment"> * **        X -- a pointer to an array of unsigned characters.</span>
<a name="l00288"></a>00288 <span class="comment"> * **        count -- the number of bits of X to use.</span>
<a name="l00289"></a>00289 <span class="comment"> * **                 (if not a multiple of 8, uses high bits of last byte.)</span>
<a name="l00290"></a>00290 <span class="comment"> * ** Update MDp using the number of bits of X given by count.</span>
<a name="l00291"></a>00291 <span class="comment"> * ** This is the basic input routine for an MD5 user.</span>
<a name="l00292"></a>00292 <span class="comment"> * ** The routine completes the MD computation when count &lt; 512, so</span>
<a name="l00293"></a>00293 <span class="comment"> * ** every MD computation should end with one call to MDupdate with a</span>
<a name="l00294"></a>00294 <span class="comment"> * ** count less than 512.  A call with count 0 will be ignored if the</span>
<a name="l00295"></a>00295 <span class="comment"> * ** MD has already been terminated (done != 0), so an extra call with count</span>
<a name="l00296"></a>00296 <span class="comment"> * ** 0 can be given as a ``courtesy close&#39;&#39; to force termination if desired.</span>
<a name="l00297"></a>00297 <span class="comment"> * ** Returns : 0 if processing succeeds or was already done;</span>
<a name="l00298"></a>00298 <span class="comment"> * **          -1 if processing was already done</span>
<a name="l00299"></a>00299 <span class="comment"> * **          -2 if count was too large</span>
<a name="l00300"></a>00300 <span class="comment"> */</span>
<a name="l00301"></a>00301 <span class="keywordtype">int</span>
<a name="l00302"></a>00302 MDupdate(<a class="code" href="structMDstruct.html">MDptr</a> MDp, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *X, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> count)
<a name="l00303"></a>00303 {
<a name="l00304"></a>00304     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>    i, tmp, bit, byte, mask;
<a name="l00305"></a>00305     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>   XX[64];
<a name="l00306"></a>00306     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>  *p;
<a name="l00307"></a>00307     <span class="comment">/*</span>
<a name="l00308"></a>00308 <span class="comment">     * return with no error if this is a courtesy close with count</span>
<a name="l00309"></a>00309 <span class="comment">     * ** zero and MDp-&gt;done is true.</span>
<a name="l00310"></a>00310 <span class="comment">     */</span>
<a name="l00311"></a>00311     <span class="keywordflow">if</span> (count == 0 &amp;&amp; MDp-&gt;done)
<a name="l00312"></a>00312         <span class="keywordflow">return</span> 0;
<a name="l00313"></a>00313     <span class="comment">/*</span>
<a name="l00314"></a>00314 <span class="comment">     * check to see if MD is already done and report error </span>
<a name="l00315"></a>00315 <span class="comment">     */</span>
<a name="l00316"></a>00316     <span class="keywordflow">if</span> (MDp-&gt;done) {
<a name="l00317"></a>00317         <span class="keywordflow">return</span> -1;
<a name="l00318"></a>00318     }
<a name="l00319"></a>00319     <span class="comment">/*</span>
<a name="l00320"></a>00320 <span class="comment">     * if (MDp-&gt;done) { fprintf(stderr,&quot;\nError: MDupdate MD already done.&quot;); return; }</span>
<a name="l00321"></a>00321 <span class="comment">     */</span>
<a name="l00322"></a>00322     <span class="comment">/*</span>
<a name="l00323"></a>00323 <span class="comment">     * Add count to MDp-&gt;count </span>
<a name="l00324"></a>00324 <span class="comment">     */</span>
<a name="l00325"></a>00325     tmp = count;
<a name="l00326"></a>00326     p = MDp-&gt;count;
<a name="l00327"></a>00327     <span class="keywordflow">while</span> (tmp) {
<a name="l00328"></a>00328         tmp += *p;
<a name="l00329"></a>00329         *p++ = tmp;
<a name="l00330"></a>00330         tmp = tmp &gt;&gt; 8;
<a name="l00331"></a>00331     }
<a name="l00332"></a>00332     <span class="comment">/*</span>
<a name="l00333"></a>00333 <span class="comment">     * Process data </span>
<a name="l00334"></a>00334 <span class="comment">     */</span>
<a name="l00335"></a>00335     <span class="keywordflow">if</span> (count == 512) {         <span class="comment">/* Full block of data to handle */</span>
<a name="l00336"></a>00336         MDblock(MDp, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *) X);
<a name="l00337"></a>00337     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (count &gt; 512)     <span class="comment">/* Check for count too large */</span>
<a name="l00338"></a>00338         <span class="keywordflow">return</span> -2;
<a name="l00339"></a>00339     <span class="comment">/*</span>
<a name="l00340"></a>00340 <span class="comment">     * { fprintf(stderr,&quot;\nError: MDupdate called with illegal count value %d.&quot;,count);</span>
<a name="l00341"></a>00341 <span class="comment">     * return;</span>
<a name="l00342"></a>00342 <span class="comment">     * }</span>
<a name="l00343"></a>00343 <span class="comment">     */</span>
<a name="l00344"></a>00344     <span class="keywordflow">else</span> {                      <span class="comment">/* partial block -- must be last block so finish up */</span>
<a name="l00345"></a>00345         <span class="comment">/*</span>
<a name="l00346"></a>00346 <span class="comment">         * Find out how many bytes and residual bits there are </span>
<a name="l00347"></a>00347 <span class="comment">         */</span>
<a name="l00348"></a>00348         <span class="keywordtype">int</span>             copycount;
<a name="l00349"></a>00349         byte = count &gt;&gt; 3;
<a name="l00350"></a>00350         bit = count &amp; 7;
<a name="l00351"></a>00351         copycount = byte;
<a name="l00352"></a>00352         <span class="keywordflow">if</span> (bit)
<a name="l00353"></a>00353             copycount++;
<a name="l00354"></a>00354         <span class="comment">/*</span>
<a name="l00355"></a>00355 <span class="comment">         * Copy X into XX since we need to modify it </span>
<a name="l00356"></a>00356 <span class="comment">         */</span>
<a name="l00357"></a>00357         memset(XX, 0, <span class="keyword">sizeof</span>(XX));
<a name="l00358"></a>00358         memcpy(XX, X, copycount);
<a name="l00359"></a>00359 
<a name="l00360"></a>00360         <span class="comment">/*</span>
<a name="l00361"></a>00361 <span class="comment">         * Add padding &#39;1&#39; bit and low-order zeros in last byte </span>
<a name="l00362"></a>00362 <span class="comment">         */</span>
<a name="l00363"></a>00363         mask = ((<span class="keywordtype">unsigned</span> long) 1) &lt;&lt; (7 - bit);
<a name="l00364"></a>00364         XX[byte] = (XX[byte] | mask) &amp; ~(mask - 1);
<a name="l00365"></a>00365         <span class="comment">/*</span>
<a name="l00366"></a>00366 <span class="comment">         * If room for bit count, finish up with this block </span>
<a name="l00367"></a>00367 <span class="comment">         */</span>
<a name="l00368"></a>00368         <span class="keywordflow">if</span> (byte &lt;= 55) {
<a name="l00369"></a>00369             <span class="keywordflow">for</span> (i = 0; i &lt; 8; i++)
<a name="l00370"></a>00370                 XX[56 + i] = MDp-&gt;count[i];
<a name="l00371"></a>00371             MDblock(MDp, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *) XX);
<a name="l00372"></a>00372         } <span class="keywordflow">else</span> {                <span class="comment">/* need to do two blocks to finish up */</span>
<a name="l00373"></a>00373             MDblock(MDp, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *) XX);
<a name="l00374"></a>00374             <span class="keywordflow">for</span> (i = 0; i &lt; 56; i++)
<a name="l00375"></a>00375                 XX[i] = 0;
<a name="l00376"></a>00376             <span class="keywordflow">for</span> (i = 0; i &lt; 8; i++)
<a name="l00377"></a>00377                 XX[56 + i] = MDp-&gt;count[i];
<a name="l00378"></a>00378             MDblock(MDp, (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *) XX);
<a name="l00379"></a>00379         }
<a name="l00380"></a>00380         <span class="comment">/*</span>
<a name="l00381"></a>00381 <span class="comment">         * Set flag saying we&#39;re done with MD computation </span>
<a name="l00382"></a>00382 <span class="comment">         */</span>
<a name="l00383"></a>00383         MDp-&gt;done = 1;
<a name="l00384"></a>00384     }
<a name="l00385"></a>00385     <span class="keywordflow">return</span> 0;
<a name="l00386"></a>00386 }
<a name="l00387"></a>00387 
<a name="l00388"></a>00388 <span class="comment">/*</span>
<a name="l00389"></a>00389 <span class="comment"> * MDchecksum(data, len, MD5): do a checksum on an arbirtrary amount of data </span>
<a name="l00390"></a>00390 <span class="comment"> */</span>
<a name="l00391"></a>00391 <span class="keywordtype">int</span>
<a name="l00392"></a>00392 MDchecksum(u_char * data, <span class="keywordtype">size_t</span> len, u_char * mac, <span class="keywordtype">size_t</span> maclen)
<a name="l00393"></a>00393 {
<a name="l00394"></a>00394     <a class="code" href="structMDstruct.html">MDstruct</a>        md;
<a name="l00395"></a>00395     <a class="code" href="structMDstruct.html">MDstruct</a>       *MD = &amp;md;
<a name="l00396"></a>00396     <span class="keywordtype">int</span>             rc = 0;
<a name="l00397"></a>00397 
<a name="l00398"></a>00398     MDbegin(MD);
<a name="l00399"></a>00399     <span class="keywordflow">while</span> (len &gt;= 64) {
<a name="l00400"></a>00400         rc = MDupdate(MD, data, 64 * 8);
<a name="l00401"></a>00401         <span class="keywordflow">if</span> (rc)
<a name="l00402"></a>00402             <span class="keywordflow">goto</span> check_end;
<a name="l00403"></a>00403         data += 64;
<a name="l00404"></a>00404         len -= 64;
<a name="l00405"></a>00405     }
<a name="l00406"></a>00406     rc = MDupdate(MD, data, len * 8);
<a name="l00407"></a>00407     <span class="keywordflow">if</span> (rc)
<a name="l00408"></a>00408         <span class="keywordflow">goto</span> check_end;
<a name="l00409"></a>00409 
<a name="l00410"></a>00410     <span class="comment">/*</span>
<a name="l00411"></a>00411 <span class="comment">     * copy the checksum to the outgoing data (all of it that is requested). </span>
<a name="l00412"></a>00412 <span class="comment">     */</span>
<a name="l00413"></a>00413     MDget(MD, mac, maclen);
<a name="l00414"></a>00414 
<a name="l00415"></a>00415   check_end:
<a name="l00416"></a>00416     memset(&amp;md, 0, <span class="keyword">sizeof</span>(md));
<a name="l00417"></a>00417     <span class="keywordflow">return</span> rc;
<a name="l00418"></a>00418 }
<a name="l00419"></a>00419 
<a name="l00420"></a>00420 
<a name="l00421"></a>00421 <span class="comment">/*</span>
<a name="l00422"></a>00422 <span class="comment"> * MDsign(data, len, MD5): do a checksum on an arbirtrary amount</span>
<a name="l00423"></a>00423 <span class="comment"> * of data, and prepended with a secret in the standard fashion </span>
<a name="l00424"></a>00424 <span class="comment"> */</span>
<a name="l00425"></a>00425 <span class="keywordtype">int</span>
<a name="l00426"></a>00426 MDsign(u_char * data, <span class="keywordtype">size_t</span> len, u_char * mac, <span class="keywordtype">size_t</span> maclen,
<a name="l00427"></a>00427        u_char * secret, <span class="keywordtype">size_t</span> secretlen)
<a name="l00428"></a>00428 {
<a name="l00429"></a>00429 <span class="preprocessor">#define HASHKEYLEN 64</span>
<a name="l00430"></a>00430 <span class="preprocessor"></span>
<a name="l00431"></a>00431     <a class="code" href="structMDstruct.html">MDstruct</a>        MD;
<a name="l00432"></a>00432     u_char          K1[HASHKEYLEN];
<a name="l00433"></a>00433     u_char          K2[HASHKEYLEN];
<a name="l00434"></a>00434     u_char          extendedAuthKey[HASHKEYLEN];
<a name="l00435"></a>00435     u_char          buf[HASHKEYLEN];
<a name="l00436"></a>00436     <span class="keywordtype">size_t</span>          i;
<a name="l00437"></a>00437     u_char         *cp, *newdata = 0;
<a name="l00438"></a>00438     <span class="keywordtype">int</span>             rc = 0;
<a name="l00439"></a>00439 
<a name="l00440"></a>00440     <span class="comment">/*</span>
<a name="l00441"></a>00441 <span class="comment">     * memset(K1,0,HASHKEYLEN);</span>
<a name="l00442"></a>00442 <span class="comment">     * memset(K2,0,HASHKEYLEN);</span>
<a name="l00443"></a>00443 <span class="comment">     * memset(buf,0,HASHKEYLEN);</span>
<a name="l00444"></a>00444 <span class="comment">     * memset(extendedAuthKey,0,HASHKEYLEN);</span>
<a name="l00445"></a>00445 <span class="comment">     */</span>
<a name="l00446"></a>00446 
<a name="l00447"></a>00447     <span class="keywordflow">if</span> (secretlen != 16 || secret == NULL || mac == NULL || data == NULL ||
<a name="l00448"></a>00448         len &lt;= 0 || maclen &lt;= 0) {
<a name="l00449"></a>00449         <span class="comment">/*</span>
<a name="l00450"></a>00450 <span class="comment">         * DEBUGMSGTL((&quot;md5&quot;,&quot;MD5 signing not properly initialized&quot;)); </span>
<a name="l00451"></a>00451 <span class="comment">         */</span>
<a name="l00452"></a>00452         <span class="keywordflow">return</span> -1;
<a name="l00453"></a>00453     }
<a name="l00454"></a>00454 
<a name="l00455"></a>00455     memset(extendedAuthKey, 0, HASHKEYLEN);
<a name="l00456"></a>00456     memcpy(extendedAuthKey, secret, secretlen);
<a name="l00457"></a>00457     <span class="keywordflow">for</span> (i = 0; i &lt; HASHKEYLEN; i++) {
<a name="l00458"></a>00458         K1[i] = extendedAuthKey[i] ^ 0x36;
<a name="l00459"></a>00459         K2[i] = extendedAuthKey[i] ^ 0x5c;
<a name="l00460"></a>00460     }
<a name="l00461"></a>00461 
<a name="l00462"></a>00462     MDbegin(&amp;MD);
<a name="l00463"></a>00463     rc = MDupdate(&amp;MD, K1, HASHKEYLEN * 8);
<a name="l00464"></a>00464     <span class="keywordflow">if</span> (rc)
<a name="l00465"></a>00465         <span class="keywordflow">goto</span> update_end;
<a name="l00466"></a>00466 
<a name="l00467"></a>00467     i = len;
<a name="l00468"></a>00468     <span class="keywordflow">if</span> (((uintptr_t) data) % <span class="keyword">sizeof</span>(<span class="keywordtype">long</span>) != 0) {
<a name="l00469"></a>00469         <span class="comment">/*</span>
<a name="l00470"></a>00470 <span class="comment">         * this relies on the ability to use integer math and thus we</span>
<a name="l00471"></a>00471 <span class="comment">         * must rely on data that aligns on 32-bit-word-boundries </span>
<a name="l00472"></a>00472 <span class="comment">         */</span>
<a name="l00473"></a>00473         <a class="code" href="group__util.html#ga623784b8aac0469fcd84e24ccdeda0bd" title="Duplicates a memory block.">memdup</a>(&amp;newdata, data, len);
<a name="l00474"></a>00474         cp = newdata;
<a name="l00475"></a>00475     } <span class="keywordflow">else</span> {
<a name="l00476"></a>00476         cp = data;
<a name="l00477"></a>00477     }
<a name="l00478"></a>00478 
<a name="l00479"></a>00479     <span class="keywordflow">while</span> (i &gt;= 64) {
<a name="l00480"></a>00480         rc = MDupdate(&amp;MD, cp, 64 * 8);
<a name="l00481"></a>00481         <span class="keywordflow">if</span> (rc)
<a name="l00482"></a>00482             <span class="keywordflow">goto</span> update_end;
<a name="l00483"></a>00483         cp += 64;
<a name="l00484"></a>00484         i -= 64;
<a name="l00485"></a>00485     }
<a name="l00486"></a>00486 
<a name="l00487"></a>00487     rc = MDupdate(&amp;MD, cp, i * 8);
<a name="l00488"></a>00488     <span class="keywordflow">if</span> (rc)
<a name="l00489"></a>00489         <span class="keywordflow">goto</span> update_end;
<a name="l00490"></a>00490 
<a name="l00491"></a>00491     memset(buf, 0, HASHKEYLEN);
<a name="l00492"></a>00492     MDget(&amp;MD, buf, HASHKEYLEN);
<a name="l00493"></a>00493 
<a name="l00494"></a>00494     MDbegin(&amp;MD);
<a name="l00495"></a>00495     rc = MDupdate(&amp;MD, K2, HASHKEYLEN * 8);
<a name="l00496"></a>00496     <span class="keywordflow">if</span> (rc)
<a name="l00497"></a>00497         <span class="keywordflow">goto</span> update_end;
<a name="l00498"></a>00498     rc = MDupdate(&amp;MD, buf, 16 * 8);
<a name="l00499"></a>00499     <span class="keywordflow">if</span> (rc)
<a name="l00500"></a>00500         <span class="keywordflow">goto</span> update_end;
<a name="l00501"></a>00501 
<a name="l00502"></a>00502     <span class="comment">/*</span>
<a name="l00503"></a>00503 <span class="comment">     * copy the sign checksum to the outgoing pointer </span>
<a name="l00504"></a>00504 <span class="comment">     */</span>
<a name="l00505"></a>00505     MDget(&amp;MD, mac, maclen);
<a name="l00506"></a>00506 
<a name="l00507"></a>00507   update_end:
<a name="l00508"></a>00508     memset(buf, 0, HASHKEYLEN);
<a name="l00509"></a>00509     memset(K1, 0, HASHKEYLEN);
<a name="l00510"></a>00510     memset(K2, 0, HASHKEYLEN);
<a name="l00511"></a>00511     memset(extendedAuthKey, 0, HASHKEYLEN);
<a name="l00512"></a>00512     memset(&amp;MD, 0, <span class="keyword">sizeof</span>(MD));
<a name="l00513"></a>00513 
<a name="l00514"></a>00514     <span class="keywordflow">if</span> (newdata)
<a name="l00515"></a>00515         free(newdata);
<a name="l00516"></a>00516     <span class="keywordflow">return</span> rc;
<a name="l00517"></a>00517 }
<a name="l00518"></a>00518 
<a name="l00519"></a>00519 <span class="keywordtype">void</span>
<a name="l00520"></a>00520 MDget(<a class="code" href="structMDstruct.html">MDstruct</a> * MD, u_char * buf, <span class="keywordtype">size_t</span> buflen)
<a name="l00521"></a>00521 {
<a name="l00522"></a>00522     <span class="keywordtype">int</span>             i, j;
<a name="l00523"></a>00523 
<a name="l00524"></a>00524     <span class="comment">/*</span>
<a name="l00525"></a>00525 <span class="comment">     * copy the checksum to the outgoing data (all of it that is requested). </span>
<a name="l00526"></a>00526 <span class="comment">     */</span>
<a name="l00527"></a>00527     <span class="keywordflow">for</span> (i = 0; i &lt; 4 &amp;&amp; i * 4 &lt; (int) buflen; i++)
<a name="l00528"></a>00528         <span class="keywordflow">for</span> (j = 0; j &lt; 4 &amp;&amp; i * 4 + j &lt; (int) buflen; j++)
<a name="l00529"></a>00529             buf[i * 4 + j] = (MD-&gt;buffer[i] &gt;&gt; j * 8) &amp; 0xff;
<a name="l00530"></a>00530 }
<a name="l00531"></a>00531 
<a name="l00532"></a>00532 <span class="comment">/*</span>
<a name="l00533"></a>00533 <span class="comment"> * ** End of md5.c</span>
<a name="l00534"></a>00534 <span class="comment"> * ****************************(cut)****************************************</span>
<a name="l00535"></a>00535 <span class="comment"> */</span>
<a name="l00536"></a>00536 
<a name="l00537"></a>00537 <span class="preprocessor">#endif </span><span class="comment">/* NETSNMP_DISABLE_MD5 */</span>
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>