rtsp_crypto.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdint.h>
  4. #include "rtsp_conn.h"
  5. /**
  6. * RTSP Encrypted Communication
  7. * Handles ChaCha20-Poly1305 encrypted frame read/write
  8. */
  9. // Maximum size of an encrypted block
  10. #define RTSP_ENCRYPTED_BLOCK_MAX 0x400
  11. /**
  12. * Read and decrypt a block from socket
  13. * Format: [2-byte length (little-endian)][encrypted data + 16-byte tag]
  14. *
  15. * @param socket Client socket
  16. * @param conn Connection state (must have hap_session and encrypted_mode)
  17. * @param buffer Output buffer for decrypted data
  18. * @param buffer_size Size of output buffer
  19. * @return Decrypted length on success, -1 on error
  20. */
  21. int rtsp_crypto_read_block(int socket, rtsp_conn_t *conn, uint8_t *buffer,
  22. size_t buffer_size);
  23. /**
  24. * Encrypt and write data to socket
  25. * Splits into multiple blocks if needed (max RTSP_ENCRYPTED_BLOCK_MAX each)
  26. * Format: [2-byte length (little-endian)][encrypted data + 16-byte tag]
  27. *
  28. * @param socket Client socket
  29. * @param conn Connection state (must have hap_session and encrypted_mode)
  30. * @param data Data to encrypt and send
  31. * @param data_len Length of data
  32. * @return 0 on success, -1 on error
  33. */
  34. int rtsp_crypto_write_frame(int socket, rtsp_conn_t *conn, const uint8_t *data,
  35. size_t data_len);