mdfour.c

ソースコードを見る。


関数

static void mdfour64 (uint32 *M)
static void copy64 (uint32 *M, unsigned char *in)
static void copy4 (unsigned char *out, uint32 x)
void mdfour_begin (struct mdfour *md)
static void mdfour_tail (unsigned char *in, uint32 n)
void mdfour_update (struct mdfour *md, unsigned char *in, uint32 n)
void mdfour_result (struct mdfour *md, unsigned char *out)
void mdfour (unsigned char *out, unsigned char *in, int n)
static void file_checksum1 (char *fname)
static void file_checksum2 (char *fname)
int main (int argc, char *argv[])

変数

static struct mdfourm
int protocol_version = 28

関数

static void mdfour64 ( uint32 *  M  )  [static]

mdfour.c43 行で定義されています。

参照先 mdfour::Amdfour::Bmdfour::Cmdfour::Dm.

参照元 mdfour_tail()mdfour_update().

00044 {
00045         uint32 AA, BB, CC, DD;
00046         uint32 A,B,C,D;
00047 
00048         A = m->A; B = m->B; C = m->C; D = m->D; 
00049         AA = A; BB = B; CC = C; DD = D;
00050 
00051         ROUND1(A,B,C,D,  0,  3);  ROUND1(D,A,B,C,  1,  7);  
00052         ROUND1(C,D,A,B,  2, 11);  ROUND1(B,C,D,A,  3, 19);
00053         ROUND1(A,B,C,D,  4,  3);  ROUND1(D,A,B,C,  5,  7);  
00054         ROUND1(C,D,A,B,  6, 11);  ROUND1(B,C,D,A,  7, 19);
00055         ROUND1(A,B,C,D,  8,  3);  ROUND1(D,A,B,C,  9,  7);  
00056         ROUND1(C,D,A,B, 10, 11);  ROUND1(B,C,D,A, 11, 19);
00057         ROUND1(A,B,C,D, 12,  3);  ROUND1(D,A,B,C, 13,  7);  
00058         ROUND1(C,D,A,B, 14, 11);  ROUND1(B,C,D,A, 15, 19);      
00059 
00060 
00061         ROUND2(A,B,C,D,  0,  3);  ROUND2(D,A,B,C,  4,  5);  
00062         ROUND2(C,D,A,B,  8,  9);  ROUND2(B,C,D,A, 12, 13);
00063         ROUND2(A,B,C,D,  1,  3);  ROUND2(D,A,B,C,  5,  5);  
00064         ROUND2(C,D,A,B,  9,  9);  ROUND2(B,C,D,A, 13, 13);
00065         ROUND2(A,B,C,D,  2,  3);  ROUND2(D,A,B,C,  6,  5);  
00066         ROUND2(C,D,A,B, 10,  9);  ROUND2(B,C,D,A, 14, 13);
00067         ROUND2(A,B,C,D,  3,  3);  ROUND2(D,A,B,C,  7,  5);  
00068         ROUND2(C,D,A,B, 11,  9);  ROUND2(B,C,D,A, 15, 13);
00069 
00070         ROUND3(A,B,C,D,  0,  3);  ROUND3(D,A,B,C,  8,  9);  
00071         ROUND3(C,D,A,B,  4, 11);  ROUND3(B,C,D,A, 12, 15);
00072         ROUND3(A,B,C,D,  2,  3);  ROUND3(D,A,B,C, 10,  9);  
00073         ROUND3(C,D,A,B,  6, 11);  ROUND3(B,C,D,A, 14, 15);
00074         ROUND3(A,B,C,D,  1,  3);  ROUND3(D,A,B,C,  9,  9);  
00075         ROUND3(C,D,A,B,  5, 11);  ROUND3(B,C,D,A, 13, 15);
00076         ROUND3(A,B,C,D,  3,  3);  ROUND3(D,A,B,C, 11,  9);  
00077         ROUND3(C,D,A,B,  7, 11);  ROUND3(B,C,D,A, 15, 15);
00078 
00079         A += AA; B += BB; 
00080         C += CC; D += DD;
00081         
00082         A &= MASK32; B &= MASK32; 
00083         C &= MASK32; D &= MASK32;
00084 
00085         m->A = A; m->B = B; m->C = C; m->D = D;
00086 }

static void copy64 ( uint32 *  M,
unsigned char *  in 
) [static]

mdfour.c88 行で定義されています。

参照元 mdfour_tail()mdfour_update().

00089 {
00090         int i;
00091 
00092         for (i=0;i<16;i++)
00093                 M[i] = (in[i*4+3]<<24) | (in[i*4+2]<<16) |
00094                         (in[i*4+1]<<8) | (in[i*4+0]<<0);
00095 }

static void copy4 ( unsigned char *  out,
uint32  x 
) [static]

mdfour.c97 行で定義されています。

参照元 mdfour_result()mdfour_tail().

00098 {
00099         out[0] = x&0xFF;
00100         out[1] = (x>>8)&0xFF;
00101         out[2] = (x>>16)&0xFF;
00102         out[3] = (x>>24)&0xFF;
00103 }

void mdfour_begin ( struct mdfour md  ) 

mdfour.c105 行で定義されています。

参照先 mdfour::Amdfour::Bmdfour::Cmdfour::Dmdmdfour::totalNmdfour::totalN2.

参照元 file_checksum()file_checksum1()get_checksum2()mdfour()sum_init().

00106 {
00107         md->A = 0x67452301;
00108         md->B = 0xefcdab89;
00109         md->C = 0x98badcfe;
00110         md->D = 0x10325476;
00111         md->totalN = 0;
00112         md->totalN2 = 0;
00113 }

static void mdfour_tail ( unsigned char *  in,
uint32  n 
) [static]

mdfour.c116 行で定義されています。

参照先 bufcopy4()copy64()mmdfour64()protocol_versionmdfour::totalNmdfour::totalN2.

参照元 mdfour_update().

00117 {
00118         unsigned char buf[128];
00119         uint32 M[16];
00120         extern int protocol_version;
00121 
00122         /*
00123          * Count total number of bits, modulo 2^64
00124          */
00125         m->totalN += n << 3;
00126         if (m->totalN < (n << 3)) {
00127                 m->totalN2++;
00128         }
00129         m->totalN2 += n >> 29;
00130 
00131         memset(buf, 0, 128);
00132         if (n) memcpy(buf, in, n);
00133         buf[n] = 0x80;
00134 
00135         if (n <= 55) {
00136                 copy4(buf+56, m->totalN);
00137                 /*
00138                  * Prior to protocol version 27 only the number of bits
00139                  * modulo 2^32 was included.  MD4 requires the number
00140                  * of bits modulo 2^64, which was fixed starting with
00141                  * protocol version 27.
00142                  */
00143                 if (protocol_version >= 27) {
00144                         copy4(buf+60, m->totalN2);
00145                 }
00146                 copy64(M, buf);
00147                 mdfour64(M);
00148         } else {
00149                 copy4(buf+120, m->totalN); 
00150                 /*
00151                  * Prior to protocol version 27 only the number of bits
00152                  * modulo 2^32 was included.  MD4 requires the number
00153                  * of bits modulo 2^64, which was fixed starting with
00154                  * protocol version 27.
00155                  */
00156                 if (protocol_version >= 27) {
00157                         copy4(buf+124, m->totalN2); 
00158                 }
00159                 copy64(M, buf);
00160                 mdfour64(M);
00161                 copy64(M, buf+64);
00162                 mdfour64(M);
00163         }
00164 }

void mdfour_update ( struct mdfour md,
unsigned char *  in,
uint32  n 
)

mdfour.c166 行で定義されています。

参照先 copy64()mmdmdfour64()mdfour_tail()mdfour::totalNmdfour::totalN2.

参照元 file_checksum()file_checksum1()get_checksum2()mdfour()sum_end()sum_update().

00167 {
00168         uint32 M[16];
00169 
00170         m = md;
00171 
00172         if (n == 0) mdfour_tail(in, n);
00173 
00174         while (n >= 64) {
00175                 copy64(M, in);
00176                 mdfour64(M);
00177                 in += 64;
00178                 n -= 64;
00179                 m->totalN += 64 << 3;
00180                 if (m->totalN < 64 << 3) {
00181                         m->totalN2++;
00182                 }
00183         }
00184 
00185         if (n) mdfour_tail(in, n);
00186 }

void mdfour_result ( struct mdfour md,
unsigned char *  out 
)

mdfour.c189 行で定義されています。

参照先 mdfour::Amdfour::Bmdfour::Ccopy4()mdfour::Dmmd.

参照元 file_checksum()file_checksum1()get_checksum2()mdfour()sum_end().

00190 {
00191         m = md;
00192 
00193         copy4(out, m->A);
00194         copy4(out+4, m->B);
00195         copy4(out+8, m->C);
00196         copy4(out+12, m->D);
00197 }

void mdfour ( unsigned char *  out,
unsigned char *  in,
int  n 
)

mdfour.c200 行で定義されています。

参照先 mdmdfour_begin()mdfour_result()mdfour_update().

00201 {
00202         struct mdfour md;
00203         mdfour_begin(&md);
00204         mdfour_update(&md, in, n);
00205         mdfour_result(&md, out);
00206 }

static void file_checksum1 ( char *  fname  )  [static]

mdfour.c211 行で定義されています。

参照先 bufmdmdfour_begin()mdfour_result()mdfour_update()protocol_version.

参照元 main().

00212 {
00213         int fd, i, was_multiple_of_64 = 1;
00214         struct mdfour md;
00215         unsigned char buf[64*1024], sum[16];
00216         
00217         fd = open(fname,O_RDONLY);
00218         if (fd == -1) {
00219                 perror("fname");
00220                 exit(1);
00221         }
00222         
00223         mdfour_begin(&md);
00224 
00225         while (1) {
00226                 int n = read(fd, buf, sizeof(buf));
00227                 if (n <= 0)
00228                         break;
00229                 was_multiple_of_64 = !(n % 64);
00230                 mdfour_update(&md, buf, n);
00231         }
00232         if (was_multiple_of_64 && protocol_version >= 27)
00233                 mdfour_update(&md, buf, 0);
00234 
00235         close(fd);
00236 
00237         mdfour_result(&md, sum);
00238 
00239         for (i=0;i<16;i++)
00240                 printf("%02X", sum[i]);
00241         printf("\n");
00242 }

static void file_checksum2 ( char *  fname  )  [static]

mdfour.c247 行で定義されています。

参照先 bufmd.

参照元 main().

00248 {
00249         int fd, i;
00250         MDstruct md;
00251         unsigned char buf[64], sum[16];
00252 
00253         fd = open(fname,O_RDONLY);
00254         if (fd == -1) {
00255                 perror("fname");
00256                 exit(1);
00257         }
00258         
00259         MDbegin(&md);
00260 
00261         while (1) {
00262                 int n = read(fd, buf, sizeof(buf));
00263                 if (n <= 0) break;
00264                 MDupdate(&md, buf, n*8);
00265         }
00266 
00267         if (!md.done) {
00268                 MDupdate(&md, buf, 0);
00269         }
00270 
00271         close(fd);
00272 
00273         memcpy(sum, md.buffer, 16);
00274 
00275         for (i=0;i<16;i++)
00276                 printf("%02X", sum[i]);
00277         printf("\n");
00278 }

int main ( int  argc,
char *  argv[] 
)

mdfour.c281 行で定義されています。

参照先 file_checksum1()file_checksum2().

00282 {
00283         file_checksum1(argv[1]);
00284 #if 0
00285         file_checksum2(argv[1]);
00286 #endif
00287         return 0;
00288 }


変数

struct mdfour* m [static]

mdfour.c29 行で定義されています。

参照元 file_checksum()get_checksum2()mdfour64()mdfour_result()mdfour_tail()mdfour_update()msg2genr_flush()msg2sndr_flush()msg_list_add().

int protocol_version = 28

mdfour.c209 行で定義されています。


rsyncに対してSat Dec 5 19:45:44 2009に生成されました。  doxygen 1.4.7