SMx icon indicating copy to clipboard operation
SMx copied to clipboard

SM3计算结果和pdf文档不一致呢?

Open tan00 opened this issue 6 years ago • 3 comments

SM3文档示例1

输入消息为“abc”,其ASCII码表示为616263 ... 杂凑值 66c7f0f4 62eeedd9 d1f2d46b dc10e4e2 4167c487 5cf2f7a2 297da02b 8f4ba8e0

在linux下编译输出结果为

Message: abc Hash: 37bc43d1 1cab393d 7899ef62 24f568ec 18a8fd85 1d165c50 0c375402 0f466a04

代码粗略看了下, 至少位移的宏看起来有问题

#define  SHL(x,n) (((x) & 0xFFFFFFFF) << n)
#define ROTL(x,n) (SHL((x),n) | ((x) >> (32 - n)))

GMSSL里面的SM3代码, 位移宏为

#define ROTL(x,n)  (((x)<<(n)) | ((x)>>(32-(n))))

GMSSL SM3输出没有问题。

tan00 avatar Dec 17 '19 09:12 tan00

1.问题:64的linux系统下编译会出现SM3计算结果和pdf文档不一致 解决方案:在编译的时候加 -m32 即可

2.衍生问题:添加 -m32 后ubuntu下报错/usr/include/features.h:367:25: fatal error: sys/cdefs.h: No such file or directory 解决方案:sudo apt-get install libc6-dev-i386

zhang-kt avatar Nov 04 '20 08:11 zhang-kt

sm2那边有个sm3,输出是正常的

halloayu avatar Mar 03 '22 08:03 halloayu

fixed. Thanks for your attentions!

NEWPLAN avatar Feb 11 '23 14:02 NEWPLAN