On Wed, Sep 15, 2021 at 12:01 PM Jeffrey Walton <noloa...@gmail.com> wrote:
>
> > But my problem afterward (which I didn't mention to this point, because I 
> > thought it will solve itself when I have a correct y-coordinate) is, that 
> > if I try to save this public key as PEM, I only get
> >
> > -----BEGIN PUBLIC KEY-----
> > MFowMFow-----END PUBLIC KEY-----
> >
> > as result. This was also my result with wrong y and failed validation.

Here's what I am seeing with your data. It looks OK to me. I think we
need to see your program to determine what is going sideways.

$ cat test.cxx
#include <iostream>
#include <string>

#include "cryptlib.h"
#include "filters.h"
#include "eccrypto.h"
#include "osrng.h"
#include "files.h"
#include "sha.h"
#include "hex.h"

#include "pem.h"

int main(int argc, char* argv[])
{
    using namespace CryptoPP;

    std::string pt =
        "40BA49FCBA45C7EEB2261B1BE0EBC7C14D6484B9EF8A23B060EBE67F97252BBC"
        "987BA49DF364A0C9926F2B6DE1BAF46068A13A2C5C9812B2F3451F48B75719EE";

    HexDecoder decoder;
    decoder.Put((byte*)&pt[0], pt.size());
    decoder.MessageEnd();

    ECP::Point q;
    size_t len = decoder.MaxRetrievable();

    q.identity = false;
    q.x.Decode(decoder, len/2);
    q.y.Decode(decoder, len/2);

    ECDSA<ECP, SHA256>::PublicKey pkey;
    pkey.Initialize(ASN1::brainpoolP256r1(), q);

    FileSink fs("pubkey.pem");
    PEM_Save(fs, pkey);

    return 0;
}

And:

$ ./test.exe
$ cat pubkey.pem
-----BEGIN PUBLIC KEY-----
MFowFAYHKoZIzj0CAQYJKyQDAwIIAQEHA0IABEC6Sfy6RcfusiYbG+Drx8FNZIS5
74ojsGDr5n+XJSu8mHuknfNkoMmSbytt4br0YGihOixcmBKy80UfSLdXGe4=
-----END PUBLIC KEY-----

And: $ openssl ec -in pubkey.pem -inform PEM -pubin -text
Public-Key: (256 bit)
pub:
    04:40:ba:49:fc:ba:45:c7:ee:b2:26:1b:1b:e0:eb:
    c7:c1:4d:64:84:b9:ef:8a:23:b0:60:eb:e6:7f:97:
    25:2b:bc:98:7b:a4:9d:f3:64:a0:c9:92:6f:2b:6d:
    e1:ba:f4:60:68:a1:3a:2c:5c:98:12:b2:f3:45:1f:
    48:b7:57:19:ee
ASN1 OID: brainpoolP256r1

Jeff

-- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cryptopp-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/CAH8yC8kX0OOrO2KwNGfehzjfY%2BR3tTJ0pAWH58QvFQqpg9TUhQ%40mail.gmail.com.

Reply via email to