-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crypto3: add mersenne31, koalabear and babybear
- Loading branch information
Showing
21 changed files
with
905 additions
and
10 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
crypto3/libs/algebra/include/nil/crypto3/algebra/fields/arithmetic_params/babybear.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2025 Andrey Nefedov <[email protected]> | ||
// | ||
// 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_BABYBEAR_ARITHMETIC_PARAMS_HPP | ||
#define CRYPTO3_ALGEBRA_FIELDS_BABYBEAR_ARITHMETIC_PARAMS_HPP | ||
|
||
#include <nil/crypto3/algebra/fields/params.hpp> | ||
|
||
#include <nil/crypto3/algebra/fields/babybear/base_field.hpp> | ||
|
||
namespace nil::crypto3::algebra::fields { | ||
template<> | ||
struct arithmetic_params<babybear_base_field> : public params<babybear_base_field> { | ||
constexpr static integral_type arithmetic_generator = 1u; | ||
constexpr static integral_type multiplicative_generator = 31u; | ||
constexpr static integral_type root_of_unity = 0x1a427a41u; | ||
}; | ||
} // namespace nil::crypto3::algebra::fields | ||
|
||
#endif // CRYPTO3_ALGEBRA_FIELDS_BABYBEAR_ARITHMETIC_PARAMS_HPP |
41 changes: 41 additions & 0 deletions
41
crypto3/libs/algebra/include/nil/crypto3/algebra/fields/arithmetic_params/koalabear.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2025 Andrey Nefedov <[email protected]> | ||
// | ||
// 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_KOALABEAR_ARITHMETIC_PARAMS_HPP | ||
#define CRYPTO3_ALGEBRA_FIELDS_KOALABEAR_ARITHMETIC_PARAMS_HPP | ||
|
||
#include <nil/crypto3/algebra/fields/params.hpp> | ||
|
||
#include <nil/crypto3/algebra/fields/koalabear/base_field.hpp> | ||
|
||
namespace nil::crypto3::algebra::fields { | ||
template<> | ||
struct arithmetic_params<koalabear_base_field> : public params<koalabear_base_field> { | ||
constexpr static integral_type arithmetic_generator = 1u; | ||
constexpr static integral_type multiplicative_generator = 3u; | ||
constexpr static integral_type root_of_unity = 0x6ac49f88u; | ||
}; | ||
} // namespace nil::crypto3::algebra::fields | ||
|
||
#endif // CRYPTO3_ALGEBRA_FIELDS_KOALABEAR_ARITHMETIC_PARAMS_HPP |
41 changes: 41 additions & 0 deletions
41
crypto3/libs/algebra/include/nil/crypto3/algebra/fields/arithmetic_params/mersenne31.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2025 Andrey Nefedov <[email protected]> | ||
// | ||
// 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_MERSENNE31_ARITHMETIC_PARAMS_HPP | ||
#define CRYPTO3_ALGEBRA_FIELDS_MERSENNE31_ARITHMETIC_PARAMS_HPP | ||
|
||
#include <nil/crypto3/algebra/fields/params.hpp> | ||
|
||
#include <nil/crypto3/algebra/fields/mersenne31/base_field.hpp> | ||
|
||
namespace nil::crypto3::algebra::fields { | ||
template<> | ||
struct arithmetic_params<mersenne31_base_field> | ||
: public params<mersenne31_base_field> { | ||
constexpr static integral_type arithmetic_generator = 1u; | ||
constexpr static integral_type multiplicative_generator = 7u; | ||
}; | ||
} // namespace nil::crypto3::algebra::fields | ||
|
||
#endif // CRYPTO3_ALGEBRA_FIELDS_MERSENNE31_ARITHMETIC_PARAMS_HPP |
61 changes: 61 additions & 0 deletions
61
crypto3/libs/algebra/include/nil/crypto3/algebra/fields/babybear/base_field.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2025 Andrey Nefedov <[email protected]> | ||
// | ||
// 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_BABYBEAR_BASE_FIELD_HPP | ||
#define CRYPTO3_ALGEBRA_FIELDS_BABYBEAR_BASE_FIELD_HPP | ||
|
||
#include <cstddef> | ||
|
||
#include <nil/crypto3/multiprecision/big_mod.hpp> | ||
#include <nil/crypto3/multiprecision/big_uint.hpp> | ||
#include <nil/crypto3/multiprecision/literals.hpp> | ||
|
||
#include <nil/crypto3/algebra/fields/detail/element/fp.hpp> | ||
|
||
#include <nil/crypto3/algebra/fields/field.hpp> | ||
#include <nil/crypto3/algebra/fields/params.hpp> | ||
|
||
namespace nil::crypto3::algebra::fields { | ||
/** | ||
* @brief A struct representing a Baby Bear field | ||
*/ | ||
class babybear_base_field : public field<31> { | ||
public: | ||
using policy_type = field<31>; | ||
|
||
constexpr static std::size_t value_bits = modulus_bits; | ||
constexpr static std::size_t arity = 1; | ||
|
||
using integral_type = policy_type::integral_type; | ||
|
||
// 2^31 - 2^27 + 1 | ||
constexpr static integral_type modulus = 0x78000001_big_uint31; | ||
constexpr static integral_type group_order_minus_one_half = (modulus - 1u) / 2; | ||
|
||
using modular_type = nil::crypto3::multiprecision::auto_big_mod<modulus>; | ||
using value_type = detail::element_fp<params<babybear_base_field>>; | ||
}; | ||
} // namespace nil::crypto3::algebra::fields | ||
|
||
#endif // CRYPTO3_ALGEBRA_FIELDS_BABYBEAR_BASE_FIELD_HPP |
61 changes: 61 additions & 0 deletions
61
crypto3/libs/algebra/include/nil/crypto3/algebra/fields/koalabear/base_field.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2025 Andrey Nefedov <[email protected]> | ||
// | ||
// 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_KOALABEAR_BASE_FIELD_HPP | ||
#define CRYPTO3_ALGEBRA_FIELDS_KOALABEAR_BASE_FIELD_HPP | ||
|
||
#include <cstddef> | ||
|
||
#include <nil/crypto3/multiprecision/big_mod.hpp> | ||
#include <nil/crypto3/multiprecision/big_uint.hpp> | ||
#include <nil/crypto3/multiprecision/literals.hpp> | ||
|
||
#include <nil/crypto3/algebra/fields/detail/element/fp.hpp> | ||
|
||
#include <nil/crypto3/algebra/fields/field.hpp> | ||
#include <nil/crypto3/algebra/fields/params.hpp> | ||
|
||
namespace nil::crypto3::algebra::fields { | ||
/** | ||
* @brief A struct representing a Koala Bear field | ||
*/ | ||
class koalabear_base_field : public field<31> { | ||
public: | ||
using policy_type = field<31>; | ||
|
||
constexpr static std::size_t value_bits = modulus_bits; | ||
constexpr static std::size_t arity = 1; | ||
|
||
using integral_type = policy_type::integral_type; | ||
|
||
// 2^31 - 2^24 + 1 | ||
constexpr static integral_type modulus = 0x7f000001_big_uint31; | ||
constexpr static integral_type group_order_minus_one_half = (modulus - 1u) / 2; | ||
|
||
using modular_type = nil::crypto3::multiprecision::auto_big_mod<modulus>; | ||
using value_type = detail::element_fp<params<koalabear_base_field>>; | ||
}; | ||
} // namespace nil::crypto3::algebra::fields | ||
|
||
#endif // CRYPTO3_ALGEBRA_FIELDS_KOALABEAR_BASE_FIELD_HPP |
61 changes: 61 additions & 0 deletions
61
crypto3/libs/algebra/include/nil/crypto3/algebra/fields/mersenne31/base_field.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//---------------------------------------------------------------------------// | ||
// Copyright (c) 2025 Andrey Nefedov <[email protected]> | ||
// | ||
// 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_MERSENNE31_BASE_FIELD_HPP | ||
#define CRYPTO3_ALGEBRA_FIELDS_MERSENNE31_BASE_FIELD_HPP | ||
|
||
#include <cstddef> | ||
|
||
#include <nil/crypto3/multiprecision/big_mod.hpp> | ||
#include <nil/crypto3/multiprecision/big_uint.hpp> | ||
#include <nil/crypto3/multiprecision/literals.hpp> | ||
|
||
#include <nil/crypto3/algebra/fields/detail/element/fp.hpp> | ||
|
||
#include <nil/crypto3/algebra/fields/field.hpp> | ||
#include <nil/crypto3/algebra/fields/params.hpp> | ||
|
||
namespace nil::crypto3::algebra::fields { | ||
/** | ||
* @brief A struct representing a Mersenne31 field | ||
*/ | ||
class mersenne31_base_field : public field<31> { | ||
public: | ||
using policy_type = field<31>; | ||
|
||
constexpr static std::size_t value_bits = modulus_bits; | ||
constexpr static std::size_t arity = 1; | ||
|
||
using integral_type = policy_type::integral_type; | ||
|
||
// 2^31 - 1 | ||
constexpr static integral_type modulus = 0x7fffffff_big_uint31; | ||
constexpr static integral_type group_order_minus_one_half = (modulus - 1u) / 2; | ||
|
||
using modular_type = nil::crypto3::multiprecision::auto_big_mod<modulus>; | ||
using value_type = detail::element_fp<params<mersenne31_base_field>>; | ||
}; | ||
} // namespace nil::crypto3::algebra::fields | ||
|
||
#endif // CRYPTO3_ALGEBRA_FIELDS_MERSENNE31_BASE_FIELD_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.