X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gost12sum.c;h=f643b8bbf407ac39db738914b9c559cd170ea694;hb=a430c355a1d2eff5df6c96c7b6f928a609c2dd73;hp=887eb1c0984d422a9c48efa5ef6e84863ad544f0;hpb=f2f9fc54848f46535bee3f120a32e4cc91ba2b15;p=openssl-gost%2Fengine.git diff --git a/gost12sum.c b/gost12sum.c index 887eb1c..f643b8b 100644 --- a/gost12sum.c +++ b/gost12sum.c @@ -10,7 +10,16 @@ **********************************************************************/ #include #include -#include +#ifdef _MSC_VER +# include "getopt.h" +# ifndef PATH_MAX +# define PATH_MAX _MAX_PATH +# endif +# include +typedef SSIZE_T ssize_t; +#else +# include +#endif #include #include #ifdef _WIN32 @@ -34,18 +43,17 @@ int hash_file(gost_hash_ctx * ctx, char *filename, char *sum, int mode); int hash_stream(gost_hash_ctx * ctx, int fd, char *sum); int get_line(FILE *f, char *hash, char *filename, int verbose); -void help(const char *progname) +void help() { fprintf(stderr, "Calculates GOST R 34.11-2012 hash function\n\n"); - fprintf(stderr, "%s [-bvl] [-c [file]]| [files]|-x\n" + fprintf(stderr, "gostsum12 [-bvl] [-c [file]]| [files]|-x\n" "\t-c check message digests (default is generate)\n" "\t-v verbose, print file names when checking\n" "\t-b read files in binary mode\n" "\t-l use 512 bit hash (default 256 bit)\n" "\t-x read filenames from stdin rather than from arguments \n" "The input for -c should be the list of message digests and file names\n" - "that is printed on stdout by this program when it generates" - "digests.\n", progname); + "that is printed on stdout by this program when it generates digests.\n"); exit(3); } @@ -108,7 +116,7 @@ int main(int argc, char **argv) break; default: fprintf(stderr, "invalid option %c", optopt); - help(argv[0]); + help(); } } if (check_file) { @@ -216,7 +224,7 @@ int hash_stream(gost_hash_ctx * ctx, int fd, char *sum) { unsigned char buffer[BUF_SIZE]; ssize_t bytes; - size_t i; + size_t i; start_hash12(ctx); while ((bytes = read(fd, buffer, BUF_SIZE)) > 0) { @@ -227,7 +235,7 @@ int hash_stream(gost_hash_ctx * ctx, int fd, char *sum) } finish_hash12(ctx, buffer); for (i = 0; i < (hashsize / 8); i++) { - sprintf(sum + 2 * i, "%02x", buffer[hashsize/8-1-i]); + sprintf(sum + 2 * i, "%02x", buffer[i]); } return 1; } @@ -261,7 +269,7 @@ int get_line(FILE *f, char *hash, char *filename, int verbose) return 1; nextline: if (verbose) - printf("%s\n", filename); + printf("%s\n", filename); } return 0; }