yacl/crypto/tpre/kdf的问题
maths644311798 opened this issue · 2 comments
maths644311798 commented
在yacl/crypto/tpre/kdf.cc中,kdf的实现和SM2的文档(就是kdf.h给的文档 )不一致。这段代码
if (i == index - 1) {
if (key_len % 32 != 0) {
dgst_len = (key_len) % 32;
} else {
dgst_len = 0;
}
}
中key_len被32整除时,按照文档的做法,应该是设置dgst_len = 32. 下面抄录文档这一句
若klen/v是整数,令Ha!klen/v = Haklen/v
Jamie-Cui commented
This code was contributed by external developers, it will take some time for us to verify. @xfap Would you like to take a look?
xfap commented
@maths644311798 Hi, the kdf function here is not a wrong implementation but a different impl. way. The reason for setting to 0 instead of 32, is bacause the index is setted as int index = (key_len + 32) / 32;
. When key_len%32==0
, there will be a redundant hash round, so the last dgst_len should set to 0.