コード例 #1
0
/** Compute Tor SAFECOOKIE response.
 *
 *    ServerHash is computed as:
 *      HMAC-SHA256("Tor safe cookie authentication server-to-controller hash",
 *                  CookieString | ClientNonce | ServerNonce)
 *    (with the HMAC key as its first argument)
 *
 *    After a controller sends a successful AUTHCHALLENGE command, the
 *    next command sent on the connection must be an AUTHENTICATE command,
 *    and the only authentication string which that AUTHENTICATE command
 *    will accept is:
 *
 *      HMAC-SHA256("Tor safe cookie authentication controller-to-server hash",
 *                  CookieString | ClientNonce | ServerNonce)
 *
 */
static std::vector<uint8_t> ComputeResponse(const std::string &key, const std::vector<uint8_t> &cookie,  const std::vector<uint8_t> &clientNonce, const std::vector<uint8_t> &serverNonce)
{
    CHMAC_SHA256 computeHash((const uint8_t*)key.data(), key.size());
    std::vector<uint8_t> computedHash(CHMAC_SHA256::OUTPUT_SIZE, 0);
    computeHash.Write(begin_ptr(cookie), cookie.size());
    computeHash.Write(begin_ptr(clientNonce), clientNonce.size());
    computeHash.Write(begin_ptr(serverNonce), serverNonce.size());
    computeHash.Finalize(begin_ptr(computedHash));
    return computedHash;
}
コード例 #2
0
ファイル: random.cpp プロジェクト: polopoints/polopoints
void RandAddSeedPerfmon()
{
    RandAddSeed();

#ifdef WIN32
    // Don't need this on Linux, OpenSSL automatically uses /dev/urandom
    // Seed with the entire set of perfmon data

    // This can take up to 2 seconds, so only do it every 10 minutes
    static int64_t nLastPerfmon;
    if (GetTime() < nLastPerfmon + 10 * 60)
        return;
    nLastPerfmon = GetTime();

    std::vector<unsigned char> vData(250000, 0);
    long ret = 0;
    unsigned long nSize = 0;
    const size_t nMaxSize = 10000000; // Bail out at more than 10MB of performance data
    while (true) {
        nSize = vData.size();
        ret = RegQueryValueExA(HKEY_PERFORMANCE_DATA, "Global", NULL, NULL, begin_ptr(vData), &nSize);
        if (ret != ERROR_MORE_DATA || vData.size() >= nMaxSize)
            break;
        vData.resize(std::max((vData.size() * 3) / 2, nMaxSize)); // Grow size of buffer exponentially
    }
    RegCloseKey(HKEY_PERFORMANCE_DATA);
    if (ret == ERROR_SUCCESS) {
        RAND_add(begin_ptr(vData), nSize, nSize / 100.0);
        memory_cleanse(begin_ptr(vData), nSize);
        LogPrint("rand", "%s: %lu bytes\n", __func__, nSize);
    } else {
        static bool warned = false; // Warn only once
        if (!warned) {
            LogPrint("INFO", "%s: Warning: RegQueryValueExA(HKEY_PERFORMANCE_DATA) failed with code %i\n", __func__, ret);
            warned = true;
        }
    }
#endif
}
コード例 #3
0
/* --- tracksをレンダリングする --------------------------------------*/
void igs::maxmin::slrender::render(
    const double radius, const double smooth_outer_range,
    const int polygon_number, const double roll_degree

    ,
    const bool min_sw

    ,
    std::vector<int> &lens_offsets, std::vector<int> &lens_sizes,
    std::vector<std::vector<double>> &lens_ratio

    ,
    const std::vector<std::vector<double>> &tracks /* RGBのどれか */
    ,
    const std::vector<double> &alpha_ref /* alpha値で影響度合を決める */
    ,
    std::vector<double> &result /* 計算結果 */
    ) {
  /* 初期位置 */
  std::vector<const double *> begin_ptr(lens_offsets.size());
  set_begin_ptr_(tracks, lens_offsets, 0, begin_ptr);

  /* 効果半径に変化がある場合 */
  if (0 < alpha_ref.size()) {
    double before_radius = 0.0;
    for (unsigned xx = 0; xx < result.size(); ++xx) {
      /* 次の処理の半径 */
      const double radius2 = alpha_ref.at(xx) * radius;

      /* ゼロ以上なら処理する */
      if (0.0 < alpha_ref.at(xx)) {
        /* 前のPixelと違う大きさならreshapeする */
        if (radius2 != before_radius) {
          igs::maxmin::reshape_lens_matrix(
              radius2, igs::maxmin::outer_radius_from_radius(
                           radius2, smooth_outer_range),
              igs::maxmin::diameter_from_outer_radius(radius +
                                                      smooth_outer_range),
              polygon_number, roll_degree, lens_offsets, lens_sizes,
              lens_ratio);
          set_begin_ptr_(tracks, lens_offsets, xx, begin_ptr);
        }
        /* 各ピクセルの処理 */
        result.at(xx) =
            maxmin_(result.at(xx), min_sw, begin_ptr, lens_sizes, lens_ratio);
      } /* alpha_refがゼロなら変化なし */

      /* 次の位置へ移動 */
      for (unsigned ii = 0; ii < begin_ptr.size(); ++ii) {
        if (begin_ptr.at(ii) != 0) {
          ++begin_ptr.at(ii);
        }
      }
      if (radius2 != before_radius) {
        before_radius = radius2;
      }
    }
  }
  /* 効果半径が変わらない場合 */
  else {
    for (unsigned xx = 0; xx < result.size(); ++xx) {
      /* 各ピクセルの処理 */
      result.at(xx) =
          maxmin_(result.at(xx), min_sw, begin_ptr, lens_sizes, lens_ratio);

      /* 次の位置へ移動 */
      for (unsigned ii = 0; ii < begin_ptr.size(); ++ii) {
        if (begin_ptr.at(ii) != 0) {
          ++begin_ptr.at(ii);
        }
      }
    }
  }
}