Questions tagged [constant-time]

Constant time functions are needed in cryptography software to prevent attacks based on time measuring of the operations.

Constant time functions are needed in cryptography software to prevent attacks based on time measuring of the operations.

25 questions
25
votes
4 answers

Near constant time rotate that does not violate the standards

I'm having a heck of a time trying to come up with a constant time rotate that does not violate the C/C++ standards. The problem is the edge/corner cases, where operations are called out in algorithms and those algorithms cannot be changed. For…
jww
  • 83,594
  • 69
  • 338
  • 732
21
votes
3 answers

Does memory dependence speculation prevent BN_consttime_swap from being constant-time?

Context The function BN_consttime_swap in OpenSSL is a thing of beauty. In this snippet, condition has been computed as 0 or (BN_ULONG)-1: #define BN_CONSTTIME_SWAP(ind) \ do { \ t = (a->d[ind] ^ b->d[ind]) & condition; \ …
Pascal Cuoq
  • 75,447
  • 6
  • 144
  • 260
7
votes
5 answers

Fast constant time evaluation of "x==7" to 1 (true) or 0 (false) in Java

I want to port a crypto function from C to Java. The function has to run in constant time, so no conditional branchings (and no table lookups based on x) are allowed. The original C code is: int x,result; ... result = (x==7); ... So that 'result'…
Chris
  • 187
  • 7
6
votes
1 answer

What is the time complexity of Java's ArrayList.sublist(startIndex, endIndex) method?

The question basically says it all. Suppose I have a (sorted) list that can contain anywhere from 1K to 1M items. I have a starting index and an ending index. If I use the ArrayList.sublist(start, end) method, is the time complexity O(n) or O(1)? I…
Grace F.
  • 63
  • 1
  • 3
5
votes
2 answers

Is masking effective for thwarting side channel attacks?

I'm working with some bigint public-key cryptography code. Is it safe to use bitwise masking to ensure that the calculation timing and memory addresses accessed are independent of the data values? Is this technique vulnerable to side-channel attacks…
Nayuki
  • 16,655
  • 5
  • 47
  • 75
3
votes
2 answers

Is JavaScript switch statement linear or constant time?

I have the following JavaScript on my site so that when certain specific searches are performed, the answer is hardcoded to a specific page: function redirect() { var input = document.getElementById('searchBox').value.toLowerCase(); switch…
WilliamKF
  • 36,283
  • 61
  • 170
  • 271
2
votes
3 answers

Create array structure in JavaScript that omits indexing

Indexing (maintaining indices) in an array makes Array.prototype.shift and Array.prototype.unshift O(N) instead of O(1). However, if we just want to use pop() / push() / shift() and unshift() and never use indices for lookup, is there a way to…
Alexander Mills
  • 1
  • 80
  • 344
  • 642
2
votes
1 answer

LFU cache, how is get and set in O(1)?

Preparing for interviews and I came across something that is making me question my understanding of big O constant time algorithms. A question on LeetCode asks to create a solution to the LFU cache problem. There are 3 methods to…
Jimbo
  • 1,533
  • 3
  • 10
  • 14
1
vote
0 answers

Cannot detect any meaningful timing difference in PHP (constant timing attack)

There's quite a few articles around PHP stating that constant timing attacks are possible when doing direct string comparisons. I've written some sample code to try and determine the order of magnitude difference but it's showing that it's not…
Adrian
  • 305
  • 1
  • 5
  • 17
1
vote
2 answers

Why do we need to add a "sleep" method to make a constant time attack succeed?

In this website: http://elijahcaine.me/remote-timing-attacks/ the author describes well what is a constant time attack and how to protect against this type of vulnerability. But in the code that the author have done: # secret.py from time import…
Segfault
  • 23
  • 5
1
vote
1 answer

Why does the hash() function in python take constant time to operate on strings of variable length?

From the run time of programs including the hash() operation on variable length strings I felt that it might be that the hash() function takes constant time to operate on different length strings. To verify my assumption I made the following…
1
vote
1 answer

Efficient circular buffer with constant-time access

In a machine learning project written in python, I need an efficient circular buffer like collections.deque but with constant-time access to any element like numpy.array. The problem is that deque is apparently a linked list. Is there something…
1
vote
1 answer

Python Error: ModuleNotFoundError: No module named 'cryptography.hazmat.bindings._constant_time'

I'm trying to run a script that I've been able to run in the past. It stops with error: ModuleNotFoundError: No module named 'cryptography.hazmat.bindings._constant_time' I recently removed python 3.6 and installed python ActiveState: ActivePython…
1
vote
1 answer

Constant-time string comparison function

To compare two strings, I currently use strcmp or one of its variants. However, because strcmp take longer if more characters match, it is vulnerable to timing attacks. Is there a constant-time string comparison function in the standard library on…
Sjoerd
  • 68,958
  • 15
  • 118
  • 167
1
vote
0 answers

Datastructure to store mutable key/value pair in O(1) time in Java

I have a World which can contain multiple Bullets, all of the Bullet has a Position (Center). Which basically is the following class Position{ private double xCoordinate; private double yCoordinate; } We need to implement a function in O(1)…
Li Jianing
  • 11
  • 4
1
2