diff --git a/src/calculate_bucket.hpp b/src/calculate_bucket.hpp index c5571a06e..aead712ff 100644 --- a/src/calculate_bucket.hpp +++ b/src/calculate_bucket.hpp @@ -49,7 +49,7 @@ const uint16_t kC = 127; const uint16_t kBC = kB * kC; // This (times k) is the length of the metadata that must be kept for each entry. For example, -// for a tbale 4 entry, we must keep 4k additional bits for each entry, which is used to +// for a table 4 entry, we must keep 4k additional bits for each entry, which is used to // compute f5. static const uint8_t kVectorLens[] = {0, 0, 1, 2, 4, 4, 3, 2}; @@ -72,7 +72,7 @@ void load_tables() // Class to evaluate F1 class F1Calculator { public: - F1Calculator() {} + F1Calculator() = default; inline F1Calculator(uint8_t k, const uint8_t* orig_key) { @@ -166,13 +166,13 @@ class F1Calculator { uint64_t start = first_x * k_ / kF1BlockSizeBits; // 'end' is one past the last keystream block number to be generated uint64_t end = cdiv((first_x + n) * k_, kF1BlockSizeBits); - uint64_t n_blks = end - start; + uint64_t num_blocks = end - start; uint32_t start_bit = first_x * k_ % kF1BlockSizeBits; uint8_t x_shift = k_ - kExtraBits; assert(n <= (1U << kBatchSizes)); - chacha8_get_keystream(&this->enc_ctx_, start, n_blks, buf_); + chacha8_get_keystream(&this->enc_ctx_, start, num_blocks, buf_); for (uint64_t x = first_x; x < first_x + n; x++) { uint64_t y = Util::SliceInt64FromBytes(buf_, start_bit, k_); @@ -184,12 +184,12 @@ class F1Calculator { private: // Size of the plot - uint8_t k_; + uint8_t k_{}; // ChaCha8 context - struct chacha8_ctx enc_ctx_; + struct chacha8_ctx enc_ctx_{}; - uint8_t *buf_; + uint8_t *buf_{}; }; struct rmap_item { @@ -200,7 +200,7 @@ struct rmap_item { // Class to evaluate F2 .. F7. class FxCalculator { public: - FxCalculator() {} + FxCalculator() = default; inline FxCalculator(uint8_t k, uint8_t table_index) { @@ -214,7 +214,7 @@ class FxCalculator { } } - inline ~FxCalculator() {} + inline ~FxCalculator() = default; // Disable copying FxCalculator(const FxCalculator&) = delete; @@ -264,7 +264,7 @@ class FxCalculator { } // Given two buckets with entries (y values), computes which y values match, and returns a list - // of the pairs of indeces into bucket_L and bucket_R. Indeces l and r match iff: + // of the pairs of indices into bucket_L and bucket_R. Indices l and r match iff: // let yl = bucket_L[l].y, yr = bucket_R[r].y // // For any 0 <= m < kExtraBitsPow: @@ -285,8 +285,7 @@ class FxCalculator { int32_t idx_count = 0; uint16_t parity = (bucket_L[0].y / kBC) % 2; - for (size_t i = 0; i < rmap_clean.size(); i++) { - uint16_t yl = rmap_clean[i]; + for (size_t yl : rmap_clean) { this->rmap[yl].count = 0; } rmap_clean.clear(); @@ -308,7 +307,7 @@ class FxCalculator { for (uint8_t i = 0; i < kExtraBitsPow; i++) { uint16_t r_target = L_targets[parity][r][i]; for (size_t j = 0; j < rmap[r_target].count; j++) { - if(idx_L != NULL) { + if(idx_L != nullptr) { idx_L[idx_count]=pos_L; idx_R[idx_count]=rmap[r_target].pos + j; } @@ -320,8 +319,8 @@ class FxCalculator { } private: - uint8_t k_; - uint8_t table_index_; + uint8_t k_{}; + uint8_t table_index_{}; std::vector rmap; std::vector rmap_clean; }; diff --git a/src/util.hpp b/src/util.hpp index 2933fa2cb..3e97de3e8 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -162,28 +162,6 @@ namespace Util { return s.str(); } - inline void WriteZeroesHeap(std::ofstream &file, uint32_t num_bytes) - { - uint8_t *buf = new uint8_t[num_bytes]; - memset(buf, 0, num_bytes); - file.write(reinterpret_cast(buf), num_bytes); - delete[] buf; - } - - inline void WriteZeroesStack(std::ofstream &file, uint32_t num_bytes) - { -#ifdef _WIN32 - uint8_t *buf = new uint8_t[num_bytes]; - memset(buf, 0, num_bytes); - file.write(reinterpret_cast(buf), num_bytes); - delete[] buf; -#else - uint8_t buf[num_bytes]; - memset(buf, 0, num_bytes); - file.write(reinterpret_cast(buf), num_bytes); -#endif - } - inline void IntToTwoBytes(uint8_t *result, const uint16_t input) { uint16_t r = bswap_16(input); @@ -204,25 +182,6 @@ namespace Util { return bswap_16(i); } - /* - * Converts a 32 bit int to bytes. - */ - inline void IntToFourBytes(uint8_t *result, const uint32_t input) - { - uint32_t r = bswap_32(input); - memcpy(result, &r, sizeof(r)); - } - - /* - * Converts a byte array to a 32 bit int. - */ - inline uint32_t FourBytesToInt(const uint8_t *bytes) - { - uint32_t i; - memcpy(&i, bytes, sizeof(i)); - return bswap_32(i); - } - /* * Converts a 64 bit int to bytes. */ @@ -380,48 +339,6 @@ namespace Util { double b = ldexp(frac, exp); return b; } - - inline uint64_t find_islands(std::vector > edges) - { - std::map > edge_indeces; - for (uint64_t edge_index = 0; edge_index < edges.size(); edge_index++) { - edge_indeces[edges[edge_index].first].push_back(edge_index); - edge_indeces[edges[edge_index].second].push_back(edge_index); - } - std::set visited_nodes; - std::queue nodes_to_visit; - uint64_t num_islands = 0; - for (auto new_edge : edges) { - uint64_t old_size = visited_nodes.size(); - if (visited_nodes.find(new_edge.first) == visited_nodes.end()) { - visited_nodes.insert(new_edge.first); - nodes_to_visit.push(new_edge.first); - } - if (visited_nodes.find(new_edge.second) == visited_nodes.end()) { - visited_nodes.insert(new_edge.second); - nodes_to_visit.push(new_edge.second); - } - while (!nodes_to_visit.empty()) { - uint64_t node = nodes_to_visit.front(); - nodes_to_visit.pop(); - for (uint64_t edge_index : edge_indeces[node]) { - std::pair edge = edges[edge_index]; - if (visited_nodes.find(edge.first) == visited_nodes.end()) { - visited_nodes.insert(edge.first); - nodes_to_visit.push(edge.first); - } - if (visited_nodes.find(edge.second) == visited_nodes.end()) { - visited_nodes.insert(edge.second); - nodes_to_visit.push(edge.second); - } - } - } - if (visited_nodes.size() > old_size) { - num_islands++; - } - } - return num_islands; - } } #endif // SRC_CPP_UTIL_HPP_ diff --git a/src/verifier.hpp b/src/verifier.hpp index 21edc9227..36ad514d1 100644 --- a/src/verifier.hpp +++ b/src/verifier.hpp @@ -74,7 +74,7 @@ class Verifier { F1Calculator f1(k, id); for (uint8_t i = 0; i < 64; i++) - proof.push_back(Bits(proof_bits.SliceBitsToInt(k * i, k * (i + 1)), k)); + proof.emplace_back(proof_bits.SliceBitsToInt(k * i, k * (i + 1)), k); // Calculates f1 for each of the given xs. Note that the proof is in proof order. for (uint8_t i = 0; i < 64; i++) { @@ -89,8 +89,8 @@ class Verifier { std::vector new_ys; std::vector new_metadata; for (int i = 0; i < (1 << (8 - depth)); i += 2) { - PlotEntry l_plot_entry; - PlotEntry r_plot_entry; + PlotEntry l_plot_entry{}; + PlotEntry r_plot_entry{}; l_plot_entry.y = ys[i].GetValue(); r_plot_entry.y = ys[i + 1].GetValue(); std::vector bucket_L = {l_plot_entry}; @@ -101,7 +101,7 @@ class Verifier { if (cdiff != 1) { return LargeBits(); } else { - if(f.FindMatches(bucket_L, bucket_R, NULL, NULL) != 1) { + if(f.FindMatches(bucket_L, bucket_R, nullptr, nullptr) != 1) { return LargeBits(); } } @@ -111,8 +111,8 @@ class Verifier { new_ys.push_back(std::get<0>(results)); new_metadata.push_back(std::get<1>(results)); } - for (size_t i = 0; i < new_ys.size(); i++) { - if (new_ys[i].GetSize() <= 0) { + for (auto & new_y : new_ys) { + if (new_y.GetSize() <= 0) { return LargeBits(); } } @@ -136,7 +136,7 @@ class Verifier { private: // Compares two lists of k values, a and b. a > b iff max(a) > max(b), // if there is a tie, the next largest value is compared. - static bool CompareProofBits(LargeBits left, LargeBits right, uint8_t k) + static bool CompareProofBits(const LargeBits& left, const LargeBits& right, uint8_t k) { uint16_t size = left.GetSize() / k; assert(left.GetSize() == right.GetSize());