Skip to content

Commit

Permalink
docs: libdave comments
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Oct 16, 2024
1 parent 5c6dcec commit 8ebc0af
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/dpp/dave/array_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,4 @@ inline array_view<T> make_array_view(std::vector<T>& data)
return array_view<T>(data.data(), data.size());
}

} // namespace dpp::dave

}
3 changes: 1 addition & 2 deletions src/dpp/dave/cipher_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ std::unique_ptr<cipher_interface> create_cipher(dpp::cluster& cl, const encrypti
return cipher->is_valid() ? std::move(cipher) : nullptr;
}

} // namespace dpp::dave

}
3 changes: 1 addition & 2 deletions src/dpp/dave/cipher_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@ class cipher_interface { // NOLINT
*/
std::unique_ptr<cipher_interface> create_cipher(dpp::cluster& cl, const encryption_key& key);

} // namespace dpp::dave

}
3 changes: 1 addition & 2 deletions src/dpp/dave/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ class clock : public clock_interface {
}
};

} // namespace dpp::dave

}
4 changes: 1 addition & 3 deletions src/dpp/dave/codec_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,4 @@ bool process_frame_av1(outbound_frame_processor & processor, array_view<const ui
*/
bool validate_encrypted_frame(outbound_frame_processor& processor, array_view<uint8_t> frame);

} // namespace dpp::dave::codec_utils


}
33 changes: 33 additions & 0 deletions src/dpp/dave/cryptor_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,49 @@ class aead_cipher_manager {
*/
void cleanup_expired_ciphers();

/**
* @brief chrono clock
*/
const clock_interface& current_clock;

/**
* @brief key ratchet for cryptor
*/
std::unique_ptr<key_ratchet_interface> current_key_ratchet;

/**
* @brief Cryptor for each generation with expiry
*/
std::unordered_map<key_generation, expiring_cipher> cryptor_generations;

/**
* @brief Time ratchet was created
*/
time_point ratchet_creation;

/**
* @brief Time ratchet expired
*/
time_point ratchet_expiry;

/**
* @brief Oldest generation for ratchet
*/
key_generation oldest_generation{0};

/**
* @brief Newest generation for ratchet
*/
key_generation newest_generation{0};

/**
* @brief Newest nonce
*/
std::optional<big_nonce> newest_processed_nonce;

/**
* @brief List of missing nonces from sequence
*/
std::deque<big_nonce> missing_nonces;

/**
Expand Down
24 changes: 24 additions & 0 deletions src/dpp/dave/decryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,39 @@ class decryptor {
*/
void return_frame_processor(std::unique_ptr<inbound_frame_processor> frame_processor);

/**
* @brief Chrono clock
*/
clock current_clock;

/**
* @brief Cryptor manager list
*/
std::deque<aead_cipher_manager> cryptor_managers;

/**
* @brief Mutex for thread safety of frame processor list
*/
std::mutex frame_processors_mutex;

/**
* @brief List of frame processors
*/
std::vector<std::unique_ptr<inbound_frame_processor>> frame_processors;

/**
* @brief Passthrough expiry time
*/
time_point allow_pass_through_until{time_point::min()};

/**
* @brief Last stats generation time
*/
time_point last_stats_time{time_point::min()};

/**
* @brief Stats for audio and video decryption
*/
std::array<decryption_stats, 2> stats;

/**
Expand Down
60 changes: 57 additions & 3 deletions src/dpp/dave/encryptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ struct encryption_stats {
class encryptor {
public:
/**
* @brief Constructor
* @param cl Creator
*/
* @brief Constructor
* @param cl Creator
*/
encryptor(dpp::cluster& cl) : creator(cl) { };

/**
Expand Down Expand Up @@ -219,25 +219,79 @@ class encryptor {
*/
void update_current_protocol_version(protocol_version version);

/**
* @brief True if passthrough is enabled
*/
std::atomic_bool passthrough_mode_enable{false};

/**
* @brief Key generation mutex for thread safety
*/
std::mutex key_gen_mutex;

/**
* @brief Current encryption (send) ratchet
*/
std::unique_ptr<key_ratchet_interface> ratchet;

/**
* @brief Current encryption cipher
*/
std::shared_ptr<cipher_interface> cryptor;

/**
* @brief Current key generation number
*/
key_generation current_key_generation{0};

/**
* @brief Current truncated sync nonce
*/
truncated_sync_nonce truncated_nonce{0};

/**
* @brief Frame processor list mutex
*/
std::mutex frame_processors_mutex;

/**
* @brief List of outbound frame processors
*/
std::vector<std::unique_ptr<outbound_frame_processor>> frame_processors;

/**
* @brief A pair of 32 bit SSRC and codec in use for that SSRC
*/
using ssrc_codec_pair = std::pair<uint32_t, codec>;

/**
* @brief List of codec pairs for SSRCs
*/
std::vector<ssrc_codec_pair> ssrc_codec_pairs;

/**
* @brief A chrono time point
*/
using time_point = std::chrono::time_point<std::chrono::steady_clock>;

/**
* @brief Last time stats were updated
*/
time_point last_stats_time{time_point::min()};

/**
* @brief Stores audio/video encryption stats
*/
std::array<encryption_stats, 2> stats;

/**
* @brief Callback for version change, if any
*/
protocol_version_changed_callback changed_callback;

/**
* Current protocol version supported
*/
protocol_version current_protocol_version{max_protocol_version()};

/**
Expand Down
54 changes: 54 additions & 0 deletions src/dpp/dave/frame_processors.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,44 @@ class inbound_frame_processor {
*/
void add_ciphertext_bytes(const uint8_t* data, size_t size);

/**
* @brief True if frames are encrypted
*/
bool encrypted{false};

/**
* @brief Original size
*/
size_t original_size{0};

/**
* @brief AEAD tag
*/
array_view<const uint8_t> tag;

/**
* @brief Truncated nonce
*/
truncated_sync_nonce truncated_nonce;

/**
* @brief Unencrypted parts of the frames
*/
ranges unencrypted_ranges;

/**
* @brief additional authenticated data
*/
std::vector<uint8_t> authenticated;

/**
* @brief Ciphertext
*/
std::vector<uint8_t> ciphertext;

/**
* @brief Plaintext
*/
std::vector<uint8_t> plaintext;

/**
Expand Down Expand Up @@ -283,11 +314,34 @@ class outbound_frame_processor {
void add_encrypted_bytes(const uint8_t* bytes, size_t size);

private:
/**
* @brief Codec used to decrypt
*/
codec frame_codec{codec::cd_unknown};

/**
* @brief Frame index
*/
size_t frame_index{0};

/**
* @brief Unencrypted bytes
*/
std::vector<uint8_t> unencrypted_bytes;

/**
* @brief Encrypted bytes
*/
std::vector<uint8_t> encrypted_bytes;

/**
* @brief Ciphertext bytes
*/
std::vector<uint8_t> ciphertext_bytes;

/**
* @brief Unencrypted ranges that need to be kept plaintext to allow for RTP routing
*/
ranges unencrypted_ranges;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/dpp/dave/parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ ::mlspp::ExtensionList leaf_node_extensions_for_protocol_version(protocol_versio
*/
::mlspp::ExtensionList group_extensions_for_protocol_version(protocol_version version, const ::mlspp::ExternalSender& external_sender) noexcept;

} // namespace dpp::dave::mls
}
Loading

0 comments on commit 8ebc0af

Please sign in to comment.