C sha1实现不能在Unix上运行

时间:2012-08-20 09:51:30

标签: c windows unix sha

我在C中使用了this implementation的SHA1。在Windows上正常工作,但它在Unix上没有输出正确的哈希值(在Ubuntu和Mac OS 10.8上尝试过)。此外,在Ubuntu上,它从同一个消息中输出不同的哈希值。

我想我可以使用其他实现,只是好奇为什么会这样。

修改

谢谢,你们是对的。将其更改为

typedef unsigned int UINT4;

似乎工作正常。

3 个答案:

答案 0 :(得分:6)

这些是64位unix'es吗?

/* UINT4 defines a four byte word */
typedef unsigned long int UINT4;

实际上是64位Linux上的8个字节(但在64位Windows上是4个字节)

https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models

答案 1 :(得分:2)

如果任何平台是64位且具有64位unsigned long,则此代码可能存在问题:

/* UINT4 defines a four byte word */
typedef unsigned long int UINT4;

没有仔细阅读代码,看看UINT4的使用方式是否会破坏,如果它实际上是8个字节,但听起来很可疑。

答案 2 :(得分:1)

  

typedef unsigned long int UINT4;

也许你的Unix实现使用64位无符号长整数。

尝试

#include <stdint.h>

/* ... */

typedef uint32_t UINT4;

并使用C99编译器。