diff --git a/src/carrot_core/account_secrets.cpp b/src/carrot_core/account_secrets.cpp index 2f8b16d56..c7c8652fb 100644 --- a/src/carrot_core/account_secrets.cpp +++ b/src/carrot_core/account_secrets.cpp @@ -51,7 +51,7 @@ void make_carrot_provespend_key(const crypto::secret_key &s_master, { // k_ps = H_n(s_m) const auto transcript = sp::make_fixed_transcript(); - derive_scalar(transcript.data(), transcript.size, &s_master, to_bytes(k_prove_spend_out)); + derive_scalar(transcript.data(), transcript.size(), &s_master, to_bytes(k_prove_spend_out)); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_viewbalance_secret(const crypto::secret_key &s_master, @@ -59,7 +59,7 @@ void make_carrot_viewbalance_secret(const crypto::secret_key &s_master, { // s_vb = H_32(s_m) const auto transcript = sp::make_fixed_transcript(); - derive_bytes_32(transcript.data(), transcript.size, &s_master, to_bytes(s_view_balance_out)); + derive_bytes_32(transcript.data(), transcript.size(), &s_master, to_bytes(s_view_balance_out)); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_generateimage_key(const crypto::secret_key &s_view_balance, @@ -67,7 +67,7 @@ void make_carrot_generateimage_key(const crypto::secret_key &s_view_balance, { // k_gi = H_n(s_vb) const auto transcript = sp::make_fixed_transcript(); - derive_scalar(transcript.data(), transcript.size, &s_view_balance, to_bytes(k_generate_image_out)); + derive_scalar(transcript.data(), transcript.size(), &s_view_balance, to_bytes(k_generate_image_out)); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_viewincoming_key(const crypto::secret_key &s_view_balance, @@ -75,7 +75,7 @@ void make_carrot_viewincoming_key(const crypto::secret_key &s_view_balance, { // k_v = H_n(s_vb) const auto transcript = sp::make_fixed_transcript(); - derive_scalar(transcript.data(), transcript.size, &s_view_balance, to_bytes(k_view_out)); + derive_scalar(transcript.data(), transcript.size(), &s_view_balance, to_bytes(k_view_out)); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_generateaddress_secret(const crypto::secret_key &s_view_balance, @@ -83,7 +83,7 @@ void make_carrot_generateaddress_secret(const crypto::secret_key &s_view_balance { // s_ga = H_32(s_vb) const auto transcript = sp::make_fixed_transcript(); - derive_bytes_32(transcript.data(), transcript.size, &s_view_balance, to_bytes(s_generate_address_out)); + derive_bytes_32(transcript.data(), transcript.size(), &s_view_balance, to_bytes(s_generate_address_out)); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_spend_pubkey(const crypto::secret_key &k_generate_image, diff --git a/src/carrot_core/address_utils.cpp b/src/carrot_core/address_utils.cpp index bfa429f31..d27479144 100644 --- a/src/carrot_core/address_utils.cpp +++ b/src/carrot_core/address_utils.cpp @@ -52,7 +52,7 @@ void make_carrot_index_extension_generator(const crypto::secret_key &s_generate_ { // s^j_gen = H_32[s_ga](j_major, j_minor) const auto transcript = sp::make_fixed_transcript(j_major, j_minor); - derive_bytes_32(transcript.data(), transcript.size, &s_generate_address, &address_generator_out); + derive_bytes_32(transcript.data(), transcript.size(), &s_generate_address, &address_generator_out); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_subaddress_scalar(const crypto::public_key &spend_pubkey, @@ -64,7 +64,7 @@ void make_carrot_subaddress_scalar(const crypto::public_key &spend_pubkey, // k^j_subscal = H_n(K_s, j_major, j_minor, s^j_gen) const auto transcript = sp::make_fixed_transcript( spend_pubkey, j_major, j_minor); - derive_scalar(transcript.data(), transcript.size, &s_address_generator, subaddress_scalar_out.data); + derive_scalar(transcript.data(), transcript.size(), &s_address_generator, subaddress_scalar_out.data); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_address_spend_pubkey(const crypto::public_key &spend_pubkey, diff --git a/src/carrot_core/enote_utils.cpp b/src/carrot_core/enote_utils.cpp index 72f24cff5..98c82ad39 100644 --- a/src/carrot_core/enote_utils.cpp +++ b/src/carrot_core/enote_utils.cpp @@ -88,7 +88,7 @@ void make_carrot_enote_ephemeral_privkey(const janus_anchor_t &anchor_norm, // k_e = (H_64(anchor_norm, input_context, K^j_s, K^j_v, pid)) mod l const auto transcript = sp::make_fixed_transcript( anchor_norm, input_context, address_spend_pubkey, address_view_pubkey, payment_id); - derive_scalar(transcript.data(), transcript.size, nullptr, &enote_ephemeral_privkey_out); + derive_scalar(transcript.data(), transcript.size(), nullptr, &enote_ephemeral_privkey_out); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_enote_ephemeral_pubkey_cryptonote(const crypto::secret_key &enote_ephemeral_privkey, @@ -163,7 +163,7 @@ void make_carrot_view_tag(const unsigned char s_sender_receiver_unctx[32], { // vt = H_3(s_sr || input_context || Ko) const auto transcript = sp::make_fixed_transcript(input_context, onetime_address); - derive_bytes_3(transcript.data(), transcript.size, s_sender_receiver_unctx, &view_tag_out); + derive_bytes_3(transcript.data(), transcript.size(), s_sender_receiver_unctx, &view_tag_out); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_input_context_coinbase(const std::uint64_t block_index, input_context_t &input_context_out) @@ -189,7 +189,7 @@ void make_carrot_sender_receiver_secret(const unsigned char s_sender_receiver_un // s^ctx_sr = H_32(s_sr, D_e, input_context) const auto transcript = sp::make_fixed_transcript( enote_ephemeral_pubkey, input_context); - derive_bytes_32(transcript.data(), transcript.size, s_sender_receiver_unctx, &s_sender_receiver_out); + derive_bytes_32(transcript.data(), transcript.size(), s_sender_receiver_unctx, &s_sender_receiver_out); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_onetime_address_extension_g(const crypto::hash &s_sender_receiver, @@ -198,7 +198,7 @@ void make_carrot_onetime_address_extension_g(const crypto::hash &s_sender_receiv { // k^o_g = H_n("..g..", s^ctx_sr, C_a) const auto transcript = sp::make_fixed_transcript(amount_commitment); - derive_scalar(transcript.data(), transcript.size, &s_sender_receiver, &sender_extension_out); + derive_scalar(transcript.data(), transcript.size(), &s_sender_receiver, &sender_extension_out); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_onetime_address_extension_t(const crypto::hash &s_sender_receiver, @@ -207,7 +207,7 @@ void make_carrot_onetime_address_extension_t(const crypto::hash &s_sender_receiv { // k^o_t = H_n("..t..", s^ctx_sr, C_a) const auto transcript = sp::make_fixed_transcript(amount_commitment); - derive_scalar(transcript.data(), transcript.size, &s_sender_receiver, &sender_extension_out); + derive_scalar(transcript.data(), transcript.size(), &s_sender_receiver, &sender_extension_out); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_onetime_address_extension_pubkey(const crypto::hash &s_sender_receiver, @@ -253,7 +253,7 @@ void make_carrot_amount_blinding_factor(const crypto::hash &s_sender_receiver, // k_a = H_n(s^ctx_sr, enote_type) const auto transcript = sp::make_fixed_transcript( static_cast(enote_type)); - derive_scalar(transcript.data(), transcript.size, &s_sender_receiver, &amount_blinding_factor_out); + derive_scalar(transcript.data(), transcript.size(), &s_sender_receiver, &amount_blinding_factor_out); } //------------------------------------------------------------------------------------------------------------------- void make_carrot_anchor_encryption_mask(const crypto::hash &s_sender_receiver, @@ -262,7 +262,7 @@ void make_carrot_anchor_encryption_mask(const crypto::hash &s_sender_receiver, { // m_anchor = H_16(s^ctx_sr, Ko) const auto transcript = sp::make_fixed_transcript(onetime_address); - derive_bytes_16(transcript.data(), transcript.size, &s_sender_receiver, &anchor_encryption_mask_out); + derive_bytes_16(transcript.data(), transcript.size(), &s_sender_receiver, &anchor_encryption_mask_out); } //------------------------------------------------------------------------------------------------------------------- encrypted_janus_anchor_t encrypt_carrot_anchor(const janus_anchor_t &anchor, @@ -295,7 +295,7 @@ void make_carrot_amount_encryption_mask(const crypto::hash &s_sender_receiver, { // m_a = H_8(s^ctx_sr, Ko) const auto transcript = sp::make_fixed_transcript(onetime_address); - derive_bytes_8(transcript.data(), transcript.size, &s_sender_receiver, &amount_encryption_mask_out); + derive_bytes_8(transcript.data(), transcript.size(), &s_sender_receiver, &amount_encryption_mask_out); } //------------------------------------------------------------------------------------------------------------------- encrypted_amount_t encrypt_carrot_amount(const rct::xmr_amount amount, @@ -328,7 +328,7 @@ void make_carrot_payment_id_encryption_mask(const crypto::hash &s_sender_receive { // m_pid = H_8(s^ctx_sr, Ko) const auto transcript = sp::make_fixed_transcript(onetime_address); - derive_bytes_8(transcript.data(), transcript.size, &s_sender_receiver, &payment_id_encryption_mask_out); + derive_bytes_8(transcript.data(), transcript.size(), &s_sender_receiver, &payment_id_encryption_mask_out); } //------------------------------------------------------------------------------------------------------------------- encrypted_payment_id_t encrypt_legacy_payment_id(const payment_id_t payment_id, @@ -365,7 +365,7 @@ void make_carrot_janus_anchor_special(const crypto::x25519_pubkey &enote_ephemer // anchor_sp = H_16(D_e, input_context, Ko, k_v, K_s) const auto transcript = sp::make_fixed_transcript( enote_ephemeral_pubkey, input_context, account_spend_pubkey); - derive_bytes_16(transcript.data(), transcript.size, &k_view, &anchor_special_out); + derive_bytes_16(transcript.data(), transcript.size(), &k_view, &anchor_special_out); } //------------------------------------------------------------------------------------------------------------------- void recover_address_spend_pubkey(const crypto::public_key &onetime_address, diff --git a/src/carrot_core/transcript_fixed.h b/src/carrot_core/transcript_fixed.h index 8dcf2963e..3179cbe23 100644 --- a/src/carrot_core/transcript_fixed.h +++ b/src/carrot_core/transcript_fixed.h @@ -77,9 +77,6 @@ template class SpFixedTranscript final { public: -//public static member variables - static constexpr std::size_t size = 1 + SpFixedTranscript::domain_sep_size() + detail::sizeof_sum(); - //constructors /// normal constructor SpFixedTranscript(const Ts&... args) @@ -102,6 +99,11 @@ public: //member functions constexpr const void* data() const noexcept { return m_transcript; } + static constexpr std::size_t size() + { + return 1 + domain_sep_size() + detail::sizeof_sum(); + } + //destructors ~SpFixedTranscript() { @@ -171,7 +173,7 @@ private: //member variables /// the transcript buffer - unsigned char m_transcript[size]; + unsigned char m_transcript[size()]; }; template diff --git a/tests/unit_tests/carrot_transcript_fixed.cpp b/tests/unit_tests/carrot_transcript_fixed.cpp index e708a8ac7..860619a83 100644 --- a/tests/unit_tests/carrot_transcript_fixed.cpp +++ b/tests/unit_tests/carrot_transcript_fixed.cpp @@ -46,15 +46,15 @@ TEST(carrot_transcript_fixed, ts_size) { static constexpr const unsigned char DS1[] = "perspicacious"; const auto transcript1 = sp::make_fixed_transcript((uint32_t)32); - EXPECT_EQ(1 + 13 + 4, transcript1.size); + EXPECT_EQ(1 + 13 + 4, transcript1.size()); static constexpr const unsigned char DS2[] = "recrudescence"; const auto transcript2 = sp::make_fixed_transcript((uint32_t)32, (uint64_t)64); - EXPECT_EQ(1 + 13 + 4 + 8, transcript2.size); + EXPECT_EQ(1 + 13 + 4 + 8, transcript2.size()); // vt = H_3(s_sr || input_context || Ko) const auto transcript_vt = sp::make_fixed_transcript( carrot::input_context_t{}, crypto::public_key{}); - EXPECT_EQ(1 + 15 + 33 + 32, transcript_vt.size); + EXPECT_EQ(1 + 15 + 33 + 32, transcript_vt.size()); }