passport_encryption.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. namespace Passport {
  9. bytes::vector GenerateSecretBytes();
  10. bytes::vector EncryptSecureSecret(
  11. bytes::const_span secret,
  12. bytes::const_span passwordHashForSecret);
  13. bytes::vector DecryptSecureSecret(
  14. bytes::const_span encryptedSecret,
  15. bytes::const_span passwordHashForSecret);
  16. bytes::vector SerializeData(const std::map<QString, QString> &data);
  17. std::map<QString, QString> DeserializeData(bytes::const_span bytes);
  18. struct DataError {
  19. // QByteArray - bad existing scan with such file_hash
  20. // QString - bad data field value with such key
  21. // std::nullopt - additional scan required
  22. std::variant<v::null_t, QByteArray, QString> key;
  23. QString type; // personal_details, passport, etc.
  24. QString text;
  25. };
  26. std::vector<DataError> DeserializeErrors(bytes::const_span json);
  27. struct EncryptedData {
  28. bytes::vector secret;
  29. bytes::vector hash;
  30. bytes::vector bytes;
  31. };
  32. EncryptedData EncryptData(bytes::const_span bytes);
  33. EncryptedData EncryptData(
  34. bytes::const_span bytes,
  35. bytes::const_span dataSecret);
  36. bytes::vector DecryptData(
  37. bytes::const_span encrypted,
  38. bytes::const_span dataHash,
  39. bytes::const_span dataSecret);
  40. bytes::vector PrepareValueHash(
  41. bytes::const_span dataHash,
  42. bytes::const_span valueSecret);
  43. bytes::vector EncryptValueSecret(
  44. bytes::const_span valueSecret,
  45. bytes::const_span secret,
  46. bytes::const_span valueHash);
  47. bytes::vector DecryptValueSecret(
  48. bytes::const_span encrypted,
  49. bytes::const_span secret,
  50. bytes::const_span valueHash);
  51. uint64 CountSecureSecretId(bytes::const_span secret);
  52. bytes::vector EncryptCredentialsSecret(
  53. bytes::const_span secret,
  54. bytes::const_span publicKey);
  55. } // namespace Passport