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

int pcrypt_crypt_parse_anspubkey ( const char *  string,
ipmsg_cap_t peer_cap,
unsigned char **  crypt_e,
unsigned char **  crypt_n 
)

IPMSG_ANSPUBKEYパケットの解析を行う

Parameters:
[in] string IPMSG_ANSPUBKEYパケット(拡張部)を記録した文字列
[out] peer_cap ピアの暗号化能力格納先アドレスを示す ポインタ変数のアドレス
[out] crypt_e ピアの暗号化指数(hex形式)格納先アドレスを示す ポインタ変数のアドレス(複製を返却, 呼び出し元で要開放)
[out] crypt_n ピアの公開モジューロ(hex形式)格納先アドレスを示す ポインタ変数のアドレス(複製を返却, 呼び出し元で要開放)
Return values:
0 正常終了
-EINVAL 引数異常(不正な暗号化能力IDを指定した).
-ENOMEM メモリ不足

Definition at line 941 of file pubcrypt.c.

Referenced by ipmsg_proc_anspubkey().

                                                      {
      char       *val_e = NULL;
      char       *val_n = NULL;
      char          *sp = NULL;
      char          *ep = NULL;
      char      *buffer = NULL;
      char         *hex = NULL;
      ssize_t   remains = 0;
      ipmsg_cap_t   cap = 0;
      size_t        len = 0;
      int            rc = 0;

      if  ( (string == NULL) || (peer_cap == NULL) || 
          (crypt_e == NULL)  || (crypt_n == NULL) )
            return -EINVAL;
  
      buffer = g_strdup(string);
      if (buffer == NULL)
            return -ENOMEM;

      len = strlen(string);
      remains = len;

      /*
       * 暗号化能力
       */
      sp = buffer;
      ep = memchr(sp, ':', remains);
      if (ep == NULL) {
            rc = -EINVAL;
            goto error_out;
      }

      *ep = '\0';
      remains = len - ( (unsigned long)ep - (unsigned long)buffer );
      if (remains <= 0) {
            rc = -EINVAL;
            goto error_out;
      }
      ++ep;
      cap = (ipmsg_cap_t)strtol(sp, (char **)NULL, 16);
      dbg_out("parsed capability:%x\n",cap);
      sp = ep;

      /*
       * 公開指数
       */
      ep = memchr(sp, '-', remains);
      if (ep == NULL) {
            rc = -EINVAL;
            goto error_out;
      }
      *ep = '\0';
      remains = len - ( (unsigned long)ep - (unsigned long)buffer );
      if (remains <= 0) {
            rc = -EINVAL;
            goto error_out;
      }
      ++ep;
      dbg_out("parsed public exponential:%s\n", sp);

      val_e = g_strdup(sp);
      if (val_e == NULL) {
            rc = -ENOMEM;
            goto error_out;
      }
      sp=ep;


      /*
       *公開モジューロ(法)
       */
      dbg_out("parsed public modulo:%s\n", sp);
      val_n = g_strdup(sp);
      if (val_n == NULL) {
            rc = -ENOMEM;
            dbg_out("Error code:%d\n", rc);
            goto error_out;
      }

      /*
       *返却
       */
      *peer_cap = cap;
      *crypt_e = val_e;
      *crypt_n = val_n;
      rc = 0;

error_out:
      if (buffer != NULL)
            g_free(buffer);

      return rc;
}


Generated by  Doxygen 1.6.0   Back to index