Elliptic Curve Point Arithmetic in Crypto++

断了今生、忘了曾经 提交于 2021-01-28 06:31:35

问题


#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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!