简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM