/* * Botan is released under the Simplified BSD License (see license.txt) */ #include #include namespace Botan::PCurve { namespace { namespace {{ curve["Name"] }} { {% if crandall > 0 -%} template class {{ curve["Name"] | capitalize }}Rep final { public: static constexpr auto P = Params::P; static constexpr size_t N = Params::N; typedef typename Params::W W; static constexpr W C = {{ crandall }}; constexpr static std::array one() { return std::array{1}; } constexpr static std::array redc(const std::array& z) { return redc_crandall(std::span{z}); } constexpr static std::array to_rep(const std::array& x) { return x; } constexpr static std::array wide_to_rep(const std::array& x) { return redc(x); } constexpr static std::array from_rep(const std::array& z) { return z; } }; {% endif %} // clang-format off class Params final : public EllipticCurveParameters< "{{ "%X" % curve['P'] }}", "{{ "%X" % curve['A'] }}", "{{ "%X" % curve['B'] }}", "{{ "%X" % curve['N'] }}", "{{ "%X" % curve['X'] }}", "{{ "%X" % curve['Y'] }}"> { }; // clang-format on class Curve final : public EllipticCurve 0 %}, {{ curve["Name"] | capitalize}}Rep{% endif %}> { public: // Return the square of the inverse of x static constexpr FieldElement fe_invert2(const FieldElement& x) { // Generated using https://github.com/mmcloughlin/addchain {{ addchain_fe2 }} } {% if addchain_fe_sqrt != None -%} // Return the square root of this field element (if it is a quadratic residue) static constexpr FieldElement fe_sqrt(const FieldElement& x) { // Generated using https://github.com/mmcloughlin/addchain {{ addchain_fe_sqrt }} } {%- endif %} // Return the inverse of an integer modulo the order static constexpr Scalar scalar_invert(const Scalar& x) { // Generated using https://github.com/mmcloughlin/addchain {{ addchain_scalar }} } }; } // namespace {{ curve["Name"] }} } // namespace std::shared_ptr PCurveInstance::{{ curve["Name"] }}() { return PrimeOrderCurveImpl<{{ curve["Name"] }}::Curve>::instance(); } } // namespace Botan::PCurve