ZaStoGram_desktop/Telegram/SourceFiles/e2e_cloud/vault/password_kdf.h
loop-uh 25ae099c66 Bring the Argon2 sources the vault already depends on
The slice landed one commit too early: the vault links
tdesktop::lib_argon2 and the build recipe for it was written, but the
recipe was invisible — the bare "cmake" .gitignore pattern struck a
second time on lib_argon2.cmake — and ThirdParty/argon2 itself never
existed, so origin/dev stopped at configure with a missing include.
The reference implementation comes in as a submodule pinned to the
20190702 release, whose layout is exactly what the recipe lists.

The tail of the work rides along: a file-backed chunk store, and a
security floor for new vaults — creation now demands at least 64 MiB
and three passes from the Argon2id config instead of accepting
anything structurally valid, with the vault test pinning that
boundary.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-31 22:42:13 +03:00

59 lines
1.5 KiB
C++

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include <QtCore/QByteArray>
#include <array>
#include <cstdint>
#include <optional>
namespace E2ECloud {
struct Argon2idConfig {
std::uint16_t parameterVersion = 1;
std::uint32_t memoryKibibytes = 0;
std::uint32_t iterations = 0;
std::uint32_t parallelism = 0;
friend inline bool operator==(
const Argon2idConfig &,
const Argon2idConfig &) = default;
};
struct Argon2idParameters {
std::uint16_t parameterVersion = 1;
std::uint32_t memoryKibibytes = 0;
std::uint32_t iterations = 0;
std::uint32_t parallelism = 0;
std::array<std::uint8_t, 16> salt = {};
friend inline bool operator==(
const Argon2idParameters &,
const Argon2idParameters &) = default;
};
using PasswordDerivedKey = std::array<std::uint8_t, 32>;
class PasswordKdf {
public:
virtual ~PasswordKdf() = default;
[[nodiscard]] virtual std::optional<PasswordDerivedKey> deriveArgon2id(
const QByteArray &password,
const Argon2idParameters &parameters) const = 0;
};
[[nodiscard]] bool IsValidArgon2idParameters(
const Argon2idParameters &parameters);
[[nodiscard]] bool IsValidArgon2idConfig(const Argon2idConfig &config);
[[nodiscard]] bool IsSecureArgon2idConfigForNewVault(
const Argon2idConfig &config);
} // namespace E2ECloud