Skip to content

Commit

Permalink
Add missing parameters for BLS12-377 curve and enable it's benchmarks #…
Browse files Browse the repository at this point in the history
  • Loading branch information
vo-nil committed Aug 15, 2024
1 parent 05f6457 commit d3f0f7b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
2 changes: 0 additions & 2 deletions benchmarks/algebra/curves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,10 @@ BOOST_AUTO_TEST_CASE(bls12_381)
benchmark_curve_operations<nil::crypto3::algebra::curves::bls12<381>>("BLS12-381");
}

/*
BOOST_AUTO_TEST_CASE(bls12_377)
{
benchmark_curve_operations<nil::crypto3::algebra::curves::bls12<377>>("BLS12-377");
}
*/

BOOST_AUTO_TEST_CASE(mnt4_298)
{
Expand Down
19 changes: 18 additions & 1 deletion libs/algebra/include/nil/crypto3/algebra/pairing/bls12.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2020-2021 Mikhail Komarov <[email protected]>
// Copyright (c) 2020-2021 Nikita Kaskov <[email protected]>
// Copyright (c) 2024 Vasiliy Olekhov <[email protected]>
//
// MIT License
//
Expand Down Expand Up @@ -29,6 +30,7 @@
#include <nil/crypto3/algebra/curves/jubjub.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
#include <nil/crypto3/algebra/pairing/detail/bls12/381/params.hpp>
#include <nil/crypto3/algebra/pairing/detail/bls12/377/params.hpp>
#include <nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0/ate_double_miller_loop.hpp>
#include <nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0/ate_miller_loop.hpp>
#include <nil/crypto3/algebra/pairing/forms/short_weierstrass/jacobian_with_a4_0/ate_precompute_g1.hpp>
Expand All @@ -45,7 +47,21 @@ namespace nil {
struct pairing_policy<curves::bls12<381>> {
using curve_type = curves::bls12<381>;

using chained_curve_type = curves::jubjub;
using precompute_g1 = pairing::short_weierstrass_jacobian_with_a4_0_ate_precompute_g1<curve_type>;
using precompute_g2 = pairing::short_weierstrass_jacobian_with_a4_0_ate_precompute_g2<curve_type>;
using miller_loop = pairing::short_weierstrass_jacobian_with_a4_0_ate_miller_loop<curve_type>;
using double_miller_loop =
pairing::short_weierstrass_jacobian_with_a4_0_ate_double_miller_loop<curve_type>;
using final_exponentiation =
pairing::short_weierstrass_jacobian_with_a4_0_final_exponentiation<curve_type>;

using g1_precomputed_type = typename precompute_g1::g1_precomputed_type;
using g2_precomputed_type = typename precompute_g2::g2_precomputed_type;
};

template<>
struct pairing_policy<curves::bls12<377>> {
using curve_type = curves::bls12<377>;

using precompute_g1 = pairing::short_weierstrass_jacobian_with_a4_0_ate_precompute_g1<curve_type>;
using precompute_g2 = pairing::short_weierstrass_jacobian_with_a4_0_ate_precompute_g2<curve_type>;
Expand All @@ -59,6 +75,7 @@ namespace nil {
using g2_precomputed_type = typename precompute_g2::g2_precomputed_type;
};


} // namespace pairing
} // namespace algebra
} // namespace crypto3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
#ifndef CRYPTO3_ALGEBRA_PAIRING_BLS12_377_BASIC_PARAMS_HPP
#define CRYPTO3_ALGEBRA_PAIRING_BLS12_377_BASIC_PARAMS_HPP

#include <nil/crypto3/algebra/curves/detail/bls12/g1.hpp>
#include <nil/crypto3/algebra/curves/detail/bls12/g2.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>

namespace nil {
namespace crypto3 {
Expand All @@ -49,27 +48,36 @@ namespace nil {
constexpr static const std::size_t integral_type_max_bits =
curve_type::base_field_type::modulus_bits;

constexpr static const std::size_t integral_type_max_bits = base_field_bits;

constexpr static const integral_type ate_loop_count = integral_type(0x8508C00000000001_cppui_modular64);
constexpr static const bool ate_is_loop_count_neg = false;
constexpr static const integral_type ate_loop_count =
0x8508C00000000001_cppui_modular64;
constexpr static const bool ate_is_loop_count_neg =
false;
// constexpr static const extended_integral_type final_exponent = extended_integral_type(
// 0x1B2FF68C1ABDC48AB4F04ED12CC8F9B2F161B41C7EB8865B9AD3C9BB0571DD94C6BDE66548DC13624D9D741024CEB315F46A89CC2482605EB6AFC6D8977E5E2CCBEC348DD362D59EC2B5BC62A1B467AE44572215548ABC98BB4193886ED89CCEAEDD0221ABA84FB33E5584AC29619A87A00C315178155496857C995EAB4A8A9AF95F4015DB27955AE408D6927D0AB37D52F3917C4DDEC88F8159F7BCBA7EB65F1AAE4EEB4E70CB20227159C08A7FDFEA9B62BB308918EAC3202569DD1BCDD86B431E3646356FC3FB79F89B30775E006993ADB629586B6C874B7688F86F11EF7AD94A40EB020DA3C532B317232FA56DC564637B331A8E8832EAB84269F00B506602C8594B7F7DA5A5D8D851FFF6AB1D38A354FC8E0B8958E2A9E5CE2D7E50EC36D761D9505FE5E1F317257E2DF2952FCD4C93B85278C20488B4CCAEE94DB3FEC1CE8283473E4B493843FA73ABE99AF8BAFCE29170B2B863B9513B5A47312991F60C5A4F6872B5D574212BF00D797C0BEA3C0F7DFD748E63679FDA9B1C50F2DF74DE38F38E004AE0DF997A10DB31D209CACBF58BA0678BFE7CD0985BC43258D72D8D5106C21635AE1E527EB01FCA3032D50D97756EC9EE756EABA7F21652A808A4E2539E838EF7EC4B178B29E3B976C46BD0ECDD32C1FB75E6E0AEF2D8B5661F595A98023F3520381ABA8DA6CCE785DBB0A0BBA025478D75EE749619CDB7C42A21098ECE86A00C6C2046C1E00000063C69000000000000_cppui_modular4269);

constexpr static const integral_type final_exponent_z =
integral_type(0x8508C00000000001_cppui_modular64);
constexpr static const bool final_exponent_is_z_neg = false;
0x8508C00000000001_cppui_modular64;
constexpr static const bool final_exponent_is_z_neg =
false;

using g2_field_type_value = typename curve_type::template g2_type<>::field_type::value_type;

using g2_field_type_value = typename curve_type::g2_type::field_type::value_type;
constexpr static const g2_field_type_value twist =
curve_type::template g2_type<>::params_type::twist;

constexpr static const g2_field_type_value twist = g2_type::params_type::twist;
constexpr static const g2_field_type_value twist_coeff_b =
curve_type::template g2_type<>::params_type::b;
};

constexpr typename pairing_params<curves::bls12<377>>::integral_type const
pairing_params<curves::bls12<377>>::ate_loop_count;

constexpr typename pairing_params<curves::bls12<377>>::integral_type const
pairing_params<curves::bls12<377>>::final_exponent_z;
constexpr typename pairing_params<curves::bls12<377>>::g2_field_type_value const
pairing_params<curves::bls12<377>>::twist;
constexpr typename pairing_params<curves::bls12<377>>::g2_field_type_value const
pairing_params<curves::bls12<377>>::twist_coeff_b;

constexpr bool const pairing_params<curves::bls12<377>>::final_exponent_is_z_neg;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ namespace nil {
constexpr static const std::size_t integral_type_max_bits =
curve_type::base_field_type::modulus_bits;

constexpr static const integral_type ate_loop_count = 0xD201000000010000_cppui_modular64;
constexpr static const bool ate_is_loop_count_neg = true;
constexpr static const integral_type ate_loop_count =
0xD201000000010000_cppui_modular64;
constexpr static const bool ate_is_loop_count_neg =
true;
// constexpr static const extended_integral_type final_exponent = extended_integral_type(
// 0x2EE1DB5DCC825B7E1BDA9C0496A1C0A89EE0193D4977B3F7D4507D07363BAA13F8D14A917848517BADC3A43D1073776AB353F2C30698E8CC7DEADA9C0AADFF5E9CFEE9A074E43B9A660835CC872EE83FF3A0F0F1C0AD0D6106FEAF4E347AA68AD49466FA927E7BB9375331807A0DCE2630D9AA4B113F414386B0E8819328148978E2B0DD39099B86E1AB656D2670D93E4D7ACDD350DA5359BC73AB61A0C5BF24C374693C49F570BCD2B01F3077FFB10BF24DDE41064837F27611212596BC293C8D4C01F25118790F4684D0B9C40A68EB74BB22A40EE7169CDC1041296532FEF459F12438DFC8E2886EF965E61A474C5C85B0129127A1B5AD0463434724538411D1676A53B5A62EB34C05739334F46C02C3F0BD0C55D3109CD15948D0A1FAD20044CE6AD4C6BEC3EC03EF19592004CEDD556952C6D8823B19DADD7C2498345C6E5308F1C511291097DB60B1749BF9B71A9F9E0100418A3EF0BC627751BBD81367066BCA6A4C1B6DCFC5CCEB73FC56947A403577DFA9E13C24EA820B09C1D9F7C31759C3635DE3F7A3639991708E88ADCE88177456C49637FD7961BE1A4C7E79FB02FAA732E2F3EC2BEA83D196283313492CAA9D4AFF1C910E9622D2A73F62537F2701AAEF6539314043F7BBCE5B78C7869AEB2181A67E49EEED2161DAF3F881BD88592D767F67C4717489119226C2F011D4CAB803E9D71650A6F80698E2F8491D12191A04406FBC8FBD5F48925F98630E68BFB24C0BCB9B55DF57510_cppui_modular4314);

constexpr static const integral_type final_exponent_z = 0xD201000000010000_cppui_modular64;
constexpr static const bool final_exponent_is_z_neg = true;
constexpr static const integral_type final_exponent_z =
0xD201000000010000_cppui_modular64;
constexpr static const bool final_exponent_is_z_neg =
true;

using g2_field_type_value = typename curve_type::template g2_type<>::field_type::value_type;

Expand Down

0 comments on commit d3f0f7b

Please sign in to comment.