我在 C 中使用 SHA1 的这种实现。在 Windows 上运行良好,但在 Unix 上不能输出正确的哈希值(在 Ubuntu 和 Mac OS 10.8 上试过)。此外,在 Ubuntu 上,它从同一条消息中输出不同的哈希值。
我想我可以使用另一种实现,只是好奇为什么会这样。
编辑
谢谢,你们是对的。将其更改为
typedef unsigned int UINT4;
似乎工作正常。
我在 C 中使用 SHA1 的这种实现。在 Windows 上运行良好,但在 Unix 上不能输出正确的哈希值(在 Ubuntu 和 Mac OS 10.8 上试过)。此外,在 Ubuntu 上,它从同一条消息中输出不同的哈希值。
我想我可以使用另一种实现,只是好奇为什么会这样。
编辑
谢谢,你们是对的。将其更改为
typedef unsigned int UINT4;
似乎工作正常。
这些是 64 位的 unix 吗?
/* 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
如果任何平台是 64 位且具有 64 位unsigned long
,则此代码可能存在问题:
/* UINT4 defines a four byte word */
typedef unsigned long int UINT4;
没有仔细阅读代码以查看如果UINT4
它实际上是 8 个字节,使用的方式是否会中断,但这听起来很可疑。
typedef unsigned long int UINT4;
也许您的 Unix 实现使用 64 位无符号长整数。
尝试
#include <stdint.h>
/* ... */
typedef uint32_t UINT4;
并使用 C99 编译器。