【发布时间】:2014-01-15 03:05:12
【问题描述】:
我在 CryptoPP 上翻来覆去,找不到这个特定问题的答案。这是示例源代码(部分)
AutoSeededRandomPool prng;
//Generate a private key
ECDSA<ECP, CryptoPP::SHA256>::PrivateKey privateKey;
privateKey.Initialize(prng, CryptoPP::ASN1::secp256r1());
// Generate publicKey
ECDSA<ECP, CryptoPP::SHA256>::PublicKey publicKey;
privateKey.MakePublicKey(publicKey);
// Extract Component values
Integer p = privateKey.GetGroupParameters().GetCurve().GetField().GetModulus();
Integer a = privateKey.GetGroupParameters().GetCurve().GetA();
Integer b = privateKey.GetGroupParameters().GetCurve().GetB();
Integer Gx = privateKey.GetGroupParameters().GetSubgroupGenerator().x;
Integer Gy = privateKey.GetGroupParameters().GetSubgroupGenerator().y;
Integer n = privateKey.GetGroupParameters().GetSubgroupOrder();
Integer h = privateKey.GetGroupParameters().GetCofactor();
Integer Qx = publicKey.GetPublicElement().x;
Integer Qy = publicKey.GetPublicElement().y;
Integer x = privateKey.GetPrivateExponent();
// Construct Point elelemt;
ECP curve(p,a,b);
ECP::Point G(Gx,Gy);
ECP::Point Q(Qx,Qy);
//Build publicKey using elements (no point compression)
ECDSA<ECP, CryptoPP::SHA256>::PublicKey GeneratedPublicKey;
GeneratedPublicKey.Initialize(curve,G,n,Q);
assert(GeneratedPublicKey.Validate(prng, 3));
//Build publicKey using elements (with point compression)?
通过这种方式,我可以使用组件值生成 publicKey。然而,我不能 使它与点压缩一起工作——这意味着我没有 Qy 值——有没有 怎么做? Initialize 方法有两个重载,但都不是针对点的 压缩情况。
我的问题是关于“PublicKey.Initialize(curve,G,n,Q)”的 Crypto++。由于我不能用我当前的项目转移整个 publicKey - 我不得不指定域 参数作为索引值,只能传递 Qx 值。所以我应该初始化 publicKey 使用类似“PublicKey.Initialize(curve,G,n,Q)”的东西但是,我找不到关于点压缩的初始化 API。
所以,这不是关于“如何进行点压缩”而是“有没有办法初始化 没有 Qy 值的公钥?”
【问题讨论】:
-
准确告诉我们您拥有什么。您从未在
//Build publicKey using elements (with point compression)?处告诉过您正在使用的参数。如果它是 ASN.1 编码值,请使用dumpasn1向我们展示。如果原始形式是二进制,则显示给我们十六进制编码。