Logo Search packages:      
Sourcecode: g2ipmsg version File versions  Download package

int pcrypt_get_key_filename ( const ipmsg_cap_t  key_type,
char **  pubkey,
char **  privkey 
)

IPMSGの公開鍵暗号化能力IDから鍵情報格納先ファイル名を割り出す.

Parameters:
[in] key_type IPMSGの公開鍵暗号化能力ID
[out] pubkey 公開鍵格納ファイル
[out] privkey 秘密鍵格納ファイル
Return values:
0 正常終了
-EINVAL 引数異常 (msg_str, sign, peer_e, peer_nの いずれかがNULL).
-ENOMEM メモリ不足

Definition at line 1873 of file pubcrypt.c.

References pcrypt_get_rsa_key_length().

Referenced by pcrypt_load_rsa_key(), and pcrypt_store_rsa_key().

                                                                                   {
      int                    rc = 0;
      size_t            key_len = 0;
      size_t      key_fname_len = 0;
      RSA                  *rsa = NULL;
      size_t key_priv_fname_len = 0;
      size_t  key_pub_fname_len = 0;
      char        *pub_key_file = NULL;
      char       *priv_key_file = NULL;
      int                     j = 0;

  
      if ( (pubkey == NULL) || (privkey == NULL) )
            return -EINVAL;

      rc = pcrypt_get_rsa_key_length(key_type, &key_len);
      if (rc != 0)
            return rc;

      dbg_out("Key bits:%d\n", key_len);

      /* キー長をbit長で表した値の桁数を算出  */
      for(j = key_len, key_fname_len = 1;j != 0;j /= 10, ++key_fname_len);

      /* +1 は, 末尾のヌルターミネート分 */
      key_priv_fname_len = strlen(RSA_PRIVKEY_FNAME_PREFIX) + key_fname_len + 1;
      priv_key_file = g_malloc(key_priv_fname_len);
      if (priv_key_file == NULL)
            return -EINVAL;

      key_pub_fname_len = strlen(RSA_PUBKEY_FNAME_PREFIX) + key_fname_len + 1;
      pub_key_file = g_malloc(key_pub_fname_len);
      if (pub_key_file == NULL)
            goto priv_key_file_free_out;

      snprintf(priv_key_file,key_priv_fname_len - 1, "%s%d", 
          RSA_PRIVKEY_FNAME_PREFIX, key_len);

      snprintf(pub_key_file, key_pub_fname_len - 1, "%s%d", 
          RSA_PUBKEY_FNAME_PREFIX, key_len);

      dbg_out("Public key files are Private-key:%s Public-key:%s\n",
          priv_key_file, pub_key_file);
  
      *pubkey  = pub_key_file;
      *privkey = priv_key_file;

      return 0;

pub_key_file_free_out:
      if (pub_key_file != NULL)
            g_free(pub_key_file);

priv_key_file_free_out:
      if (priv_key_file != NULL)
            g_free(priv_key_file);

      return rc;
}


Generated by  Doxygen 1.6.0   Back to index