Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [[alloc] init] C++ Cryptography Suite
# [[alloc] init] C++ Cryptography Suite

[![Twitter](https://img.shields.io/twitter/follow/alloc_init_)](https://twitter.com/alloc_init_)
[![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=flat-square&logo=telegram&logoColor=dark)](https://t.me/alloc_init)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,9 @@ namespace nil {
}

template<typename FieldValueType>
typename std::enable_if<is_field<typename FieldValueType::field_type>::value &&
!is_extended_field<typename FieldValueType::field_type>::value,
element_edwards_g2>::type
operator*=(const FieldValueType &right) {
requires Field<typename FieldValueType::field_type> &&
(!ExtendedField<typename FieldValueType::field_type>)
element_edwards_g2 operator*=(const FieldValueType &right) {
return (*this) *= right.data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ namespace nil {
namespace detail {
// TODO: temporary implementation due to absence of GroupValueType type_trait
// Should be implemented as class method
template<typename GroupValueType, typename = typename std::enable_if<
is_curve_group<typename GroupValueType::group_type>::value &&
!is_field<typename GroupValueType::group_type>::value>::type>
template<typename GroupValueType, typename = typename std::enable_if<is_curve_group<
typename GroupValueType::group_type>::value>::type>
bool subgroup_check(const GroupValueType &p) {
return (p * GroupValueType::group_type::curve_type::q).is_zero();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
namespace nil::crypto3::marshalling::types::detail {
template<typename FieldValueType>
typename std::enable_if<
algebra::is_extended_field_element<FieldValueType>::value,
algebra::ExtendedFieldValue<FieldValueType>,
std::array<typename FieldValueType::field_type::integral_type, FieldValueType::field_type::arity>>::type
fill_field_data(const FieldValueType &field_elem);
}
Expand All @@ -52,7 +52,7 @@ namespace nil::crypto3::algebra::fields::detail {
typename T::base_field_type;
{ T::non_residue } -> std::convertible_to<typename T::base_field_type::value_type>;
{ T::dim_unity_root } -> std::convertible_to<typename T::base_field_type::value_type>;
} && is_field<typename T::base_field_type>::value;
} && Field<typename T::base_field_type>;

struct FieldArchetype;

Expand Down Expand Up @@ -92,12 +92,20 @@ namespace nil::crypto3::algebra::fields::detail {
constexpr self &operator+=(const self &) {
return *this;
}
constexpr self operator-(const self &) const {
return {};
}
constexpr bool is_zero() const {
return true;
}
constexpr bool is_one() const {
return true;
}
constexpr self inversed() const {
return *this;
}

template<std::integral PowerType>
constexpr self pow(const PowerType &) const {
constexpr self pow(const boost::multiprecision::cpp_int &) const {
return *this;
}
};
Expand Down Expand Up @@ -347,6 +355,10 @@ namespace nil::crypto3::algebra::fields::detail {
return power(*this, pwr);
}

constexpr element_fpn pow(const boost::multiprecision::cpp_int &pwr) const {
return power(*this, pwr);
}

constexpr element_fpn inversed() const {
auto f = one();
for (std::size_t i = 1; i < dimension; ++i) {
Expand Down Expand Up @@ -401,7 +413,7 @@ namespace nil::crypto3::algebra::fields::detail {

template<typename FieldValueType>
friend typename std::enable_if<
algebra::is_extended_field_element<FieldValueType>::value,
algebra::ExtendedFieldValue<FieldValueType>,
std::array<typename FieldValueType::field_type::integral_type, FieldValueType::field_type::arity>>::type
nil::crypto3::marshalling::types::detail::fill_field_data(const FieldValueType &field_elem);
};
Expand Down Expand Up @@ -432,8 +444,8 @@ namespace nil::crypto3::algebra::fields::detail {
return element_fpn_details::one_instance<Params>;
}

static_assert(is_field_element<element_fpn<BinomialFieldExtensionParamsArchetype>>::value);
static_assert(is_extended_field_element<element_fpn<BinomialFieldExtensionParamsArchetype>>::value);
static_assert(FieldValue<element_fpn<BinomialFieldExtensionParamsArchetype>>);
static_assert(ExtendedFieldValue<element_fpn<BinomialFieldExtensionParamsArchetype>>);
} // namespace nil::crypto3::algebra::fields::detail

template<nil::crypto3::algebra::fields::detail::BinomialFieldExtensionParams Params>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,66 +33,66 @@ namespace nil {
namespace algebra {
namespace fields {
namespace detail {
template<
typename FieldElement, typename Integral,
typename = typename std::enable_if<is_field_element<FieldElement>::value &&
std::is_constructible<FieldElement, Integral>::value>::type>
template<typename FieldElement, typename Integral>
requires(!std::same_as<std::remove_cvref_t<Integral>, FieldElement> &&
requires { typename FieldElement::field_type; } &&
std::constructible_from<FieldElement, Integral>)
constexpr FieldElement operator+(const FieldElement &A, Integral B) {
return A + FieldElement(B);
}

template<
typename FieldElement, typename Integral,
typename = typename std::enable_if<is_field_element<FieldElement>::value &&
std::is_constructible<FieldElement, Integral>::value>::type>
template<typename FieldElement, typename Integral>
requires(!std::same_as<std::remove_cvref_t<Integral>, FieldElement> &&
requires { typename FieldElement::field_type; } &&
std::constructible_from<FieldElement, Integral>)
constexpr FieldElement operator-(const FieldElement &A, Integral B) {
return A - FieldElement(B);
}

template<
typename FieldElement, typename Integral,
typename = typename std::enable_if<is_field_element<FieldElement>::value &&
std::is_constructible<FieldElement, Integral>::value>::type>
template<typename FieldElement, typename Integral>
requires(!std::same_as<std::remove_cvref_t<Integral>, FieldElement> &&
requires { typename FieldElement::field_type; } &&
std::constructible_from<FieldElement, Integral>)
constexpr FieldElement operator*(const FieldElement &A, Integral B) {
return A * FieldElement(B);
}

template<
typename FieldElement, typename Integral,
typename = typename std::enable_if<is_field_element<FieldElement>::value &&
std::is_constructible<FieldElement, Integral>::value>::type>
template<typename FieldElement, typename Integral>
requires(!std::same_as<std::remove_cvref_t<Integral>, FieldElement> &&
requires { typename FieldElement::field_type; } &&
std::constructible_from<FieldElement, Integral>)
constexpr FieldElement operator/(const FieldElement &A, Integral B) {
return A / FieldElement(B);
}

template<
typename FieldElement, typename Integral,
typename = typename std::enable_if<is_field_element<FieldElement>::value &&
std::is_constructible<FieldElement, Integral>::value>::type>
template<typename FieldElement, typename Integral>
requires(!std::same_as<std::remove_cvref_t<Integral>, FieldElement> &&
requires { typename FieldElement::field_type; } &&
std::constructible_from<FieldElement, Integral>)
constexpr FieldElement operator+(Integral A, const FieldElement &B) {
return FieldElement(A) + B;
}

template<
typename FieldElement, typename Integral,
typename = typename std::enable_if<is_field_element<FieldElement>::value &&
std::is_constructible<FieldElement, Integral>::value>::type>
template<typename FieldElement, typename Integral>
requires(!std::same_as<std::remove_cvref_t<Integral>, FieldElement> &&
requires { typename FieldElement::field_type; } &&
std::constructible_from<FieldElement, Integral>)
constexpr FieldElement operator-(Integral A, const FieldElement &B) {
return FieldElement(A) - B;
}

template<
typename FieldElement, typename Integral,
typename = typename std::enable_if<is_field_element<FieldElement>::value &&
std::is_constructible<FieldElement, Integral>::value>::type>
template<typename FieldElement, typename Integral>
requires(!std::same_as<std::remove_cvref_t<Integral>, FieldElement> &&
requires { typename FieldElement::field_type; } &&
std::constructible_from<FieldElement, Integral>)
constexpr FieldElement operator*(Integral A, const FieldElement &B) {
return FieldElement(A) * B;
}

template<
typename FieldElement, typename Integral,
typename = typename std::enable_if<is_field_element<FieldElement>::value &&
std::is_constructible<FieldElement, Integral>::value>::type>
template<typename FieldElement, typename Integral>
requires(!std::same_as<std::remove_cvref_t<Integral>, FieldElement> &&
requires { typename FieldElement::field_type; } &&
std::constructible_from<FieldElement, Integral>)
constexpr FieldElement operator/(Integral A, const FieldElement &B) {
return FieldElement(A) / B;
}
Expand Down
16 changes: 8 additions & 8 deletions libs/algebra/include/nil/crypto3/algebra/marshalling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace nil {

template<typename InputFieldValueIterator>
static inline typename std::enable_if<
!algebra::is_extended_field<field_type>::value &&
!algebra::ExtendedField<field_type> &&
std::is_same<chunk_type,
typename std::iterator_traits<InputFieldValueIterator>::value_type>::value,
std::pair<bool, field_value_type>>::type
Expand All @@ -74,7 +74,7 @@ namespace nil {

template<typename InputFieldValueIterator>
static inline typename std::enable_if<
algebra::is_extended_field<field_type>::value &&
algebra::ExtendedField<field_type> &&
std::is_same<chunk_type,
typename std::iterator_traits<InputFieldValueIterator>::value_type>::value,
std::pair<bool, field_value_type>>::type
Expand All @@ -98,7 +98,7 @@ namespace nil {

template<typename OutputIterator>
static inline typename std::enable_if<
!algebra::is_extended_field<field_type>::value &&
!algebra::ExtendedField<field_type> &&
std::is_same<chunk_type, typename std::iterator_traits<OutputIterator>::value_type>::value,
size_t>::type
field_element_to_bytes(const field_value_type &element, OutputIterator out_first,
Expand All @@ -114,7 +114,7 @@ namespace nil {

template<typename OutputIterator>
static inline typename std::enable_if<
algebra::is_extended_field<field_type>::value &&
algebra::ExtendedField<field_type> &&
std::is_same<chunk_type, typename std::iterator_traits<OutputIterator>::value_type>::value,
size_t>::type
field_element_to_bytes(const field_value_type &element, OutputIterator out_first,
Expand Down Expand Up @@ -194,7 +194,7 @@ namespace nil {

template<typename FieldType, typename InputFieldValueIterator>
static inline typename std::enable_if<
!algebra::is_extended_field<FieldType>::value &&
!algebra::ExtendedField<FieldType> &&
std::is_same<chunk_type,
typename std::iterator_traits<InputFieldValueIterator>::value_type>::value &&
(std::is_same<fp_type, FieldType>::value || std::is_same<fr_type, FieldType>::value),
Expand All @@ -205,7 +205,7 @@ namespace nil {

template<typename FieldType, typename InputFieldValueIterator>
static inline typename std::enable_if<
algebra::is_extended_field<FieldType>::value &&
algebra::ExtendedField<FieldType> &&
std::is_same<chunk_type,
typename std::iterator_traits<InputFieldValueIterator>::value_type>::value,
std::pair<bool, typename FieldType::value_type>>::type
Expand Down Expand Up @@ -249,7 +249,7 @@ namespace nil {

template<typename FieldType, typename OutputIterator>
static inline typename std::enable_if<
!algebra::is_extended_field<FieldType>::value &&
!algebra::ExtendedField<FieldType> &&
(std::is_same<fp_type, FieldType>::value || std::is_same<fr_type, FieldType>::value) &&
std::is_same<chunk_type, typename std::iterator_traits<OutputIterator>::value_type>::value,
size_t>::type
Expand All @@ -260,7 +260,7 @@ namespace nil {

template<typename FieldType, typename OutputIterator>
static inline typename std::enable_if<
algebra::is_extended_field<FieldType>::value &&
algebra::ExtendedField<FieldType> &&
std::is_same<chunk_type, typename std::iterator_traits<OutputIterator>::value_type>::value,
size_t>::type
field_element_to_bytes(const typename FieldType::value_type &element, OutputIterator out_first,
Expand Down
8 changes: 4 additions & 4 deletions libs/algebra/include/nil/crypto3/algebra/random_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ namespace nil {
typename FieldType,
typename DistributionType = boost::random::uniform_int_distribution<typename FieldType::integral_type>,
typename UniformRandomBitGenerator = boost::random::random_device>
typename std::enable_if<is_field<FieldType>::value && !(is_extended_field<FieldType>::value),
typename FieldType::value_type>::type
requires Field<FieldType> && (!ExtendedField<FieldType>)
typename FieldType::value_type
random_element(UniformRandomBitGenerator &&rng = UniformRandomBitGenerator()) {

using field_type = FieldType;
Expand All @@ -75,8 +75,8 @@ namespace nil {
typename FieldType,
typename DistributionType = boost::random::uniform_int_distribution<typename FieldType::integral_type>,
typename UniformRandomBitGenerator = boost::random::random_device>
typename std::enable_if<is_field<FieldType>::value && is_extended_field<FieldType>::value,
typename FieldType::value_type>::type
requires Field<FieldType> && ExtendedField<FieldType>
typename FieldType::value_type
random_element(UniformRandomBitGenerator &&rng = UniformRandomBitGenerator()) {

using field_type = FieldType;
Expand Down
Loading
Loading