2013-06-19 08:54:52 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "util.h"
|
2013-07-07 14:29:45 +00:00
|
|
|
#include "crypt.h"
|
2013-06-19 08:54:52 +00:00
|
|
|
#include "md5.h"
|
|
|
|
|
2013-07-07 14:29:45 +00:00
|
|
|
struct md5 s;
|
|
|
|
struct crypt_ops md5_ops = {
|
|
|
|
md5_init,
|
|
|
|
md5_update,
|
|
|
|
md5_sum,
|
|
|
|
&s,
|
|
|
|
};
|
2013-06-19 08:54:52 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2013-08-15 09:55:21 +00:00
|
|
|
eprintf("usage: %s [-c] [file...]\n", argv0);
|
2013-06-19 08:54:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2013-07-07 14:29:45 +00:00
|
|
|
FILE *fp;
|
|
|
|
uint8_t md[MD5_DIGEST_LENGTH];
|
2013-06-19 08:54:52 +00:00
|
|
|
|
|
|
|
ARGBEGIN {
|
2013-08-15 09:55:21 +00:00
|
|
|
case 'c':
|
|
|
|
eprintf("not implemented\n");
|
2013-06-19 08:54:52 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
if (argc == 0) {
|
2013-07-07 14:29:45 +00:00
|
|
|
cryptsum(&md5_ops, stdin, "<stdin>", md);
|
|
|
|
mdprint(md, "<stdin>", sizeof(md));
|
2013-06-19 08:54:52 +00:00
|
|
|
} else {
|
|
|
|
for (; argc > 0; argc--) {
|
2013-07-07 14:29:45 +00:00
|
|
|
if ((fp = fopen(*argv, "r")) == NULL)
|
|
|
|
eprintf("fopen %s:", *argv);
|
|
|
|
cryptsum(&md5_ops, fp, *argv, md);
|
|
|
|
mdprint(md, *argv, sizeof(md));
|
|
|
|
fclose(fp);
|
2013-06-19 08:54:52 +00:00
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|