no more clicks on SPDIF & CSpot

This commit is contained in:
Philippe G
2022-01-13 18:21:36 -08:00
parent 3fb1c16f56
commit 60584ae207
11 changed files with 57 additions and 34 deletions

View File

@@ -24,13 +24,28 @@ void AudioChunk::appendData(const std::vector<uint8_t> &data)
this->decryptedData.insert(this->decryptedData.end(), data.begin(), data.end());
}
void AudioChunk::decrypt()
void AudioChunk::readData(uint8_t *target, size_t offset, size_t nbytes) {
auto readPos = offset + nbytes;
auto modulo = (readPos % 16);
auto ivReadPos = readPos;
if (modulo != 0) {
ivReadPos += (16 - modulo);
}
if (ivReadPos > decryptedCount) {
// calculate the IV for right position
auto calculatedIV = this->getIVSum((oldStartPos + decryptedCount) / 16);
crypto->aesCTRXcrypt(this->audioKey, calculatedIV, decryptedData.data() + decryptedCount, ivReadPos - decryptedCount);
decryptedCount = ivReadPos;
}
memcpy(target, this->decryptedData.data() + offset, nbytes);
}
void AudioChunk::finalize()
{
// calculate the IV for right position
auto calculatedIV = this->getIVSum(startPosition / 16);
crypto->aesCTRXcrypt(this->audioKey, calculatedIV, decryptedData);
this->oldStartPos = this->startPosition;
this->startPosition = this->endPosition - this->decryptedData.size();
this->isLoaded = true;
}

View File

@@ -80,7 +80,7 @@ void AudioChunkManager::runTask() {
switch (data.size()) {
case DATA_SIZE_HEADER: {
CSPOT_LOG(debug, "ID: %d: header decrypt!", seqId);
CSPOT_LOG(debug, "ID: %d: header finalize!", seqId);
auto headerSize = ntohs(extract<uint16_t>(data, 2));
// Got file size!
chunk->headerFileSize =
@@ -92,9 +92,9 @@ void AudioChunkManager::runTask() {
if (chunk->endPosition > chunk->headerFileSize) {
chunk->endPosition = chunk->headerFileSize;
}
CSPOT_LOG(debug, "ID: %d: Starting decrypt!",
CSPOT_LOG(debug, "ID: %d: finalize chunk!",
seqId);
chunk->decrypt();
chunk->finalize();
chunk->isLoadedSemaphore->give();
break;

View File

@@ -113,9 +113,7 @@ size_t ChunkedByteStream::attemptRead(uint8_t *buffer, size_t bytes, std::shared
toRead = chunk->decryptedData.size() - offset;
}
// Copy data
memcpy(buffer, chunk->decryptedData.data() + offset, toRead);
chunk->readData(buffer, offset, toRead);
return toRead;
}

View File

@@ -35,7 +35,7 @@ std::vector<uint8_t> LoginBlob::decodeBlob(const std::vector<uint8_t> &blob, con
}
encryptionKey = std::vector<uint8_t>(encryptionKey.begin(), encryptionKey.begin() + 16);
crypto->aesCTRXcrypt(encryptionKey, iv, encrypted);
crypto->aesCTRXcrypt(encryptionKey, iv, encrypted.data(), encrypted.size());
return encrypted;
}