I just want to use SHA-3-512. So I used the KeccakCodePackage.
I read the specification and used them.To check my result I use the following Online-Hash-Website.
My result for "Some Data" is:
15d7fb5fcb81cf8f178cd9ea946c298db9d6b3d3509a35d369fc58cbc923fab549df95dffddb371a5ef21745b3bf7f7a15ee7785a0ee81b97e9d87911e
While the Online-Converter returns the following:
15d7fb5fcb081cf80f178cd9ea946c298db9d6b3d3509a35d369fc58cbc923fab549df95dffd0db371a5ef210745b30b0f7f7a15ee7785a0ee81b97e9d87911e
I used the following configuration:
char* inputData = (char*)malloc(sizeof(char) * 15);
char* outputData = (char*)malloc(sizeof(char) * 1024);
inputData = "Some Data";
unsigned int rate = 576;
unsigned int capacity = 1024;
unsigned char suffix = 0x06;
unsigned int hashLength = 64;
int spongeResult = KeccakWidth1600_Sponge(rate, capacity , inputData, sizeof(inputData)+1, suffix , outputData, hashLength);
The complete code can be found here.
The code that prints the value is:
int i;
for(i = 0; i < hashLength; i++){
printf("%x", *(outputData + i) & 0xff);
}
I realized that there are more zeros within the other hash. So, my question: What is wrong in my code?
EDIT: Here's the entire program:
#include <stdio.h>
#include <stdlib.h>
#include "KeccakCodePackage/bin/generic64/libkeccak.a.headers/KeccakSpongeWidth1600.h"
void main(){
printf("%s\n", "Run Keccak Test");
char* inputData = (char*)malloc(sizeof(char) * 15);
char* outputData = (char*)malloc(sizeof(char) * 1024);
inputData = "Some Data";
unsigned int rate = 576;
unsigned int capacity = 1024;
unsigned char suffix = 0x06;
unsigned int hashLength = 64;
printf("%s", "Hash the following data: \n");
printf("%s\n", inputData);
int spongeResult = KeccakWidth1600_Sponge(rate, capacity , inputData, sizeof(inputData)+1, suffix , outputData, hashLength);
if(spongeResult == 1){
printf("%s", "Sponge was not successful\n");
}else{
printf("%s", "Sponge successful\n");
int i;
for(i = 0; i < hashLength; i++){
printf("%x", *(outputData + i) & 0xff);
}
}
printf("%s", "\nFinished Keccak test.\n");
}
The problem is in the way you're printing the value.
int i;
for(i = 0; i < hashLength; i++){
printf("%x", *(outputData + i) & 0xff);
}
The %x
format will print a single hex digit for a value less than 16. You need to print such values with a leading 0, using %02x
.