TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Dude, is my code constant time? (2016)

59 pointsby rdpintqogeogsaaover 3 years ago

5 comments

gnulinuxover 3 years ago
From the linked github code:<p><pre><code> &#x2F;* Intel actually recommends calling CPUID to serialize the execution flow and reduce variance in measurement due to out-of-order execution. We don&#x27;t do that here yet. see §3.2.1 http:&#x2F;&#x2F;www.intel.com&#x2F;content&#x2F;www&#x2F;us&#x2F;en&#x2F;embedded&#x2F;training&#x2F;ia-32-ia-64-benchmark-code-execution-paper.html *&#x2F; static int64_t cpucycles(void) { unsigned int hi, lo; __asm__ volatile(&quot;rdtsc\n\t&quot; : &quot;=a&quot;(lo), &quot;=d&quot;(hi)); return ((int64_t)lo) | (((int64_t)hi) &lt;&lt; 32); } </code></pre> Where `cpucycles` returns the number of CPU cycles since its reset (as 64 bit integer). [1]<p>Seems really useful for benchmarking!<p>Note that this code was last updated Oct 2020 and there is a note on top. Also reading about this instruction, sounds like it doesn&#x27;t work in hyperthreaded CPUs? I was wondering if anyone knows an even more accurate (?) version of this code? Possibly by conforming to Intel&#x27;s suggestion (or not)?<p>Author in the article claims:<p>&gt; (The code calls the RDTSC instruction to get accurate cycle-level timing measurements.)<p>This implies the above `cpucycles` is more accurate than using high resolution clocks. Is this still accurate in multicore or hyperthreaded CPUs? if not does this mean dudect doesn&#x27;t work as accurately in such systems?<p>Really curious about this, if anyone can point me to more code I&#x27;ll be very happy!<p>[1] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Time_Stamp_Counter" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Time_Stamp_Counter</a>
评论 #29991094 未加载
评论 #29991458 未加载
评论 #29990134 未加载
captainmuonover 3 years ago
I wonder if there isn&#x27;t just a simple way to make timing attacks impossible. Find out the longest possible runtime, add some overhead, and then do the encryption in a different thread or process. Then call back after a constant time. It seems like this should be a primitive that is used a lot.
评论 #29992881 未加载
Waterluvianover 3 years ago
I haven’t followed this stuff but I was loosely aware of the concept of a timing attack. I had no idea they were actually successfully employed.
评论 #29989301 未加载
Zababaover 3 years ago
Concretly, how often do security breaches happen due to timing attack? I can&#x27;t grasp how severe this things are.
评论 #29992726 未加载
评论 #29992665 未加载
GrumpyNlover 3 years ago
The site doesnt load.
评论 #29989268 未加载