Skip to content

Commit

Permalink
Add an extra bit to scalar fields of secp where necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
martun committed May 20, 2024
1 parent dcda57b commit 4661461
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,8 @@ namespace nil {
template<typename Coordinates>
using group_type = babyjubjub_types::g1_type<forms::twisted_edwards, Coordinates>;

#ifdef STANDARD_EC_INF_POINTS_ENABLED
constexpr static const std::array<typename base_field_type::value_type, 2> zero_fill = {
base_field_type::value_type::zero(), base_field_type::value_type::one()};
#else
constexpr static const std::array<typename base_field_type::value_type, 2> zero_fill = {
base_field_type::value_type::zero(), base_field_type::value_type::zero()};
#endif

constexpr static const std::array<typename base_field_type::value_type, 2> one_fill = {
typename base_field_type::value_type(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,8 @@ namespace nil {
#ifdef __ZKLLVM__
#else

#ifdef STANDARD_EC_INF_POINTS_ENABLED
constexpr static std::array<typename field_type::value_type, 2> zero_fill = {
field_type::value_type::zero(), field_type::value_type::one()};
#else
constexpr static std::array<typename field_type::value_type, 2> zero_fill = {
field_type::value_type::zero(), field_type::value_type::zero()};
#endif

constexpr static std::array<typename field_type::value_type, 2> one_fill = {
typename field_type::value_type(0x09u),
Expand Down
5 changes: 0 additions & 5 deletions include/nil/crypto3/algebra/curves/detail/jubjub/params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,8 @@ namespace nil {
template<typename Coordinates>
using group_type = jubjub_types::g1_type<forms::twisted_edwards, Coordinates>;

#ifdef STANDARD_EC_INF_POINTS_ENABLED
constexpr static const std::array<typename field_type::value_type, 2> zero_fill = {
field_type::value_type::zero(), field_type::value_type::one()};
#else
constexpr static const std::array<typename field_type::value_type, 2> zero_fill = {
field_type::value_type::zero(), field_type::value_type::zero()};
#endif

// according to https://neuromancer.sk/std/other/JubJub
constexpr static const std::array<typename field_type::value_type, 2> one_fill = {
Expand Down
14 changes: 8 additions & 6 deletions include/nil/crypto3/algebra/fields/secp/secp_k1/scalar_field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ namespace nil {
template<std::size_t Version>
struct secp_k1_scalar_field;

// We need to derive from field<161> here, since the modulus is actually 161 bits long.
template<>
struct secp_k1_scalar_field<160> : public field<160> {
typedef field<160> policy_type;
struct secp_k1_scalar_field<160> : public field<161> {
typedef field<161> policy_type;

constexpr static const std::size_t modulus_bits = policy_type::modulus_bits;
typedef typename policy_type::integral_type integral_type;
Expand All @@ -57,7 +58,7 @@ namespace nil {
constexpr static const std::size_t number_bits = policy_type::number_bits;

constexpr static const integral_type modulus =
0x0100000000000000000001b8fa16dfab9aca16b6b3_cppui_modular160;
0x0100000000000000000001b8fa16dfab9aca16b6b3_cppui_modular161;

typedef typename policy_type::modular_backend modular_backend;
constexpr static const modular_params_type modulus_params = modulus.backend();
Expand Down Expand Up @@ -101,9 +102,10 @@ namespace nil {
constexpr static const std::size_t arity = 1;
};

// We need to derive from field<225> here, since the modulus is actually 225 bits long.
template<>
struct secp_k1_scalar_field<224> : public field<224> {
typedef field<224> policy_type;
struct secp_k1_scalar_field<224> : public field<225> {
typedef field<225> policy_type;

constexpr static const std::size_t modulus_bits = policy_type::modulus_bits;
typedef typename policy_type::integral_type integral_type;
Expand All @@ -113,7 +115,7 @@ namespace nil {
constexpr static const std::size_t number_bits = policy_type::number_bits;

constexpr static const integral_type modulus =
0x010000000000000000000000000001dce8d2ec6184caf0a971769fb1f7_cppui_modular224;
0x010000000000000000000000000001dce8d2ec6184caf0a971769fb1f7_cppui_modular225;

typedef typename policy_type::modular_backend modular_backend;
constexpr static const modular_params_type modulus_params = modulus.backend();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ namespace nil {
template<std::size_t Version>
struct secp_r1_scalar_field;

// We need to derive from field<161> here, since the modulus is actually 161 bits long.
template<>
struct secp_r1_scalar_field<160> : public field<160> {
typedef field<160> policy_type;
struct secp_r1_scalar_field<160> : public field<161> {
typedef field<161> policy_type;

constexpr static const std::size_t modulus_bits = policy_type::modulus_bits;
typedef typename policy_type::integral_type integral_type;
Expand All @@ -57,7 +58,7 @@ namespace nil {
constexpr static const std::size_t number_bits = policy_type::number_bits;

constexpr static const integral_type modulus =
0x0100000000000000000001f4c8f927aed3ca752257_cppui_modular160;
0x0100000000000000000001f4c8f927aed3ca752257_cppui_modular161;

typedef typename policy_type::modular_backend modular_backend;
constexpr static const modular_params_type modulus_params = modulus.backend();
Expand All @@ -67,7 +68,7 @@ namespace nil {
boost::multiprecision::backends::modular_params_ct<modular_backend, modulus_params>>>
modular_type;

typedef typename detail::element_fp<params<secp_r1_scalar_field<160>>> value_type;
typedef typename detail::element_fp<params<secp_r1_scalar_field<161>>> value_type;

constexpr static const std::size_t value_bits = modulus_bits;
constexpr static const std::size_t arity = 1;
Expand Down

0 comments on commit 4661461

Please sign in to comment.