Add and use Random::shuffle.
This commit is contained in:
parent
af54239018
commit
4b7c1aee03
@ -19,7 +19,6 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
|
||||
namespace td {
|
||||
namespace mtproto {
|
||||
@ -398,10 +397,7 @@ class TlsHelloStore {
|
||||
CHECK(storer.get_offset() == data.size());
|
||||
parts.push_back(std::move(data));
|
||||
}
|
||||
for (size_t i = 1; i < parts.size(); i++) {
|
||||
auto pos = static_cast<size_t>(Random::secure_int32()) % (i + 1);
|
||||
std::swap(parts[i], parts[pos]);
|
||||
}
|
||||
Random::shuffle(parts);
|
||||
for (auto &part : parts) {
|
||||
dest_.copy_from(part);
|
||||
dest_.remove_prefix(part.size());
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/Slice.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace td {
|
||||
|
||||
class Random {
|
||||
@ -24,6 +26,15 @@ class Random {
|
||||
// works only for current thread
|
||||
static void add_seed(Slice bytes, double entropy = 0);
|
||||
static void secure_cleanup();
|
||||
|
||||
template <class T>
|
||||
static void shuffle(vector<T> &v) {
|
||||
for (size_t i = 1; i < v.size(); i++) {
|
||||
auto pos = static_cast<size_t>(secure_int32()) % (i + 1);
|
||||
using std::swap;
|
||||
swap(v[i], v[pos]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static uint32 fast_uint32();
|
||||
|
Loading…
Reference in New Issue
Block a user