Annotation of OpenXM/src/ox_ntl/crypt/sha1/sha1test.c, Revision 1.2
1.2 ! iwane 1: /* $OpenXM: OpenXM/src/ox_ntl/crypt/sha1/sha1test.c,v 1.1 2004/05/16 15:02:39 iwane Exp $ */
1.1 iwane 2:
3: /* openssl sha1 ${FILE} */
4:
5: #include <stdio.h>
1.2 ! iwane 6: #include <unistd.h>
! 7: #include <fcntl.h>
1.1 iwane 8:
9: #include "sha1.h"
10:
11: void
12: Usage(char *cmd)
13: {
1.2 ! iwane 14: printf("Usage: %s [-f][-s] file\n", cmd);
1.1 iwane 15: exit (-1);
16: }
17:
18:
19: int
20: main(int argc, char *argv[])
21: {
22: FILE *fp;
23: char buf[1000000];
24: int ret;
25: int i;
26: unsigned char sha[100];
1.2 ! iwane 27: int flag = 0;
1.1 iwane 28:
1.2 ! iwane 29: enum {
! 30: SHA = 1,
! 31: F_SHA = 2
! 32: };
! 33:
! 34: for (i = 1; i < argc; i++) {
! 35: if (strcmp(argv[i], "-f") == 0) {
! 36: flag |= F_SHA;
! 37: } else if (strcmp(argv[i], "-s") == 0) {
! 38: flag |= SHA;
! 39: } else {
! 40: break;
! 41: }
! 42: }
! 43:
! 44: if (flag == 0)
! 45: flag |= SHA;
! 46: argc -= i;
! 47:
! 48: if (argc != 1)
1.1 iwane 49: Usage(argv[0]);
50:
1.2 ! iwane 51: argv += i - 1;
! 52:
! 53: if (flag & SHA) {
! 54: fp = fopen(argv[1], "r");
! 55: if (fp == NULL) {
! 56: fprintf(stderr, "file not found: %s\n", argv[1]);
! 57: exit (-1);
! 58: }
! 59:
! 60: ret = fread(buf, 1, sizeof(buf), fp);
! 61:
! 62: sha1(sha, (unsigned char *)buf, ret);
! 63:
! 64: fclose(fp);
! 65:
! 66: printf("SHA1(%s)= ", argv[1]);
! 67: for (i = 0; i < 20; i++) {
! 68: printf("%02x", sha[i] & 0xff);
! 69: }
! 70: printf("\n");
1.1 iwane 71: }
72:
1.2 ! iwane 73: if (flag & F_SHA) {
! 74: int fd;
1.1 iwane 75:
1.2 ! iwane 76: fd = open(argv[1], O_RDONLY, NULL);
! 77: if (fd == -1) {
! 78: fprintf(stderr, "file not found: %s\n", argv[1]);
! 79: exit (-1);
! 80: }
! 81:
! 82: fsha1(sha, fd);
! 83: close(fd);
! 84:
! 85: printf("SHA1(%s)= ", argv[1]);
! 86: for (i = 0; i < 20; i++) {
! 87: printf("%02x", sha[i] & 0xff);
! 88: }
! 89: printf("\n");
! 90: }
1.1 iwane 91:
92:
93: return (0);
94: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>