1
#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?

TCX
  • 31
  • 2
  • You're right, that arithmetic should hold true. I wonder if the `GetCurve.Equal()` call isn't for comparing points? I can't see it in the docs because the docs are shit. – Woodstock Dec 18 '20 at 14:26
  • I don't think the problem is with `Equal`. The coordinates of the points can be printed with `g_ec_.x` / `g_ec_.y`. I compared the coordinates with the results given by ECPy. For ECPy, the computation gives the expected result, i.e. P+P-P == P. But the the ECPy coordinates already differ from the cryptopp coordinates after the first addition, i.e. the coordinates for P+P are different. So there seems to be a more general problem than just the `Equal` function. – f9c69e9781fa194211448473495534 Dec 23 '20 at 16:17
  • @f9c69e9781fa194211448473495534 interesting... I wonder if this is an issue with the library, ofc the points should be the same if the curve geometry and curve arithmetic is implemented correctly. – Woodstock Jan 05 '21 at 14:19
  • Yeah I'm also suspecting there might be some issue with ECC in crypto++, also in this [question](https://stackoverflow.com/questions/65441187/cryptopped25519verifier-shows-different-result-from-libsignal). – f9c69e9781fa194211448473495534 Jan 05 '21 at 14:24
  • 1
    This appears to have been fixed in the 8.4 release ([reference](https://github.com/weidai11/cryptopp/issues/994)). – f9c69e9781fa194211448473495534 Jan 11 '21 at 20:19

0 Answers0