<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 27, 2024 at 2:27 PM Christian Huitema <<a href="mailto:huitema@huitema.net">huitema@huitema.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
On 8/25/2024 6:28 PM, Jerry Leichter wrote:<br>
>> ...<br>
> Yes, but what exactly does "don't optimize this code" mean?  There are typically many ways to express the same source statements in specific machine instructions, and which ones are "optimized" is in the eye of the beholder.<br>
<br>
Yes. It might work in practice, but it seems to be essentially a <br>
negative statement, "don't do this behavior that I know is harmful". And <br>
you are right that just "not optimizing" does not provide any guarantee <br>
about side effects of the default behavior.<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">I don't think we need to go beyond 'don't perform code substitution/elimination' or perhaps 'don't do any optimization that would confuse the debugger'.</div><div class="gmail_default" style="font-size:small"></div></div><div><div class="gmail_default" style="font-size:small">Since I am working in C#, I can play a few tricks such as using code reflection to get at private variables and zero them on exit. Or I could simply substitute my own RedInt class for BigInt with appropriate handling.</div></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> The original message to which I was responding actually gives two examples of what you *really* need to be able to say:  "Don't leave copies of this data around," and "this loop needs to run in constant time."  Neither of these corresponds in any direct way to "don't optimize this code."  In fact, generating a constant-time loop is highly instruction set - and sometimes particular implementation of that instruction set - specific.  There is no particular reason to think that the non-optimized output from the compiler - whatever that might mean - will always be constant-time, no matter what the source code says.<br>
<br>
Yes indeed. We want to say something like, "compiler, please, try to <br>
execute the following statements in constant time, whatever the <br>
variations in cache and branches." And yes, it is something better done <br>
in the compiler itself than by trying to write code with magical properties.</blockquote><div><div><br></div><div><div class="gmail_default">I don't think we need to try constant time because I don't think any compiler is capable of guaranteeing that.</div><br></div><div><div class="gmail_default" style="font-size:small">I never trusted the Montgomery ladder, I prefer blinding. Though some folk seem to not get the fact that whether you add a random value to mask a private key or split it into two, it's the same thing.</div><br></div><div class="gmail_default" style="font-size:small"><br></div></div></div></div>