簡體   English   中英

具有EVP_PKEY的OpenSSL RSA_size

[英]OpenSSL RSA_size with EVP_PKEY

我對RSA_size有疑問。

在WIN32上崩潰但在Linux平台上可以運行的版本:

  ... 
  EVP_PKEY* pPublicKey = null;
  unsigned int uKeySize = 0;
  const unsigned char *pData;
  pData = a_publicKey->Key.Data; /* Key.Data = unsigned char *p containing the Key in a string version */
  pPublicKey = d2i_PublicKey(EVP_PKEY_RSA, null, &pData, a_publicKey->Key.Length);
  if(pPublicKey != null)
  {
    uKeySize = RSA_size(pPublicKey->pkey.rsa); //Crash
  }
  ...

可以在win32上運行的版本(未經Linux測試,但我想它也可以正常運行):

  ... 
  EVP_PKEY* pPublicKey = null;
  RSA* pRsaPublicKey = null;
  unsigned int uKeySize = 0;
  const unsigned char *pData;
  pData = a_publicKey->Key.Data; /* Key.Data = unsigned char *p containing the Key in a string version */
  pPublicKey = d2i_PublicKey(EVP_PKEY_RSA, null, &pData, a_publicKey->Key.Length);
  if(pPublicKey != null)
  {
    pRsaPublicKey = EVP_PKEY_get1_RSA(pPublicKey);
    EVP_PKEY_free(pPublicKey);
    uKeySize = RSA_size(pRsaPublicKey);
  }
  ...

我不明白為什么第一個版本會崩潰。 但是,當我查看pkey.rsa結構時,其值與第二版RSA指針中的值不同。 有任何想法嗎 ?

我查看了EVP_PKEY結構,似乎WIN32和linux版本是不同的...所以我想我正在為WIN32使用一個非常老的版本。

WIN32版本:

struct evp_pkey_st
    {
    int type;
    int save_type;
    int references;
    union   {
        char *ptr;
#ifndef OPENSSL_NO_RSA
        struct rsa_st *rsa; /* RSA */
#endif
#ifndef OPENSSL_NO_DSA
        struct dsa_st *dsa; /* DSA */
#endif
#ifndef OPENSSL_NO_DH
        struct dh_st *dh;   /* DH */
#endif
#ifndef OPENSSL_NO_EC
        struct ec_key_st *ec;   /* ECC */
#endif
        } pkey;
    int save_parameters;
    STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
    } /* EVP_PKEY */;

linux的:

struct evp_pkey_st
    {
    int type;
    int save_type;
    int references;
    const EVP_PKEY_ASN1_METHOD *ameth;
    ENGINE *engine;
    union   {
        char *ptr;
#ifndef OPENSSL_NO_RSA
        struct rsa_st *rsa; /* RSA */
#endif
#ifndef OPENSSL_NO_DSA
        struct dsa_st *dsa; /* DSA */
#endif
#ifndef OPENSSL_NO_DH
        struct dh_st *dh;   /* DH */
#endif
#ifndef OPENSSL_NO_EC
        struct ec_key_st *ec;   /* ECC */
#endif
        } pkey;
    int save_parameters;
    STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
    } /* EVP_PKEY */;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM