Re: [EVP_PKEY] How to duplicate it ? - Openssl

This is a discussion on Re: [EVP_PKEY] How to duplicate it ? - Openssl ; Why not just copy the key? EVP_PKEY *cp_key (EVP_PKEY *pkey) { /* error handling omittet */ EVP_PKEY *pnew; int key_type; pnew = EVP_PKEY_new(); switch(pkey->type) { case EVP_PKEY_RSA: DSA *dsa = EVP_PKEY_get1_DSA(pkey); EVP_PKEY_set1_DSA(pnew, dsa); break; case EVP_PKEY_DSA: RSA *rsa = EVP_PKEY_get1_RSA(pkey); ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Re: [EVP_PKEY] How to duplicate it ?

  1. Re: [EVP_PKEY] How to duplicate it ?

    Why not just copy the key?

    EVP_PKEY *cp_key (EVP_PKEY *pkey) {

    /* error handling omittet */
    EVP_PKEY *pnew;
    int key_type;

    pnew = EVP_PKEY_new();
    switch(pkey->type) {
    case EVP_PKEY_RSA:
    DSA *dsa = EVP_PKEY_get1_DSA(pkey);
    EVP_PKEY_set1_DSA(pnew, dsa);
    break;
    case EVP_PKEY_DSA:
    RSA *rsa = EVP_PKEY_get1_RSA(pkey);
    EVP_PKEY_set1_RSA(pnew, rsa);
    break;
    case EVP_PKEY_DH:
    DH *dh = EVP_PKEY_get1_DH(pkey);
    EVP_PKEY_set1_DH(pnew, dh);
    break;
    case EVP_PKEY_EC:
    EC_KEY *ec = EVP_PKEY_get1_EC(pkey);
    EVP_PKEY_set1_EC(pnew, ec);
    break;

    default:
    fprintf(stderr, "unknown key type %.\n", pkey->type);
    }

    return pnew;
    }

    Thomas
    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


  2. Re: [EVP_PKEY] How to duplicate it ?

    Thomas Mangold wrote:
    > Why not just copy the key?
    >
    > EVP_PKEY *cp_key (EVP_PKEY *pkey) {
    >
    > /* error handling omittet */
    > EVP_PKEY *pnew;
    > int key_type;
    >
    > pnew = EVP_PKEY_new();
    > switch(pkey->type) {
    > case EVP_PKEY_RSA:
    > DSA *dsa = EVP_PKEY_get1_DSA(pkey);
    > EVP_PKEY_set1_DSA(pnew, dsa);
    > break;
    > case EVP_PKEY_DSA:
    > RSA *rsa = EVP_PKEY_get1_RSA(pkey);
    > EVP_PKEY_set1_RSA(pnew, rsa);
    > break;
    > case EVP_PKEY_DH:
    > DH *dh = EVP_PKEY_get1_DH(pkey);
    > EVP_PKEY_set1_DH(pnew, dh);
    > break;
    > case EVP_PKEY_EC:
    > EC_KEY *ec = EVP_PKEY_get1_EC(pkey);
    > EVP_PKEY_set1_EC(pnew, ec);
    > break;
    >
    > default:
    > fprintf(stderr, "unknown key type %.\n", pkey->type);
    > }
    >
    > return pnew;
    > }
    >
    > Thomas
    > __________________________________________________ ____________________
    > OpenSSL Project http://www.openssl.org
    > User Support Mailing List openssl-users@openssl.org
    > Automated List Manager majordomo@openssl.org
    >
    >

    Hello,

    this way doesn't work in my case (i think) :

    EVP_PKEY* to = cp_key(from);
    cout << EVP_PKEY_cmp_parameters(from, to);

    this code displays -1, so i think the duplication doesn't word.
    __________________________________________________ ____________________
    OpenSSL Project http://www.openssl.org
    User Support Mailing List openssl-users@openssl.org
    Automated List Manager majordomo@openssl.org


+ Reply to Thread