我正在使用CryptoPP 8.2。
Wiki Here中的示例有效。现在,我想通过套接字发送生成的密钥,以计算另一端的共享密钥。我如何将接收到的密钥设置为FHMQV_Domain类?
OID CURVE = secp256r1();
FHMQV_Domain<DL_GroupParameters_EC<ECP>> fhmqvA(CURVE,true); //Client
FHMQV_Domain<DL_GroupParameters_EC<ECP>> fhmqvB(CURVE,false); //Server
我还没有在此类中看到任何用于设置自定义键的方法。
SecByteBlock sprivA(fhmqvA.StaticPrivateKeyLength()), spubA(fhmqvA.StaticPublicKeyLength());
// Party A, ephemeral (temporary) key pair
SecByteBlock eprivA(fhmqvA.EphemeralPrivateKeyLength()), epubA(fhmqvA.EphemeralPublicKeyLength());
// Party B, static (long term) key pair
SecByteBlock sprivB(fhmqvB.StaticPrivateKeyLength()), spubB(fhmqvB.StaticPublicKeyLength());
// Party B, ephemeral (temporary) key pair
SecByteBlock eprivB(fhmqvB.EphemeralPrivateKeyLength()), epubB(fhmqvB.EphemeralPublicKeyLength());
// Imitate a long term (static) key
fhmqvA.GenerateStaticKeyPair(rng, sprivA, spubA);
// Ephemeral (temporary) key
fhmqvA.GenerateEphemeralKeyPair(rng, eprivA, epubA);
// Imitate a long term (static) key
fhmqvB.GenerateStaticKeyPair(rng, sprivB, spubB);
// Ephemeral (temporary) key
fhmqvB.GenerateEphemeralKeyPair(rng, eprivB, epubB);
这只会生成随机密钥。我想在它们已知时提供它们。
在Wiki页面中,它具有使用BufferedTransformation创建带有组参数和选项的类的功能。但是我不知道如何创建它,或者这是否正是我想要的。
◆ FHMQV_Domain() [3/7]
Construct a FHMQV domain.
Parameters
bt BufferedTransformation with group parameters and options
clientRole flag indicating initiator or recipient```
我正在使用此功能创建课程
◆ FHMQV_Domain() [2/7]
任何帮助将不胜感激。
好的,我要回答这个问题,因为我自己解决了这个问题,以防万一有人遇到我的问题。
在问题所示的示例中,我们必须将spubB和epubB创建为SecByteBlock
,其大小分别为StaticPublicKeyLength
和EphemeralPublicKeyLength
。
然后我们可以使用memcpy
将B public static和B public ephemeral键设置为其BytePtr()
。
因此,对于上面的示例,它看起来像这样
memcpy(spubB.BytePtr(),(B Static public key's byte array),spubB.SizeInBytes()); //Sets the public static key.
memcpy(epubB.BytePtr(),(B Public ephemeral key's byte array),epubB.SizeInBytes()); //Sets the ephemeral key.