我只想使用 SHA-3-512。所以我使用了KeccakCodePackage。
我阅读了规范并使用了它们。要检查我的结果,我使用以下Online-Hash-Website。
我对“一些数据”的结果是:
15d7fb5fcb81cf8f178cd9ea946c298db9d6b3d3509a35d369fc58cbc923fab549df95dffddb371a5ef21745b3bf7f7a15ee7785a0ee81b97e9d87911e
而在线转换器返回以下内容:
15d7fb5fcb081cf80f178cd9ea946c298db9d6b3d3509a35d369fc58cbc923fab549df95dffd0db371a5ef210745b30b0f7f7a15ee7785a0ee81b97e9d87911e
我使用了以下配置:
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);
完整的代码可以在这里找到。
打印值的代码是:
int i;
for(i = 0; i < hashLength; i++){
printf("%x", *(outputData + i) & 0xff);
}
我意识到另一个哈希中有更多的零。所以,我的问题是:我的代码有什么问题?
编辑:这是整个程序:
#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");
}