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 "api/api_cloud_password.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "core/core_cloud_password.h" #include "core/core_cloud_password.h"
#include "apiwrap.h" #include "apiwrap.h"
@ -27,7 +27,7 @@ void CloudPassword::reload() {
)).done([=](const MTPaccount_Password &result) { )).done([=](const MTPaccount_Password &result) {
_requestId = 0; _requestId = 0;
result.match([&](const MTPDaccount_password &data) { 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) { if (_state) {
*_state = Core::ParseCloudPasswordState(data); *_state = Core::ParseCloudPasswordState(data);
} else { } else {

View file

@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_sending.h" #include "api/api_sending.h"
#include "api/api_text_entities.h" #include "api/api_text_entities.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_photo.h" #include "data/data_photo.h"
@ -76,7 +76,7 @@ void SendExistingMedia(
const auto newId = FullMsgId( const auto newId = FullMsgId(
peerToChannel(peer->id), peerToChannel(peer->id),
session->data().nextLocalMessageId()); session->data().nextLocalMessageId());
const auto randomId = openssl::RandomValue<uint64>(); const auto randomId = base::RandomValue<uint64>();
auto flags = NewMessageFlags(peer); auto flags = NewMessageFlags(peer);
auto sendFlags = MTPmessages_SendMedia::Flags(0); auto sendFlags = MTPmessages_SendMedia::Flags(0);
@ -248,7 +248,7 @@ bool SendDice(Api::MessageToSend &message) {
const auto newId = FullMsgId( const auto newId = FullMsgId(
peerToChannel(peer->id), peerToChannel(peer->id),
session->data().nextLocalMessageId()); session->data().nextLocalMessageId());
const auto randomId = openssl::RandomValue<uint64>(); const auto randomId = base::RandomValue<uint64>();
auto &histories = history->owner().histories(); auto &histories = history->owner().histories();
auto flags = NewMessageFlags(peer); 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/core_cloud_password.h"
#include "core/application.h" #include "core/application.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "base/random.h"
#include "base/qt_adapters.h" #include "base/qt_adapters.h"
#include "base/call_delayed.h" #include "base/call_delayed.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
@ -3724,7 +3725,7 @@ void ApiWrap::forwardMessages(
ids.reserve(count); ids.reserve(count);
randomIds.reserve(count); randomIds.reserve(count);
for (const auto item : draft.items) { for (const auto item : draft.items) {
const auto randomId = openssl::RandomValue<uint64>(); const auto randomId = base::RandomValue<uint64>();
if (genClientSideMessage) { if (genClientSideMessage) {
if (const auto message = item->toHistoryMessage()) { if (const auto message = item->toHistoryMessage()) {
const auto newId = FullMsgId( const auto newId = FullMsgId(
@ -4034,7 +4035,7 @@ void ApiWrap::sendMessage(MessageToSend &&message) {
auto newId = FullMsgId( auto newId = FullMsgId(
peerToChannel(peer->id), peerToChannel(peer->id),
_session->data().nextLocalMessageId()); _session->data().nextLocalMessageId());
auto randomId = openssl::RandomValue<uint64>(); auto randomId = base::RandomValue<uint64>();
TextUtilities::Trim(sending); TextUtilities::Trim(sending);
@ -4158,7 +4159,7 @@ void ApiWrap::sendBotStart(not_null<UserData*> bot, PeerData *chat) {
sendMessage(std::move(message)); sendMessage(std::move(message));
return; return;
} }
const auto randomId = openssl::RandomValue<uint64>(); const auto randomId = base::RandomValue<uint64>();
request(MTPmessages_StartBot( request(MTPmessages_StartBot(
bot->inputUser, bot->inputUser,
chat ? chat->input : MTP_inputPeerEmpty(), chat ? chat->input : MTP_inputPeerEmpty(),
@ -4184,7 +4185,7 @@ void ApiWrap::sendInlineResult(
const auto newId = FullMsgId( const auto newId = FullMsgId(
peerToChannel(peer->id), peerToChannel(peer->id),
_session->data().nextLocalMessageId()); _session->data().nextLocalMessageId());
const auto randomId = openssl::RandomValue<uint64>(); const auto randomId = base::RandomValue<uint64>();
auto flags = NewMessageFlags(peer); auto flags = NewMessageFlags(peer);
auto sendFlags = MTPmessages_SendInlineBotResult::Flag::f_clear_draft | 0; auto sendFlags = MTPmessages_SendInlineBotResult::Flag::f_clear_draft | 0;
@ -4340,7 +4341,7 @@ void ApiWrap::sendMedia(
not_null<HistoryItem*> item, not_null<HistoryItem*> item,
const MTPInputMedia &media, const MTPInputMedia &media,
Api::SendOptions options) { Api::SendOptions options) {
const auto randomId = openssl::RandomValue<uint64>(); const auto randomId = base::RandomValue<uint64>();
_session->data().registerMessageRandomId(randomId, item->fullId()); _session->data().registerMessageRandomId(randomId, item->fullId());
sendMediaWithRandomId(item, media, options, randomId); sendMediaWithRandomId(item, media, options, randomId);
@ -4414,7 +4415,7 @@ void ApiWrap::sendAlbumWithUploaded(
const MessageGroupId &groupId, const MessageGroupId &groupId,
const MTPInputMedia &media) { const MTPInputMedia &media) {
const auto localId = item->fullId(); const auto localId = item->fullId();
const auto randomId = openssl::RandomValue<uint64>(); const auto randomId = base::RandomValue<uint64>();
_session->data().registerMessageRandomId(randomId, localId); _session->data().registerMessageRandomId(randomId, localId);
const auto albumIt = _sendingAlbums.find(groupId.raw()); const auto albumIt = _sendingAlbums.find(groupId.raw());
@ -4768,7 +4769,7 @@ void ApiWrap::createPoll(
MTP_int(replyTo), MTP_int(replyTo),
PollDataToInputMedia(&data), PollDataToInputMedia(&data),
MTP_string(), MTP_string(),
MTP_long(openssl::RandomValue<uint64>()), MTP_long(base::RandomValue<uint64>()),
MTPReplyMarkup(), MTPReplyMarkup(),
MTPVector<MTPMessageEntity>(), MTPVector<MTPMessageEntity>(),
MTP_int(action.options.scheduled) 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 "lang/lang_keys.h"
#include "mtproto/sender.h" #include "mtproto/sender.h"
#include "base/flat_set.h" #include "base/flat_set.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "boxes/peer_list_controllers.h" #include "boxes/peer_list_controllers.h"
#include "boxes/peers/add_participants_box.h" #include "boxes/peers/add_participants_box.h"
@ -383,7 +383,7 @@ void AddContactBox::save() {
lastName = QString(); lastName = QString();
} }
_sentName = firstName; _sentName = firstName;
_contactId = openssl::RandomValue<uint64>(); _contactId = base::RandomValue<uint64>();
_addRequest = _session->api().request(MTPcontacts_ImportContacts( _addRequest = _session->api().request(MTPcontacts_ImportContacts(
MTP_vector<MTPInputContact>( MTP_vector<MTPInputContact>(
1, 1,

View file

@ -30,7 +30,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/unique_qptr.h" #include "base/unique_qptr.h"
#include "base/event_filter.h" #include "base/event_filter.h"
#include "base/call_delayed.h" #include "base/call_delayed.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
@ -885,7 +885,7 @@ not_null<Ui::InputField*> CreatePollBox::setupSolution(
object_ptr<Ui::RpWidget> CreatePollBox::setupContent() { object_ptr<Ui::RpWidget> CreatePollBox::setupContent() {
using namespace Settings; using namespace Settings;
const auto id = openssl::RandomValue<uint64>(); const auto id = base::RandomValue<uint64>();
const auto error = lifetime().make_state<Errors>(Error::Question); const auto error = lifetime().make_state<Errors>(Error::Question);
auto result = object_ptr<Ui::VerticalLayout>(this); 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 "boxes/peer_list_controllers.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "ui/widgets/checkbox.h" #include "ui/widgets/checkbox.h"
#include "ui/ui_utility.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(); auto &histories = history->owner().histories();
const auto requestType = Data::Histories::RequestType::Send; const auto requestType = Data::Histories::RequestType::Send;
histories.sendRequest(history, requestType, [=](Fn<void()> finish) { 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(); const auto api = &chat->session().api();
history->sendRequestId = api->request(MTPmessages_SendMedia( history->sendRequestId = api->request(MTPmessages_SendMedia(
MTP_flags(0), MTP_flags(0),

View file

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/rate_call_box.h" #include "boxes/rate_call_box.h"
#include "calls/calls_instance.h" #include "calls/calls_instance.h"
#include "base/openssl_help.h" #include "base/openssl_help.h"
#include "base/random.h"
#include "mtproto/mtproto_dh_utils.h" #include "mtproto/mtproto_dh_utils.h"
#include "mtproto/mtproto_config.h" #include "mtproto/mtproto_config.h"
#include "core/application.h" #include "core/application.h"
@ -233,7 +234,7 @@ void Call::startOutgoing() {
_api.request(MTPphone_RequestCall( _api.request(MTPphone_RequestCall(
MTP_flags(flags), MTP_flags(flags),
_user->inputUser, _user->inputUser,
MTP_int(openssl::RandomValue<int32>()), MTP_int(base::RandomValue<int32>()),
MTP_bytes(_gaHash), MTP_bytes(_gaHash),
MTP_phoneCallProtocol( MTP_phoneCallProtocol(
MTP_flags(MTPDphoneCallProtocol::Flag::f_udp_p2p 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_peer_values.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "base/global_shortcuts.h" #include "base/global_shortcuts.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "webrtc/webrtc_video_track.h" #include "webrtc/webrtc_video_track.h"
#include "webrtc/webrtc_media_devices.h" #include "webrtc/webrtc_media_devices.h"
#include "webrtc/webrtc_create_adm.h" #include "webrtc/webrtc_create_adm.h"
@ -1008,7 +1008,7 @@ void GroupCall::start(TimeId scheduleDate) {
_createRequestId = _api.request(MTPphone_CreateGroupCall( _createRequestId = _api.request(MTPphone_CreateGroupCall(
MTP_flags(scheduleDate ? Flag::f_schedule_date : Flag(0)), MTP_flags(scheduleDate ? Flag::f_schedule_date : Flag(0)),
_peer->input, _peer->input,
MTP_int(openssl::RandomValue<int32>()), MTP_int(base::RandomValue<int32>()),
MTPstring(), // title MTPstring(), // title
MTP_int(scheduleDate) MTP_int(scheduleDate)
)).done([=](const MTPUpdates &result) { )).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/ui_utility.h"
#include "ui/cached_round_corners.h" #include "ui/cached_round_corners.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "window/window_adaptive.h" #include "window/window_adaptive.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"
@ -667,7 +667,7 @@ void FieldAutocomplete::showAnimated() {
return; return;
} }
if (_cache.isNull()) { if (_cache.isNull()) {
_stickersSeed = openssl::RandomValue<uint64>(); _stickersSeed = base::RandomValue<uint64>();
_scroll->show(); _scroll->show();
_cache = Ui::GrabWidget(this); _cache = Ui::GrabWidget(this);
} }

View file

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

View file

@ -109,9 +109,6 @@ inline std::array<char, 32> hashMd5Hex(const void *data, int size) {
return result; return result;
} }
// good random (using openssl implementation)
void memset_rand(void *data, uint32 len);
QString translitRusEng(const QString &rus); QString translitRusEng(const QString &rus);
QString rusKeyboardLayoutSwitch(const QString &from); 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/platform/base_platform_info.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "base/call_delayed.h" #include "base/call_delayed.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "facades.h" // Notify::switchInlineBotButtonReceived #include "facades.h" // Notify::switchInlineBotButtonReceived
#include "app.h" #include "app.h"
#include "styles/style_boxes.h" // st::backgroundSize #include "styles/style_boxes.h" // st::backgroundSize
@ -2427,7 +2427,7 @@ PhotoData *Session::photoFromWeb(
return nullptr; return nullptr;
} }
return photo( return photo(
openssl::RandomValue<PhotoId>(), base::RandomValue<PhotoId>(),
uint64(0), uint64(0),
QByteArray(), QByteArray(),
base::unixtime::now(), base::unixtime::now(),
@ -2692,7 +2692,7 @@ DocumentData *Session::documentFromWeb(
const ImageLocation &thumbnailLocation, const ImageLocation &thumbnailLocation,
const ImageLocation &videoThumbnailLocation) { const ImageLocation &videoThumbnailLocation) {
const auto result = document( const auto result = document(
openssl::RandomValue<DocumentId>(), base::RandomValue<DocumentId>(),
uint64(0), uint64(0),
QByteArray(), QByteArray(),
base::unixtime::now(), base::unixtime::now(),
@ -2714,7 +2714,7 @@ DocumentData *Session::documentFromWeb(
const ImageLocation &thumbnailLocation, const ImageLocation &thumbnailLocation,
const ImageLocation &videoThumbnailLocation) { const ImageLocation &videoThumbnailLocation) {
const auto result = document( const auto result = document(
openssl::RandomValue<DocumentId>(), base::RandomValue<DocumentId>(),
uint64(0), uint64(0),
QByteArray(), QByteArray(),
base::unixtime::now(), base::unixtime::now(),

View file

@ -24,7 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtproto_config.h" #include "mtproto/mtproto_config.h"
#include "ui/toast/toast.h" #include "ui/toast/toast.h"
#include "ui/image/image_location_factory.h" #include "ui/image/image_location_factory.h"
#include "base/openssl_help.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "styles/style_chat_helpers.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 "mtproto/mtproto_response.h"
#include "base/value_ordering.h" #include "base/value_ordering.h"
#include "base/bytes.h" #include "base/bytes.h"
#include "base/openssl_help.h" #include "base/random.h"
#include <set> #include <set>
#include <deque> #include <deque>
@ -1748,7 +1748,7 @@ auto ApiWrap::prepareFileProcess(
result->location = file.location; result->location = file.location;
result->size = file.size; result->size = file.size;
result->origin = origin; result->origin = origin;
result->randomId = openssl::RandomValue<uint64>(); result->randomId = base::RandomValue<uint64>();
return result; return result;
} }

View file

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

View file

@ -9,7 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_send_progress.h" #include "api/api_send_progress.h"
#include "base/event_filter.h" #include "base/event_filter.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "core/application.h" #include "core/application.h"
@ -98,7 +98,7 @@ enum class FilterType {
[[nodiscard]] not_null<DocumentData*> DummyDocument( [[nodiscard]] not_null<DocumentData*> DummyDocument(
not_null<Data::Session*> owner) { not_null<Data::Session*> owner) {
return owner->document( return owner->document(
openssl::RandomValue<DocumentId>(), base::RandomValue<DocumentId>(),
uint64(0), uint64(0),
QByteArray(), QByteArray(),
base::unixtime::now(), 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 "inline_bots/inline_bot_result.h"
#include "api/api_text_entities.h" #include "api/api_text_entities.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "data/data_photo.h" #include "data/data_photo.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_session.h" #include "data/data_session.h"
@ -416,7 +416,7 @@ void Result::createGame(not_null<Main::Session*> session) {
return; return;
} }
const auto gameId = openssl::RandomValue<GameId>(); const auto gameId = base::RandomValue<GameId>();
_game = session->data().game( _game = session->data().game(
gameId, gameId,
0, 0,

View file

@ -18,7 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "main/main_account.h" #include "main/main_account.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "styles/style_intro.h" #include "styles/style_intro.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
@ -192,7 +192,7 @@ void PasswordCheckWidget::requestPasswordData() {
).done([=](const MTPaccount_Password &result) { ).done([=](const MTPaccount_Password &result) {
_sentRequest = 0; _sentRequest = 0;
result.match([&](const MTPDaccount_password &data) { 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); _passwordState = Core::ParseCloudPasswordState(data);
passwordChecked(); 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_ffmpeg.h"
#include "media/clip/media_clip_check_streaming.h" #include "media/clip/media_clip_check_streaming.h"
#include "core/file_location.h" #include "core/file_location.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "base/invoke_queued.h" #include "base/invoke_queued.h"
#include "logs.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())); managers.push_back(new Manager(threads.back()));
threads.back()->start(); threads.back()->start();
} else { } else {
_threadIndex = int32(openssl::RandomValue<uint32>() % threads.size()); _threadIndex = int32(base::RandomValue<uint32>() % threads.size());
int32 loadLevel = 0x7FFFFFFF; int32 loadLevel = 0x7FFFFFFF;
for (int32 i = 0, l = threads.size(); i < l; ++i) { for (int32 i = 0, l = threads.size(); i < l; ++i) {
int32 level = managers.at(i)->loadLevel(); 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_session_controller.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "base/qt_signal_producer.h" #include "base/qt_signal_producer.h"
#include "base/event_filter.h" #include "base/event_filter.h"
@ -2847,7 +2847,7 @@ void OverlayWidget::initThemePreview() {
const auto weakSession = base::make_weak(&_document->session()); const auto weakSession = base::make_weak(&_document->session());
const auto path = _document->location().name(); 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); const auto weak = Ui::MakeWeak(_widget);
crl::async([=, data = std::move(current)]() mutable { crl::async([=, data = std::move(current)]() mutable {
auto preview = GeneratePreview( auto preview = GeneratePreview(

View file

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "mtproto/config_loader.h" #include "mtproto/config_loader.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "mtproto/special_config_request.h" #include "mtproto/special_config_request.h"
#include "mtproto/facade.h" #include "mtproto/facade.h"
#include "mtproto/mtproto_dc_options.h" #include "mtproto/mtproto_dc_options.h"
@ -185,8 +185,7 @@ void ConfigLoader::sendSpecialRequest() {
} }
const auto weak = base::make_weak(this); const auto weak = base::make_weak(this);
const auto index = openssl::RandomValue<uint32>() const auto index = base::RandomValue<uint32>() % _specialEndpoints.size();
% _specialEndpoints.size();
const auto endpoint = _specialEndpoints.begin() + index; const auto endpoint = _specialEndpoints.begin() + index;
_specialEnumCurrent = specialToRealDcId(endpoint->dcId); _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/connection_resolving.h"
#include "mtproto/session.h" #include "mtproto/session.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "base/openssl_help.h" #include "base/random.h"
namespace MTP { namespace MTP {
namespace details { namespace details {
@ -189,7 +189,7 @@ ConnectionPointer AbstractConnection::Create(
} }
uint32 AbstractConnection::extendedNotSecurePadding() const { uint32 AbstractConnection::extendedNotSecurePadding() const {
return uint32(openssl::RandomValue<uchar>() & 0x3F); return uint32(base::RandomValue<uchar>() & 0x3F);
} }
} // namespace details } // namespace details

View file

@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "mtproto/connection_http.h" #include "mtproto/connection_http.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "base/qthelp_url.h" #include "base/qthelp_url.h"
namespace MTP { namespace MTP {
@ -21,7 +21,7 @@ constexpr auto kFullConnectionTimeout = crl::time(8000);
HttpConnection::HttpConnection(QThread *thread, const ProxyData &proxy) HttpConnection::HttpConnection(QThread *thread, const ProxyData &proxy)
: AbstractConnection(thread, proxy) : AbstractConnection(thread, proxy)
, _checkNonce(openssl::RandomValue<MTPint128>()) { , _checkNonce(base::RandomValue<MTPint128>()) {
_manager.moveToThread(thread); _manager.moveToThread(thread);
_manager.setProxy(ToNetworkProxy(proxy)); _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 "mtproto/details/mtproto_abstract_socket.h"
#include "base/bytes.h" #include "base/bytes.h"
#include "base/openssl_help.h" #include "base/openssl_help.h"
#include "base/random.h"
#include "base/qthelp_url.h" #include "base/qthelp_url.h"
extern "C" {
#include <openssl/aes.h>
} // extern "C"
namespace MTP { namespace MTP {
namespace details { namespace details {
namespace { namespace {
@ -181,11 +178,11 @@ bytes::span TcpConnection::Protocol::VersionD::finalizePacket(
Expects(buffer.size() > 2 && buffer.size() < 0x1000003U); Expects(buffer.size() > 2 && buffer.size() < 0x1000003U);
const auto intsSize = uint32(buffer.size() - 2); 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; const auto bytesSize = intsSize * sizeof(mtpPrime) + padding;
buffer[1] = bytesSize; buffer[1] = bytesSize;
for (auto added = 0; added < padding; added += 4) { 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); return bytes::make_span(buffer).subspan(4, 4 + bytesSize);
@ -233,7 +230,7 @@ TcpConnection::TcpConnection(
const ProxyData &proxy) const ProxyData &proxy)
: AbstractConnection(thread, proxy) : AbstractConnection(thread, proxy)
, _instance(instance) , _instance(instance)
, _checkNonce(openssl::RandomValue<MTPint128>()) { , _checkNonce(base::RandomValue<MTPint128>()) {
} }
ConnectionPointer TcpConnection::clone(const ProxyData &proxy) { 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 "mtproto/mtp_instance.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "base/openssl_help.h" #include "base/openssl_help.h"
#include "base/random.h"
#include "scheme.h" #include "scheme.h"
#include <QtCore/QPointer> #include <QtCore/QPointer>
@ -84,7 +85,7 @@ SerializedRequest DcKeyBinder::prepareRequest(
Expects(temporaryKey != nullptr); Expects(temporaryKey != nullptr);
Expects(temporaryKey->expiresAt() != 0); Expects(temporaryKey->expiresAt() != 0);
const auto nonce = openssl::RandomValue<uint64>(); const auto nonce = base::RandomValue<uint64>();
const auto msgId = base::unixtime::mtproto_msg_id(); const auto msgId = base::unixtime::mtproto_msg_id();
auto result = SerializedRequest::Serialize(MTPauth_BindTempAuthKey( auto result = SerializedRequest::Serialize(MTPauth_BindTempAuthKey(
MTP_long(_persistentKey->keyId()), 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/connection_abstract.h"
#include "mtproto/mtproto_dh_utils.h" #include "mtproto/mtproto_dh_utils.h"
#include "base/openssl_help.h" #include "base/openssl_help.h"
#include "base/random.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "scheme.h" #include "scheme.h"
#include "logs.h" #include "logs.h"
@ -99,6 +100,8 @@ template <typename PQInnerData>
[[nodiscard]] bytes::vector EncryptPQInnerRSA( [[nodiscard]] bytes::vector EncryptPQInnerRSA(
const PQInnerData &data, const PQInnerData &data,
const RSAPublicKey &key) { const RSAPublicKey &key) {
DEBUG_LOG(("AuthKey Info: encrypting pq inner..."));
constexpr auto kPrime = sizeof(mtpPrime); constexpr auto kPrime = sizeof(mtpPrime);
constexpr auto kDataWithPaddingPrimes = 192 / kPrime; constexpr auto kDataWithPaddingPrimes = 192 / kPrime;
constexpr auto kMaxSizeInPrimes = 144 / kPrime; constexpr auto kMaxSizeInPrimes = 144 / kPrime;
@ -126,6 +129,8 @@ template <typename PQInnerData>
const auto dataWithPaddingBytes = bytes::make_span(dataWithPadding); const auto dataWithPaddingBytes = bytes::make_span(dataWithPadding);
bytes::set_random(dataWithPaddingBytes.subspan(sizeInPrimes * kPrime)); bytes::set_random(dataWithPaddingBytes.subspan(sizeInPrimes * kPrime));
DEBUG_LOG(("AuthKey Info: starting key generation for pq inner..."));
while (true) { while (true) {
auto dataWithHash = mtpBuffer(); auto dataWithHash = mtpBuffer();
dataWithHash.reserve(kDataWithPaddingPrimes + kDataHashPrimes); dataWithHash.reserve(kDataWithPaddingPrimes + kDataHashPrimes);
@ -136,7 +141,7 @@ template <typename PQInnerData>
// data_with_hash := data_pad_reversed // data_with_hash := data_pad_reversed
// + SHA256(temp_key + data_with_padding); // + 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); dataWithHash.resize(kDataWithPaddingPrimes + kDataHashPrimes);
const auto dataWithHashBytes = bytes::make_span(dataWithHash); const auto dataWithHashBytes = bytes::make_span(dataWithHash);
bytes::copy( bytes::copy(
@ -148,6 +153,8 @@ template <typename PQInnerData>
aesEncrypted.resize(dataWithHash.size()); aesEncrypted.resize(dataWithHash.size());
const auto aesEncryptedBytes = bytes::make_span(aesEncrypted); 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); // aes_encrypted := AES256_IGE(data_with_hash, temp_key, 0);
const auto tempIv = bytes::array<kIvSize>{ { bytes::type(0) } }; const auto tempIv = bytes::array<kIvSize>{ { bytes::type(0) } };
aesIgeEncryptRaw( aesIgeEncryptRaw(
@ -157,6 +164,8 @@ template <typename PQInnerData>
tempKey.data(), tempKey.data(),
tempIv.data()); tempIv.data());
DEBUG_LOG(("AuthKey Info: counting hash for pq inner..."));
// temp_key_xor := temp_key XOR SHA256(aes_encrypted); // temp_key_xor := temp_key XOR SHA256(aes_encrypted);
const auto fullSize = (kKeySize / kPrime) + dataWithHash.size(); const auto fullSize = (kKeySize / kPrime) + dataWithHash.size();
keyAesEncrypted.resize(fullSize); keyAesEncrypted.resize(fullSize);
@ -166,13 +175,18 @@ template <typename PQInnerData>
keyAesEncryptedBytes[i] = tempKey[i] ^ aesHash[i]; keyAesEncryptedBytes[i] = tempKey[i] ^ aesHash[i];
} }
DEBUG_LOG(("AuthKey Info: checking chosen key for pq inner..."));
// key_aes_encrypted := temp_key_xor + aes_encrypted; // key_aes_encrypted := temp_key_xor + aes_encrypted;
bytes::copy( bytes::copy(
keyAesEncryptedBytes.subspan(kKeySize), keyAesEncryptedBytes.subspan(kKeySize),
aesEncryptedBytes); aesEncryptedBytes);
if (IsGoodEncryptedInner(keyAesEncryptedBytes, key)) { if (IsGoodEncryptedInner(keyAesEncryptedBytes, key)) {
DEBUG_LOG(("AuthKey Info: chosen key for pq inner is good."));
return key.encrypt(keyAesEncryptedBytes); 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")); ).arg(expiresIn ? "temporary" : "persistent"));
attempt->stage = Stage::WaitingPQ; attempt->stage = Stage::WaitingPQ;
attempt->expiresIn = expiresIn; attempt->expiresIn = expiresIn;
attempt->data.nonce = openssl::RandomValue<MTPint128>(); attempt->data.nonce = base::RandomValue<MTPint128>();
sendNotSecureRequest(MTPReq_pq_multi(attempt->data.nonce)); sendNotSecureRequest(MTPReq_pq_multi(attempt->data.nonce));
} }
@ -374,16 +388,19 @@ void DcKeyCreator::pqAnswered(
LOG(("AuthKey Error: Unexpected stage %1").arg(int(attempt->stage))); LOG(("AuthKey Error: Unexpected stage %1").arg(int(attempt->stage)));
return failed(); return failed();
} }
DEBUG_LOG(("AuthKey Info: getting dc RSA key..."));
const auto rsaKey = _dcOptions->getDcRSAKey( const auto rsaKey = _dcOptions->getDcRSAKey(
_dcId, _dcId,
data.vserver_public_key_fingerprints().v); data.vserver_public_key_fingerprints().v);
if (!rsaKey.valid()) { if (!rsaKey.valid()) {
DEBUG_LOG(("AuthKey Error: unknown public key."));
return failed(DcKeyError::UnknownPublicKey); return failed(DcKeyError::UnknownPublicKey);
} }
attempt->data.server_nonce = data.vserver_nonce(); 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 &pq = data.vpq().v;
const auto parsed = ParsePQ(data.vpq().v); const auto parsed = ParsePQ(data.vpq().v);
if (parsed.p.isEmpty() || parsed.q.isEmpty()) { 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())); DEBUG_LOG(("AuthKey Error: problematic pq: %1").arg(Logs::mb(pq.constData(), pq.length()).str()));
return failed(); return failed();
} }
DEBUG_LOG(("AuthKey Info: parse pq done."));
const auto dhEncString = [&] { const auto dhEncString = [&] {
return (attempt->expiresIn == 0) return (attempt->expiresIn == 0)
@ -417,6 +435,7 @@ void DcKeyCreator::pqAnswered(
rsaKey); rsaKey);
}(); }();
if (dhEncString.empty()) { if (dhEncString.empty()) {
DEBUG_LOG(("AuthKey Error: could not encrypt pq inner."));
return failed(); return failed();
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/passcode_box.h" #include "boxes/passcode_box.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "lang/lang_hardcoded.h" #include "lang/lang_hardcoded.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "base/qthelp_url.h" #include "base/qthelp_url.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "base/call_delayed.h" #include "base/call_delayed.h"
@ -1431,7 +1431,7 @@ void FormController::restoreScan(
void FormController::prepareFile( void FormController::prepareFile(
EditFile &file, EditFile &file,
const QByteArray &content) { const QByteArray &content) {
const auto fileId = openssl::RandomValue<uint64>(); const auto fileId = base::RandomValue<uint64>();
file.fields.size = content.size(); file.fields.size = content.size();
file.fields.id = fileId; file.fields.id = fileId;
file.fields.dcId = _controller->session().mainDcId(); file.fields.dcId = _controller->session().mainDcId();
@ -2652,7 +2652,7 @@ bool FormController::applyPassword(const MTPDaccount_password &result) {
settings.newSecureAlgo = Core::ValidateNewSecureSecretAlgo( settings.newSecureAlgo = Core::ValidateNewSecureSecretAlgo(
Core::ParseSecureSecretAlgo(result.vnew_secure_algo())); Core::ParseSecureSecretAlgo(result.vnew_secure_algo()));
settings.pendingResetDate = result.vpending_reset_date().value_or_empty(); 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)); 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_edit_scans.h"
#include "passport/passport_panel.h" #include "passport/passport_panel.h"
#include "passport/ui/passport_details_row.h" #include "passport/ui/passport_details_row.h"
#include "base/openssl_help.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "boxes/passcode_box.h" #include "boxes/passcode_box.h"
#include "boxes/confirm_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 "base/platform/linux/base_linux_glibmm_helper.h"
#include "platform/linux/linux_wayland_integration.h" #include "platform/linux/linux_wayland_integration.h"
#include "storage/localstorage.h" #include "storage/localstorage.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "base/qt_adapters.h" #include "base/qt_adapters.h"
#include <QtGui/QWindow> #include <QtGui/QWindow>
@ -391,7 +391,7 @@ void XDPFileDialog::openPortal() {
} }
const auto handleToken = Glib::ustring("tdesktop") 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( options["handle_token"] = Glib::Variant<Glib::ustring>::create(
handleToken); handleToken);

View file

@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/linux/linux_wayland_integration.h" #include "platform/linux/linux_wayland_integration.h"
#include "core/application.h" #include "core/application.h"
#include "window/window_controller.h" #include "window/window_controller.h"
#include "base/openssl_help.h" #include "base/random.h"
#include <QtGui/QWindow> #include <QtGui/QWindow>
@ -93,7 +93,7 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
}(); }();
const auto handleToken = Glib::ustring("tdesktop") const auto handleToken = Glib::ustring("tdesktop")
+ std::to_string(openssl::RandomValue<uint>()); + std::to_string(base::RandomValue<uint>());
auto uniqueName = connection->get_unique_name(); auto uniqueName = connection->get_unique_name();
uniqueName.erase(0, 1); 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 "platform/linux/specific_linux.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "ui/platform/linux/ui_linux_wayland_integration.h" #include "ui/platform/linux/ui_linux_wayland_integration.h"
#include "platform/linux/linux_desktop_environment.h" #include "platform/linux/linux_desktop_environment.h"
@ -113,7 +113,7 @@ void PortalAutostart(bool start, bool silent) {
}(); }();
const auto handleToken = Glib::ustring("tdesktop") 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; std::map<Glib::ustring, Glib::VariantBase> options;
options["handle_token"] = Glib::Variant<Glib::ustring>::create( 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 "base/platform/base_platform_info.h"
#include "platform/platform_specific.h" #include "platform/platform_specific.h"
#include "base/platform/mac/base_utilities_mac.h" #include "base/platform/mac/base_utilities_mac.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "history/history.h" #include "history/history.h"
#include "ui/empty_userpic.h" #include "ui/empty_userpic.h"
#include "main/main_session.h" #include "main/main_session.h"
@ -230,7 +230,7 @@ private:
}; };
Manager::Private::Private(Manager *manager) Manager::Private::Private(Manager *manager)
: _managerId(openssl::RandomValue<uint64>()) : _managerId(base::RandomValue<uint64>())
, _managerIdString(QString::number(_managerId)) , _managerIdString(QString::number(_managerId))
, _delegate([[NotificationDelegate alloc] initWithManager:manager managerId:_managerId]) { , _delegate([[NotificationDelegate alloc] initWithManager:manager managerId:_managerId]) {
Core::App().settings().workModeValue( 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 "mtproto/mtproto_auth_key.h"
#include "base/platform/base_platform_file_utilities.h" #include "base/platform/base_platform_file_utilities.h"
#include "base/openssl_help.h" #include "base/openssl_help.h"
#include "base/random.h"
#include <crl/crl_object_on_thread.h> #include <crl/crl_object_on_thread.h>
#include <QtCore/QtEndian> #include <QtCore/QtEndian>
@ -270,7 +271,7 @@ FileKey GenerateKey(const QString &basePath) {
path.reserve(basePath.size() + 0x11); path.reserve(basePath.size() + 0x11);
path += basePath; path += basePath;
do { do {
result = openssl::RandomValue<FileKey>(); result = base::RandomValue<FileKey>();
path.resize(basePath.size()); path.resize(basePath.size());
path += ToFilePart(result); path += ToFilePart(result);
} while (!result || KeyAlreadyUsed(path)); } while (!result || KeyAlreadyUsed(path));
@ -460,7 +461,7 @@ void FileWriteDescriptor::finish() {
if (fullSize & 0x0F) { if (fullSize & 0x0F) {
fullSize += 0x10 - (fullSize & 0x0F); fullSize += 0x10 - (fullSize & 0x0F);
toEncrypt.resize(fullSize); toEncrypt.resize(fullSize);
memset_rand(toEncrypt.data() + size, fullSize - size); base::RandomFill(toEncrypt.data() + size, fullSize - size);
} }
*(uint32*)toEncrypt.data() = size; *(uint32*)toEncrypt.data() = size;
QByteArray encrypted(0x10 + fullSize, Qt::Uninitialized); // 128bit of sha1 - key128, sizeof(data), data 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 "apiwrap.h"
#include "core/crash_reports.h" #include "core/crash_reports.h"
#include "base/bytes.h" #include "base/bytes.h"
#include "base/openssl_help.h"
namespace { namespace {

View file

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

View file

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "base/openssl_help.h"
#include "base/variant.h" #include "base/variant.h"
#include "api/api_common.h" #include "api/api_common.h"
#include "ui/chat/attach/attach_prepare.h" #include "ui/chat/attach/attach_prepare.h"
@ -31,44 +30,24 @@ struct SendMediaPrepare {
const QString &file, const QString &file,
const PeerId &peer, const PeerId &peer,
SendMediaType type, SendMediaType type,
MsgId replyTo) : id(openssl::RandomValue<PhotoId>()), MsgId replyTo);
file(file),
peer(peer),
type(type),
replyTo(replyTo) {
}
SendMediaPrepare( SendMediaPrepare(
const QImage &img, const QImage &img,
const PeerId &peer, const PeerId &peer,
SendMediaType type, SendMediaType type,
MsgId replyTo) : id(openssl::RandomValue<PhotoId>()), MsgId replyTo);
img(img),
peer(peer),
type(type),
replyTo(replyTo) {
}
SendMediaPrepare( SendMediaPrepare(
const QByteArray &data, const QByteArray &data,
const PeerId &peer, const PeerId &peer,
SendMediaType type, SendMediaType type,
MsgId replyTo) : id(openssl::RandomValue<PhotoId>()), MsgId replyTo);
data(data),
peer(peer),
type(type),
replyTo(replyTo) {
}
SendMediaPrepare( SendMediaPrepare(
const QByteArray &data, const QByteArray &data,
int duration, int duration,
const PeerId &peer, const PeerId &peer,
SendMediaType type, SendMediaType type,
MsgId replyTo) : id(openssl::RandomValue<PhotoId>()), MsgId replyTo);
data(data),
peer(peer),
type(type),
duration(duration),
replyTo(replyTo) {
}
PhotoId id; PhotoId id;
QString file; QString file;
QImage img; 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.h"
#include "data/data_document_media.h" #include "data/data_document_media.h"
#include "base/platform/base_platform_info.h" #include "base/platform/base_platform_info.h"
#include "base/random.h"
#include "ui/effects/animation_value.h" #include "ui/effects/animation_value.h"
#include "core/update_checker.h" #include "core/update_checker.h"
#include "core/file_location.h" #include "core/file_location.h"
@ -445,7 +446,7 @@ void writeSettings() {
FileWriteDescriptor settings(name, _basePath); FileWriteDescriptor settings(name, _basePath);
if (_settingsSalt.isEmpty() || !SettingsKey) { if (_settingsSalt.isEmpty() || !SettingsKey) {
_settingsSalt.resize(LocalEncryptSaltSize); _settingsSalt.resize(LocalEncryptSaltSize);
memset_rand(_settingsSalt.data(), _settingsSalt.size()); base::RandomFill(_settingsSalt.data(), _settingsSalt.size());
SettingsKey = CreateLegacyLocalKey(QByteArray(), _settingsSalt); SettingsKey = CreateLegacyLocalKey(QByteArray(), _settingsSalt);
} }
settings.writeData(_settingsSalt); settings.writeData(_settingsSalt);

View file

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtproto_config.h" #include "mtproto/mtproto_config.h"
#include "main/main_domain.h" #include "main/main_domain.h"
#include "main/main_account.h" #include "main/main_account.h"
#include "base/random.h"
namespace Storage { namespace Storage {
namespace { namespace {
@ -94,8 +95,8 @@ void Domain::generateLocalKey() {
auto pass = QByteArray(MTP::AuthKey::kSize, Qt::Uninitialized); auto pass = QByteArray(MTP::AuthKey::kSize, Qt::Uninitialized);
auto salt = QByteArray(LocalEncryptSaltSize, Qt::Uninitialized); auto salt = QByteArray(LocalEncryptSaltSize, Qt::Uninitialized);
memset_rand(pass.data(), pass.size()); base::RandomFill(pass.data(), pass.size());
memset_rand(salt.data(), salt.size()); base::RandomFill(salt.data(), salt.size());
_localKey = CreateLocalKey(pass, salt); _localKey = CreateLocalKey(pass, salt);
encryptLocalKey(QByteArray()); encryptLocalKey(QByteArray());
@ -103,7 +104,7 @@ void Domain::generateLocalKey() {
void Domain::encryptLocalKey(const QByteArray &passcode) { void Domain::encryptLocalKey(const QByteArray &passcode) {
_passcodeKeySalt.resize(LocalEncryptSaltSize); _passcodeKeySalt.resize(LocalEncryptSaltSize);
memset_rand(_passcodeKeySalt.data(), _passcodeKeySalt.size()); base::RandomFill(_passcodeKeySalt.data(), _passcodeKeySalt.size());
_passcodeKey = CreateLocalKey(passcode, _passcodeKeySalt); _passcodeKey = CreateLocalKey(passcode, _passcodeKeySalt);
EncryptedDescriptor passKeyData(MTP::AuthKey::kSize); 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/chat/group_call_userpics.h"
#include "ui/paint/blobs.h" #include "ui/paint/blobs.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"
namespace Ui { namespace Ui {
@ -237,7 +237,7 @@ void GroupCallUserpics::sendRandomLevels() {
} }
for (auto &userpic : _list) { for (auto &userpic : _list) {
if (const auto blobs = userpic.blobsAnimation.get()) { 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.); userpic.blobsAnimation->blobs.setLevel(float64(value) / 100.);
} }
} }

View file

@ -12,7 +12,7 @@
#include "ui/painter.h" #include "ui/painter.h"
#include "ui/widgets/call_button.h" #include "ui/widgets/call_button.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "styles/palette.h" #include "styles/palette.h"
#include "styles/style_widgets.h" #include "styles/style_widgets.h"
#include "styles/style_calls.h" #include "styles/style_calls.h"
@ -681,7 +681,7 @@ CallMuteButton::IconState CallMuteButton::randomWavingState() {
{ 240, 420 }, { 240, 420 },
{ 420, 540 }, { 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 }; 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 "ui/effects/fireworks_animation.h"
#include "base/openssl_help.h" #include "base/random.h"
namespace Ui { namespace Ui {
namespace { namespace {
@ -37,12 +37,8 @@ std::vector<QBrush> PrepareBrushes() {
}; };
} }
int RandomInt(uint32 till) {
return int(openssl::RandomValue<uint32>() % till);
}
[[nodiscard]] float64 RandomFloat01() { [[nodiscard]] float64 RandomFloat01() {
return openssl::RandomValue<uint32>() return base::RandomValue<uint32>()
/ float64(std::numeric_limits<uint32>::max()); / float64(std::numeric_limits<uint32>::max());
} }
@ -190,22 +186,24 @@ void FireworksAnimation::startFall() {
void FireworksAnimation::initParticle(Particle &particle, bool falling) { void FireworksAnimation::initParticle(Particle &particle, bool falling) {
using Type = Particle::Type; using Type = Particle::Type;
particle.color = RandomInt(_brushes.size()); using base::RandomIndex;
particle.type = RandomInt(2) ? Type::Rectangle : Type::Circle;
particle.right = (RandomInt(2) == 1); particle.color = RandomIndex(_brushes.size());
particle.finishedStart = 1 + RandomInt(2); particle.type = RandomIndex(2) ? Type::Rectangle : Type::Circle;
particle.right = (RandomIndex(2) == 1);
particle.finishedStart = 1 + RandomIndex(2);
if (particle.type == Type::Circle) { if (particle.type == Type::Circle) {
particle.size = style::ConvertScale(6 + RandomFloat01() * 3); particle.size = style::ConvertScale(6 + RandomFloat01() * 3);
} else { } else {
particle.size = style::ConvertScale(6 + RandomFloat01() * 6); particle.size = style::ConvertScale(6 + RandomFloat01() * 6);
particle.rotation = RandomInt(360); particle.rotation = RandomIndex(360);
} }
if (falling) { if (falling) {
particle.y = -RandomFloat01() * kFireworkHeight * 1.2f; particle.y = -RandomFloat01() * kFireworkHeight * 1.2f;
particle.x = 5 + RandomInt(kFireworkWidth - 10); particle.x = 5 + RandomIndex(kFireworkWidth - 10);
particle.xFinished = particle.finishedStart; particle.xFinished = particle.finishedStart;
} else { } else {
const auto xOffset = 4 + RandomInt(10); const auto xOffset = 4 + RandomIndex(10);
const auto yOffset = kFireworkHeight / 4; const auto yOffset = kFireworkHeight / 4;
if (particle.right) { if (particle.right) {
particle.x = kFireworkWidth + xOffset; 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.moveX = (particle.right ? -1 : 1) * (1.2 + RandomFloat01() * 4);
particle.moveY = -(4 + 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 "window/notifications_utilities.h"
#include "base/platform/base_platform_file_utilities.h" #include "base/platform/base_platform_file_utilities.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "core/application.h" #include "core/application.h"
#include "data/data_peer.h" #include "data/data_peer.h"
#include "ui/empty_userpic.h" #include "ui/empty_userpic.h"
@ -61,7 +61,7 @@ QString CachedUserpics::get(
} }
v.path = u"%1tdata/temp/%2.png"_q.arg( v.path = u"%1tdata/temp/%2.png"_q.arg(
cWorkingDir(), cWorkingDir(),
QString::number(openssl::RandomValue<uint64>(), 16)); QString::number(base::RandomValue<uint64>(), 16));
if (key.first || key.second) { if (key.first || key.second) {
if (peer->isSelf()) { if (peer->isSelf()) {
const auto method = (_type == Type::Rounded) 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/localstorage.h"
#include "storage/localimageloader.h" #include "storage/localimageloader.h"
#include "storage/file_upload.h" #include "storage/file_upload.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "base/parse_helper.h" #include "base/parse_helper.h"
#include "base/zlib_help.h" #include "base/zlib_help.h"
#include "base/unixtime.h" #include "base/unixtime.h"
@ -484,7 +484,7 @@ SendMediaReady PrepareWallPaper(MTP::DcId dcId, const QImage &image) {
attributes.push_back(MTP_documentAttributeImageSize( attributes.push_back(MTP_documentAttributeImageSize(
MTP_int(image.width()), MTP_int(image.width()),
MTP_int(image.height()))); MTP_int(image.height())));
const auto id = openssl::RandomValue<DocumentId>(); const auto id = base::RandomValue<DocumentId>();
const auto document = MTP_document( const auto document = MTP_document(
MTP_flags(0), MTP_flags(0),
MTP_long(id), 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/base_file_utilities.h"
#include "base/zlib_help.h" #include "base/zlib_help.h"
#include "base/unixtime.h" #include "base/unixtime.h"
#include "base/openssl_help.h" #include "base/random.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_document.h" #include "data/data_document.h"
#include "data/data_cloud_themes.h" #include "data/data_cloud_themes.h"
@ -338,7 +338,7 @@ bool CopyColorsToPalette(
auto result = QString(); auto result = QString();
result.reserve(kRandomSlugSize); result.reserve(kRandomSlugSize);
for (auto i = 0; i != kRandomSlugSize; ++i) { for (auto i = 0; i != kRandomSlugSize; ++i) {
const auto value = openssl::RandomValue<uint8>() % values; const auto value = base::RandomValue<uint8>() % values;
if (value < letters) { if (value < letters) {
result.append(char('A' + value)); result.append(char('A' + value));
} else if (value < 2 * letters) { } else if (value < 2 * letters) {
@ -443,7 +443,7 @@ SendMediaReady PrepareThemeMedia(
auto attributes = QVector<MTPDocumentAttribute>( auto attributes = QVector<MTPDocumentAttribute>(
1, 1,
MTP_documentAttributeFilename(MTP_string(filename))); MTP_documentAttributeFilename(MTP_string(filename)));
const auto id = openssl::RandomValue<DocumentId>(); const auto id = base::RandomValue<DocumentId>();
const auto document = MTP_document( const auto document = MTP_document(
MTP_flags(0), MTP_flags(0),
MTP_long(id), 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 "window/themes/window_themes_generate_name.h"
#include "base/openssl_help.h" #include "base/random.h"
namespace Window { namespace Window {
namespace Theme { namespace Theme {
@ -339,13 +339,13 @@ QString GenerateName(const QColor &accent) {
return result; return result;
}; };
const auto random = [&](const std::vector<const char*> &values) { 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]); return capitalized(values[index]);
}; };
const auto min = ranges::min_element(kColors, pred); const auto min = ranges::min_element(kColors, pred);
Assert(min != end(kColors)); Assert(min != end(kColors));
const auto color = capitalized(min->second); const auto color = capitalized(min->second);
return (openssl::RandomValue<uint8>() % 2 == 0) return (base::RandomValue<uint8>() % 2 == 0)
? random(kAdjectives) + ' ' + color ? random(kAdjectives) + ' ' + color
: color + ' ' + random(kSubjectives); : 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