\doxysubsection{mdfour.\+c}
\label{mdfour_8c_source}\index{mdfour.c@{mdfour.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001 \textcolor{comment}{/*= -\/*-\/ c-\/basic-\/offset: 4; indent-\/tabs-\/mode: nil; -\/*-\/}}
\DoxyCodeLine{00002 \textcolor{comment}{ *}}
\DoxyCodeLine{00003 \textcolor{comment}{ * librsync -\/-\/ the library for network deltas}}
\DoxyCodeLine{00004 \textcolor{comment}{ *}}
\DoxyCodeLine{00005 \textcolor{comment}{ * Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>}}
\DoxyCodeLine{00006 \textcolor{comment}{ * Copyright (C) 1997-\/1999 by Andrew Tridgell}}
\DoxyCodeLine{00007 \textcolor{comment}{ * Copyright (C) 2002, 2003 by Donovan Baarda <abo@minkirri.apana.org.au>}}
\DoxyCodeLine{00008 \textcolor{comment}{ *}}
\DoxyCodeLine{00009 \textcolor{comment}{ * This program is free software; you can redistribute it and/or modify}}
\DoxyCodeLine{00010 \textcolor{comment}{ * it under the terms of the GNU Lesser General Public License as published by}}
\DoxyCodeLine{00011 \textcolor{comment}{ * the Free Software Foundation; either version 2.1 of the License, or}}
\DoxyCodeLine{00012 \textcolor{comment}{ * (at your option) any later version.}}
\DoxyCodeLine{00013 \textcolor{comment}{ *}}
\DoxyCodeLine{00014 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}}
\DoxyCodeLine{00015 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{00016 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}}
\DoxyCodeLine{00017 \textcolor{comment}{ * GNU Lesser General Public License for more details.}}
\DoxyCodeLine{00018 \textcolor{comment}{ *}}
\DoxyCodeLine{00019 \textcolor{comment}{ * You should have received a copy of the GNU Lesser General Public License}}
\DoxyCodeLine{00020 \textcolor{comment}{ * along with this program; if not, write to the Free Software}}
\DoxyCodeLine{00021 \textcolor{comment}{ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.}}
\DoxyCodeLine{00022 \textcolor{comment}{ */}}
\DoxyCodeLine{00023 }
\DoxyCodeLine{00024 \textcolor{preprocessor}{\#include "{}config.h"{}}             \textcolor{comment}{/* IWYU pragma: keep */}}
\DoxyCodeLine{00025 \textcolor{preprocessor}{\#include <stdint.h>}}
\DoxyCodeLine{00026 \textcolor{preprocessor}{\#include <string.h>}}
\DoxyCodeLine{00027 \textcolor{preprocessor}{\#include "{}librsync.h"{}}}
\DoxyCodeLine{00028 \textcolor{preprocessor}{\#include "{}mdfour.h"{}}}
\DoxyCodeLine{00029 }
\DoxyCodeLine{00030 \textcolor{preprocessor}{\#define F(X,Y,Z) (((X)\&(Y)) | ((\string~(X))\&(Z)))}}
\DoxyCodeLine{00031 \textcolor{preprocessor}{\#define G(X,Y,Z) (((X)\&(Y)) | ((X)\&(Z)) | ((Y)\&(Z)))}}
\DoxyCodeLine{00032 \textcolor{preprocessor}{\#define H(X,Y,Z) ((X)\string^(Y)\string^(Z))}}
\DoxyCodeLine{00033 \textcolor{preprocessor}{\#define lshift(x,s) (((x)<<(s)) | ((x)>>(32-\/(s))))}}
\DoxyCodeLine{00034 }
\DoxyCodeLine{00035 \textcolor{preprocessor}{\#define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s)}}
\DoxyCodeLine{00036 \textcolor{preprocessor}{\#define ROUND2(a,b,c,d,k,s) a = lshift(a + G(b,c,d) + X[k] + 0x5A827999U, s)}}
\DoxyCodeLine{00037 \textcolor{preprocessor}{\#define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + 0x6ED9EBA1U, s)}}
\DoxyCodeLine{00038 \textcolor{comment}{}}
\DoxyCodeLine{00039 \textcolor{comment}{/** padding data used for finalising */}}
\DoxyCodeLine{00040 \textcolor{keyword}{static} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} PADDING[64] = \{}
\DoxyCodeLine{00041     0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
\DoxyCodeLine{00042     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,}
\DoxyCodeLine{00043     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
\DoxyCodeLine{00044 \};}
\DoxyCodeLine{00045 }
\DoxyCodeLine{00046 \textcolor{keyword}{static} \textcolor{keywordtype}{void} rs\_mdfour\_block(rs\_mdfour\_t *md, \textcolor{keywordtype}{void} \textcolor{keyword}{const} *p);}
\DoxyCodeLine{00047 \textcolor{comment}{}}
\DoxyCodeLine{00048 \textcolor{comment}{/** Update an MD4 accumulator from a 64-\/byte chunk.}}
\DoxyCodeLine{00049 \textcolor{comment}{ *}}
\DoxyCodeLine{00050 \textcolor{comment}{ * This cannot be used for the last chunk of the file, which must be padded and}}
\DoxyCodeLine{00051 \textcolor{comment}{ * contain the file length. rs\_mdfour\_tail() is used for that.}}
\DoxyCodeLine{00052 \textcolor{comment}{ *}}
\DoxyCodeLine{00053 \textcolor{comment}{ * \(\backslash\)todo Recode to be fast, and to use system integer types. Perhaps if we can}}
\DoxyCodeLine{00054 \textcolor{comment}{ * find an mdfour implementation already on the system (e.g. in OpenSSL) then}}
\DoxyCodeLine{00055 \textcolor{comment}{ * we should use it instead of our own?}}
\DoxyCodeLine{00056 \textcolor{comment}{ *}}
\DoxyCodeLine{00057 \textcolor{comment}{ * \(\backslash\)param *m An rs\_mdfour\_t instance to accumulate with.}}
\DoxyCodeLine{00058 \textcolor{comment}{ *}}
\DoxyCodeLine{00059 \textcolor{comment}{ * \(\backslash\)param *p An array of uint32 integers, as read little-\/endian from the file. */}}
\DoxyCodeLine{00060 \textcolor{keyword}{static} \textcolor{keywordtype}{void} rs\_mdfour64(rs\_mdfour\_t *m, \textcolor{keyword}{const} \textcolor{keywordtype}{void} *p)}
\DoxyCodeLine{00061 \{}
\DoxyCodeLine{00062     uint32\_t AA, BB, CC, DD;}
\DoxyCodeLine{00063     uint32\_t A, B, C, D;}
\DoxyCodeLine{00064     \textcolor{keyword}{const} uint32\_t *X = (\textcolor{keyword}{const} uint32\_t *)p;}
\DoxyCodeLine{00065 }
\DoxyCodeLine{00066     A = m-\/>A;}
\DoxyCodeLine{00067     B = m-\/>B;}
\DoxyCodeLine{00068     C = m-\/>C;}
\DoxyCodeLine{00069     D = m-\/>D;}
\DoxyCodeLine{00070     AA = A;}
\DoxyCodeLine{00071     BB = B;}
\DoxyCodeLine{00072     CC = C;}
\DoxyCodeLine{00073     DD = D;}
\DoxyCodeLine{00074 }
\DoxyCodeLine{00075     ROUND1(A, B, C, D, 0, 3);}
\DoxyCodeLine{00076     ROUND1(D, A, B, C, 1, 7);}
\DoxyCodeLine{00077     ROUND1(C, D, A, B, 2, 11);}
\DoxyCodeLine{00078     ROUND1(B, C, D, A, 3, 19);}
\DoxyCodeLine{00079     ROUND1(A, B, C, D, 4, 3);}
\DoxyCodeLine{00080     ROUND1(D, A, B, C, 5, 7);}
\DoxyCodeLine{00081     ROUND1(C, D, A, B, 6, 11);}
\DoxyCodeLine{00082     ROUND1(B, C, D, A, 7, 19);}
\DoxyCodeLine{00083     ROUND1(A, B, C, D, 8, 3);}
\DoxyCodeLine{00084     ROUND1(D, A, B, C, 9, 7);}
\DoxyCodeLine{00085     ROUND1(C, D, A, B, 10, 11);}
\DoxyCodeLine{00086     ROUND1(B, C, D, A, 11, 19);}
\DoxyCodeLine{00087     ROUND1(A, B, C, D, 12, 3);}
\DoxyCodeLine{00088     ROUND1(D, A, B, C, 13, 7);}
\DoxyCodeLine{00089     ROUND1(C, D, A, B, 14, 11);}
\DoxyCodeLine{00090     ROUND1(B, C, D, A, 15, 19);}
\DoxyCodeLine{00091 }
\DoxyCodeLine{00092     ROUND2(A, B, C, D, 0, 3);}
\DoxyCodeLine{00093     ROUND2(D, A, B, C, 4, 5);}
\DoxyCodeLine{00094     ROUND2(C, D, A, B, 8, 9);}
\DoxyCodeLine{00095     ROUND2(B, C, D, A, 12, 13);}
\DoxyCodeLine{00096     ROUND2(A, B, C, D, 1, 3);}
\DoxyCodeLine{00097     ROUND2(D, A, B, C, 5, 5);}
\DoxyCodeLine{00098     ROUND2(C, D, A, B, 9, 9);}
\DoxyCodeLine{00099     ROUND2(B, C, D, A, 13, 13);}
\DoxyCodeLine{00100     ROUND2(A, B, C, D, 2, 3);}
\DoxyCodeLine{00101     ROUND2(D, A, B, C, 6, 5);}
\DoxyCodeLine{00102     ROUND2(C, D, A, B, 10, 9);}
\DoxyCodeLine{00103     ROUND2(B, C, D, A, 14, 13);}
\DoxyCodeLine{00104     ROUND2(A, B, C, D, 3, 3);}
\DoxyCodeLine{00105     ROUND2(D, A, B, C, 7, 5);}
\DoxyCodeLine{00106     ROUND2(C, D, A, B, 11, 9);}
\DoxyCodeLine{00107     ROUND2(B, C, D, A, 15, 13);}
\DoxyCodeLine{00108 }
\DoxyCodeLine{00109     ROUND3(A, B, C, D, 0, 3);}
\DoxyCodeLine{00110     ROUND3(D, A, B, C, 8, 9);}
\DoxyCodeLine{00111     ROUND3(C, D, A, B, 4, 11);}
\DoxyCodeLine{00112     ROUND3(B, C, D, A, 12, 15);}
\DoxyCodeLine{00113     ROUND3(A, B, C, D, 2, 3);}
\DoxyCodeLine{00114     ROUND3(D, A, B, C, 10, 9);}
\DoxyCodeLine{00115     ROUND3(C, D, A, B, 6, 11);}
\DoxyCodeLine{00116     ROUND3(B, C, D, A, 14, 15);}
\DoxyCodeLine{00117     ROUND3(A, B, C, D, 1, 3);}
\DoxyCodeLine{00118     ROUND3(D, A, B, C, 9, 9);}
\DoxyCodeLine{00119     ROUND3(C, D, A, B, 5, 11);}
\DoxyCodeLine{00120     ROUND3(B, C, D, A, 13, 15);}
\DoxyCodeLine{00121     ROUND3(A, B, C, D, 3, 3);}
\DoxyCodeLine{00122     ROUND3(D, A, B, C, 11, 9);}
\DoxyCodeLine{00123     ROUND3(C, D, A, B, 7, 11);}
\DoxyCodeLine{00124     ROUND3(B, C, D, A, 15, 15);}
\DoxyCodeLine{00125 }
\DoxyCodeLine{00126     A += AA;}
\DoxyCodeLine{00127     B += BB;}
\DoxyCodeLine{00128     C += CC;}
\DoxyCodeLine{00129     D += DD;}
\DoxyCodeLine{00130 }
\DoxyCodeLine{00131     m-\/>A = A;}
\DoxyCodeLine{00132     m-\/>B = B;}
\DoxyCodeLine{00133     m-\/>C = C;}
\DoxyCodeLine{00134     m-\/>D = D;}
\DoxyCodeLine{00135 \}}
\DoxyCodeLine{00136 \textcolor{comment}{}}
\DoxyCodeLine{00137 \textcolor{comment}{/** These next routines are necessary because MD4 is specified in terms of}}
\DoxyCodeLine{00138 \textcolor{comment}{ * little-\/endian int32s, but we have a byte buffer. On little-\/endian platforms,}}
\DoxyCodeLine{00139 \textcolor{comment}{ * I think we can just use the buffer pointer directly.}}
\DoxyCodeLine{00140 \textcolor{comment}{ *}}
\DoxyCodeLine{00141 \textcolor{comment}{ * There are some nice endianness routines in glib, including assembler}}
\DoxyCodeLine{00142 \textcolor{comment}{ * variants. If we ever depended on glib, then it could be good to use them}}
\DoxyCodeLine{00143 \textcolor{comment}{ * instead. */}}
\DoxyCodeLine{00144 \textcolor{keyword}{inline} \textcolor{keyword}{static} \textcolor{keywordtype}{void} copy4( \textcolor{comment}{/* @out@ */} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *out, uint32\_t \textcolor{keyword}{const} x)}
\DoxyCodeLine{00145 \{}
\DoxyCodeLine{00146     out[0] = (\textcolor{keywordtype}{unsigned} char)(x);}
\DoxyCodeLine{00147     out[1] = (\textcolor{keywordtype}{unsigned} char)(x >> 8);}
\DoxyCodeLine{00148     out[2] = (\textcolor{keywordtype}{unsigned} char)(x >> 16);}
\DoxyCodeLine{00149     out[3] = (\textcolor{keywordtype}{unsigned} char)(x >> 24);}
\DoxyCodeLine{00150 \}}
\DoxyCodeLine{00151 }
\DoxyCodeLine{00152 \textcolor{comment}{/* We need this if there is a uint64 */}}
\DoxyCodeLine{00153 \textcolor{comment}{/* -\/-\/robert.weber@Colorado.edu */}}
\DoxyCodeLine{00154 \textcolor{preprocessor}{\#ifdef UINT64\_MAX}}
\DoxyCodeLine{00155 \textcolor{keyword}{inline} \textcolor{keyword}{static} \textcolor{keywordtype}{void} copy8( \textcolor{comment}{/* @out@ */} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *out, uint64\_t \textcolor{keyword}{const} x)}
\DoxyCodeLine{00156 \{}
\DoxyCodeLine{00157     out[0] = (\textcolor{keywordtype}{unsigned} char)(x);}
\DoxyCodeLine{00158     out[1] = (\textcolor{keywordtype}{unsigned} char)(x >> 8);}
\DoxyCodeLine{00159     out[2] = (\textcolor{keywordtype}{unsigned} char)(x >> 16);}
\DoxyCodeLine{00160     out[3] = (\textcolor{keywordtype}{unsigned} char)(x >> 24);}
\DoxyCodeLine{00161     out[4] = (\textcolor{keywordtype}{unsigned} char)(x >> 32);}
\DoxyCodeLine{00162     out[5] = (\textcolor{keywordtype}{unsigned} char)(x >> 40);}
\DoxyCodeLine{00163     out[6] = (\textcolor{keywordtype}{unsigned} char)(x >> 48);}
\DoxyCodeLine{00164     out[7] = (\textcolor{keywordtype}{unsigned} char)(x >> 56);}
\DoxyCodeLine{00165 \}}
\DoxyCodeLine{00166 \textcolor{preprocessor}{\#endif                          }\textcolor{comment}{/* UINT64\_MAX */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00167 }
\DoxyCodeLine{00168 \textcolor{comment}{/* We only need this if we are big-\/endian */}}
\DoxyCodeLine{00169 \textcolor{preprocessor}{\#ifdef WORDS\_BIGENDIAN}}
\DoxyCodeLine{00170 \textcolor{keyword}{inline} \textcolor{keyword}{static} \textcolor{keywordtype}{void} copy64( \textcolor{comment}{/* @out@ */} uint32\_t *M, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} \textcolor{keyword}{const} *in)}
\DoxyCodeLine{00171 \{}
\DoxyCodeLine{00172     \textcolor{keywordtype}{int} i = 16;}
\DoxyCodeLine{00173 }
\DoxyCodeLine{00174     \textcolor{keywordflow}{while} (i-\/-\/) \{}
\DoxyCodeLine{00175         *M++ =}
\DoxyCodeLine{00176             (((uint32\_t)in[3] << 24) | ((uint32\_t)in[2] << 16) |}
\DoxyCodeLine{00177              ((uint32\_t)in[1] << 8) | (uint32\_t)in[0]);}
\DoxyCodeLine{00178         in += 4;}
\DoxyCodeLine{00179     \}}
\DoxyCodeLine{00180 \}}
\DoxyCodeLine{00181 \textcolor{comment}{}}
\DoxyCodeLine{00182 \textcolor{comment}{/** Accumulate a block, making appropriate conversions for bigendian machines.}}
\DoxyCodeLine{00183 \textcolor{comment}{ */}}
\DoxyCodeLine{00184 \textcolor{keyword}{inline} \textcolor{keyword}{static} \textcolor{keywordtype}{void} rs\_mdfour\_block(rs\_mdfour\_t *md, \textcolor{keywordtype}{void} \textcolor{keyword}{const} *p)}
\DoxyCodeLine{00185 \{}
\DoxyCodeLine{00186     uint32\_t M[16];}
\DoxyCodeLine{00187 }
\DoxyCodeLine{00188     copy64(M, p);}
\DoxyCodeLine{00189     rs\_mdfour64(md, M);}
\DoxyCodeLine{00190 \}}
\DoxyCodeLine{00191 }
\DoxyCodeLine{00192 \textcolor{preprocessor}{\#else                           }\textcolor{comment}{/* WORDS\_BIGENDIAN */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00193 }
\DoxyCodeLine{00194 \textcolor{preprocessor}{\#  ifdef \_\_i386\_\_}}
\DoxyCodeLine{00195 }
\DoxyCodeLine{00196 \textcolor{comment}{/* If we are on an IA-\/32 machine, we can process directly. */}}
\DoxyCodeLine{00197 \textcolor{keyword}{inline} \textcolor{keyword}{static} \textcolor{keywordtype}{void} rs\_mdfour\_block(rs\_mdfour\_t *md, \textcolor{keywordtype}{void} \textcolor{keyword}{const} *p)}
\DoxyCodeLine{00198 \{}
\DoxyCodeLine{00199     rs\_mdfour64(md, p);}
\DoxyCodeLine{00200 \}}
\DoxyCodeLine{00201 }
\DoxyCodeLine{00202 \textcolor{preprocessor}{\#  else                         }\textcolor{comment}{/* !WORDS\_BIGENDIAN \&\& !\_\_i386\_\_ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00203 }
\DoxyCodeLine{00204 \textcolor{comment}{/* We are little-\/endian, but not on i386 and therefore may not be able to do}}
\DoxyCodeLine{00205 \textcolor{comment}{   unaligned access safely/quickly.}}
\DoxyCodeLine{00206 \textcolor{comment}{}}
\DoxyCodeLine{00207 \textcolor{comment}{   So if the input is not already aligned correctly, copy it to an aligned}}
\DoxyCodeLine{00208 \textcolor{comment}{   buffer first. */}}
\DoxyCodeLine{00209 \textcolor{keyword}{inline} \textcolor{keyword}{static} \textcolor{keywordtype}{void} rs\_mdfour\_block(rs\_mdfour\_t *md, \textcolor{keywordtype}{void} \textcolor{keyword}{const} *p)}
\DoxyCodeLine{00210 \{}
\DoxyCodeLine{00211     \textcolor{keywordflow}{if} ((uintptr\_t)p \& 3) \{}
\DoxyCodeLine{00212         uint32\_t M[16];}
\DoxyCodeLine{00213 }
\DoxyCodeLine{00214         memcpy(M, p, 16 * \textcolor{keyword}{sizeof}(uint32\_t));}
\DoxyCodeLine{00215         rs\_mdfour64(md, M);}
\DoxyCodeLine{00216     \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{00217         rs\_mdfour64(md, (\textcolor{keyword}{const} uint32\_t *)p);}
\DoxyCodeLine{00218     \}}
\DoxyCodeLine{00219 \}}
\DoxyCodeLine{00220 }
\DoxyCodeLine{00221 \textcolor{preprocessor}{\#  endif                        }\textcolor{comment}{/* !\_\_i386\_\_ */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00222 \textcolor{preprocessor}{\#endif                          }\textcolor{comment}{/* WORDS\_BIGENDIAN */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00223 }
\DoxyCodeLine{00224 \textcolor{keywordtype}{void} rs\_mdfour\_begin(rs\_mdfour\_t *md)}
\DoxyCodeLine{00225 \{}
\DoxyCodeLine{00226     memset(md, 0, \textcolor{keyword}{sizeof}(*md));}
\DoxyCodeLine{00227     md-\/>A = 0x67452301U;}
\DoxyCodeLine{00228     md-\/>B = 0xefcdab89U;}
\DoxyCodeLine{00229     md-\/>C = 0x98badcfeU;}
\DoxyCodeLine{00230     md-\/>D = 0x10325476U;}
\DoxyCodeLine{00231 \textcolor{preprocessor}{\#ifdef UINT64\_MAX}}
\DoxyCodeLine{00232     md-\/>totalN = 0;}
\DoxyCodeLine{00233 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00234     md-\/>totalN\_hi = md-\/>totalN\_lo = 0;}
\DoxyCodeLine{00235 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00236 \}}
\DoxyCodeLine{00237 \textcolor{comment}{}}
\DoxyCodeLine{00238 \textcolor{comment}{/** Handle special behaviour for processing the last block of a file when}}
\DoxyCodeLine{00239 \textcolor{comment}{ * calculating its MD4 checksum.}}
\DoxyCodeLine{00240 \textcolor{comment}{ *}}
\DoxyCodeLine{00241 \textcolor{comment}{ * This must be called exactly once per file.}}
\DoxyCodeLine{00242 \textcolor{comment}{ *}}
\DoxyCodeLine{00243 \textcolor{comment}{ * Modified by Robert Weber to use uint64 in order that we can sum files > 2\string^29}}
\DoxyCodeLine{00244 \textcolor{comment}{ * = 512 MB. -\/-\/Robert.Weber@colorado.edu */}}
\DoxyCodeLine{00245 \textcolor{keyword}{static} \textcolor{keywordtype}{void} rs\_mdfour\_tail(rs\_mdfour\_t *m)}
\DoxyCodeLine{00246 \{}
\DoxyCodeLine{00247 \textcolor{preprocessor}{\#ifdef UINT64\_MAX}}
\DoxyCodeLine{00248     uint64\_t b;}
\DoxyCodeLine{00249 \textcolor{preprocessor}{\#else                           }\textcolor{comment}{/* UINT64\_MAX */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00250     uint32\_t b[2];}
\DoxyCodeLine{00251 \textcolor{preprocessor}{\#endif                          }\textcolor{comment}{/* UINT64\_MAX */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00252     \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} buf[8];}
\DoxyCodeLine{00253     \textcolor{keywordtype}{size\_t} pad\_len;}
\DoxyCodeLine{00254 }
\DoxyCodeLine{00255     \textcolor{comment}{/* convert the totalN byte count into a bit count buffer */}}
\DoxyCodeLine{00256 \textcolor{preprocessor}{\#ifdef UINT64\_MAX}}
\DoxyCodeLine{00257     b = m-\/>totalN << 3;}
\DoxyCodeLine{00258     copy8(buf, b);}
\DoxyCodeLine{00259 \textcolor{preprocessor}{\#else                           }\textcolor{comment}{/* UINT64\_MAX */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00260     b[0] = m-\/>totalN\_lo << 3;}
\DoxyCodeLine{00261     b[1] = ((m-\/>totalN\_hi << 3) | (m-\/>totalN\_lo >> 29));}
\DoxyCodeLine{00262     copy4(buf, b[0]);}
\DoxyCodeLine{00263     copy4(buf + 4, b[1]);}
\DoxyCodeLine{00264 \textcolor{preprocessor}{\#endif                          }\textcolor{comment}{/* UINT64\_MAX */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00265 }
\DoxyCodeLine{00266     \textcolor{comment}{/* calculate length and process the padding data */}}
\DoxyCodeLine{00267     pad\_len = (m-\/>tail\_len < 56) ? (56 -\/ m-\/>tail\_len) : (120 -\/ m-\/>tail\_len);}
\DoxyCodeLine{00268     rs\_mdfour\_update(m, PADDING, pad\_len);}
\DoxyCodeLine{00269     \textcolor{comment}{/* process the bit count */}}
\DoxyCodeLine{00270     rs\_mdfour\_update(m, buf, 8);}
\DoxyCodeLine{00271 \}}
\DoxyCodeLine{00272 }
\DoxyCodeLine{00273 \textcolor{keywordtype}{void} rs\_mdfour\_update(rs\_mdfour\_t *md, \textcolor{keywordtype}{void} \textcolor{keyword}{const} *in\_void, \textcolor{keywordtype}{size\_t} n)}
\DoxyCodeLine{00274 \{}
\DoxyCodeLine{00275     \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} \textcolor{keyword}{const} *in = (\textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} \textcolor{keyword}{const} *)in\_void;}
\DoxyCodeLine{00276 }
\DoxyCodeLine{00277     \textcolor{comment}{/* increment totalN */}}
\DoxyCodeLine{00278 \textcolor{preprocessor}{\#ifdef UINT64\_MAX}}
\DoxyCodeLine{00279     md-\/>totalN += n;}
\DoxyCodeLine{00280 \textcolor{preprocessor}{\#else                           }\textcolor{comment}{/* UINT64\_MAX */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00281     \textcolor{keywordflow}{if} ((md-\/>totalN\_lo += n) < n)}
\DoxyCodeLine{00282         md-\/>totalN\_hi++;}
\DoxyCodeLine{00283 \#endif                          \textcolor{comment}{/* UINT64\_MAX */}}
\DoxyCodeLine{00284 }
\DoxyCodeLine{00285     \textcolor{comment}{/* If there's any leftover data in the tail buffer, then first we have to}}
\DoxyCodeLine{00286 \textcolor{comment}{       make it up to a whole block to process it. */}}
\DoxyCodeLine{00287     if (md-\/>tail\_len) \{}
\DoxyCodeLine{00288         \textcolor{keywordtype}{size\_t} tail\_gap = 64 -\/ md-\/>tail\_len;}
\DoxyCodeLine{00289         \textcolor{keywordflow}{if} (tail\_gap <= n) \{}
\DoxyCodeLine{00290             memcpy(\&md-\/>tail[md-\/>tail\_len], in, tail\_gap);}
\DoxyCodeLine{00291             rs\_mdfour\_block(md, md-\/>tail);}
\DoxyCodeLine{00292             in += tail\_gap;}
\DoxyCodeLine{00293             n -\/= tail\_gap;}
\DoxyCodeLine{00294             md-\/>tail\_len = 0;}
\DoxyCodeLine{00295         \}}
\DoxyCodeLine{00296     \}}
\DoxyCodeLine{00297     \textcolor{comment}{/* process complete blocks of input */}}
\DoxyCodeLine{00298     \textcolor{keywordflow}{while} (n >= 64) \{}
\DoxyCodeLine{00299         rs\_mdfour\_block(md, in);}
\DoxyCodeLine{00300         in += 64;}
\DoxyCodeLine{00301         n -\/= 64;}
\DoxyCodeLine{00302     \}}
\DoxyCodeLine{00303     \textcolor{comment}{/* Put remaining bytes onto tail */}}
\DoxyCodeLine{00304     \textcolor{keywordflow}{if} (n) \{}
\DoxyCodeLine{00305         memcpy(\&md-\/>tail[md-\/>tail\_len], in, n);}
\DoxyCodeLine{00306         md-\/>tail\_len += (int)n;}
\DoxyCodeLine{00307     \}}
\DoxyCodeLine{00308 \}}
\DoxyCodeLine{00309 }
\DoxyCodeLine{00310 \textcolor{keywordtype}{void} rs\_mdfour\_result(rs\_mdfour\_t *md, \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *out)}
\DoxyCodeLine{00311 \{}
\DoxyCodeLine{00312     rs\_mdfour\_tail(md);}
\DoxyCodeLine{00313 }
\DoxyCodeLine{00314     copy4(out, md-\/>A);}
\DoxyCodeLine{00315     copy4(out + 4, md-\/>B);}
\DoxyCodeLine{00316     copy4(out + 8, md-\/>C);}
\DoxyCodeLine{00317     copy4(out + 12, md-\/>D);}
\DoxyCodeLine{00318 \}}
\DoxyCodeLine{00319 }
\DoxyCodeLine{00320 \textcolor{keywordtype}{void} rs\_mdfour(\textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{char} *out, \textcolor{keywordtype}{void} \textcolor{keyword}{const} *in, \textcolor{keywordtype}{size\_t} n)}
\DoxyCodeLine{00321 \{}
\DoxyCodeLine{00322     rs\_mdfour\_t md;}
\DoxyCodeLine{00323 }
\DoxyCodeLine{00324     rs\_mdfour\_begin(\&md);}
\DoxyCodeLine{00325     rs\_mdfour\_update(\&md, in, n);}
\DoxyCodeLine{00326     rs\_mdfour\_result(\&md, out);}
\DoxyCodeLine{00327 \}}

\end{DoxyCode}
