繁体   English   中英

C sha1实现在Unix上不起作用

[英]C sha1 implementation not working on Unix

我正在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://zh.wikipedia.org/wiki/64-位_计算#64-位_数据_模型

如果任何平台是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编译器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM