<div dir="auto"><div data-smartmail="gmail_signature" dir="auto"><br></div><div class="gmail_extra" dir="auto"><div class="gmail_quote">Den 27 apr. 2017 07:20 skrev "John Denker via cryptography" <<a href="mailto:cryptography@metzdowd.com">cryptography@metzdowd.com</a>>:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">On 04/26/2017 03:28 PM, Jon Callas wrote:<br>
<br>
> Personally, I would recommend that you *not* use counter mode or<br>
> anything resembling it for writing files.<br>
<br>
</div>I agree with that 100%.<br>
<br>
A cipher "mode" is a kludge that kinda maybe sorta allows people<br>
to survive in situations where they can't (or won't) re-key ...<br>
but you should always ask yourself, why not just re-key?  If<br>
your cipher cannot be efficiently or securely re-keyed, maybe<br>
you need a better cipher.<br>
<br>
Constructive suggestion:  Use something like ChaCha20, which<br>
is designed to do a good job with file encryption (and a lot<br>
of other things).  It has an enormous keyspace, and can be<br>
re-keyed efficiently.  Construct the key from at least:<br>
  -- The master key.<br>
  -- The block number.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">This part;</div><div dir="auto"><br></div><div class="gmail_extra" dir="auto"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  -- A sequence number, depending on how many times the<br>
   block has been rewritten.  (This allows random access,<br>
   as well as rewriting the whole file from the beginning.)<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">This is assuming the file won't be duplicated / shared / restored from backup. It is not sufficient alone. It also means any duplicated VM fails spectacularly in keeping the plaintexts secret. </div><div dir="auto"><br></div><div dir="auto">You need a guarantee that every single write will use a unique IV. That means you need OS level support for your encryption routine on every device touching the file. </div><div dir="auto"><br></div><div dir="auto">Deriving the IV from the message helps, but for small IV:s it isn't a guarantee for security (in particular when you write often). It is also impractical for large messages. </div><div dir="auto"><br></div><div class="gmail_extra" dir="auto"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">
> Counter mode creates a stream cipher.<br>
<br>
</div>Right.<br>
<div class="quoted-text"><br>
> it's like leaving a rake in the yard with the tines up.<br>
<br>
</div>Good analogy.</blockquote></div></div></div>