From: Ilya Dryomov Date: Fri, 3 Apr 2020 13:26:18 +0000 (+0200) Subject: msg/async/crypto_onwire: allow dynamic reset_tx_handler() sequences X-Git-Tag: v15.2.5~164^2~20 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=51c7e25caa0d48d9fbe3db7bfd1a48a56139d8bf;p=ceph.git msg/async/crypto_onwire: allow dynamic reset_tx_handler() sequences Provide an iterator-like interface as initializer lists cannot be formed dynamically. Signed-off-by: Ilya Dryomov (cherry picked from commit 1fc5cc2ba7f5fbff4e6270c9d87ef50b349cf2bf) --- diff --git a/src/msg/async/crypto_onwire.cc b/src/msg/async/crypto_onwire.cc index c39632cbd6e..596e578488c 100644 --- a/src/msg/async/crypto_onwire.cc +++ b/src/msg/async/crypto_onwire.cc @@ -74,15 +74,14 @@ public: return size; } - void reset_tx_handler( - std::initializer_list update_size_sequence) override; + void reset_tx_handler(const uint32_t* first, const uint32_t* last) override; void authenticated_encrypt_update(const ceph::bufferlist& plaintext) override; ceph::bufferlist authenticated_encrypt_final() override; }; -void AES128GCM_OnWireTxHandler::reset_tx_handler( - std::initializer_list update_size_sequence) +void AES128GCM_OnWireTxHandler::reset_tx_handler(const uint32_t* first, + const uint32_t* last) { if (nonce == initial_nonce) { if (used_initial_nonce) { @@ -96,8 +95,7 @@ void AES128GCM_OnWireTxHandler::reset_tx_handler( throw std::runtime_error("EVP_EncryptInit_ex failed"); } - buffer.reserve(std::accumulate(std::begin(update_size_sequence), - std::end(update_size_sequence), AESGCM_TAG_LEN)); + buffer.reserve(std::accumulate(first, last, AESGCM_TAG_LEN)); nonce.random_seq = nonce.random_seq + 1; } diff --git a/src/msg/async/crypto_onwire.h b/src/msg/async/crypto_onwire.h index 0c544f205ac..b605951b80e 100644 --- a/src/msg/async/crypto_onwire.h +++ b/src/msg/async/crypto_onwire.h @@ -67,8 +67,17 @@ struct TxHandler { // It's undefined what will happen if client doesn't follow the order. // // TODO: switch to always_aligned_t - virtual void reset_tx_handler( - std::initializer_list update_size_sequence) = 0; + virtual void reset_tx_handler(const uint32_t* first, + const uint32_t* last) = 0; + + void reset_tx_handler(std::initializer_list update_size_sequence) { + if (update_size_sequence.size() > 0) { + const uint32_t* first = &*update_size_sequence.begin(); + reset_tx_handler(first, first + update_size_sequence.size()); + } else { + reset_tx_handler(nullptr, nullptr); + } + } // Perform encryption. Client gives full ownership right to provided // bufferlist. The method MUST NOT be called after _final() if there