AlcapDAQ  1
Macros | Functions
mddriver.c File Reference
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "global.h"
#include "md5.h"

Go to the source code of this file.

Macros

#define MD   5
 
#define TEST_BLOCK_LEN   1000
 
#define TEST_BLOCK_COUNT   1000
 
#define MD5_CTX   MD5_CTX
 
#define MDInit   MD5Init
 
#define MDUpdate   MD5Update
 
#define MDFinal   MD5Final
 

Functions

static void MDString PROTO_LIST ((char *))
 
static void MDTimeTrial PROTO_LIST ((void))
 
static void MDPrint PROTO_LIST ((unsigned char[16]))
 
int main (int argc, argv)
 
static void MDString (char *string)
 
static void MDTimeTrial ()
 
static void MDTestSuite ()
 
static void MDFile (char *filename)
 
static void MDFilter ()
 
static void MDPrint (digest)
 

Macro Definition Documentation

#define MD   5

Definition at line 20 of file mddriver.c.

Referenced by MDFile(), MDString(), MDTestSuite(), and MDTimeTrial().

#define MD5_CTX   MD5_CTX

Definition at line 62 of file mddriver.c.

#define MDFinal   MD5Final

Definition at line 65 of file mddriver.c.

Referenced by MDFile(), MDFilter(), MDString(), and MDTimeTrial().

#define MDInit   MD5Init

Definition at line 63 of file mddriver.c.

Referenced by MDFile(), MDFilter(), MDString(), and MDTimeTrial().

#define MDUpdate   MD5Update

Definition at line 64 of file mddriver.c.

Referenced by MDFile(), MDFilter(), MDString(), and MDTimeTrial().

#define TEST_BLOCK_COUNT   1000

Definition at line 40 of file mddriver.c.

Referenced by MDTimeTrial().

#define TEST_BLOCK_LEN   1000

Definition at line 39 of file mddriver.c.

Referenced by MDTimeTrial().

Function Documentation

int main ( int  argc,
argv   
)

Definition at line 77 of file mddriver.c.

References i, MDFile(), MDFilter(), MDString(), MDTestSuite(), and MDTimeTrial().

81 {
82  int i;
83 
84  if (argc > 1)
85  for (i = 1; i < argc; i++)
86  if (argv[i][0] == '-' && argv[i][1] == 's')
87  MDString (argv[i] + 2);
88  else if (strcmp (argv[i], "-t") == 0)
89  MDTimeTrial ();
90  else if (strcmp (argv[i], "-x") == 0)
91  MDTestSuite ();
92  else
93  MDFile (argv[i]);
94  else
95  MDFilter ();
96 
97  return (0);
98 }
static void MDFile ( char *  filename)
static

Definition at line 178 of file mddriver.c.

References file, MD, MDFinal, MDInit, MDPrint(), MDUpdate, and printf().

Referenced by main().

180 {
181  FILE *file;
182  MD5_CTX context;
183  int len;
184  unsigned char buffer[1024], digest[16];
185 
186  if ((file = fopen (filename, "rb")) == NULL)
187  printf ("%s can't be opened\n", filename);
188 
189  else {
190  MDInit (&context);
191  while (len = fread (buffer, 1, 1024, file))
192  MDUpdate (&context, buffer, len);
193  MDFinal (digest, &context);
194 
195  fclose (file);
196 
197  printf ("MD%d (%s) = ", MD, filename);
198  MDPrint (digest);
199  printf ("\n");
200  }
201 }
static void MDFilter ( )
static

Definition at line 205 of file mddriver.c.

References MDFinal, MDInit, MDPrint(), MDUpdate, and printf().

Referenced by main().

206 {
207  MD5_CTX context;
208  int len;
209  unsigned char buffer[16], digest[16];
210 
211  MDInit (&context);
212  while (len = fread (buffer, 1, 16, stdin))
213  MDUpdate (&context, buffer, len);
214  MDFinal (digest, &context);
215 
216  MDPrint (digest);
217  printf ("\n");
218 }
static void MDPrint ( digest  )
static

Definition at line 222 of file mddriver.c.

References i, and printf().

Referenced by MDFile(), MDFilter(), MDString(), and MDTimeTrial().

224 {
225 
226  unsigned int i;
227 
228  for (i = 0; i < 16; i++)
229  printf ("%02x", digest[i]);
230 }
static void MDString ( char *  string)
static

Definition at line 102 of file mddriver.c.

References MD, MDFinal, MDInit, MDPrint(), MDUpdate, and printf().

Referenced by main(), and MDTestSuite().

104 {
105  MD5_CTX context;
106  unsigned char digest[16];
107  unsigned int len = strlen (string);
108 
109  MDInit (&context);
110  MDUpdate (&context, string, len);
111  MDFinal (digest, &context);
112 
113  printf ("MD%d (\"%s\") = ", MD, string);
114  MDPrint (digest);
115  printf ("\n");
116 }
static void MDTestSuite ( )
static

Definition at line 160 of file mddriver.c.

References MD, MDString(), and printf().

Referenced by main().

161 {
162  printf ("MD%d test suite:\n", MD);
163 
164  MDString ("");
165  MDString ("a");
166  MDString ("abc");
167  MDString ("message digest");
168  MDString ("abcdefghijklmnopqrstuvwxyz");
169  MDString
170  ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
171  MDString
172  ("1234567890123456789012345678901234567890\
173 1234567890123456789012345678901234567890");
174 }
static void MDTimeTrial ( )
static

Definition at line 121 of file mddriver.c.

References i, MD, MDFinal, MDInit, MDPrint(), MDUpdate, printf(), TEST_BLOCK_COUNT, TEST_BLOCK_LEN, and time.

Referenced by main().

122 {
123  MD5_CTX context;
124  time_t endTime, startTime;
125  unsigned char block[TEST_BLOCK_LEN], digest[16];
126  unsigned int i;
127 
128 
129  printf
130  ("MD%d time trial. Digesting %d %d-byte blocks ...", MD,
132 
133  /* Initialize block */
134  for (i = 0; i < TEST_BLOCK_LEN; i++)
135  block[i] = (unsigned char)(i & 0xff);
136 
137  /* Start timer */
138  time (&startTime);
139 
140  /* Digest blocks */
141  MDInit (&context);
142  for (i = 0; i < TEST_BLOCK_COUNT; i++)
143  MDUpdate (&context, block, TEST_BLOCK_LEN);
144  MDFinal (digest, &context);
145 
146  /* Stop timer */
147  time (&endTime);
148 
149  printf (" done\n");
150  printf ("Digest = ");
151  MDPrint (digest);
152  printf ("\nTime = %ld seconds\n", (long)(endTime-startTime));
153  printf
154  ("Speed = %ld bytes/second\n",
155  (long)TEST_BLOCK_LEN * (long)TEST_BLOCK_COUNT/(endTime-startTime));
156 }
static void MDFile PROTO_LIST ( (char *)  )
static
static void MDFilter PROTO_LIST ( (void)  )
static
static void MDPrint PROTO_LIST ( (unsigned char[16])  )
static