gpt4 book ai didi

c - 凯卡克 SHA-3-512 : Missed a detail

转载 作者:行者123 更新时间:2023-11-30 14:50:17 24 4
gpt4 key购买 nike

我只想使用 SHA-3-512。所以我用了KeccakCodePackage .

我读了specification并使用它们。为了检查我的结果,我使用以下 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);

完整代码可见here .

打印该值的代码是:

    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");
}

最佳答案

问题在于您打印值的方式。

    int i;
for(i = 0; i < hashLength; i++){
printf("%x", *(outputData + i) & 0xff);
}

%x 格式将为小于 16 的值打印单个十六进制数字。您需要使用 %02x 打印带有前导 0 的此类值。

关于c - 凯卡克 SHA-3-512 : Missed a detail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49080212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com