}
}
+/* Return: -1 = Error, 0 = Mismatch, 1 = Match */
int HashMatch(const char StoredDigest[], const char *filename, int quiet)
{
char mode = 't';
char MsgDigest[hashbitlen/2];
if (HashWithMode(filename, MsgDigest, mode) < 0)
- return 0;
+ return -1;
if (strcmp(MsgDigest, StoredDigest)) {
printf("%s: FAILED\n", filename);
return 0;
}
+
if (quiet > 0)
printf("%s: OK\n", filename);
return 1;
}
+/* Return: -1 = some errors/mismatches, 1 = all ok */
int VerifyHashesFromFile(FILE *fp, int status, int warn, int quiet)
{
- char hash[500], MsgDigest_tmp[hashbitlen/2];
+ char hash[PATH_MAX + hashbitlen/4 + 4];
+ char MsgDigest_tmp[hashbitlen/2];
int NoMatch = 0, NotProper = 0, Computed = 0;
int line = 0;
char file_tmp[PATH_MAX];
line ++;
Computed++;
- unsigned int hashVersion = decomposeHashLine(hash,MsgDigest_tmp,file_tmp);
+ int hashVersion = decomposeHashLine(hash,MsgDigest_tmp,file_tmp);
if (hashVersion == -1)
{
fprintf(stderr, "skein%d: %s is using newer version of skein%d algorithm\n",hashbitlen,file_tmp,hashbitlen);
NotProper ++;
NoMatch ++;
}
- else if (!HashMatch(MsgDigest_tmp, file_tmp, quiet))
+ else if (HashMatch(MsgDigest_tmp, file_tmp, quiet) <= 0)
{
NoMatch++;
}
return (NotProper || NoMatch) ? -1 : 1;
}
-int isProper(char MsgDigest[])
+int isProper(const char MsgDigest[])
{
- if ((strlen(MsgDigest) - hashbitlen/4) != 0)
+ int len = strlen(MsgDigest);
+ if (len != (hashbitlen / 4))
return 0;
int index = 0;
- char c = 0;
- for(index = 0; index < strlen(MsgDigest);index++)
+ for (index = 0; index < len; index++)
{
- c = MsgDigest[index];
- if(!(( c >= '0' && c <= '9' ) || ( c >= 'A' && c <= 'F')))
- return 0;
+ char c = MsgDigest[index];
+ if (c >= '0' && c <= '9') continue;
+ if (c >= 'A' && c <= 'F') continue;
+ return 0;
}
return 1;
exit(1);
}
-int is_goodfile(const char filename[], int verbose)
+int is_goodfile(const char filename[])
{
if (!strcmp(filename, "-"))
return 1;
struct stat s;
if (stat(filename, &s) < 0) {
- if (verbose) fprintf(stderr, "skein%dsum: %s: no such file or directory\n", hashbitlen, filename);
+ fprintf(stderr, "skein%dsum: %s: no such file or directory\n", hashbitlen, filename);
return 0;
}
return 1;
if (s.st_mode & S_IFDIR) {
- if (verbose) fprintf(stderr, "skein%dsum: %s: is a directory\n", hashbitlen, filename);
+ fprintf(stderr, "skein%dsum: %s: is a directory\n", hashbitlen, filename);
return 0;
}
for (file_index = first_file; file_index < argc; file_index++)
{
const char *filename = argv[file_index];
- if (!is_goodfile(filename, 1)) {
+ if (!is_goodfile(filename)) {
errorFound++;
continue;
}
for (file_index = first_file; file_index < argc; file_index++)
{
const char *filename = argv[file_index];
- if (!is_goodfile(filename, 1)) {
+ if (!is_goodfile(filename)) {
errorFound++;
continue;
}