ysato.5654
ysato.5654

Reputation: 13

ECDH in OpenSSL

I have a question about ECDH in the OpenSSL library.

In file 'ecdhtest.c' at 159 line, we can confirm the value of private key as follows:

BN_print(out, a->priv_key);

But, the error happened when I built using Makefile.

ecdsatest.c:221:22: error: incomplete definition of type 'struct ec_key_st'
    BN_print(out, key->priv_key);
                  ~~~^
../include/openssl/evp.h:147:16: note: forward declaration of 'struct ec_key_st'
        struct ec_key_st *ec;   /* ECC */
               ^
1 error generated.

I think that the type of key->priv_key is BIGNUM.

I would like to confirm the value of the private key.

If you have some idea, please help me.

Upvotes: 1

Views: 666

Answers (1)

Ctx
Ctx

Reputation: 18410

The definition of struct ec_key_st is held opaque by intent. It is defined in ec_lcl.h from the openssl distribution, which is not part of the public interface. In version 1.0.1k, it looks like this:

struct ec_key_st {
    int version;
    EC_GROUP *group;
    EC_POINT *pub_key;
    BIGNUM   *priv_key;
    unsigned int enc_flag;
    point_conversion_form_t conv_form;
    int     references;
    int     flags;
    EC_EXTRA_DATA *method_data;
} /* EC_KEY */;

but it may not be stable from version to version.

However, you can obtain the private key using the accessor function

const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);

which would be the clean way to do that.

Upvotes: 1

Related Questions