
Attacking scrypt via Cache Timing Side-Channel Mark Matthew Anderson Stanford University Abstract running KDF algorithms make the process of enumerat- ing all possible inputs a very laborious task. For exam- This paper gives a motivation for the design of memory- ple, if a given KDF takes 1ms to process, it would take hard key derivation functions (KDFs), a summary of an amount of time on the order of 1028 years for a single a memory-hard password-based key derivation function machine to evaluate the KDF on all possible values of a called scrypt, and an overview of cache timing attacks. 128-bit input. A cache timing attack against scrypt is introduced and Though designed to take a long time to evaluate, an is- described in detail. Finally, additional work necessary sue with standard KDFs is that attackers are often able to to implement the attack and measures to prevent the at- accelerate their computation by means of algorithmic op- tack are discussed. Since it is an actively-used utility timizations and highly parallel or specialized hardware. for generating cryptographic keys, constructing a pass- Ruddick and Yan demonstrate such attacks on the pop- word stealing attack against scrypt raises serious secu- ular PBKDF2 [1]. By shortening the execution time of rity concerns for any applications that make use of it. the KDF, an attacker is able to eliminate any protection against a dictionary attack. 1 Introduction As a stronger measure to prevent dictionary attacks, researchers have designed KDFs that are memory inten- 1.1 Memory-Hard KDFs sive in addition to being time intensive. Designing a KDF to be memory-hard is a way to preserve the long KDFs are functions that compute random looking runtime of the KDF by impeding any efforts to accelerate cryptographic keys from human-generated passwords. its execution. Memory is an expensive and slow piece of Human-generated passwords are far from random; users hardware. When large amounts of memory are required often choose passwords that are based on predictable fac- to execute a function, parallelized hardware (like a GPU) tors, like words or phrases that are familiar or meaning- is ineffective at providing any speedup, since all the par- ful to the user. While these passwords are still somewhat allel hardware is competing for a fixed and small amount random, KDFs are used in practice to generate keys with of shared memory. Likewise, building specialized hard- far higher degrees of randomness by applying pseudo- ware with enough parallelism and memory to quickly random functions to the user’s input. The output of the evaluate the memory-hard KDF is impractical because KDF is intended to appear independent from the user’s the designs are prohibitively expensive. input and to be impossible to invert. The increased ran- domness provided by KDFs makes key guessing attacks 1.2 The scrypt Algorithm extremely unlikely to conduct successfully. In addition to generating an output that is difficult to The scrypt algorithm [2, 3] was designed by Colin predict and invert, standard KDFs are also designed to Percival to be a memory-hard KDF. It takes as input a take a relatively large amount of time to execute in or- password (PW), a salt (S), a memory cost parameter (C), der to reduce the practicality of dictionary attacks. If an indexing parameter (I), a parallelization parameter KDFs were quickly computable, an attacker could eas- (P), and a desired output length parameter (Ls). Note- ily find an output’s preimage by evaluating the KDF for worthy parameters within the function are an array of a large set of potential passwords and finding which input blocks to be mixed (B), and a parameter that corresponds produces an output that matches the target value. Long- to the length of the inputs and outputs of the function MHMix (LMHM). The scrypt algorithm is defined by information when data accesses or function calls in a pro- the following function: gram are dependent on this secret information. Yuval Yarom’s PRIME+PROBE method [4] is an ex- scrypt(PW;S;C;I;P;Ls) : ample of a cache timing attack, and is the best technique (B[0];:::;B[P − 1]) PBKDF2(PW;S;1;P · LMHM) to use against scrypt. The PRIME+PROBE method is for j = 0 to P − 1 do used to track the access patterns of data over time by B[ j] MHMix(B[ j];C;I) intentionally thrashing target data in the cache and ob- end for serving when the victim puts that data back in cache. return PBKDF2(PW;B[0]jj:::jjB[P − 1];1;Ls) First, the attacker flushes the victim’s data from cache (the PRIME stage) by accessing data that it knows will The MHMix function is what gives scrypt its memory- evict the victim’s data from cache. Then, after waiting hard property. MHMix takes as input a block to be to give the victim an opportunity to access its data, the expanded and hashed (B), a memory cost parameter (C), attacker attempts to access the data it put in cache (the and an indexing parameter (I). Parameters used within PROBE stage). If the time to retrieve the data is relatively the function are a temporary block placeholder (X), a short, that means that the victim did not access its data. If memory-consuming array of hashes (A), and an indexing the time to retrieve the data is relatively long, the victim variable (k). MHMix uses a hashing function Mix whose accessed the target data, which caused the attacker’s data details are important to the scrypt algorithm, but not to be evicted from cache, forcing the attacker to wait for directly pertinent to the cache timing attack. MHMix its data to be retrieved from a lower-level memory. takes the input block, hashes it many times while saving The PRIME+PROBE attack can be used any time the the hash results, and computes an output derived from attacker shares some level of processor cache with the some of the hash results that are chosen by interpreting victim. This can happen when the attacker and victim certain hash values as indices. Since the hash values will processes are two processes running on the same ma- be unique to each password input to scrypt, the indices chine or when the attacker and victim are working on of the hash values that are accessed and used in the separate virtual machines that are hosted on the same output will also be unique to each password. Since the machine. Note that it is not necessary that the attacker hash values that are needed to compute the true scrypt and victim be using the same core on a multi-core pro- output are password-dependent, an adversary conducting cessor, they only need to be sharing cache memory on a brute force dictionary attack against scrypt will be some level. unable to predict which values will contribute to the final output and will be forced to store all values to potentially 2 Attack on scrypt be used, making array A in MHMix use large amounts of memory. MHMix is defined as: 2.1 Vulnerability MHMix(B;C;I): What makes the cache timing attack on scrypt possible X B is the following code from the MHMix function: for j = 0 to C − 1 do A[ j] X k ((int)X) mod C X Mix(X;I) X Mix(X ⊕ A[k];I) end for As previously mentioned, A is the array that gives for j = 0 to C − 1 do scrypt its memory-hard property. A stores all the re- k ((int)X) mod C peated hashes of B, such that A[n] = Mixn(B), where X Mix(X ⊕ A[k];I) Mixn(B) is the result of hashing B n times (e.g. end for Mix2(B) = Mix(Mix(B;I);I)). In the above lines of return X code, elements of A are chosen to be used in calculation of the scrypt result by interpreting hash results, which 1.3 Cache Timing Attacks are unique to and derived from secret information (the evaluation of PBKDF2 on the user’s password), as inte- Cache timing attacks are a class of side-channel attacks gers and using them to index through A (with the variable that extract information based on the availability or un- k). Since these memory accesses are dependent on the availability of data in a processor’s cache. These attacks password, patterning the memory accesses observed dur- are used to determine when certain data or instructions ing an execution of scrypt will give information about are being used. Knowledge of when particular data or the result of the evaluation of PBKDF2 in the first step instructions are in use can disclose details about secret of the scrypt algorithm. 2 Learning enough information about the PBKDF2 hash index of the first element accessed in the output construc- of the victim’s password allows an adversary to re- tion stage of MHMix, the attacker learns the value of duce an attack on scrypt to an attack on PBKDF2, MixC(·) mod C evaluated on the input to MHMix. With thereby bypassing the memory-hardness of scrypt. knowledge of this value, the attacker can reduce the set More specifically, once the memory access pattern of of potential passwords to the subset whose correspond- scrypt is observed, the attacker can construct a dictio- ing DI are equal to this value. From here, the attacker nary of PBKDF2 hashes of potential passwords, com- can either continue to observe evaluations of MHMix in pute what their access patterns will be, and compare the this manner and further reduce the set of potential pass- observed memory access patterns to the access patterns words, or they can brute force through the reduced candi- of the hashes in the dictionary.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages5 Page
-
File Size-