I have a requirement where an encrypted file is read in random order of 32k chunks and decrypted and final content hash is computed. This hash should match the original content of file.

I need this as while I am reading file from source I want decryption and hash computation to happen, else I will have to write all the contents and then decrypt and compute hash, which will require two pass/(read/write) of file.

I believe AES stream mode would help in random order decryption, I have to try this though, but I am not sure about which hash function would help here, if its possible to compute any hash reading data in random chunks.

Any pointers would be of great help. Thanks for time.

  • 1
    $\begingroup$ Hash functions are sequential, however you may be able to build a custom hash function with some kind of block based function followed by finite field multiplication and a finalization step $\endgroup$ – Richie Frame Dec 23 '16 at 5:13
  • 4
    $\begingroup$ Look up Merkle Trees $\endgroup$ – CodesInChaos Dec 23 '16 at 9:22
  • $\begingroup$ Just curious. Is your use of the hash anything other then ensuring integraty of data? I mean if you do not require it for deduplication purposes then why not store the hash of the cypher text $\endgroup$ – dave.zap Dec 23 '16 at 14:04
  • 1
    $\begingroup$ @RichieFrame Right, but it might be expensive to do so; more information here. For an unsuspecting visitor, Merkle Trees are definitely more practical. $\endgroup$ – Maarten Bodewes Dec 24 '16 at 1:01
  • $\begingroup$ Thanks all for suggestions, I'll look at Merkle Trees and give it a shot. $\endgroup$ – baba.kabira Dec 26 '16 at 4:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.