2
$\begingroup$

I'd like to create a simple file-cipher, which provides seekable encryption (so I can decrypt any part of the encrypted message, without the need of decrypt from the start).

Here's my current idea: I generate a 128-bit IV, that will be the first 16 byte of the encrypted file. Then I use AES CTR, and encrypt the file. The initial counter value is IV, then I increment it for each 16-byte block.

The source file is chunk based: each chunk is followed by its SHA256. My need is to be able to read each whole chunk securely. After a chunk decrypted, its hash will be verified.

Is this method secure (suppose that counter values don't overlap)?

Is there a better (more secure) method to achieve this?

Note: I choose to use 128-bit IV, because of the comment of Ilmari Karonen here.

$\endgroup$
7
  • $\begingroup$ Are you updating data, or is it write-once? $\endgroup$ Commented Nov 29, 2017 at 21:27
  • $\begingroup$ @CodesInChaos: it is write-once. If the data is updated, then a new IV will be generated for the whole file. $\endgroup$
    – geza
    Commented Nov 29, 2017 at 21:27
  • 4
    $\begingroup$ The big problem is the lack of integrity protection for partial reads. Also encrypting a hash is not a secure MAC. $\endgroup$ Commented Nov 29, 2017 at 21:28
  • $\begingroup$ @CodesInChaos: thanks for the response! As for your first concern, I've edited my question. I hope it is safe now to do partial reads (I'll always read a whole chunk from the file). About your second comment: what is the problem with encrypting a hash? Why isn't it secure? Is there a possible attack? $\endgroup$
    – geza
    Commented Nov 29, 2017 at 21:36
  • $\begingroup$ Truncation is another attack to watch out for. @maarten I added the link later on. About the same time geza added their response. $\endgroup$ Commented Nov 29, 2017 at 21:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.