7 ms·
CTTK: Constant-Time Toolkit
- kccqzy 9y agoHow does this compare with typical branch-free programming? The kind that’s so latency-sensitive that we don’t even trust the branch predictor and don’t want to pay for mispredictions?
- pornin 9y agoA part of constant-time coding is to avoid branches based on secret data, thus branch-free programming techniques apply. However, there is more to it; for instance, you must also avoid any memory access whose address depends on secret data (otherwise, the secret could leak through observation of the cache status). On the other hand, branches that do not depend on secret data are OK in constant-time code. Typically, when you process a chunk of data, the chunk length is not secret, and there will be a loop whose exit condition really is a conditional jump that depends on the length.
- blattimwind 9y agoOne somewhat ugly truth is, that you can't implement some algorithms securely in software while retaining good or even acceptable performance. As we've seen previously, performance is critical for crypto, because people will choose something faster over the proper, secure alternative, especially if the insecurity is not an obvious or hard failure, as it is with side channels. The modern approach to this issue is to design algorithms specifically for software implementation and avoid entire classes of side channels already in the design of the algorithm. This is one of the noticeable differences between older primitives (NIST/SECG ECC, DSA, RSA, a whole bunch of ciphers) and newer primitives designed for software (EdDSA over sensible curves, X25519, Chacha20 and so on).
- sitkack 9y agobranch-free is helpful but not a cure all. Any operation that takes a time variable on its input is subject to leaking information. Many X86 instructions appear to be constant time, but under certain conditions are not. So even when used in a branch-free style, information can still leak depending on the data and the instructions used.
- userbinator 9y agoMany X86 instructions appear to be constant time, but under certain conditions are not. One not-so-well-known and possibly surprising fact is that on the NetBurst (P4) microarchitecture, 32-bit arithmetic operations that produce a carry/borrow between the two 16-bit halves introduce an extra clock cycle of latency, because the ALUs are only 16 bits wide.
- HelloNurse 9y agoThis one is the opposite sort, in which code is carefully antioptimized to be as slow as the worst case (and optimized to make the worst case fast).
- fenollp 9y agoIf that interests you you should take a look at https://github.com/PLSysSec/FaCT https://github.com/PLSysSec/FaCT
- bringtheaction 9y agoTheir README did not say anything about what the project is but they have another document in the repo root that does. https://github.com/PLSysSec/FaCT/blob/rewrite/proposal.md https://github.com/PLSysSec/FaCT/blob/rewrite/proposal.md
- ozzmotik 9y agooh hey thanks for pointing that out, I was noticing that there wasn't much detail about the project in the Readme. ++ to you for finding that
- hacker_9 9y agoWhy not just append `thread.sleep(random() % 1000)' to your calculations if you are worried about timing attacks?
- a_t48 9y agoEverything else aside (where does one put the sleep?) probably stuff like https://www.sjoerdlangkemper.nl/2016/02/11/cracking-php-rand/ https://www.sjoerdlangkemper.nl/2016/02/11/cracking-php-rand...
- brilee 9y agoI'm not sure how that article applies; it discusses the hazards of using a PRNG. I think the actual objection is that it just increases the number of samples required, but doesn't fix the problem.
- barrkel 9y agoEven if your random() is cryptographically strong and not just an LCG, many samples over time will still be able to extract a signal.
- mikeash 9y agoThat adds noise to the signal. The signal can still be recovered with more data, so while this helps, it’s not a complete solution.
- pornin 9y agoMeasuring the total runtime is only one of many kinds of timing attacks. The most effective timing attacks do not do that; instead, they measure time taken to access some specific memory areas _after_ the execution of the target code, in order to work out which cache lines were loaded by that code (this applies to both data and code caches, btw). These are "timing attacks" since they ultimately come from a measure of elapsed time, but not necessarily the time taken by the target code itself. Also, when a thread is sleeping, the OS will schedule other threads, which opens many additional ways for attackers to notice that sleeping started.
- 9y ago
- friendlydude12 9y agoCalling this “Constant time” is a bit confusing. I thought it was going to be a library of algorithms for solving O(1) problems. “Timing attack resistant” would be a better name.
- IncRnd 9y agoConstant Time refers to algorithms that execute in constant time without predictive branches on secret data. Constant Time is the accepted standard name for such.
- friendlydude12 9y agoIt also refers to time complexity: https://en.wikipedia.org/wiki/Time_complexity#Constant_time https://en.wikipedia.org/wiki/Time_complexity#Constant_time this predates the crypto jargon.
- IncRnd 9y ago> It also refers to time complexity: https://en.wikipedia.org/wiki/Time_complexity#Constant_time https://en.wikipedia.org/wiki/Time_complexity#Constant_time this predates the crypto jargon. Looking at the very first sentence of your link: An algorithm is said to be constant time (also written as O(1) time) if the value of T(n) is bounded by a value that does not depend on the size of the input. That is true in this case. Also, from the article here: It shall be noted that the expression "constant-time" is traditional but slightly confusing: constant-time code does not always execute in a constant amount of time; rather, this means that any variation in execution time is uncorrelated with secret information. You are drawing a distinction that doesn't exist.
- friendlydude12 9y agoThere is in fact a distinction between the two usages. I can show it with a simple counter example: def matches_secret(a): return a == “secret” The execution time of matches_secret is bounded by a constant and the variation in execution time is correlated with secret information. This precisely means that matches_secret is constant time in the O(1) sense and not in the security sense referenced by the original article.
- platz 9y agoI think the ability to actually exploit timing attacks is bit over indexed. Almost all of the time you need direct access on the machine, i.e. not a webserver. So it's more of a concern for native environments as opposed to networked environments.
- heywire 9y agoIf the system being attacked does not limit attempts, one might repeat their requests until they achieve statistical significance. The first Stripe CTF had a level that dealt with timing attacks, and that is the approach I took.
- tptacek 9y agoExcept for the fact that virtually all modern serverside applications live on shared hardware with anonymous cotenants, and all modern clientside applications are JIT'd from random websites, but sure.
- IncRnd 9y agoI'm not sure why you believe that, since your belief runs contrary to the real-world oracular attacks against .Net and Ruby on Rails. Also, see Lucky-13, POODLE, and Logjam.
- amenghra 9y agoYou should read "Remote Timing Attacks are Practical" (https://crypto.stanford.edu/~dabo/papers/ssl-timing.pdf https://crypto.stanford.edu/~dabo/papers/ssl-timing.pdf) published in 2003 by David Brumley and Dan Boneh.
- zaarn 9y agoI wonder if it would be viable to abuse the movfuscator to achieve similar effects. Since all code in the movfuscator runs in a loop without branches, it would be effectively constant time too...