Beispiel #1
0
TEST(ec, Sign)
{
  static constexpr std::array<u8, 20> HASH{{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9,
                                            0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9}};
  const std::array<u8, 60> sig = Common::ec::Sign(PRIVATE_KEY.data(), HASH.data());
  // r and s must be non-null.
  EXPECT_FALSE(std::all_of(sig.cbegin(), sig.cbegin() + 30, [](u8 b) { return b == 0; }));
  EXPECT_FALSE(std::all_of(sig.cbegin() + 30, sig.cend(), [](u8 b) { return b == 0; }));
}
Beispiel #2
0
CertReader::CertReader(std::vector<u8>&& bytes) : SignedBlobReader(std::move(bytes))
{
  if (!IsSignatureValid())
    return;

  // XXX: in old GCC versions, capturing 'this' does not work for some lambdas. The workaround
  // is to not use auto for the parameter (even though the type is obvious).
  // This can be dropped once we require GCC 7.
  using CertStructInfo = std::tuple<SignatureType, PublicKeyType, size_t>;
  static constexpr std::array<CertStructInfo, 4> types{{
      {SignatureType::RSA4096, PublicKeyType::RSA2048, sizeof(CertRSA4096RSA2048)},
      {SignatureType::RSA2048, PublicKeyType::RSA2048, sizeof(CertRSA2048RSA2048)},
      {SignatureType::RSA2048, PublicKeyType::ECC, sizeof(CertRSA2048ECC)},
      {SignatureType::ECC, PublicKeyType::ECC, sizeof(CertECC)},
  }};

  const auto info = std::find_if(types.cbegin(), types.cend(), [this](const CertStructInfo& entry) {
    return m_bytes.size() >= std::get<2>(entry) && std::get<0>(entry) == GetSignatureType() &&
           std::get<1>(entry) == GetPublicKeyType();
  });

  if (info == types.cend())
    return;

  m_bytes.resize(std::get<2>(*info));
  m_is_valid = true;
}
Beispiel #3
0
 void print_positions(const std::array<position_t, N>& positions)
 {
    std::for_each(positions.cbegin(), positions.cend(), [](const position_t& pos)
          {
             std::cout << '(' << pos.first << ", " << pos.second << ')' << std::endl;
          });
 }
void FIRC16xR16x32Decim8::configure(
	const std::array<tap_t, taps_count>& taps,
	const int32_t scale
) {
	std::copy(taps.cbegin(), taps.cend(), taps_.begin());
	output_scale = scale;
	z_.fill({});
}
Beispiel #5
0
 void print_graph(const std::array<std::vector<char>, N>& graph)
 {
    int position = 0;
    std::for_each(graph.cbegin(), graph.cend(), [&](const std::vector<char>& vec)
          {
             std::cout << position++ << ": ";
             print_vec(vec);
          });
 }
Beispiel #6
0
std::string CArchiveScanner::ArchiveData::GetKeyDescription(const std::string& keyLower)
{
	const auto pred = [&keyLower](const KnownInfoTag& t) { return (t.name == keyLower); };
	const auto iter = std::find_if(knownTags.cbegin(), knownTags.cend(), pred);

	if (iter != knownTags.cend())
		return (iter->desc);

	return "<custom property>";
}
bool BinaryDependenciesLdd::isLibraryNotInExcludeList(const PlainText::StringRecord & record)
{
  Q_ASSERT(record.columnCount() > 0);

  const auto cmp = [record](const char * const excludeName){
    LibraryName libName(record.data(0));
    return ( QString::compare( libName.name(), QLatin1String(excludeName), Qt::CaseSensitive ) == 0);
  };
  const auto it = std::find_if( LibrayExcludeListLinux.cbegin(), LibrayExcludeListLinux.cend(), cmp );
  return (it == LibrayExcludeListLinux.cend());
}
Beispiel #8
0
bool CArchiveScanner::ArchiveData::IsValid(std::string& err) const
{
	const auto pred = [this](const KnownInfoTag& t) { return (t.required && info.find(t.name) == info.end()); };
	const auto iter = std::find_if(knownTags.cbegin(), knownTags.cend(), pred);

	if (iter == knownTags.cend())
		return true;

	err = "Missing tag \"" + iter->name + "\".";
	return false;
}
Beispiel #9
0
typename std::enable_if<	
	(std::is_integral<T>::value && std::is_floating_point<U>::value && sizeof(T) < sizeof(U)) ||
	(std::is_floating_point<T>::value && std::is_floating_point<U>::value &&
	sizeof(T) <= sizeof(U)) ||
	(std::is_integral<T>::value && std::is_integral<U>::value &&
	((std::is_unsigned<T>::value && std::is_unsigned<U>::value) ||
	(std::is_signed<T>::value && std::is_signed<U>::value)) &&
	sizeof(T) <= sizeof(U)), void>::type
Copy(const std::array<T, N> &src, std::array<U, N> &dst)
{
	std::copy(src.cbegin(), src.cend(), dst.begin());
}
Beispiel #10
0
typename std::enable_if<
	std::is_floating_point<T>::value, void>::type
round_to(const std::array<T, N> &src, std::array<U, N> &dst)
{
	auto it_src = src.cbegin();
	auto it_dst_end = dst.end();	
	for (auto it_dst = dst.begin(); it_dst != it_dst_end; ++it_src, ++it_dst)
#if _MSC_VER > 1700		// from VS2013
		*it_dst = static_cast<U>(std::round(*it_src));
#else					// up to VS2013
		if (*it_src >= 0)
			SafeCast(std::floor(*it_src + 0.5), *it_dst);
		else
			SafeCast(std::ceil(*it_src - 0.5), *it_dst);
#endif
}
	void SetUp() override
	{
		m_nodeIds[0] = 3;
		m_nodeIds[1] = 1;
		m_nodeIds[2] = 14;
		m_nodeIds[3] = 9;
		m_nodeIdsAsVector.assign(m_nodeIds.cbegin(), m_nodeIds.cend());

		m_restState.setNumDof(3, 15);
		m_invalidState.setNumDof(3, 15);
		Vector& x0 = m_restState.getPositions();
		Vector& invalidx0 = m_invalidState.getPositions();
		std::array<Vector3d, 4> points = {{
				Vector3d(0.0, 0.0, 0.0), Vector3d(1.0, 0.0, 0.0),
				Vector3d(0.0, 1.0, 0.0), Vector3d(0.0, 0.0, 1.0)
			}
		};

		// Tet is aligned with the axis (X,Y,Z), centered on (0.0, 0.0, 0.0), embedded in a cube of size 1
		for (size_t nodeId = 0; nodeId < 4; ++nodeId)
		{
			SurgSim::Math::getSubVector(x0, m_nodeIds[nodeId], 3) = points[nodeId];
			SurgSim::Math::getSubVector(invalidx0, m_nodeIds[nodeId], 3) = points[nodeId];
		}
		// In the invalid state, the tetrahedron is degenerated to a triangle (last 2 points are equal)
		SurgSim::Math::getSubVector(invalidx0, m_nodeIds[3], 3) = points[2];

		m_rho = 1000.0;
		m_E = 1e6;
		m_nu = 0.45;

		Vector3d axis(1.0, 0.2, -0.3);
		axis.normalize();
		m_rotation = SurgSim::Math::makeRotationMatrix(4.1415, axis);
		m_R12x12 = Eigen::Matrix<double, 12, 12>::Zero();
		for (size_t nodeId = 0; nodeId < 4; ++nodeId)
		{
			m_R12x12.block<3, 3>(3 * nodeId, 3 * nodeId) = m_rotation;
		}
		m_translation = Vector3d(1.2, 2.3, 3.4);
	}
Beispiel #12
0
void app::benchmark::task_func()
{
  #if(APP_BENCHMARK_TYPE == APP_BENCHMARK_TYPE_CRC32)

    const std::array<std::uint8_t, 9U> data =
    {{
      0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U, 0x38U, 0x39U
    }};

    typedef mcal::benchmark::benchmark_port_type port_type;

    mcal::irq::disable_all();
    port_type::set_pin_high();

    app_benchmark_crc = math::checksums::crc32_mpeg2(data.cbegin(),
                                                     data.cend());

    port_type::set_pin_low();
    mcal::irq::enable_all();

    if(app_benchmark_crc == UINT32_C(0x0376E6E7))
    {
      // The benchmark is OK.
      // Perform one nop and leave.

      mcal::cpu::nop();
    }
    else
    {
      // The benchmark result is not OK!
      // Remain in a blocking loop and crash the system.

      for(;;) { mcal::cpu::nop(); }
    }

  #endif // APP_BENCHMARK_TYPE == APP_BENCHMARK_TYPE_CRC32
}
void FIR64AndDecimateBy2Real::configure(
	const std::array<int16_t, taps_count>& new_taps
) {
	std::copy(new_taps.cbegin(), new_taps.cend(), taps.begin());
}