diff --git a/README.md b/README.md index 186c2aa9a..8704f4b19 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/detail/scalar_mul.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/detail/scalar_mul.hpp index 6d7cb3ed3..89d8c4148 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/detail/scalar_mul.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/detail/scalar_mul.hpp @@ -112,23 +112,20 @@ namespace nil { return res; } - template - std::enable_if_t::value, CurveElementType> constexpr - operator*(const CurveElementType &point, const std::size_t &multiplier) { + template + constexpr CurveElementType operator*(const CurveElementType &point, const std::size_t &multiplier) { typename CurveElementType::params_type::scalar_field_type::value_type scalar(multiplier); return point * scalar; } - template - std::enable_if_t::value, CurveElementType> constexpr - operator*(const std::size_t &multiplier, const CurveElementType &point) { + template + constexpr CurveElementType operator*(const std::size_t &multiplier, const CurveElementType &point) { typename CurveElementType::params_type::scalar_field_type::value_type scalar(multiplier); return point * scalar; } - template - std::enable_if_t::value, bool> - subgroup_check(CurveElementType point) { + template + bool subgroup_check(CurveElementType point) { auto scalar_modulus = CurveElementType::group_type::curve_type::scalar_field_type::modulus; scalar_mul_inplace(point, scalar_modulus); return point.is_zero(); diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/detail/subgroup_check.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/detail/subgroup_check.hpp index f0347d7ad..fec8f1c54 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/detail/subgroup_check.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/detail/subgroup_check.hpp @@ -33,10 +33,8 @@ namespace nil { namespace algebra { namespace curves { namespace detail { - // TODO: temporary implementation due to absence of GroupValueType type_trait - // Should be implemented as class method - template::value>::type> + template + requires CurveGroup bool subgroup_check(const GroupValueType &p) { return (p * GroupValueType::group_type::curve_type::q).is_zero(); } diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/arithmetic_params/goldilocks64.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/arithmetic_params/goldilocks64.hpp deleted file mode 100644 index 991a753f3..000000000 --- a/libs/algebra/include/nil/crypto3/algebra/fields/arithmetic_params/goldilocks64.hpp +++ /dev/null @@ -1,71 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2024 Alexey Kokoshnikov -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -//---------------------------------------------------------------------------// - -#ifndef CRYPTO3_ALGEBRA_FIELDS_GOLDILOCKS64_ARITHMETIC_PARAMS_HPP -#define CRYPTO3_ALGEBRA_FIELDS_GOLDILOCKS64_ARITHMETIC_PARAMS_HPP - -#include - -#include - -namespace nil { - namespace crypto3 { - namespace algebra { - namespace fields { - - template<> - struct arithmetic_params : public params { - private: - typedef params policy_type; - - public: - typedef typename policy_type::modular_type modular_type; - typedef typename policy_type::integral_type integral_type; - - constexpr static const std::size_t s = 0x20; - constexpr static const integral_type arithmetic_generator = 0x01; - constexpr static const integral_type geometric_generator = 0x02; - constexpr static const integral_type multiplicative_generator = 0x07; - constexpr static const integral_type root_of_unity = 0x185629DCDA58878C_cppui_modular64; - }; - - constexpr std::size_t const arithmetic_params::s; - - constexpr typename arithmetic_params::integral_type const - arithmetic_params::root_of_unity; - - constexpr typename arithmetic_params::integral_type const - arithmetic_params::arithmetic_generator; - - constexpr typename arithmetic_params::integral_type const - arithmetic_params::geometric_generator; - - constexpr typename arithmetic_params::integral_type const - arithmetic_params::multiplicative_generator; - } // namespace fields - } // namespace algebra - } // namespace crypto3 -} // namespace nil - -#endif // CRYPTO3_ALGEBRA_FIELDS_GOLDILOCKS64_ARITHMETIC_PARAMS_HPP diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/arithmetic_params/m31.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/arithmetic_params/m31.hpp deleted file mode 100644 index 9f7da34c2..000000000 --- a/libs/algebra/include/nil/crypto3/algebra/fields/arithmetic_params/m31.hpp +++ /dev/null @@ -1,71 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2024 Alexey Kokoshnikov -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -//---------------------------------------------------------------------------// - -#ifndef CRYPTO3_ALGEBRA_FIELDS_M31_ARITHMETIC_PARAMS_HPP -#define CRYPTO3_ALGEBRA_FIELDS_M31_ARITHMETIC_PARAMS_HPP - -#include - -#include - -namespace nil { - namespace crypto3 { - namespace algebra { - namespace fields { - - template<> - struct arithmetic_params : public params { - private: - typedef params policy_type; - - public: - typedef typename policy_type::modular_type modular_type; - typedef typename policy_type::integral_type integral_type; - - constexpr static const std::size_t s = 0x20; - constexpr static const integral_type arithmetic_generator = 0x01; - constexpr static const integral_type geometric_generator = 0x02; - constexpr static const integral_type multiplicative_generator = 0x07; - constexpr static const integral_type root_of_unity = 0x185629DCDA58878C_cppui_modular64; - }; - - constexpr std::size_t const arithmetic_params::s; - - constexpr typename arithmetic_params::integral_type const - arithmetic_params::root_of_unity; - - constexpr typename arithmetic_params::integral_type const - arithmetic_params::arithmetic_generator; - - constexpr typename arithmetic_params::integral_type const - arithmetic_params::geometric_generator; - - constexpr typename arithmetic_params::integral_type const - arithmetic_params::multiplicative_generator; - } // namespace fields - } // namespace algebra - } // namespace crypto3 -} // namespace nil - -#endif // CRYPTO3_ALGEBRA_FIELDS_M31_ARITHMETIC_PARAMS_HPP diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/fpn.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/fpn.hpp index f77da3dd0..a9682db04 100644 --- a/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/fpn.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/fpn.hpp @@ -112,6 +112,8 @@ namespace nil::crypto3::algebra::fields::detail { struct FieldArchetype { using value_type = FieldValueArchetype; + struct extension_policy { }; + using underlying_field_type = FieldArchetype; constexpr static std::size_t value_bits = 10; struct integral_type { }; @@ -126,7 +128,7 @@ namespace nil::crypto3::algebra::fields::detail { struct BinomialFieldExtensionParamsArchetype { constexpr static std::size_t dimension = 3; - struct field_type { }; + using field_type = FieldArchetype; using base_field_type = FieldArchetype; constexpr static base_field_type::value_type non_residue {}; @@ -147,9 +149,9 @@ namespace nil::crypto3::algebra::fields::detail { using underlying_type = typename Params::base_field_type::value_type; constexpr static std::size_t dimension = Params::dimension; + using data_type = std::array; private: - using data_type = std::array; data_type data; public: diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/edwards/fp3.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/edwards/fp3.hpp index 7170047a9..bbcd1d53f 100644 --- a/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/edwards/fp3.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/edwards/fp3.hpp @@ -51,6 +51,7 @@ namespace nil { typedef params policy_type; public: + using field_type = fields::fp3; typedef typename policy_type::integral_type integral_type; typedef typename policy_type::extended_integral_type extended_integral_type; diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/edwards/fp6_2over3.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/edwards/fp6_2over3.hpp index f4ae39ae2..b0926bbfe 100644 --- a/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/edwards/fp6_2over3.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/edwards/fp6_2over3.hpp @@ -34,6 +34,9 @@ namespace nil { namespace crypto3 { namespace algebra { namespace fields { + template + class fp6_2over3; + namespace detail { template @@ -49,6 +52,7 @@ namespace nil { typedef params policy_type; public: + using field_type = fields::fp6_2over3; typedef typename policy_type::integral_type integral_type; constexpr static const integral_type modulus = policy_type::modulus; diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/mnt4/fp4.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/mnt4/fp4.hpp index bcdbc10a0..7d4d82e50 100644 --- a/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/mnt4/fp4.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/mnt4/fp4.hpp @@ -34,6 +34,9 @@ namespace nil { namespace crypto3 { namespace algebra { namespace fields { + template + class fp4; + namespace detail { template @@ -49,6 +52,7 @@ namespace nil { typedef params policy_type; public: + using field_type = fields::fp4; typedef typename policy_type::integral_type integral_type; constexpr static const integral_type modulus = policy_type::modulus; diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/mnt6/fp6_2over3.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/mnt6/fp6_2over3.hpp index b352b52b3..d4d835fea 100644 --- a/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/mnt6/fp6_2over3.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/fields/detail/extension_params/mnt6/fp6_2over3.hpp @@ -34,6 +34,9 @@ namespace nil { namespace crypto3 { namespace algebra { namespace fields { + template + class fp6_2over3; + namespace detail { template @@ -49,6 +52,7 @@ namespace nil { typedef params policy_type; public: + using field_type = fields::fp6_2over3; typedef typename policy_type::integral_type integral_type; constexpr static const integral_type modulus = policy_type::modulus; diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/fpn.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/fpn.hpp index 1ba2ced6c..d59a40d2d 100644 --- a/libs/algebra/include/nil/crypto3/algebra/fields/fpn.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/fields/fpn.hpp @@ -34,6 +34,9 @@ namespace nil::crypto3::algebra::fields { class fpn { public: using base_field_type = Params::base_field_type; + using policy_type = base_field_type; + using extension_policy = Params; + using underlying_field_type = base_field_type; constexpr static const std::size_t modulus_bits = base_field_type::modulus_bits; using integral_type = typename base_field_type::integral_type; @@ -45,9 +48,12 @@ namespace nil::crypto3::algebra::fields { using value_type = typename detail::element_fpn; - constexpr static const std::size_t arity = Params::dimension; + constexpr static const std::size_t extension_degree = Params::dimension; + constexpr static const std::size_t arity = extension_degree * underlying_field_type::arity; constexpr static const std::size_t value_bits = arity * modulus_bits; }; + + static_assert(ExtendedField>); } // namespace nil::crypto3::algebra::fields #endif // CRYPTO3_ALGEBRA_FIELDS_FPN_EXTENSION_HPP diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/goldilocks64/base_field.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/goldilocks64/base_field.hpp deleted file mode 100644 index ac0a7916e..000000000 --- a/libs/algebra/include/nil/crypto3/algebra/fields/goldilocks64/base_field.hpp +++ /dev/null @@ -1,93 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2024 Alexey Kokoshnikov -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -//---------------------------------------------------------------------------// - -#ifndef CRYPTO3_ALGEBRA_FIELDS_GOLDILOCKS64_BASE_FIELD_HPP -#define CRYPTO3_ALGEBRA_FIELDS_GOLDILOCKS64_BASE_FIELD_HPP - -#include - -#include -#include - -namespace nil { - namespace crypto3 { - namespace algebra { - namespace fields { - /** - * @brief A struct representing a goldilocks 64 bit field. - * https://polygon.technology/blog/plonky2-a-deep-dive#:~:text=Hamish%20Ivey%2DLaw.-,The%20Goldilocks%20Field%C2%A0,-p%20%3D%202%2064 - */ - class goldilocks64_base_field : public field<64> { - public: - typedef field<64> policy_type; - - using small_subfield = goldilocks64_base_field; - - constexpr static const std::size_t modulus_bits = policy_type::modulus_bits; - constexpr static const std::size_t number_bits = policy_type::number_bits; - constexpr static const std::size_t value_bits = modulus_bits; - constexpr static const std::size_t arity = 1; - - typedef typename policy_type::integral_type integral_type; - typedef typename policy_type::extended_integral_type extended_integral_type; -#ifdef __ZKLLVM__ - typedef __zkllvm_field_goldilocks64_base value_type; -#else - // 2^64 - 2^32 + 1 - constexpr static const integral_type modulus = 0xFFFFFFFF00000001_cppui_modular64; - constexpr static const integral_type group_order_minus_one_half = (modulus - 1u) / 2; - - typedef typename policy_type::modular_backend modular_backend; - constexpr static const modular_params_type modulus_params = modulus.backend(); - typedef boost::multiprecision::number>> - modular_type; - - typedef typename detail::element_fp> value_type; -#endif - }; - - constexpr typename std::size_t const goldilocks64_base_field::modulus_bits; - constexpr typename std::size_t const goldilocks64_base_field::number_bits; - constexpr typename std::size_t const goldilocks64_base_field::value_bits; - -#ifdef __ZKLLVM__ -#else - constexpr typename goldilocks64_base_field::integral_type const goldilocks64_base_field::modulus; - constexpr typename goldilocks64_base_field::integral_type const - goldilocks64_base_field::group_order_minus_one_half; - constexpr - typename goldilocks64_base_field::modular_params_type const goldilocks64_base_field::modulus_params; -#endif - using goldilocks64_fq = goldilocks64_base_field; - - using goldilocks64 = goldilocks64_base_field; - - } // namespace fields - } // namespace algebra - } // namespace crypto3 -} // namespace nil - -#endif // CRYPTO3_ALGEBRA_FIELDS_GOLDILOCKS64_BASE_FIELD_HPP diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/m31/base_field.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/m31/base_field.hpp deleted file mode 100644 index 29df001ae..000000000 --- a/libs/algebra/include/nil/crypto3/algebra/fields/m31/base_field.hpp +++ /dev/null @@ -1,87 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2024 Alexey Kokoshnikov -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -//---------------------------------------------------------------------------// - -#ifndef CRYPTO3_ALGEBRA_FIELDS_M31_BASE_FIELD_HPP -#define CRYPTO3_ALGEBRA_FIELDS_M31_BASE_FIELD_HPP - -#include - -#include -#include - -namespace nil { - namespace crypto3 { - namespace algebra { - namespace fields { - class m31_base_field : public field<32> { - public: - typedef field<32> policy_type; - - using small_subfield = m31_base_field; - - constexpr static const std::size_t modulus_bits = policy_type::modulus_bits; - constexpr static const std::size_t number_bits = policy_type::number_bits; - constexpr static const std::size_t value_bits = modulus_bits; - constexpr static const std::size_t arity = 1; - - typedef typename policy_type::integral_type integral_type; - typedef typename policy_type::extended_integral_type extended_integral_type; -#ifdef __ZKLLVM__ - typedef __zkllvm_field_m31_base value_type; -#else - // (1 << 31) - 1 - constexpr static const integral_type modulus = 0x7FFFFFFFF_cppui_modular32; - constexpr static const integral_type group_order_minus_one_half = (modulus - 1u) / 2; - - typedef typename policy_type::modular_backend modular_backend; - constexpr static const modular_params_type modulus_params = modulus.backend(); - typedef boost::multiprecision::number>> - modular_type; - - typedef typename detail::element_fp> value_type; -#endif - }; - - constexpr typename std::size_t const m31_base_field::modulus_bits; - constexpr typename std::size_t const m31_base_field::number_bits; - constexpr typename std::size_t const m31_base_field::value_bits; - -#ifdef __ZKLLVM__ -#else - constexpr typename m31_base_field::integral_type const m31_base_field::modulus; - constexpr typename m31_base_field::integral_type const m31_base_field::group_order_minus_one_half; - constexpr typename m31_base_field::modular_params_type const m31_base_field::modulus_params; -#endif - using m31_fq = m31_base_field; - - using m31 = m31_base_field; - - } // namespace fields - } // namespace algebra - } // namespace crypto3 -} // namespace nil - -#endif // CRYPTO3_ALGEBRA_FIELDS_M31_BASE_FIELD_HPP diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/sect/sect_k1/base_field.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/sect/sect_k1/base_field.hpp deleted file mode 100644 index fb3d13c6a..000000000 --- a/libs/algebra/include/nil/crypto3/algebra/fields/sect/sect_k1/base_field.hpp +++ /dev/null @@ -1,91 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2021 Mikhail Komarov -// Copyright (c) 2021 Ilias Khairullin -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -//---------------------------------------------------------------------------// - -#ifndef CRYPTO3_ALGEBRA_FIELDS_SECT_K1_BASE_FIELD_HPP -#define CRYPTO3_ALGEBRA_FIELDS_SECT_K1_BASE_FIELD_HPP - -#include - -#include -#include - -namespace nil { - namespace crypto3 { - namespace algebra { - namespace fields { - // TODO: check correctness of this binary field - /*! - * @brief IETF IPsec groups - * @tparam Version - */ - template - struct sect_k1_base_field; - - template<> - struct sect_k1_base_field<163> : public field<164> { - typedef field<164> policy_type; - - using small_subfield = sect_k1_base_field; - - constexpr static const std::size_t modulus_bits = policy_type::modulus_bits; - typedef typename policy_type::integral_type integral_type; - - typedef typename policy_type::extended_integral_type extended_integral_type; - - constexpr static const std::size_t number_bits = policy_type::number_bits; - - constexpr static const integral_type modulus = - 0x80000000000000000000000000000000000000000_cppui_modular164; - - typedef typename policy_type::modular_backend modular_backend; - constexpr static const modular_params_type modulus_params = modulus.backend(); - typedef boost::multiprecision::number>> - modular_type; - - typedef typename detail::element_fp>> value_type; - - constexpr static const std::size_t value_bits = modulus_bits; - constexpr static const std::size_t arity = 1; - }; - - // TODO: define nist_base_field for other base field sizes - - template - using sect_k1_fq = sect_k1_base_field; - - constexpr typename std::size_t const sect_k1_fq<163>::modulus_bits; - constexpr typename std::size_t const sect_k1_fq<163>::number_bits; - constexpr typename std::size_t const sect_k1_fq<163>::value_bits; - constexpr typename sect_k1_fq<163>::integral_type const sect_k1_fq<163>::modulus; - constexpr typename sect_k1_fq<163>::modular_params_type const sect_k1_fq<163>::modulus_params; - - } // namespace fields - } // namespace algebra - } // namespace crypto3 -} // namespace nil - -#endif // CRYPTO3_ALGEBRA_FIELDS_NIST_BASE_FIELD_HPP diff --git a/libs/algebra/include/nil/crypto3/algebra/random_element.hpp b/libs/algebra/include/nil/crypto3/algebra/random_element.hpp index 19cbd4eee..7cae3c348 100644 --- a/libs/algebra/include/nil/crypto3/algebra/random_element.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/random_element.hpp @@ -92,12 +92,12 @@ namespace nil { return typename field_type::value_type(data); } - template, typename UniformRandomBitGenerator = boost::random::random_device> - typename std::enable_if::value, typename CurveGroupType::value_type>:: - type constexpr random_element(UniformRandomBitGenerator &&rng = UniformRandomBitGenerator()) { + constexpr typename CurveGroupType::value_type + random_element(UniformRandomBitGenerator &&rng = UniformRandomBitGenerator()) { using curve_type = typename CurveGroupType::curve_type; using field_type = typename curve_type::scalar_field_type; diff --git a/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp b/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp index 5ace321c5..d4f82e4fa 100644 --- a/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp @@ -31,96 +31,12 @@ #include #include -#include -#include -#include -#include #include namespace nil { namespace crypto3 { namespace algebra { - using namespace boost::mpl::placeholders; - - BOOST_TTI_HAS_TYPE(iterator) - BOOST_TTI_HAS_TYPE(const_iterator) - - BOOST_TTI_HAS_TYPE(params_type) - BOOST_TTI_HAS_TYPE(curve_type) - BOOST_TTI_HAS_TYPE(field_type) - BOOST_TTI_HAS_TYPE(value_type) - BOOST_TTI_HAS_TYPE(base_field_type) - BOOST_TTI_HAS_TYPE(scalar_field_type) - BOOST_TTI_HAS_TYPE(gt_type) - - // BOOST_TTI_HAS_TYPE(g1_type) does not work properly on g1_type since it is a template - template> - struct has_type_g1_type : std::false_type { }; - template - struct has_type_g1_type>> : std::true_type { }; - - // BOOST_TTI_HAS_TYPE(g2_type) does not work properly on g2_type since it is a template - template> - struct has_type_g2_type : std::false_type { }; - template - struct has_type_g2_type>> : std::true_type { }; - - BOOST_TTI_HAS_TYPE(group_type) - - BOOST_TTI_HAS_STATIC_MEMBER_DATA(base_field_modulus) - - BOOST_TTI_HAS_STATIC_MEMBER_DATA(scalar_field_modulus) - - BOOST_TTI_HAS_STATIC_MEMBER_DATA(p) - - BOOST_TTI_HAS_STATIC_MEMBER_DATA(q) - - BOOST_TTI_HAS_FUNCTION(to_affine) - - BOOST_TTI_HAS_FUNCTION(to_special) - - BOOST_TTI_HAS_FUNCTION(is_special) - BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(zero) - - BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(one) - - BOOST_TTI_HAS_FUNCTION(is_zero) - - BOOST_TTI_HAS_FUNCTION(is_well_formed) - - BOOST_TTI_HAS_FUNCTION(double_inplace) - - BOOST_TTI_HAS_FUNCTION(mixed_add) - - template - struct is_curve { - static constexpr bool value = has_type_base_field_type::value && - has_type_scalar_field_type::value && has_type_g1_type::value; - }; - - /** @brief is typename T either g1 or g2 group */ - template - struct is_curve_group { - static constexpr bool value = has_type_params_type::value && - has_type_curve_type>::value && - has_type_field_type::value && has_type_value_type::value; - }; - - template - struct is_curve_element { - static const bool value = - has_type_field_type::value && has_type_group_type::value && - has_static_member_function_zero::value && has_static_member_function_one::value && - has_function_is_zero::value && has_function_is_well_formed::value && - has_function_double_inplace::value; - }; - - template - struct has_mixed_add { - static const bool value = has_function_mixed_add>::value; - }; - template concept FieldValue = requires(const T &a, const T &b, const boost::multiprecision::cpp_int &exponent) { typename T::field_type; @@ -148,10 +64,17 @@ namespace nil { }; template - concept ExtendedField = Field && requires { typename T::extension_policy; }; + concept ExtendedField = Field && requires { + typename T::extension_policy; + typename T::underlying_field_type; + }; template - concept ExtendedFieldValue = FieldValue && requires { typename T::underlying_type; }; + concept ExtendedFieldValue = FieldValue && ExtendedField && requires { + typename T::underlying_type; + requires std::same_as; + }; template concept FieldElementWithCoordinates = @@ -168,22 +91,43 @@ namespace nil { }; template - struct is_complex : std::false_type { }; + concept Curve = requires { + typename T::base_field_type; + typename T::scalar_field_type; + typename T::template g1_type<>; + requires Field; + requires Field; + }; + template - struct is_complex> : std::true_type { }; + concept CurveWithG2 = Curve && requires { typename T::template g2_type<>; }; + template - constexpr bool is_complex_v = is_complex::value; + concept CurveWithTargetGroup = Curve && requires { typename T::gt_type; }; template - struct remove_complex { - using type = T; + concept CurveElement = requires(T &value, const T &const_value) { + typename T::field_type; + typename T::group_type; + { T::zero() } -> std::convertible_to; + { T::one() } -> std::convertible_to; + { const_value.is_zero() } -> std::convertible_to; + { const_value.is_well_formed() } -> std::convertible_to; + { value.double_inplace() } -> std::same_as; }; + template - struct remove_complex> { - using type = T; + concept CurveGroup = requires { + typename T::params_type; + typename T::curve_type; + typename T::field_type; + typename T::value_type; + requires Curve; + requires Field; + requires CurveElement; + requires std::same_as; }; - template - using remove_complex_t = typename remove_complex::type; + } // namespace algebra } // namespace crypto3 } // namespace nil diff --git a/libs/algebra/include/nil/crypto3/detail/assert.hpp b/libs/algebra/include/nil/crypto3/detail/assert.hpp deleted file mode 100644 index 2fa803dd7..000000000 --- a/libs/algebra/include/nil/crypto3/detail/assert.hpp +++ /dev/null @@ -1,55 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2020-2021 Mikhail Komarov -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -//---------------------------------------------------------------------------// - -#ifndef CRYPTO3_DETAIL_ASSERT_HPP -#define CRYPTO3_DETAIL_ASSERT_HPP - -#include - -#define CRYPTO3_DETAIL_ASSERT_FLOATING_POINT(T) \ - static_assert(std::is_floating_point::type>::value, \ - "argument must be a (real or complex) floating point type"); - -#define CRYPTO3_DETAIL_ASSERT_INTEGRAL(T) \ - static_assert(std::is_integral::value, "argument must be a real integral type"); - -#define CRYPTO3_DETAIL_ASSERT_VALID_COMPLEX(T) \ - static_assert(!algebra::detail::is_complex::value || \ - std::is_floating_point::type>::value, \ - "invalid complex type argument (valid types are " \ - "complex, complex, and complex)"); - -#define CRYPTO3_DETAIL_ASSERT_ARITHMETIC(T) \ - CRYPTO3_DETAIL_ASSERT_VALID_COMPLEX(T) \ - static_assert(std::is_arithmetic::type>::value, \ - "argument must be a (real or complex) arithmetic type"); - -#define CRYPTO3_DETAIL_ASSERT_REAL(T) \ - static_assert(std::is_arithmetic::value, "argument must be a real arithmetic type"); - -#define CRYPTO3_DETAIL_ASSERT_COMPLEX(T) \ - CRYPTO3_DETAIL_ASSERT_VALID_COMPLEX(T) \ - static_assert(algebra::detail::is_complex::value, "argument must be a complex type"); - -#endif // CRYPTO3_DETAIL_ASSERT_H_ \ No newline at end of file diff --git a/libs/algebra/test/bench_test/curves.cpp b/libs/algebra/test/bench_test/curves.cpp index c8da5d8c1..175330272 100644 --- a/libs/algebra/test/bench_test/curves.cpp +++ b/libs/algebra/test/bench_test/curves.cpp @@ -98,7 +98,7 @@ void benchmark_curve_operations(std::string const& curve_name) { bench_name("G1 scalar multiplication"), [](typename g1_type::value_type& A, typename scalar_field::value_type const& B) { return A *= B; }); - if constexpr (has_type_g2_type::value) { + if constexpr (CurveWithG2) { using g2_type = typename curve_type::template g2_type<>; using g2_field = typename g2_type::field_type; @@ -131,7 +131,7 @@ void benchmark_curve_operations(std::string const& curve_name) { std::cout << "Curve " << curve_name << " does not have G2, skipping benchmarks" << std::endl; } - if constexpr (has_type_gt_type::value) { + if constexpr (CurveWithTargetGroup) { using gt_type = typename curve_type::gt_type; run_benchmark( diff --git a/libs/algebra/test/type_traits.cpp b/libs/algebra/test/type_traits.cpp index 035bece02..9e2498439 100644 --- a/libs/algebra/test/type_traits.cpp +++ b/libs/algebra/test/type_traits.cpp @@ -47,11 +47,14 @@ #include #include #include +#include #include #include +#include #include #include +#include #include @@ -64,19 +67,13 @@ template void test_field_value_types() { static_assert(FieldElementWithCoordinates); - BOOST_ASSERT(has_type_field_type::value); - BOOST_ASSERT((has_function_is_zero::value)); - BOOST_ASSERT((has_static_member_function_zero::value)); - BOOST_ASSERT((has_static_member_function_one::value)); - - BOOST_ASSERT(FieldValue); + static_assert(FieldValue); } template void test_field_types() { - BOOST_ASSERT(has_type_value_type::value); - - BOOST_ASSERT(Field); + static_assert(Field); + static_assert(ExtendedField == ExtendedFieldValue); test_field_value_types(); } @@ -85,58 +82,44 @@ template void test_extended_field_types() { test_field_types(); - BOOST_ASSERT(ExtendedField); - - BOOST_ASSERT(ExtendedFieldValue); + static_assert(ExtendedField); + static_assert(ExtendedFieldValue); + static_assert(std::same_as); test_field_value_types(); } template void test_curve_group_types() { - BOOST_ASSERT(is_curve_group::value); - BOOST_ASSERT(has_type_curve_type::value); - - BOOST_ASSERT(has_type_value_type::value); + static_assert(CurveGroup); using value_type = typename curve_group_type::value_type; - BOOST_ASSERT(has_type_field_type::value); - BOOST_ASSERT(has_type_group_type::value); - - BOOST_ASSERT((has_static_member_function_zero::value)); - BOOST_ASSERT((has_static_member_function_one::value)); - BOOST_ASSERT((has_function_is_zero::value)); - BOOST_ASSERT((has_function_is_well_formed::value)); - BOOST_ASSERT((has_function_double_inplace::value)); - - BOOST_ASSERT(is_curve_element::value); + static_assert(CurveElement); } template void test_ordinary_curve_types() { - BOOST_ASSERT(has_type_base_field_type::value); test_field_types(); - BOOST_ASSERT(has_type_scalar_field_type::value); test_field_types(); - BOOST_ASSERT(has_type_g1_type::value); test_curve_group_types>(); - BOOST_ASSERT(is_curve::value); + static_assert(Curve); } template void test_pairing_friendly_curve_types() { test_ordinary_curve_types(); - BOOST_ASSERT(has_type_g2_type::value); + static_assert(CurveWithG2); test_curve_group_types>(); using g2_base_field = typename curve_type::template g2_type<>::params_type::field_type; test_extended_field_types(); - BOOST_ASSERT(has_type_gt_type::value); + static_assert(CurveWithTargetGroup); test_extended_field_types(); } @@ -179,10 +162,39 @@ BOOST_AUTO_TEST_CASE(babyjubjub_type_traits) { BOOST_AUTO_TEST_CASE(goldilocks_field_type_traits) { test_field_types(); test_field_types(); + + using field_type = fields::goldilocks; + using params_type = fields::arithmetic_params; + + static_assert(field_type::modulus == 0xffffffff00000001ull); + static_assert(params_type::s == 32); + static_assert(params_type::multiplicative_generator == 7u); + static_assert(params_type::root_of_unity == 0x185629dcda58878cull); } BOOST_AUTO_TEST_CASE(mersenne31_field_type_traits) { test_field_types(); + + using field_type = fields::mersenne31; + using value_type = field_type::value_type; + using params_type = fields::arithmetic_params; + + static_assert(field_type::modulus == 0x7fffffffu); + static_assert(params_type::s == 1); + static_assert(value_type(params_type::root_of_unity) == -value_type::one()); +} + +BOOST_AUTO_TEST_CASE(fpn_type_traits) { + using params_type = fields::detail::BinomialFieldExtensionParamsArchetype; + using field_type = fields::fpn; + + static_assert(Field); + static_assert(ExtendedField); + static_assert(ExtendedFieldValue); + static_assert(std::same_as); + static_assert(field_type::extension_degree == params_type::dimension); + static_assert(field_type::arity == params_type::dimension * params_type::base_field_type::arity); + static_assert(field_type::value_bits == field_type::arity * field_type::modulus_bits); } BOOST_AUTO_TEST_CASE(koalabear_field_type_traits) { diff --git a/libs/block/include/nil/crypto3/detail/assert.hpp b/libs/block/include/nil/crypto3/detail/assert.hpp deleted file mode 100644 index eba8b9324..000000000 --- a/libs/block/include/nil/crypto3/detail/assert.hpp +++ /dev/null @@ -1,90 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2022 Mikhail Komarov -// Copyright (c) 2022 Nikita Kaskov -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -//---------------------------------------------------------------------------// - -#ifndef CRYPTO3_DETAIL_ASSERTS_HPP -#define CRYPTO3_DETAIL_ASSERTS_HPP - -#include -#include - -#define UNREACHABLE(msg) ::nil::crypto3::unreachable((msg), __FILE__, __LINE__) - -#define ASSERT(expr) ::nil::crypto3::assert_check((expr), #expr, __FILE__, __LINE__) - -#define ASSERT_MSG(expr, msg) ::nil::crypto3::assert_check((expr), #expr, __FILE__, __LINE__, (msg)) - -#define TODO(msg) ::nil::crypto3::todo((msg), __FILE__, __LINE__) - -#define TODO_WITH_LINK(msg, link) ::nil::crypto3::todo_with_link((msg), (link), __FILE__, __LINE__) - -namespace nil { - namespace crypto3 { - [[noreturn]] void abort_process() { - std::abort(); - } - - [[noreturn]] void unreachable(const char *msg, const char *filename, unsigned line) { - std::cerr << "UNREACHABLE at " << filename << ":" << line << std::endl; - std::cerr << '\t' << msg << std::endl; - abort_process(); - } - - [[noreturn]] void unreachable(const std::string &msg, const char *filename, unsigned line) { - unreachable(msg.c_str(), filename, line); - } - - void assert_check(bool expr, const char *expr_str, const char *filename, unsigned line, const char *msg = "") { - if (!expr) { - std::cerr << "Assertion failed at " << filename << ":" << line << ":" << std::endl; - std::cerr << '\t' << expr_str; - if (strlen(msg) != 0) { - std::cerr << " -> " << msg; - } - std::cerr << std::endl; - abort_process(); - } - } - - [[noreturn]] void todo(const char *msg, const char *filename, unsigned line) { - std::cerr << "NOT YET IMPLEMENTED at " << filename << ":" << line << std::endl; - std::cerr << '\t' << msg << std::endl; - abort_process(); - } - - [[noreturn]] void todo_with_link(const char *msg, const char *link, const char *filename, unsigned line) { - std::string new_msg(msg); - new_msg += "\n\tTracking issue: "; - new_msg += link; - todo(new_msg.c_str(), filename, line); - } - - [[noreturn]] void todo_with_link(const std::string &msg, const std::string &link, const char *filename, - unsigned line) { - todo_with_link(msg.c_str(), link.c_str(), filename, line); - } - } // namespace crypto3 -} // namespace nil - -#endif // CRYPTO3_DETAIL_ASSERTS_HPP diff --git a/libs/codec/include/nil/crypto3/detail/assert.hpp b/libs/codec/include/nil/crypto3/detail/assert.hpp deleted file mode 100644 index eba8b9324..000000000 --- a/libs/codec/include/nil/crypto3/detail/assert.hpp +++ /dev/null @@ -1,90 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2022 Mikhail Komarov -// Copyright (c) 2022 Nikita Kaskov -// -// MIT License -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -//---------------------------------------------------------------------------// - -#ifndef CRYPTO3_DETAIL_ASSERTS_HPP -#define CRYPTO3_DETAIL_ASSERTS_HPP - -#include -#include - -#define UNREACHABLE(msg) ::nil::crypto3::unreachable((msg), __FILE__, __LINE__) - -#define ASSERT(expr) ::nil::crypto3::assert_check((expr), #expr, __FILE__, __LINE__) - -#define ASSERT_MSG(expr, msg) ::nil::crypto3::assert_check((expr), #expr, __FILE__, __LINE__, (msg)) - -#define TODO(msg) ::nil::crypto3::todo((msg), __FILE__, __LINE__) - -#define TODO_WITH_LINK(msg, link) ::nil::crypto3::todo_with_link((msg), (link), __FILE__, __LINE__) - -namespace nil { - namespace crypto3 { - [[noreturn]] void abort_process() { - std::abort(); - } - - [[noreturn]] void unreachable(const char *msg, const char *filename, unsigned line) { - std::cerr << "UNREACHABLE at " << filename << ":" << line << std::endl; - std::cerr << '\t' << msg << std::endl; - abort_process(); - } - - [[noreturn]] void unreachable(const std::string &msg, const char *filename, unsigned line) { - unreachable(msg.c_str(), filename, line); - } - - void assert_check(bool expr, const char *expr_str, const char *filename, unsigned line, const char *msg = "") { - if (!expr) { - std::cerr << "Assertion failed at " << filename << ":" << line << ":" << std::endl; - std::cerr << '\t' << expr_str; - if (strlen(msg) != 0) { - std::cerr << " -> " << msg; - } - std::cerr << std::endl; - abort_process(); - } - } - - [[noreturn]] void todo(const char *msg, const char *filename, unsigned line) { - std::cerr << "NOT YET IMPLEMENTED at " << filename << ":" << line << std::endl; - std::cerr << '\t' << msg << std::endl; - abort_process(); - } - - [[noreturn]] void todo_with_link(const char *msg, const char *link, const char *filename, unsigned line) { - std::string new_msg(msg); - new_msg += "\n\tTracking issue: "; - new_msg += link; - todo(new_msg.c_str(), filename, line); - } - - [[noreturn]] void todo_with_link(const std::string &msg, const std::string &link, const char *filename, - unsigned line) { - todo_with_link(msg.c_str(), link.c_str(), filename, line); - } - } // namespace crypto3 -} // namespace nil - -#endif // CRYPTO3_DETAIL_ASSERTS_HPP diff --git a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/inference.hpp b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/inference.hpp index 1f255cddf..879f66b8e 100644 --- a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/inference.hpp +++ b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/inference.hpp @@ -60,8 +60,8 @@ namespace nil { template class is_compatible; - template - class is_compatible::value>::type> { + template + class is_compatible { using default_endianness = option::big_endian; public: diff --git a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/type_traits.hpp b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/type_traits.hpp index aa8923cc6..d1c1da32e 100644 --- a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/type_traits.hpp +++ b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/type_traits.hpp @@ -53,24 +53,6 @@ namespace nil { } // namespace crypto3 namespace marshalling { - /// @brief Compile time check function of whether a provided type is any - /// variant of nil::crypto3::marshalling::types::curve_element. - /// @tparam T Any type. - /// @return true in case provided type is any variant of @ref curve_element - /// @related nil::crypto3::marshalling::types::curve_element - template - struct is_curve_element { - - static const bool value = false; - }; - - template - struct is_curve_element< - nil::crypto3::marshalling::types::curve_element> { - - static const bool value = true; - }; - template inline constexpr bool marshalling_field_element = false; @@ -88,9 +70,9 @@ namespace nil { template struct is_container; - template - requires is_curve_element::value - struct is_container { + template + struct is_container, + void> { static const bool value = false; }; diff --git a/libs/marshalling/algebra/test/curve_element.cpp b/libs/marshalling/algebra/test/curve_element.cpp index 0cec5c3d7..8a8a2cbfe 100644 --- a/libs/marshalling/algebra/test/curve_element.cpp +++ b/libs/marshalling/algebra/test/curve_element.cpp @@ -71,7 +71,7 @@ void test_curve_element_big_endian(T val) { using curve_element_type = types::curve_element, typename T::group_type>; - static_assert(nil::marshalling::is_curve_element::value); + static_assert(nil::crypto3::algebra::CurveElement); static_assert(nil::marshalling::is_compatible::value); nil::marshalling::status_type status; diff --git a/libs/math/include/nil/crypto3/math/static_matrix/math.hpp b/libs/math/include/nil/crypto3/math/static_matrix/math.hpp index bac90f7c8..86ca50649 100644 --- a/libs/math/include/nil/crypto3/math/static_matrix/math.hpp +++ b/libs/math/include/nil/crypto3/math/static_matrix/math.hpp @@ -230,8 +230,6 @@ namespace nil::crypto3::math { /// @private template constexpr std::tuple, std::size_t, T> gauss_jordan_impl(static_matrix m) { - // CRYPTO3_DETAIL_ASSERT_FLOATING_POINT(T) - // CRYPTO3_DETAIL_ASSERT_REAL(T) auto negligible = [](const T &v) { return v == T::zero(); }; diff --git a/libs/math/include/nil/crypto3/math/static_matrix/static_matrix.hpp b/libs/math/include/nil/crypto3/math/static_matrix/static_matrix.hpp index e6f7c9f3e..13effa639 100644 --- a/libs/math/include/nil/crypto3/math/static_matrix/static_matrix.hpp +++ b/libs/math/include/nil/crypto3/math/static_matrix/static_matrix.hpp @@ -29,8 +29,6 @@ #include #include -#include - #include #include @@ -64,8 +62,6 @@ namespace nil::crypto3::math { static_assert(sizeof...(args) == N * M, "Number of arguments must match the static_matrix size"); } - // CRYPTO3_DETAIL_ASSERT_ARITHMETIC(T) - using value_type = T; using size_type = std::size_t; constexpr static const size_type column_size = N; ///< Number of rows diff --git a/libs/pubkey/include/nil/crypto3/detail/type_traits.hpp b/libs/pubkey/include/nil/crypto3/detail/type_traits.hpp index 1a5427f65..d541defba 100644 --- a/libs/pubkey/include/nil/crypto3/detail/type_traits.hpp +++ b/libs/pubkey/include/nil/crypto3/detail/type_traits.hpp @@ -296,44 +296,16 @@ namespace nil { GENERATE_HAS_MEMBER_TYPE(extension_policy) - GENERATE_HAS_MEMBER_TYPE(curve_type) - - GENERATE_HAS_MEMBER_TYPE(underlying_field_type) - GENERATE_HAS_MEMBER_TYPE(value_type) GENERATE_HAS_MEMBER_TYPE(integral_type) - GENERATE_HAS_MEMBER_TYPE(base_field_type) - - GENERATE_HAS_MEMBER_TYPE(number_type) - - GENERATE_HAS_MEMBER_TYPE(scalar_field_type) - - GENERATE_HAS_MEMBER_TYPE(g1_type) - - GENERATE_HAS_MEMBER_TYPE(g2_type) - - GENERATE_HAS_MEMBER_TYPE(gt_type) - GENERATE_HAS_MEMBER(value_bits) GENERATE_HAS_MEMBER(modulus_bits) - GENERATE_HAS_MEMBER(base_field_bits) - - GENERATE_HAS_MEMBER(base_field_modulus) - - GENERATE_HAS_MEMBER(scalar_field_bits) - - GENERATE_HAS_MEMBER(scalar_field_modulus) - GENERATE_HAS_MEMBER(arity) - GENERATE_HAS_MEMBER(p) - - GENERATE_HAS_MEMBER(q) - GENERATE_HAS_MEMBER_FUNCTION(to_affine_coordinates) GENERATE_HAS_MEMBER_FUNCTION(to_special) @@ -419,41 +391,6 @@ namespace nil { typedef T type; }; - template - struct is_curve { - static const bool value = - has_base_field_bits::value && has_base_field_type::value && has_number_type::value && - has_base_field_modulus::value && has_scalar_field_bits::value && - has_scalar_field_type::value && has_scalar_field_modulus::value && has_g1_type::value && - has_g2_type::value && has_gt_type::value && has_p::value && has_q::value; - typedef T type; - }; - - template // TODO: we should add some other params to curve group policy to identify it more - // clearly - struct is_curve_group { - static const bool value = has_value_type::value && has_underlying_field_type::value && - has_value_bits::value && has_curve_type::value; - typedef T type; - }; - - template - struct is_complex : std::false_type { }; - template - struct is_complex> : std::true_type { }; - template - constexpr bool is_complex_v = is_complex::value; - - template - struct remove_complex { - using type = T; - }; - template - struct remove_complex> { - using type = T; - }; - template - using remove_complex_t = typename remove_complex::type; } // namespace detail } // namespace crypto3 } // namespace nil diff --git a/libs/random/include/nil/crypto3/random/algebraic_engine.hpp b/libs/random/include/nil/crypto3/random/algebraic_engine.hpp index 113ae5b8c..90460d8b9 100644 --- a/libs/random/include/nil/crypto3/random/algebraic_engine.hpp +++ b/libs/random/include/nil/crypto3/random/algebraic_engine.hpp @@ -300,11 +300,8 @@ namespace nil { }; template - struct algebraic_engine< - AlgebraicType, - Engine, - typename std::enable_if::value && - boost::is_integral::value>::type> { + requires algebra::CurveGroup && boost::is_integral::value + struct algebraic_engine { protected: typedef AlgebraicType group_type; typedef typename group_type::value_type group_value_type; diff --git a/libs/random/include/nil/crypto3/random/algebraic_random_device.hpp b/libs/random/include/nil/crypto3/random/algebraic_random_device.hpp index 3a13a3292..629b0bb70 100644 --- a/libs/random/include/nil/crypto3/random/algebraic_random_device.hpp +++ b/libs/random/include/nil/crypto3/random/algebraic_random_device.hpp @@ -135,9 +135,8 @@ namespace nil { internal_generator_type gen; }; - template - struct algebraic_random_device< - AlgebraicType, typename std::enable_if::value>::type> { + template + struct algebraic_random_device { protected: typedef AlgebraicType group_type; typedef typename group_type::value_type group_value_type; diff --git a/libs/zk/include/nil/crypto3/zk/transcript/fiat_shamir.hpp b/libs/zk/include/nil/crypto3/zk/transcript/fiat_shamir.hpp index 52d308c93..cdb30f68e 100644 --- a/libs/zk/include/nil/crypto3/zk/transcript/fiat_shamir.hpp +++ b/libs/zk/include/nil/crypto3/zk/transcript/fiat_shamir.hpp @@ -149,9 +149,8 @@ namespace nil { } template - typename std::enable_if_t::value && - !algebra::FieldValue> - operator()(const InputRange &r) { + requires(!algebra::CurveElement && !algebra::FieldValue) + void operator()(const InputRange &r) { auto acc_convertible = hash(state); state = accumulators::extract::hash( hash(r, static_cast &>(acc_convertible))); @@ -165,8 +164,8 @@ namespace nil { } template - typename std::enable_if_t::value || algebra::FieldValue> - operator()(element const &data) { + requires(algebra::CurveElement || algebra::FieldValue) + void operator()(element const &data) { nil::marshalling::status_type status; std::vector byte_data = nil::marshalling::pack(data, status); @@ -282,14 +281,14 @@ namespace nil { } template - typename std::enable_if_t::value> - operator()(const InputRange &r) { + requires(!algebra::CurveElement) + void operator()(const InputRange &r) { absorb(static_cast(hash(r))); } template - typename std::enable_if_t::value> - operator()(element const &data) { + requires algebra::CurveElement + void operator()(element const &data) { auto affine = data.to_affine(); absorb(affine.X); absorb(affine.Y);