use hash_filehandle() to read from stdin

This commit is contained in:
Steffen Jaeckel 2017-04-23 22:37:32 +02:00
parent a6b8e52c43
commit 943c7a7cfc

View File

@ -15,10 +15,9 @@ void register_algs(void);
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int idx, x, z; int idx, z;
unsigned long w; unsigned long w, x;
unsigned char hash_buffer[MAXBLOCKSIZE]; unsigned char hash_buffer[MAXBLOCKSIZE];
hash_state md;
/* You need to register algorithms before using them */ /* You need to register algorithms before using them */
register_algs(); register_algs();
@ -38,23 +37,22 @@ int main(int argc, char **argv)
} }
if (argc == 2) { if (argc == 2) {
hash_descriptor[idx].init(&md); w = sizeof(hash_buffer);
do { if ((errno = hash_filehandle(idx, stdin, hash_buffer, &w)) != CRYPT_OK) {
x = fread(hash_buffer, 1, sizeof(hash_buffer), stdin); printf("File hash error: %s\n", error_to_string(errno));
hash_descriptor[idx].process(&md, hash_buffer, x); } else {
} while (x == sizeof(hash_buffer)); for (x = 0; x < w; x++) {
hash_descriptor[idx].done(&md, hash_buffer); printf("%02x",hash_buffer[x]);
for (x = 0; x < (int)hash_descriptor[idx].hashsize; x++) { }
printf("%02x",hash_buffer[x]); printf(" *-\n");
} }
printf(" *-\n");
} else { } else {
for (z = 2; z < argc; z++) { for (z = 2; z < argc; z++) {
w = sizeof(hash_buffer); w = sizeof(hash_buffer);
if ((errno = hash_file(idx,argv[z],hash_buffer,&w)) != CRYPT_OK) { if ((errno = hash_file(idx,argv[z],hash_buffer,&w)) != CRYPT_OK) {
printf("File hash error: %s\n", error_to_string(errno)); printf("File hash error: %s\n", error_to_string(errno));
} else { } else {
for (x = 0; x < (int)hash_descriptor[idx].hashsize; x++) { for (x = 0; x < w; x++) {
printf("%02x",hash_buffer[x]); printf("%02x",hash_buffer[x]);
} }
printf(" *%s\n", argv[z]); printf(" *%s\n", argv[z]);