Use base/random.h instead of openssl::RandomValue.

This commit is contained in:
John Preston 2021-09-15 13:21:45 +03:00
parent 52721847f4
commit 8069fdd873
57 changed files with 208 additions and 166 deletions

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "api/api_cloud_password.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "core/core_cloud_password.h"
#include "apiwrap.h"
@ -27,7 +27,7 @@ void CloudPassword::reload() {
)).done([=](const MTPaccount_Password &result) {
_requestId = 0;
result.match([&](const MTPDaccount_password &data) {
openssl::AddRandomSeed(bytes::make_span(data.vsecure_random().v));
base::RandomAddSeed(bytes::make_span(data.vsecure_random().v));
if (_state) {
*_state = Core::ParseCloudPasswordState(data);
} else {

View File

@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_sending.h"
#include "api/api_text_entities.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/unixtime.h"
#include "data/data_document.h"
#include "data/data_photo.h"
@ -76,7 +76,7 @@ void SendExistingMedia(
const auto newId = FullMsgId(
peerToChannel(peer->id),
session->data().nextLocalMessageId());
const auto randomId = openssl::RandomValue<uint64>();
const auto randomId = base::RandomValue<uint64>();
auto flags = NewMessageFlags(peer);
auto sendFlags = MTPmessages_SendMedia::Flags(0);
@ -248,7 +248,7 @@ bool SendDice(Api::MessageToSend &message) {
const auto newId = FullMsgId(
peerToChannel(peer->id),
session->data().nextLocalMessageId());
const auto randomId = openssl::RandomValue<uint64>();
const auto randomId = base::RandomValue<uint64>();
auto &histories = history->owner().histories();
auto flags = NewMessageFlags(peer);

View File

@ -46,6 +46,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/core_cloud_password.h"
#include "core/application.h"
#include "base/unixtime.h"
#include "base/random.h"
#include "base/qt_adapters.h"
#include "base/call_delayed.h"
#include "lang/lang_keys.h"
@ -3724,7 +3725,7 @@ void ApiWrap::forwardMessages(
ids.reserve(count);
randomIds.reserve(count);
for (const auto item : draft.items) {
const auto randomId = openssl::RandomValue<uint64>();
const auto randomId = base::RandomValue<uint64>();
if (genClientSideMessage) {
if (const auto message = item->toHistoryMessage()) {
const auto newId = FullMsgId(
@ -4034,7 +4035,7 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
auto newId = FullMsgId(
peerToChannel(peer->id),
_session->data().nextLocalMessageId());
auto randomId = openssl::RandomValue<uint64>();
auto randomId = base::RandomValue<uint64>();
TextUtilities::Trim(sending);
@ -4158,7 +4159,7 @@ void ApiWrap::sendBotStart(not_null<UserData*> bot, PeerData *chat) {
sendMessage(std::move(message));
return;
}
const auto randomId = openssl::RandomValue<uint64>();
const auto randomId = base::RandomValue<uint64>();
request(MTPmessages_StartBot(
bot->inputUser,
chat ? chat->input : MTP_inputPeerEmpty(),
@ -4184,7 +4185,7 @@ void ApiWrap::sendInlineResult(
const auto newId = FullMsgId(
peerToChannel(peer->id),
_session->data().nextLocalMessageId());
const auto randomId = openssl::RandomValue<uint64>();
const auto randomId = base::RandomValue<uint64>();
auto flags = NewMessageFlags(peer);
auto sendFlags = MTPmessages_SendInlineBotResult::Flag::f_clear_draft | 0;
@ -4340,7 +4341,7 @@ void ApiWrap::sendMedia(
not_null<HistoryItem*> item,
const MTPInputMedia &media,
Api::SendOptions options) {
const auto randomId = openssl::RandomValue<uint64>();
const auto randomId = base::RandomValue<uint64>();
_session->data().registerMessageRandomId(randomId, item->fullId());
sendMediaWithRandomId(item, media, options, randomId);
@ -4414,7 +4415,7 @@ void ApiWrap::sendAlbumWithUploaded(
const MessageGroupId &groupId,
const MTPInputMedia &media) {
const auto localId = item->fullId();
const auto randomId = openssl::RandomValue<uint64>();
const auto randomId = base::RandomValue<uint64>();
_session->data().registerMessageRandomId(randomId, localId);
const auto albumIt = _sendingAlbums.find(groupId.raw());
@ -4768,7 +4769,7 @@ void ApiWrap::createPoll(
MTP_int(replyTo),
PollDataToInputMedia(&data),
MTP_string(),
MTP_long(openssl::RandomValue<uint64>()),
MTP_long(base::RandomValue<uint64>()),
MTPReplyMarkup(),
MTPVector<MTPMessageEntity>(),
MTP_int(action.options.scheduled)

View File

@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "lang/lang_keys.h"
#include "mtproto/sender.h"
#include "base/flat_set.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "boxes/confirm_box.h"
#include "boxes/peer_list_controllers.h"
#include "boxes/peers/add_participants_box.h"
@ -383,7 +383,7 @@ void AddContactBox::save() {
lastName = QString();
}
_sentName = firstName;
_contactId = openssl::RandomValue<uint64>();
_contactId = base::RandomValue<uint64>();
_addRequest = _session->api().request(MTPcontacts_ImportContacts(
MTP_vector<MTPInputContact>(
1,

View File

@ -30,7 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/unique_qptr.h"
#include "base/event_filter.h"
#include "base/call_delayed.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "window/window_session_controller.h"
#include "styles/style_layers.h"
#include "styles/style_boxes.h"
@ -885,7 +885,7 @@ not_null<Ui::InputField*> CreatePollBox::setupSolution(
object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
using namespace Settings;
const auto id = openssl::RandomValue<uint64>();
const auto id = base::RandomValue<uint64>();
const auto error = lifetime().make_state<Errors>(Error::Question);
auto result = object_ptr<Ui::VerticalLayout>(this);

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "boxes/peer_list_controllers.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "boxes/confirm_box.h"
#include "ui/widgets/checkbox.h"
#include "ui/ui_utility.h"
@ -36,7 +36,7 @@ void ShareBotGame(not_null<UserData*> bot, not_null<PeerData*> chat) {
auto &histories = history->owner().histories();
const auto requestType = Data::Histories::RequestType::Send;
histories.sendRequest(history, requestType, [=](Fn<void()> finish) {
const auto randomId = openssl::RandomValue<uint64>();
const auto randomId = base::RandomValue<uint64>();
const auto api = &chat->session().api();
history->sendRequestId = api->request(MTPmessages_SendMedia(
MTP_flags(0),

View File

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/rate_call_box.h"
#include "calls/calls_instance.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "mtproto/mtproto_dh_utils.h"
#include "mtproto/mtproto_config.h"
#include "core/application.h"
@ -233,7 +234,7 @@ void Call::startOutgoing() {
_api.request(MTPphone_RequestCall(
MTP_flags(flags),
_user->inputUser,
MTP_int(openssl::RandomValue<int32>()),
MTP_int(base::RandomValue<int32>()),
MTP_bytes(_gaHash),
MTP_phoneCallProtocol(
MTP_flags(MTPDphoneCallProtocol::Flag::f_udp_p2p

View File

@ -27,7 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_peer_values.h"
#include "data/data_session.h"
#include "base/global_shortcuts.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "webrtc/webrtc_video_track.h"
#include "webrtc/webrtc_media_devices.h"
#include "webrtc/webrtc_create_adm.h"
@ -1008,7 +1008,7 @@ void GroupCall::start(TimeId scheduleDate) {
_createRequestId = _api.request(MTPphone_CreateGroupCall(
MTP_flags(scheduleDate ? Flag::f_schedule_date : Flag(0)),
_peer->input,
MTP_int(openssl::RandomValue<int32>()),
MTP_int(base::RandomValue<int32>()),
MTPstring(), // title
MTP_int(scheduleDate)
)).done([=](const MTPUpdates &result) {

View File

@ -35,7 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/ui_utility.h"
#include "ui/cached_round_corners.h"
#include "base/unixtime.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "window/window_adaptive.h"
#include "window/window_session_controller.h"
#include "styles/style_chat.h"
@ -667,7 +667,7 @@ void FieldAutocomplete::showAnimated() {
return;
}
if (_cache.isNull()) {
_stickersSeed = openssl::RandomValue<uint64>();
_stickersSeed = base::RandomValue<uint64>();
_scroll->show();
_cache = Ui::GrabWidget(this);
}

View File

@ -371,11 +371,6 @@ char *hashMd5Hex(const int32 *hashmd5, void *dest) {
return md5To;
}
void memset_rand(void *data, uint32 len) {
Assert(_sslInited);
RAND_bytes((uchar*)data, len);
}
namespace {
QMap<QString, QString> fastRusEng;
QHash<QChar, QString> fastLetterRusEng;

View File

@ -109,9 +109,6 @@ inline std::array<char, 32> hashMd5Hex(const void *data, int size) {
return result;
}
// good random (using openssl implementation)
void memset_rand(void *data, uint32 len);
QString translitRusEng(const QString &rus);
QString rusKeyboardLayoutSwitch(const QString &from);

View File

@ -60,7 +60,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h"
#include "base/unixtime.h"
#include "base/call_delayed.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "facades.h" // Notify::switchInlineBotButtonReceived
#include "app.h"
#include "styles/style_boxes.h" // st::backgroundSize
@ -2427,7 +2427,7 @@ PhotoData *Session::photoFromWeb(
return nullptr;
}
return photo(
openssl::RandomValue<PhotoId>(),
base::RandomValue<PhotoId>(),
uint64(0),
QByteArray(),
base::unixtime::now(),
@ -2692,7 +2692,7 @@ DocumentData *Session::documentFromWeb(
const ImageLocation &thumbnailLocation,
const ImageLocation &videoThumbnailLocation) {
const auto result = document(
openssl::RandomValue<DocumentId>(),
base::RandomValue<DocumentId>(),
uint64(0),
QByteArray(),
base::unixtime::now(),
@ -2714,7 +2714,7 @@ DocumentData *Session::documentFromWeb(
const ImageLocation &thumbnailLocation,
const ImageLocation &videoThumbnailLocation) {
const auto result = document(
openssl::RandomValue<DocumentId>(),
base::RandomValue<DocumentId>(),
uint64(0),
QByteArray(),
base::unixtime::now(),

View File

@ -24,7 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtproto_config.h"
#include "ui/toast/toast.h"
#include "ui/image/image_location_factory.h"
#include "base/openssl_help.h"
#include "base/unixtime.h"
#include "styles/style_chat_helpers.h"

View File

@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtproto_response.h"
#include "base/value_ordering.h"
#include "base/bytes.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include <set>
#include <deque>
@ -1748,7 +1748,7 @@ auto ApiWrap::prepareFileProcess(
result->location = file.location;
result->size = file.size;
result->origin = origin;
result->randomId = openssl::RandomValue<uint64>();
result->randomId = base::RandomValue<uint64>();
return result;
}

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "history/history_message.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/unixtime.h"
#include "lang/lang_keys.h"
#include "mainwidget.h"
@ -279,10 +279,10 @@ void FastShareMessage(not_null<HistoryItem*> item) {
for (const auto &fullId : data->msgIds) {
msgIds.push_back(MTP_int(fullId.msg));
}
auto generateRandom = [&] {
const auto generateRandom = [&] {
auto result = QVector<MTPlong>(data->msgIds.size());
for (auto &value : result) {
value = openssl::RandomValue<MTPlong>();
value = base::RandomValue<MTPlong>();
}
return result;
};

View File

@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_send_progress.h"
#include "base/event_filter.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/unixtime.h"
#include "boxes/confirm_box.h"
#include "core/application.h"
@ -98,7 +98,7 @@ enum class FilterType {
[[nodiscard]] not_null<DocumentData*> DummyDocument(
not_null<Data::Session*> owner) {
return owner->document(
openssl::RandomValue<DocumentId>(),
base::RandomValue<DocumentId>(),
uint64(0),
QByteArray(),
base::unixtime::now(),

View File

@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "inline_bots/inline_bot_result.h"
#include "api/api_text_entities.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "data/data_photo.h"
#include "data/data_document.h"
#include "data/data_session.h"
@ -416,7 +416,7 @@ void Result::createGame(not_null<Main::Session*> session) {
return;
}
const auto gameId = openssl::RandomValue<GameId>();
const auto gameId = base::RandomValue<GameId>();
_game = session->data().game(
gameId,
0,

View File

@ -18,7 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/input_fields.h"
#include "ui/widgets/labels.h"
#include "main/main_account.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "styles/style_intro.h"
#include "styles/style_boxes.h"
@ -192,7 +192,7 @@ void PasswordCheckWidget::requestPasswordData() {
).done([=](const MTPaccount_Password &result) {
_sentRequest = 0;
result.match([&](const MTPDaccount_password &data) {
openssl::AddRandomSeed(bytes::make_span(data.vsecure_random().v));
base::RandomAddSeed(bytes::make_span(data.vsecure_random().v));
_passwordState = Core::ParseCloudPasswordState(data);
passwordChecked();
});

View File

@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "media/clip/media_clip_ffmpeg.h"
#include "media/clip/media_clip_check_streaming.h"
#include "core/file_location.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/invoke_queued.h"
#include "logs.h"
@ -115,7 +115,7 @@ void Reader::init(const Core::FileLocation &location, const QByteArray &data) {
managers.push_back(new Manager(threads.back()));
threads.back()->start();
} else {
_threadIndex = int32(openssl::RandomValue<uint32>() % threads.size());
_threadIndex = int32(base::RandomValue<uint32>() % threads.size());
int32 loadLevel = 0x7FFFFFFF;
for (int32 i = 0, l = threads.size(); i < l; ++i) {
int32 level = managers.at(i)->loadLevel();

View File

@ -58,7 +58,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_session_controller.h"
#include "window/window_controller.h"
#include "base/platform/base_platform_info.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/unixtime.h"
#include "base/qt_signal_producer.h"
#include "base/event_filter.h"
@ -2847,7 +2847,7 @@ void OverlayWidget::initThemePreview() {
const auto weakSession = base::make_weak(&_document->session());
const auto path = _document->location().name();
const auto id = _themePreviewId = openssl::RandomValue<uint64>();
const auto id = _themePreviewId = base::RandomValue<uint64>();
const auto weak = Ui::MakeWeak(_widget);
crl::async([=, data = std::move(current)]() mutable {
auto preview = GeneratePreview(

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "mtproto/config_loader.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "mtproto/special_config_request.h"
#include "mtproto/facade.h"
#include "mtproto/mtproto_dc_options.h"
@ -185,8 +185,7 @@ void ConfigLoader::sendSpecialRequest() {
}
const auto weak = base::make_weak(this);
const auto index = openssl::RandomValue<uint32>()
% _specialEndpoints.size();
const auto index = base::RandomValue<uint32>() % _specialEndpoints.size();
const auto endpoint = _specialEndpoints.begin() + index;
_specialEnumCurrent = specialToRealDcId(endpoint->dcId);

View File

@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/connection_resolving.h"
#include "mtproto/session.h"
#include "base/unixtime.h"
#include "base/openssl_help.h"
#include "base/random.h"
namespace MTP {
namespace details {
@ -189,7 +189,7 @@ ConnectionPointer AbstractConnection::Create(
}
uint32 AbstractConnection::extendedNotSecurePadding() const {
return uint32(openssl::RandomValue<uchar>() & 0x3F);
return uint32(base::RandomValue<uchar>() & 0x3F);
}
} // namespace details

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "mtproto/connection_http.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/qthelp_url.h"
namespace MTP {
@ -21,7 +21,7 @@ constexpr auto kFullConnectionTimeout = crl::time(8000);
HttpConnection::HttpConnection(QThread *thread, const ProxyData &proxy)
: AbstractConnection(thread, proxy)
, _checkNonce(openssl::RandomValue<MTPint128>()) {
, _checkNonce(base::RandomValue<MTPint128>()) {
_manager.moveToThread(thread);
_manager.setProxy(ToNetworkProxy(proxy));
}

View File

@ -10,12 +10,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/details/mtproto_abstract_socket.h"
#include "base/bytes.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/qthelp_url.h"
extern "C" {
#include <openssl/aes.h>
} // extern "C"
namespace MTP {
namespace details {
namespace {
@ -181,11 +178,11 @@ bytes::span TcpConnection::Protocol::VersionD::finalizePacket(
Expects(buffer.size() > 2 && buffer.size() < 0x1000003U);
const auto intsSize = uint32(buffer.size() - 2);
const auto padding = openssl::RandomValue<uint32>() & 0x0F;
const auto padding = base::RandomValue<uint32>() & 0x0F;
const auto bytesSize = intsSize * sizeof(mtpPrime) + padding;
buffer[1] = bytesSize;
for (auto added = 0; added < padding; added += 4) {
buffer.push_back(openssl::RandomValue<mtpPrime>());
buffer.push_back(base::RandomValue<mtpPrime>());
}
return bytes::make_span(buffer).subspan(4, 4 + bytesSize);
@ -233,7 +230,7 @@ TcpConnection::TcpConnection(
const ProxyData &proxy)
: AbstractConnection(thread, proxy)
, _instance(instance)
, _checkNonce(openssl::RandomValue<MTPint128>()) {
, _checkNonce(base::RandomValue<MTPint128>()) {
}
ConnectionPointer TcpConnection::clone(const ProxyData &proxy) {

View File

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtp_instance.h"
#include "base/unixtime.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "scheme.h"
#include <QtCore/QPointer>
@ -84,7 +85,7 @@ SerializedRequest DcKeyBinder::prepareRequest(
Expects(temporaryKey != nullptr);
Expects(temporaryKey->expiresAt() != 0);
const auto nonce = openssl::RandomValue<uint64>();
const auto nonce = base::RandomValue<uint64>();
const auto msgId = base::unixtime::mtproto_msg_id();
auto result = SerializedRequest::Serialize(MTPauth_BindTempAuthKey(
MTP_long(_persistentKey->keyId()),

View File

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/connection_abstract.h"
#include "mtproto/mtproto_dh_utils.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/unixtime.h"
#include "scheme.h"
#include "logs.h"
@ -99,6 +100,8 @@ template <typename PQInnerData>
[[nodiscard]] bytes::vector EncryptPQInnerRSA(
const PQInnerData &data,
const RSAPublicKey &key) {
DEBUG_LOG(("AuthKey Info: encrypting pq inner..."));
constexpr auto kPrime = sizeof(mtpPrime);
constexpr auto kDataWithPaddingPrimes = 192 / kPrime;
constexpr auto kMaxSizeInPrimes = 144 / kPrime;
@ -126,6 +129,8 @@ template <typename PQInnerData>
const auto dataWithPaddingBytes = bytes::make_span(dataWithPadding);
bytes::set_random(dataWithPaddingBytes.subspan(sizeInPrimes * kPrime));
DEBUG_LOG(("AuthKey Info: starting key generation for pq inner..."));
while (true) {
auto dataWithHash = mtpBuffer();
dataWithHash.reserve(kDataWithPaddingPrimes + kDataHashPrimes);
@ -136,7 +141,7 @@ template <typename PQInnerData>
// data_with_hash := data_pad_reversed
// + SHA256(temp_key + data_with_padding);
const auto tempKey = openssl::RandomValue<bytes::array<kKeySize>>();
const auto tempKey = base::RandomValue<bytes::array<kKeySize>>();
dataWithHash.resize(kDataWithPaddingPrimes + kDataHashPrimes);
const auto dataWithHashBytes = bytes::make_span(dataWithHash);
bytes::copy(
@ -148,6 +153,8 @@ template <typename PQInnerData>
aesEncrypted.resize(dataWithHash.size());
const auto aesEncryptedBytes = bytes::make_span(aesEncrypted);
DEBUG_LOG(("AuthKey Info: encrypting ige for pq inner..."));
// aes_encrypted := AES256_IGE(data_with_hash, temp_key, 0);
const auto tempIv = bytes::array<kIvSize>{ { bytes::type(0) } };
aesIgeEncryptRaw(
@ -157,6 +164,8 @@ template <typename PQInnerData>
tempKey.data(),
tempIv.data());
DEBUG_LOG(("AuthKey Info: counting hash for pq inner..."));
// temp_key_xor := temp_key XOR SHA256(aes_encrypted);
const auto fullSize = (kKeySize / kPrime) + dataWithHash.size();
keyAesEncrypted.resize(fullSize);
@ -166,13 +175,18 @@ template <typename PQInnerData>
keyAesEncryptedBytes[i] = tempKey[i] ^ aesHash[i];
}
DEBUG_LOG(("AuthKey Info: checking chosen key for pq inner..."));
// key_aes_encrypted := temp_key_xor + aes_encrypted;
bytes::copy(
keyAesEncryptedBytes.subspan(kKeySize),
aesEncryptedBytes);
if (IsGoodEncryptedInner(keyAesEncryptedBytes, key)) {
DEBUG_LOG(("AuthKey Info: chosen key for pq inner is good."));
return key.encrypt(keyAesEncryptedBytes);
}
DEBUG_LOG(("AuthKey Info: chosen key for pq inner is bad..."));
}
}
@ -360,7 +374,7 @@ void DcKeyCreator::pqSend(not_null<Attempt*> attempt, TimeId expiresIn) {
).arg(expiresIn ? "temporary" : "persistent"));
attempt->stage = Stage::WaitingPQ;
attempt->expiresIn = expiresIn;
attempt->data.nonce = openssl::RandomValue<MTPint128>();
attempt->data.nonce = base::RandomValue<MTPint128>();
sendNotSecureRequest(MTPReq_pq_multi(attempt->data.nonce));
}
@ -374,16 +388,19 @@ void DcKeyCreator::pqAnswered(
LOG(("AuthKey Error: Unexpected stage %1").arg(int(attempt->stage)));
return failed();
}
DEBUG_LOG(("AuthKey Info: getting dc RSA key..."));
const auto rsaKey = _dcOptions->getDcRSAKey(
_dcId,
data.vserver_public_key_fingerprints().v);
if (!rsaKey.valid()) {
DEBUG_LOG(("AuthKey Error: unknown public key."));
return failed(DcKeyError::UnknownPublicKey);
}
attempt->data.server_nonce = data.vserver_nonce();
attempt->data.new_nonce = openssl::RandomValue<MTPint256>();
attempt->data.new_nonce = base::RandomValue<MTPint256>();
DEBUG_LOG(("AuthKey Info: parsing pq..."));
const auto &pq = data.vpq().v;
const auto parsed = ParsePQ(data.vpq().v);
if (parsed.p.isEmpty() || parsed.q.isEmpty()) {
@ -391,6 +408,7 @@ void DcKeyCreator::pqAnswered(
DEBUG_LOG(("AuthKey Error: problematic pq: %1").arg(Logs::mb(pq.constData(), pq.length()).str()));
return failed();
}
DEBUG_LOG(("AuthKey Info: parse pq done."));
const auto dhEncString = [&] {
return (attempt->expiresIn == 0)
@ -417,6 +435,7 @@ void DcKeyCreator::pqAnswered(
rsaKey);
}();
if (dhEncString.empty()) {
DEBUG_LOG(("AuthKey Error: could not encrypt pq inner."));
return failed();
}

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "mtproto/details/mtproto_domain_resolver.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/invoke_queued.h"
#include "base/call_delayed.h"
@ -47,7 +47,7 @@ QString GenerateDnsRandomPadding() {
constexpr auto kMinPadding = 13;
constexpr auto kMaxPadding = 128;
while (true) {
const auto result = 1 + (openssl::RandomValue<uchar>() / 2);
const auto result = 1 + (base::RandomValue<uchar>() / 2);
Assert(result <= kMaxPadding);
if (result >= kMinPadding) {
return result;
@ -56,7 +56,7 @@ QString GenerateDnsRandomPadding() {
}();
result.resize(count);
for (auto &ch : result) {
ch = kValid[openssl::RandomValue<uchar>() % (sizeof(kValid) - 1)];
ch = kValid[base::RandomValue<uchar>() % (sizeof(kValid) - 1)];
}
return result;
}

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "mtproto/details/mtproto_serialized_request.h"
#include "base/openssl_help.h"
#include "base/random.h"
namespace MTP::details {
namespace {
@ -30,7 +30,7 @@ uint32 CountPaddingPrimesCount(
}
// Some more random padding.
return result + ((openssl::RandomValue<uchar>() & 0x0F) << 2);
return result + ((base::RandomValue<uchar>() & 0x0F) << 2);
}
} // namespace

View File

@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "mtproto/mtproto_dh_utils.h"
#include "base/openssl_help.h"
namespace MTP {
namespace {

View File

@ -8,7 +8,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "base/bytes.h"
#include "base/openssl_help.h"
namespace openssl {
class BigNum;
} // namespace openssl
namespace MTP {

View File

@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h"
#include "core/core_settings.h"
#include "base/unixtime.h"
#include "base/openssl_help.h"
namespace MTP {
namespace details {

View File

@ -16,8 +16,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtproto_dc_options.h"
#include "mtproto/connection_abstract.h"
#include "platform/platform_specific.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/qthelp_url.h"
#include "base/openssl_help.h"
#include "base/unixtime.h"
#include "base/platform/base_platform_info.h"
#include "zlib.h"
@ -398,7 +399,7 @@ void SessionPrivate::resetSession() {
void SessionPrivate::changeSessionId() {
auto sessionId = _sessionId;
do {
sessionId = openssl::RandomValue<uint64>();
sessionId = base::RandomValue<uint64>();
} while (_sessionId == sessionId);
DEBUG_LOG(("MTP Info: setting server_session: %1").arg(sessionId));
@ -574,7 +575,7 @@ void SessionPrivate::tryToSend() {
&& !_pingIdToSend
&& !_pingId
&& _pingSendAt <= crl::now()) {
_pingIdToSend = openssl::RandomValue<mtpPingId>();
_pingIdToSend = base::RandomValue<mtpPingId>();
}
const auto forceNewMsgId = sendAll && markSessionAsStarted();
if (forceNewMsgId && _keyCreator) {
@ -2528,7 +2529,7 @@ void SessionPrivate::authKeyChecked() {
resendAll();
} // else receive salt in bad_server_salt first, then try to send all the requests
_pingIdToSend = openssl::RandomValue<uint64>(); // get server_salt
_pingIdToSend = base::RandomValue<uint64>(); // get server_salt
_sessionData->queueNeedToResumeAndSend();
}

View File

@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtproto_dc_options.h"
#include "mtproto/connection_abstract.h"
#include "mtproto/facade.h"
#include "base/openssl_help.h"
#include "base/timer.h"
namespace MTP {

View File

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "passport/passport_encryption.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "mtproto/details/mtproto_rsa_public_key.h"
#include <QtCore/QJsonDocument>
@ -108,7 +109,7 @@ bool CheckSecretBytes(bytes::const_span secret) {
bytes::vector GenerateSecretBytes() {
auto result = bytes::vector(kSecretSize);
memset_rand(result.data(), result.size());
bytes::set_random(result);
const auto full = ranges::accumulate(
result,
0ULL,
@ -334,7 +335,7 @@ EncryptedData EncryptData(
constexpr auto kFromPadding = kMinPadding + kAlignTo - 1;
constexpr auto kPaddingDelta = kMaxPadding - kFromPadding;
const auto randomPadding = kFromPadding
+ (openssl::RandomValue<uint32>() % kPaddingDelta);
+ (base::RandomValue<uint32>() % kPaddingDelta);
const auto padding = randomPadding
- ((bytes.size() + randomPadding) % kAlignTo);
Assert(padding >= kMinPadding && padding <= kMaxPadding);
@ -343,7 +344,7 @@ EncryptedData EncryptData(
Assert(unencrypted.size() % kAlignTo == 0);
unencrypted[0] = static_cast<gsl::byte>(padding);
memset_rand(unencrypted.data() + 1, padding - 1);
base::RandomFill(unencrypted.data() + 1, padding - 1);
bytes::copy(
gsl::make_span(unencrypted).subspan(padding),
bytes);

View File

@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/passcode_box.h"
#include "lang/lang_keys.h"
#include "lang/lang_hardcoded.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/qthelp_url.h"
#include "base/unixtime.h"
#include "base/call_delayed.h"
@ -1431,7 +1431,7 @@ void FormController::restoreScan(
void FormController::prepareFile(
EditFile &file,
const QByteArray &content) {
const auto fileId = openssl::RandomValue<uint64>();
const auto fileId = base::RandomValue<uint64>();
file.fields.size = content.size();
file.fields.id = fileId;
file.fields.dcId = _controller->session().mainDcId();
@ -2652,7 +2652,7 @@ bool FormController::applyPassword(const MTPDaccount_password &result) {
settings.newSecureAlgo = Core::ValidateNewSecureSecretAlgo(
Core::ParseSecureSecretAlgo(result.vnew_secure_algo()));
settings.pendingResetDate = result.vpending_reset_date().value_or_empty();
openssl::AddRandomSeed(bytes::make_span(result.vsecure_random().v));
base::RandomAddSeed(bytes::make_span(result.vsecure_random().v));
return applyPassword(std::move(settings));
}

View File

@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "passport/passport_panel_edit_scans.h"
#include "passport/passport_panel.h"
#include "passport/ui/passport_details_row.h"
#include "base/openssl_help.h"
#include "base/unixtime.h"
#include "boxes/passcode_box.h"
#include "boxes/confirm_box.h"

View File

@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/linux/base_linux_glibmm_helper.h"
#include "platform/linux/linux_wayland_integration.h"
#include "storage/localstorage.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/qt_adapters.h"
#include <QtGui/QWindow>
@ -391,7 +391,7 @@ void XDPFileDialog::openPortal() {
}
const auto handleToken = Glib::ustring("tdesktop")
+ std::to_string(openssl::RandomValue<uint>());
+ std::to_string(base::RandomValue<uint>());
options["handle_token"] = Glib::Variant<Glib::ustring>::create(
handleToken);

View File

@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/linux/linux_wayland_integration.h"
#include "core/application.h"
#include "window/window_controller.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include <QtGui/QWindow>
@ -93,7 +93,7 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
}();
const auto handleToken = Glib::ustring("tdesktop")
+ std::to_string(openssl::RandomValue<uint>());
+ std::to_string(base::RandomValue<uint>());
auto uniqueName = connection->get_unique_name();
uniqueName.erase(0, 1);

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "platform/linux/specific_linux.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/platform/base_platform_info.h"
#include "ui/platform/linux/ui_linux_wayland_integration.h"
#include "platform/linux/linux_desktop_environment.h"
@ -113,7 +113,7 @@ void PortalAutostart(bool start, bool silent) {
}();
const auto handleToken = Glib::ustring("tdesktop")
+ std::to_string(openssl::RandomValue<uint>());
+ std::to_string(base::RandomValue<uint>());
std::map<Glib::ustring, Glib::VariantBase> options;
options["handle_token"] = Glib::Variant<Glib::ustring>::create(

View File

@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h"
#include "platform/platform_specific.h"
#include "base/platform/mac/base_utilities_mac.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "history/history.h"
#include "ui/empty_userpic.h"
#include "main/main_session.h"
@ -230,7 +230,7 @@ private:
};
Manager::Private::Private(Manager *manager)
: _managerId(openssl::RandomValue<uint64>())
: _managerId(base::RandomValue<uint64>())
, _managerIdString(QString::number(_managerId))
, _delegate([[NotificationDelegate alloc] initWithManager:manager managerId:_managerId]) {
Core::App().settings().workModeValue(

View File

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtproto_auth_key.h"
#include "base/platform/base_platform_file_utilities.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include <crl/crl_object_on_thread.h>
#include <QtCore/QtEndian>
@ -270,7 +271,7 @@ FileKey GenerateKey(const QString &basePath) {
path.reserve(basePath.size() + 0x11);
path += basePath;
do {
result = openssl::RandomValue<FileKey>();
result = base::RandomValue<FileKey>();
path.resize(basePath.size());
path += ToFilePart(result);
} while (!result || KeyAlreadyUsed(path));
@ -460,7 +461,7 @@ void FileWriteDescriptor::finish() {
if (fullSize & 0x0F) {
fullSize += 0x10 - (fullSize & 0x0F);
toEncrypt.resize(fullSize);
memset_rand(toEncrypt.data() + size, fullSize - size);
base::RandomFill(toEncrypt.data() + size, fullSize - size);
}
*(uint32*)toEncrypt.data() = size;
QByteArray encrypted(0x10 + fullSize, Qt::Uninitialized); // 128bit of sha1 - key128, sizeof(data), data

View File

@ -22,7 +22,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "apiwrap.h"
#include "core/crash_reports.h"
#include "base/bytes.h"
#include "base/openssl_help.h"
namespace {

View File

@ -15,7 +15,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtp_instance.h"
#include "mtproto/mtproto_config.h"
#include "mtproto/mtproto_auth_key.h"
#include "base/openssl_help.h"
mtpFileLoader::mtpFileLoader(
not_null<Main::Session*> session,

View File

@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/file_utilities.h"
#include "core/mime_type.h"
#include "base/unixtime.h"
#include "base/random.h"
#include "base/qt_adapters.h"
#include "editor/scene/scene.h" // Editor::Scene::attachedStickers
#include "media/audio/media_audio.h"
@ -58,7 +59,7 @@ PreparedFileThumbnail PrepareFileThumbnail(QImage &&original) {
return {};
}
auto result = PreparedFileThumbnail();
result.id = openssl::RandomValue<uint64>();
result.id = base::RandomValue<uint64>();
const auto scaled = (width > kThumbnailSize || height > kThumbnailSize);
const auto scaledWidth = [&] {
return (width > height)
@ -150,6 +151,56 @@ MTPInputSingleMedia PrepareAlbumItemMedia(
} // namespace
SendMediaPrepare::SendMediaPrepare(
const QString &file,
const PeerId &peer,
SendMediaType type,
MsgId replyTo)
: id(base::RandomValue<PhotoId>())
, file(file)
, peer(peer)
, type(type)
, replyTo(replyTo) {
}
SendMediaPrepare::SendMediaPrepare(
const QImage &img,
const PeerId &peer,
SendMediaType type,
MsgId replyTo)
: id(base::RandomValue<PhotoId>())
, img(img)
, peer(peer)
, type(type)
, replyTo(replyTo) {
}
SendMediaPrepare::SendMediaPrepare(
const QByteArray &data,
const PeerId &peer,
SendMediaType type,
MsgId replyTo)
: id(base::RandomValue<PhotoId>())
, data(data)
, peer(peer)
, type(type)
, replyTo(replyTo) {
}
SendMediaPrepare::SendMediaPrepare(
const QByteArray &data,
int duration,
const PeerId &peer,
SendMediaType type,
MsgId replyTo)
: id(base::RandomValue<PhotoId>())
, data(data)
, peer(peer)
, type(type)
, duration(duration)
, replyTo(replyTo) {
}
SendMediaReady::SendMediaReady(
SendMediaType type,
const QString &file,
@ -220,7 +271,7 @@ SendMediaReady PreparePeerPhoto(MTP::DcId dcId, PeerId peerId, QImage &&image) {
push("b", scaled(320));
push("c", std::move(image), jpeg);
const auto id = openssl::RandomValue<PhotoId>();
const auto id = base::RandomValue<PhotoId>();
const auto photo = MTP_photo(
MTP_flags(0),
MTP_long(id),
@ -400,7 +451,7 @@ void TaskQueueWorker::onTaskAdded() {
_inTaskAdded = false;
}
SendingAlbum::SendingAlbum() : groupId(openssl::RandomValue<uint64>()) {
SendingAlbum::SendingAlbum() : groupId(base::RandomValue<uint64>()) {
}
void SendingAlbum::fillMedia(
@ -493,7 +544,7 @@ FileLoadTask::FileLoadTask(
const FileLoadTo &to,
const TextWithTags &caption,
std::shared_ptr<SendingAlbum> album)
: _id(openssl::RandomValue<uint64>())
: _id(base::RandomValue<uint64>())
, _session(session)
, _dcId(session->mainDcId())
, _to(to)
@ -514,7 +565,7 @@ FileLoadTask::FileLoadTask(
const VoiceWaveform &waveform,
const FileLoadTo &to,
const TextWithTags &caption)
: _id(openssl::RandomValue<uint64>())
: _id(base::RandomValue<uint64>())
, _session(session)
, _dcId(session->mainDcId())
, _to(to)

View File

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/openssl_help.h"
#include "base/variant.h"
#include "api/api_common.h"
#include "ui/chat/attach/attach_prepare.h"
@ -31,44 +30,24 @@ struct SendMediaPrepare {
const QString &file,
const PeerId &peer,
SendMediaType type,
MsgId replyTo) : id(openssl::RandomValue<PhotoId>()),
file(file),
peer(peer),
type(type),
replyTo(replyTo) {
}
MsgId replyTo);
SendMediaPrepare(
const QImage &img,
const PeerId &peer,
SendMediaType type,
MsgId replyTo) : id(openssl::RandomValue<PhotoId>()),
img(img),
peer(peer),
type(type),
replyTo(replyTo) {
}
MsgId replyTo);
SendMediaPrepare(
const QByteArray &data,
const PeerId &peer,
SendMediaType type,
MsgId replyTo) : id(openssl::RandomValue<PhotoId>()),
data(data),
peer(peer),
type(type),
replyTo(replyTo) {
}
MsgId replyTo);
SendMediaPrepare(
const QByteArray &data,
int duration,
const PeerId &peer,
SendMediaType type,
MsgId replyTo) : id(openssl::RandomValue<PhotoId>()),
data(data),
peer(peer),
type(type),
duration(duration),
replyTo(replyTo) {
}
MsgId replyTo);
PhotoId id;
QString file;
QImage img;

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_document.h"
#include "data/data_document_media.h"
#include "base/platform/base_platform_info.h"
#include "base/random.h"
#include "ui/effects/animation_value.h"
#include "core/update_checker.h"
#include "core/file_location.h"
@ -445,7 +446,7 @@ void writeSettings() {
FileWriteDescriptor settings(name, _basePath);
if (_settingsSalt.isEmpty() || !SettingsKey) {
_settingsSalt.resize(LocalEncryptSaltSize);
memset_rand(_settingsSalt.data(), _settingsSalt.size());
base::RandomFill(_settingsSalt.data(), _settingsSalt.size());
SettingsKey = CreateLegacyLocalKey(QByteArray(), _settingsSalt);
}
settings.writeData(_settingsSalt);

View File

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtproto_config.h"
#include "main/main_domain.h"
#include "main/main_account.h"
#include "base/random.h"
namespace Storage {
namespace {
@ -94,8 +95,8 @@ void Domain::generateLocalKey() {
auto pass = QByteArray(MTP::AuthKey::kSize, Qt::Uninitialized);
auto salt = QByteArray(LocalEncryptSaltSize, Qt::Uninitialized);
memset_rand(pass.data(), pass.size());
memset_rand(salt.data(), salt.size());
base::RandomFill(pass.data(), pass.size());
base::RandomFill(salt.data(), salt.size());
_localKey = CreateLocalKey(pass, salt);
encryptLocalKey(QByteArray());
@ -103,7 +104,7 @@ void Domain::generateLocalKey() {
void Domain::encryptLocalKey(const QByteArray &passcode) {
_passcodeKeySalt.resize(LocalEncryptSaltSize);
memset_rand(_passcodeKeySalt.data(), _passcodeKeySalt.size());
base::RandomFill(_passcodeKeySalt.data(), _passcodeKeySalt.size());
_passcodeKey = CreateLocalKey(passcode, _passcodeKeySalt);
EncryptedDescriptor passKeyData(MTP::AuthKey::kSize);

View File

@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/group_call_userpics.h"
#include "ui/paint/blobs.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "styles/style_chat.h"
namespace Ui {
@ -237,7 +237,7 @@ void GroupCallUserpics::sendRandomLevels() {
}
for (auto &userpic : _list) {
if (const auto blobs = userpic.blobsAnimation.get()) {
const auto value = 30 + (openssl::RandomValue<uint32>() % 70);
const auto value = 30 + base::RandomIndex(70);
userpic.blobsAnimation->blobs.setLevel(float64(value) / 100.);
}
}

View File

@ -12,7 +12,7 @@
#include "ui/painter.h"
#include "ui/widgets/call_button.h"
#include "ui/widgets/labels.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "styles/palette.h"
#include "styles/style_widgets.h"
#include "styles/style_calls.h"
@ -681,7 +681,7 @@ CallMuteButton::IconState CallMuteButton::randomWavingState() {
{ 240, 420 },
{ 420, 540 },
};
const auto index = openssl::RandomValue<uint32>() % kAnimations.size();
const auto index = base::RandomIndex(kAnimations.size());
return { 1, kAnimations[index].from, kAnimations[index].to };
}

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "ui/effects/fireworks_animation.h"
#include "base/openssl_help.h"
#include "base/random.h"
namespace Ui {
namespace {
@ -37,12 +37,8 @@ std::vector<QBrush> PrepareBrushes() {
};
}
int RandomInt(uint32 till) {
return int(openssl::RandomValue<uint32>() % till);
}
[[nodiscard]] float64 RandomFloat01() {
return openssl::RandomValue<uint32>()
return base::RandomValue<uint32>()
/ float64(std::numeric_limits<uint32>::max());
}
@ -190,22 +186,24 @@ void FireworksAnimation::startFall() {
void FireworksAnimation::initParticle(Particle &particle, bool falling) {
using Type = Particle::Type;
particle.color = RandomInt(_brushes.size());
particle.type = RandomInt(2) ? Type::Rectangle : Type::Circle;
particle.right = (RandomInt(2) == 1);
particle.finishedStart = 1 + RandomInt(2);
using base::RandomIndex;
particle.color = RandomIndex(_brushes.size());
particle.type = RandomIndex(2) ? Type::Rectangle : Type::Circle;
particle.right = (RandomIndex(2) == 1);
particle.finishedStart = 1 + RandomIndex(2);
if (particle.type == Type::Circle) {
particle.size = style::ConvertScale(6 + RandomFloat01() * 3);
} else {
particle.size = style::ConvertScale(6 + RandomFloat01() * 6);
particle.rotation = RandomInt(360);
particle.rotation = RandomIndex(360);
}
if (falling) {
particle.y = -RandomFloat01() * kFireworkHeight * 1.2f;
particle.x = 5 + RandomInt(kFireworkWidth - 10);
particle.x = 5 + RandomIndex(kFireworkWidth - 10);
particle.xFinished = particle.finishedStart;
} else {
const auto xOffset = 4 + RandomInt(10);
const auto xOffset = 4 + RandomIndex(10);
const auto yOffset = kFireworkHeight / 4;
if (particle.right) {
particle.x = kFireworkWidth + xOffset;
@ -214,7 +212,7 @@ void FireworksAnimation::initParticle(Particle &particle, bool falling) {
}
particle.moveX = (particle.right ? -1 : 1) * (1.2 + RandomFloat01() * 4);
particle.moveY = -(4 + RandomFloat01() * 4);
particle.y = yOffset / 2 + RandomInt(yOffset * 2);
particle.y = yOffset / 2 + RandomIndex(yOffset * 2);
}
}

View File

@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/notifications_utilities.h"
#include "base/platform/base_platform_file_utilities.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "core/application.h"
#include "data/data_peer.h"
#include "ui/empty_userpic.h"
@ -61,7 +61,7 @@ QString CachedUserpics::get(
}
v.path = u"%1tdata/temp/%2.png"_q.arg(
cWorkingDir(),
QString::number(openssl::RandomValue<uint64>(), 16));
QString::number(base::RandomValue<uint64>(), 16));
if (key.first || key.second) {
if (peer->isSelf()) {
const auto method = (_type == Type::Rounded)

View File

@ -18,7 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/localstorage.h"
#include "storage/localimageloader.h"
#include "storage/file_upload.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "base/parse_helper.h"
#include "base/zlib_help.h"
#include "base/unixtime.h"
@ -484,7 +484,7 @@ SendMediaReady PrepareWallPaper(MTP::DcId dcId, const QImage &image) {
attributes.push_back(MTP_documentAttributeImageSize(
MTP_int(image.width()),
MTP_int(image.height())));
const auto id = openssl::RandomValue<DocumentId>();
const auto id = base::RandomValue<DocumentId>();
const auto document = MTP_document(
MTP_flags(0),
MTP_long(id),

View File

@ -34,7 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/base_file_utilities.h"
#include "base/zlib_help.h"
#include "base/unixtime.h"
#include "base/openssl_help.h"
#include "base/random.h"
#include "data/data_session.h"
#include "data/data_document.h"
#include "data/data_cloud_themes.h"
@ -338,7 +338,7 @@ bool CopyColorsToPalette(
auto result = QString();
result.reserve(kRandomSlugSize);
for (auto i = 0; i != kRandomSlugSize; ++i) {
const auto value = openssl::RandomValue<uint8>() % values;
const auto value = base::RandomValue<uint8>() % values;
if (value < letters) {
result.append(char('A' + value));
} else if (value < 2 * letters) {
@ -443,7 +443,7 @@ SendMediaReady PrepareThemeMedia(
auto attributes = QVector<MTPDocumentAttribute>(
1,
MTP_documentAttributeFilename(MTP_string(filename)));
const auto id = openssl::RandomValue<DocumentId>();
const auto id = base::RandomValue<DocumentId>();
const auto document = MTP_document(
MTP_flags(0),
MTP_long(id),

View File

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "window/themes/window_themes_generate_name.h"
#include "base/openssl_help.h"
#include "base/random.h"
namespace Window {
namespace Theme {
@ -339,13 +339,13 @@ QString GenerateName(const QColor &accent) {
return result;
};
const auto random = [&](const std::vector<const char*> &values) {
const auto index = openssl::RandomValue<size_t>() % values.size();
const auto index = base::RandomValue<size_t>() % values.size();
return capitalized(values[index]);
};
const auto min = ranges::min_element(kColors, pred);
Assert(min != end(kColors));
const auto color = capitalized(min->second);
return (openssl::RandomValue<uint8>() % 2 == 0)
return (base::RandomValue<uint8>() % 2 == 0)
? random(kAdjectives) + ' ' + color
: color + ' ' + random(kSubjectives);
}

@ -1 +1 @@
Subproject commit 50d2d313e7127802ae25965b6144515cb5d243c2
Subproject commit e8adbd1fa6c9d423dfa07e358cd8665c77f8503d

@ -1 +1 @@
Subproject commit 403df6c4a29562bd417c92d410e49819f5a48cc1
Subproject commit 73d57840ac603107381e0e6b22d5b3bdcae492c6

@ -1 +1 @@
Subproject commit d7bdfa2b5ec149b0dd1d008a58a73469282ec58a
Subproject commit b35d2d257a421f6adce0e60d62126ee65f46f573