I'm basically designing a protocol that requires a synchronous and ordered file transmission from a server (implemented in Node.js) to a device, over TCP. Streaming the file is not an option, so each file chunk is encapsulated in a message that has other non-encrypted fields, which are out of scope of this question.
One of the requirements is that the file contents can not be sent in plain text, so an encryption scheme had to be chosen, in this case I opted for the AES-256-CBC, assume for the purpose of this question that the algorithm can't be changed.
Due to device constraints (RAM ~10KB), it's required to split the file (<5 MB) into chunks, that will be then sent to the device according to the mentioned protocol, following a send / [ack|repeat] scheme. On reception, the device is able to store the chunk on disk.
So my main question here is that in the backend I have to choose between:
Encrypting the complete file and then split it into chunks
-> On reception device would append each chunk in a file and then decrypt it when all chunks were received.
vs
Dividing the file into chunks and then encrypt each of them.
-> Requires the sending of the Initialization Vector (IV) used on each chunk encryption in order to decrypt it.
-> On chunk reception the device would have to decrypt the chunk or store each of them with the respective IV and then decrypt them after receiving the last chunk.
The goal here is to understand what security issues arise from each approach and also an overhead comparison between them.
PS: I also have an integrity validation scheme but is out of the question's ambit.
getAuthTag
is called on the encrypting end after encryption has finished, then the end decrypting callssetAuthTag
just before finishing the decryption.while (more data) {update(); send();} final(); send(); getAuthTag(); send();
, and on the receiving endwhile (more data) {receive(); update();} receive(); setAuthTag(); final();
?