# scrypt

__: Password-based key derivation function created in 2009__

**Short description**

General | |
---|---|

Designers | Colin Percival |

First published | 2009 |

Cipher detail | |

Digest sizes | variable |

Block sizes | variable |

Rounds | variable |

In cryptography, **scrypt** (pronounced "ess crypt"^{[1]}) is a password-based key derivation function created by Colin Percival in March 2009, originally for the Tarsnap online backup service.^{[2]}^{[3]} The algorithm was specifically designed to make it costly to perform large-scale custom hardware attacks by requiring large amounts of memory. In 2016, the scrypt algorithm was published by IETF as RFC 7914.^{[4]} A simplified version of scrypt is used as a proof-of-work scheme by a number of cryptocurrencies, first implemented by an anonymous programmer called ArtForz in Tenebrix and followed by Fairbrix and Litecoin soon after.^{[5]}

## Introduction

A password-based key derivation function (password-based KDF) is generally designed to be computationally intensive, so that it takes a relatively long time to compute (say on the order of several hundred milliseconds). Legitimate users only need to perform the function once per operation (e.g., authentication), and so the time required is negligible. However, a brute-force attack would likely need to perform the operation billions of times, at which point the time requirements become significant and, ideally, prohibitive.

Previous password-based KDFs (such as the popular PBKDF2 from RSA Laboratories) have relatively low resource demands, meaning they do not require elaborate hardware or very much memory to perform. They are therefore easily and cheaply implemented in hardware (for instance on an ASIC or even an FPGA). This allows an attacker with sufficient resources to launch a large-scale parallel attack by building hundreds or even thousands of implementations of the algorithm in hardware and having each search a different subset of the key space. This divides the amount of time needed to complete a brute-force attack by the number of implementations available, very possibly bringing it down to a reasonable time frame.

The scrypt function is designed to hinder such attempts by raising the resource demands of the algorithm. Specifically, the algorithm is designed to use a large amount of memory compared to other password-based KDFs,^{[6]}
making the size and the cost of a hardware implementation much more expensive, and therefore limiting the amount of parallelism an attacker can use, for a given amount of financial resources.

## Overview

The large memory requirements of scrypt come from a large vector of pseudorandom bit strings that are generated as part of the algorithm. Once the vector is generated, the elements of it are accessed in a pseudo-random order and combined to produce the derived key. A straightforward implementation would need to keep the entire vector in RAM so that it can be accessed as needed.

Because the elements of the vector are generated algorithmically, each element could be generated *on the fly* as needed, only storing one element in memory at a time and therefore cutting the memory requirements significantly. However, the generation of each element is intended to be computationally expensive, and the elements are expected to be accessed many times throughout the execution of the function. Thus there is a significant trade-off in speed to get rid of the large memory requirements.

This sort of time–memory trade-off often exists in computer algorithms: speed can be increased at the cost of using more memory, or memory requirements decreased at the cost of performing more operations and taking longer. The idea behind scrypt is to deliberately make this trade-off costly in either direction. Thus an attacker could use an implementation that doesn't require many resources (and can therefore be massively parallelized with limited expense) but runs very slowly, or use an implementation that runs more quickly but has very large memory requirements and is therefore more expensive to parallelize.

## Algorithm

FunctionscryptInputs:This algorithm includes the following parameters:Passphrase: Bytes string of characters to be hashed Salt: Bytes string of random characters that modifies the hash to protect against Rainbow table attacks CostFactor (N): Integer CPU/memory cost parameter – Must be a power of 2 (e.g. 1024) BlockSizeFactor (r): Integer blocksize parameter, which fine-tunes sequential memory read size and performance. (8 is commonly used) ParallelizationFactor (p): IntegerParallelization parameter. (1 .. 2^{32}-1 * hLen/MFlen) DesiredKeyLen (dkLen): Integer Desired key length in bytes (Intended output length in octets of the derived key; a positive integer satisfying dkLen ≤ (2^{32}− 1) * hLen.) hLen: Integer The length in octets of the hash function (32 for SHA256). MFlen: Integer The length in octets of the output of the mixing function (SMixbelow). Defined as r * 128 in RFC7914.Output:DerivedKey: Bytes array of bytes, DesiredKeyLen longStep 1. Generate expensive saltblockSize ← 128*BlockSizeFactor// Length (in bytes) of the SMix mixing function output (e.g. 128*8 = 1024 bytes)Use PBKDF2 to generate initial 128*BlockSizeFactor*p bytes of data (e.g. 128*8*3 = 3072 bytes) Treat the result as an array ofpelements, each entry beingblocksizebytes (e.g. 3 elements, each 1024 bytes) [B_{0}...B_{p−1}] ← PBKDF2_{HMAC-SHA256}(Passphrase,Salt, 1, blockSize*ParallelizationFactor) Mix each block inBCostfactor times usingROMixfunction (each block can be mixed in parallel)fori ← 0top-1doB_{i}← ROMix(B_{i}, CostFactor) All the elements of B is our new "expensive" salt expensiveSalt ← B_{0}∥B_{1}∥B_{2}∥ ... ∥B_{p-1}// where ∥ is concatenationStep 2. Use PBKDF2 to generate the desired number of bytes, but using the expensive salt we just generatedreturnPBKDF2_{HMAC-SHA256}(Passphrase, expensiveSalt, 1, DesiredKeyLen);

Where *PBKDF2(P, S, c, dkLen)* notation is defined in RFC 2898, where c is an iteration count.

This notation is used by RFC 7914 for specifying a usage of PBKDF2 with c = 1.

FunctionROMix(Block, Iterations) CreateIterationscopies ofXX ← Blockfori ← 0toIterations−1doV_{i}← X X ← BlockMix(X)fori ← 0toIterations−1doj ← Integerify(X) mod Iterations X ← BlockMix(XxorV_{j})returnX

Where RFC 7914 defines `Integerify(X)`

as the result of interpreting the last 64 bytes of X as a *little-endian* integer A_{1}.

Since Iterations equals 2 to the power of N, only the *first* Ceiling(N / 8) bytes among the *last* 64 bytes of X, interpreted as a *little-endian* integer A_{2}, are actually needed to compute `Integerify(X) mod Iterations = A`

.
_{1} mod Iterations = A_{2} mod Iterations

FunctionBlockMix(B):The block B is r 128-byte chunks (which is equivalent of 2r 64-byte chunks)r ← Length(B) / 128;Treat B as an array of 2r 64-byte chunks[B_{0}...B_{2r-1}] ← B X ← B_{2r−1}fori ← 0to2r−1doX ← Salsa20/8(X xor B_{i})// Salsa20/8 hashes from 64-bytes to 64-bytesY_{i}← Xreturn← Y_{0}∥Y_{2}∥...∥Y_{2r−2}∥ Y_{1}∥Y_{3}∥...∥Y_{2r−1}

Where *Salsa20/8* is the 8-round version of Salsa20.

## Cryptocurrency uses

Scrypt is used in many cryptocurrencies as a proof-of-work algorithm. It was first implemented for Tenebrix (released in September 2011) and served as the basis for Litecoin and Dogecoin, which also adopted its scrypt algorithm.^{[7]}^{[8]} Mining of cryptocurrencies that use scrypt is often performed on graphics processing units (GPUs) since GPUs tend to have significantly more processing power (for some algorithms) compared to the CPU.^{[9]} This led to shortages of high end GPUs due to the rising price of these currencies in the months of November and December 2013.^{[10]}

As of May 2014, specialized ASIC mining hardware is available for scrypt-based cryptocurrencies.

## Utility

The scrypt utility was written in May 2009 by Colin Percival as a demonstration of the scrypt key derivation function.^{[2]}^{[3]} It's available in most Linux and BSD distributions.

## See also

- Argon2 – winner of the Password Hashing Competition in 2015
- bcrypt – blowfish-based password-hashing function
- bcrypt – blowfish-based cross-platform file encryption utility developed in 2002
^{[11]}^{[12]}^{[13]}^{[14]} - crypt – Unix C library function
- crypt – Unix utility
- ccrypt – utility
- Key derivation function
- Key stretching
- mcrypt – utility
- PBKDF2 – a widely used standard Password-Based Key Derivation Function 2
- PufferFish – a cache-hard password hashing function based on improved bcrypt design
- Space–time tradeoff

## References

- ↑ "Colin Percival". https://twitter.com/cperciva/status/734613598383841281.
- ↑
^{2.0}^{2.1}"The scrypt key derivation function". http://www.tarsnap.com/scrypt.html. - ↑
^{3.0}^{3.1}"SCRYPT(1) General Commands Manual". https://manpages.debian.org/testing/scrypt/scrypt.1.en.html. - ↑ Percival, Colin; Josefsson, Simon. "The scrypt Password-Based Key Derivation Function". RFC Editor. https://datatracker.ietf.org/doc/html/rfc7914.
- ↑ Alec Liu. "Beyond Bitcoin: A Guide to the Most Promising Cryptocurrencies". https://motherboard.vice.com/en_us/article/4x3ywn/beyond-bitcoin-a-guide-to-the-most-promising-cryptocurrencies.
- ↑ Stronger Key Derivation Via Sequential Memory-Hard Functions, Colin Percival
- ↑ Andreas M. Antonopoulos (3 December 2014).
*Mastering Bitcoin: Unlocking Digital Cryptocurrencies*. O'Reilly Media. pp. 221, 223. ISBN 9781491902646. https://books.google.com/books?id=IXmrBQAAQBAJ&pg=PA221. - ↑ "History of cryptocurrency". https://litecoin.info/History_of_cryptocurrency.
- ↑ Roman Guelfi-Gibbs.
*Litecoin Scrypt Mining Configurations for Radeon 7950*. Amazon Digital Services. https://www.amazon.com/Litecoin-Scrypt-Mining-Configurations-Radeon-ebook/dp/B00E2RT1I4. - ↑ Joel Hruska (10 December 2013). "Massive surge in Litecoin mining leads to graphics card shortage". ExtremeTech. http://www.extremetech.com/computing/172381-massive-surge-in-litecoin-mining-leads-to-radeon-shortage.
- ↑ http://bcrypt.sourceforge.net bcrypt file encryption program homepage
- ↑ "bcrypt APK for Android – free download on Droid Informer". https://droidinformer.org/tools/bcrypt/.
- ↑ "T2 package – trunk – bcrypt – A utility to encrypt files.". http://t2sde.org/packages/bcrypt.html.
- ↑ "Oracle GoldenGateのライセンス". https://docs.oracle.com/cd/E51849_01/gg-winux/OGGLC/ogglc_licenses.htm.

## External links

Original source: https://en.wikipedia.org/wiki/Scrypt.
Read more |