K
Kenneth Kan
This is probably not only exclusive to C but I've programmed in C two
functions with the Whirlpool cryptographic hash downloaded from the
official site [http://www.larc.usp.br/~pbarreto/WhirlpoolPage.html].
One is to take a string and return a 512-bit digest and the other is
to take the path to a file and return the file digest. The weird thing
is, with both functions using the same hash, the one taking a message
returns a correct digest while the one taking the file does not (I
checked against various sources). For instance, when I have a file
called "test.txt" with "test files" as its content, the hash for "test
files" is correct but the checksum for the file is not correct
(checked against whirlpooldeep). Is it just C, the file, the hash
algorithm, or what? I'm desperate after hours of research. Here is my
source code in question. Thanks so much in advance!
void NESSIEinit(struct NESSIEstruct * const structpointer);
void NESSIEadd(const unsigned char * const source,
unsigned long sourceBits,
struct NESSIEstruct * const structpointer);
void NESSIEfinalize(struct NESSIEstruct * const structpointer,
unsigned char * const result);
char* whirlpool_file(char* path) {
u8* buffer[sizeof(u8)*DIGESTBYTES];
char* digest;
FILE* file;
int length;
struct NESSIEstruct w;
NESSIEinit(&w);
if((file = fopen(path, "r")) != NULL) {
rewind(file);
while(fread(buffer, sizeof(u8), DIGESTBYTES, file) != 0) {
NESSIEadd(buffer, sizeof(u8)*DIGESTBYTES, &w);
}
}
return whirlpool_hex(&w);
}
char* whirlpool_string(char* string) {
struct NESSIEstruct w;
NESSIEinit(&w);
NESSIEadd(string, 8*strlen(string), &w);
return whirlpool_hex(&w);
}
functions with the Whirlpool cryptographic hash downloaded from the
official site [http://www.larc.usp.br/~pbarreto/WhirlpoolPage.html].
One is to take a string and return a 512-bit digest and the other is
to take the path to a file and return the file digest. The weird thing
is, with both functions using the same hash, the one taking a message
returns a correct digest while the one taking the file does not (I
checked against various sources). For instance, when I have a file
called "test.txt" with "test files" as its content, the hash for "test
files" is correct but the checksum for the file is not correct
(checked against whirlpooldeep). Is it just C, the file, the hash
algorithm, or what? I'm desperate after hours of research. Here is my
source code in question. Thanks so much in advance!
void NESSIEinit(struct NESSIEstruct * const structpointer);
void NESSIEadd(const unsigned char * const source,
unsigned long sourceBits,
struct NESSIEstruct * const structpointer);
void NESSIEfinalize(struct NESSIEstruct * const structpointer,
unsigned char * const result);
char* whirlpool_file(char* path) {
u8* buffer[sizeof(u8)*DIGESTBYTES];
char* digest;
FILE* file;
int length;
struct NESSIEstruct w;
NESSIEinit(&w);
if((file = fopen(path, "r")) != NULL) {
rewind(file);
while(fread(buffer, sizeof(u8), DIGESTBYTES, file) != 0) {
NESSIEadd(buffer, sizeof(u8)*DIGESTBYTES, &w);
}
}
return whirlpool_hex(&w);
}
char* whirlpool_string(char* string) {
struct NESSIEstruct w;
NESSIEinit(&w);
NESSIEadd(string, 8*strlen(string), &w);
return whirlpool_hex(&w);
}