问题
#include "include/cryptopp/oids.h"
#include "include/cryptopp/eccrypto.h"
#include <cstdio>
#include <iostream>
using namespace std;
using namespace CryptoPP;
void init()
{
ECDH<ECP>::Domain ecdhc(ASN1::secp256k1());
auto g_p = ecdhc.GetGroupParameters();
auto g_ec = g_p.GetSubgroupGenerator();
auto g_ec_ = g_p.GetCurve().Subtract(g_p.GetCurve().Add(g_ec, g_ec), g_ec);
if(g_p.GetCurve().Equal(g_ec_, g_ec))
printf("P\n");
else
printf("NP\n");
}
int main()
{
init();
return 0;
}
As an example code above.
It's expected to perform the following arithmetic:
g_ec_ = (g_ec + g_ec) - g_ec
So g_ec
and g_ec_
should be the same.
But the code output False
. Can someone explain it?
来源:https://stackoverflow.com/questions/65290544/elliptic-curve-point-arithmetic-in-crypto