-
Notifications
You must be signed in to change notification settings - Fork 82
Open
Description
问题描述:
-
HashToCurve
函数在某些曲线与哈希策略的组合使用场景下,存在所生成椭圆曲线点的比特长度小于目标曲线安全位数要求的情况,导致生成的椭圆曲线点在安全性上无法完全满足目标曲线的强度要求,引入潜在的安全隐患。 -
相关代码:
yacl/crypto/ecc/openssl/openssl_group.cc
中HashToCurve
函数
复现代码
#include <vector>
#include<iostream>
#include "yacl/crypto/hash/ssl_hash.h"
#include "yacl/crypto/rand/rand.h"
#include "yacl/crypto/ecc/ecc_spi.h"
#include "yacl/crypto/ecc/openssl/openssl_group.h"
using namespace yacl::crypto;
int main(){
HashToCurveStrategy strategy = HashToCurveStrategy::TryAndRehash_SM;
auto ecc_name = "secp521r1";
std::shared_ptr<EcGroup> ecc =
EcGroupFactory::Instance().Create(ecc_name, yacl::ArgLib = "openssl");
uint64_t point_number=10000;
std::map<uint64_t, uint64_t> freq;
for(uint64_t i=0;i<point_number;i++){
const std::string msg = "message"+std::to_string(i);
EcPoint point = ecc->HashToCurve(strategy, msg);
AffinePoint ap = ecc->GetAffinePoint(point);
uint64_t len = ap.x.BitCount();
freq[len]++;
}
std::cout << "Bit length frequency:\n";
for (auto &[l, f]: freq) {
std::cout << l << " : " << f << "\n";
}
return 0;
}
当选择曲线EcGroupFactory::Instance().Create("secp521r1", yacl::ArgLib = "openssl")
和HashToCurveStrategy strategy = HashToCurveStrategy::TryAndRehash_SM,ecc->HashToCurve(strategy, msg)
生成的点的比特长度集中在234比特到256比特之间,远远达不到secp521r1的521比特。
建议
- 在选择哈希函数时进行判断,当选择的HashToCurveStrategy无法满足指定群的比特长度需求时,直接报错,防止在用户不知情的情况下降低了安全强度。
- 基于标准化方案迭代替换所有可选的哈希策略实现。
Metadata
Metadata
Assignees
Labels
No labels