AudioChunk.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "AudioChunk.h"
  2. std::vector<uint8_t> audioAESIV({0x72, 0xe0, 0x67, 0xfb, 0xdd, 0xcb, 0xcf, 0x77, 0xeb, 0xe8, 0xbc, 0x64, 0x3f, 0x63, 0x0d, 0x93});
  3. AudioChunk::AudioChunk(uint16_t seqId, std::vector<uint8_t> &audioKey, uint32_t startPosition, uint32_t predictedEndPosition)
  4. {
  5. this->crypto = std::make_unique<Crypto>();
  6. this->seqId = seqId;
  7. this->audioKey = audioKey;
  8. this->startPosition = startPosition;
  9. this->endPosition = predictedEndPosition;
  10. this->decryptedData = std::vector<uint8_t>();
  11. this->isHeaderFileSizeLoadedSemaphore = std::make_unique<WrappedSemaphore>(2);
  12. this->isLoadedSemaphore = std::make_unique<WrappedSemaphore>(2);
  13. }
  14. AudioChunk::~AudioChunk()
  15. {
  16. }
  17. void AudioChunk::appendData(std::vector<uint8_t> &data)
  18. {
  19. this->decryptedData.insert(this->decryptedData.end(), data.begin(), data.end());
  20. }
  21. void AudioChunk::decrypt()
  22. {
  23. // calculate the IV for right position
  24. auto calculatedIV = this->getIVSum(startPosition / 16);
  25. crypto->aesCTRXcrypt(this->audioKey, calculatedIV, decryptedData);
  26. this->startPosition = this->endPosition - this->decryptedData.size();
  27. this->isLoaded = true;
  28. }
  29. // Basically just big num addition
  30. std::vector<uint8_t> AudioChunk::getIVSum(uint32_t n)
  31. {
  32. return bigNumAdd(audioAESIV, n);
  33. }