Scrypt
   HOME

TheInfoList



OR:

In
cryptography Cryptography, or cryptology (from grc, , translit=kryptós "hidden, secret"; and ''graphein'', "to write", or '' -logia'', "study", respectively), is the practice and study of techniques for secure communication in the presence of adv ...
, scrypt (pronounced "ess crypt") is a password-based
key derivation function In cryptography, a key derivation function (KDF) is a cryptographic algorithm that derives one or more secret keys from a secret value such as a master key, a password, or a passphrase using a pseudorandom function (which typically uses a cry ...
created by
Colin Percival Colin A. Percival (born 1980) is a Canadian computer scientist and computer security researcher. He completed his undergraduate education at Simon Fraser University and a doctorate at the University of Oxford. While at university he joined th ...
in March 2009, originally for the Tarsnap online backup service. 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 The Internet Engineering Task Force (IETF) is a standards organization for the Internet and is responsible for the technical standards that make up the Internet protocol suite (TCP/IP). It has no formal membership roster or requirements an ...
as RFC 7914. A simplified version of scrypt is used as a
proof-of-work Proof of work (PoW) is a form of cryptographic proof in which one party (the ''prover'') proves to others (the ''verifiers'') that a certain amount of a specific computational effort has been expended. Verifiers can subsequently confirm this expe ...
scheme by a number of
cryptocurrencies A cryptocurrency, crypto-currency, or crypto is a digital currency designed to work as a medium of exchange through a computer network that is not reliant on any central authority, such as a government or bank, to uphold or maintain it. It ...
, first implemented by an anonymous programmer called ArtForz in Tenebrix and followed by Fairbrix and
Litecoin Litecoin (Abbreviation: LTC; sign: Ł) is a decentralized peer-to-peer cryptocurrency and open-source software project released under the MIT/X11 license. Inspired by Bitcoin, Litecoin was among the earliest altcoins, starting in October 201 ...
soon after.


Introduction

A password-based
key derivation function In cryptography, a key derivation function (KDF) is a cryptographic algorithm that derives one or more secret keys from a secret value such as a master key, a password, or a passphrase using a pseudorandom function (which typically uses a cry ...
(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 An application-specific integrated circuit (ASIC ) is an integrated circuit (IC) chip customized for a particular use, rather than intended for general-purpose use, such as a chip designed to run in a digital voice recorder or a high-efficie ...
or even an
FPGA A field-programmable gate array (FPGA) is an integrated circuit designed to be configured by a customer or a designer after manufacturinghence the term '' field-programmable''. The FPGA configuration is generally specified using a hardware d ...
). 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, 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 A pseudorandom sequence of numbers is one that appears to be statistically random, despite having been produced by a completely deterministic and repeatable process. Background The generation of random numbers has many uses, such as for rand ...
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

Function scrypt Inputs: ''This algorithm includes the following parameters:'' Passphrase: Bytes string of characters to be hashed
Salt Salt is a mineral composed primarily of sodium chloride (NaCl), a chemical compound belonging to the larger class of salts; salt in the form of a natural crystalline mineral is known as rock salt or halite. Salt is present in vast quant ...
: Bytes string of random characters that modifies the hash to protect against
Rainbow table A rainbow table is an efficient way to store data that has been computed in advance to facilitate cracking passwords. To protect stored passwords from compromise in case of a data breach, organizations avoid storing them directly, instead transfo ...
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): Integer ''Parallelization parameter''. (1 .. 232-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 ≤ (232− 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 (''SMix'' below). Defined as r * 128 in RFC7914. Output: DerivedKey: Bytes array of bytes, DesiredKeyLen long ''Step 1. Generate expensive salt'' blockSize ← 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 of ''p'' elements, each entry being ''blocksize'' bytes (e.g. 3 elements, each 1024 bytes) 0...Bp−1PBKDF2HMAC-SHA256(''Passphrase'', ''Salt'', 1, blockSize*ParallelizationFactor) Mix each block in B Costfactor times using ROMix function (each block can be mixed in parallel) for i ← 0 to p-1 do Bi ← ROMix(Bi, CostFactor) All the elements of B is our new "expensive" salt expensiveSalt ← B0∥B1∥B2∥ ... ∥Bp-1 ''// where ∥ is concatenation ''Step 2. Use PBKDF2 to generate the desired number of bytes, but using the expensive salt we just generated'' return PBKDF2HMAC-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. Function ROMix(Block, Iterations) Create ''Iterations'' copies of ''X'' X ← Block for i ← 0 to Iterations−1 do Vi ← X X ← BlockMix(X) for i ← 0 to Iterations−1 do j ← Integerify(X) mod Iterations X ← BlockMix(X xor Vj) return X Where RFC 7914 defines as the result of interpreting the last 64 bytes of X as a ''little-endian'' integer A1. 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 A2, are actually needed to compute Integerify(X) mod Iterations = A1 mod Iterations = A2 mod Iterations. Function BlockMix(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'' 0...B2r-1← B X ← B2r−1 for i ← 0 to 2r−1 do X ← Salsa20/8(X xor Bi) // Salsa20/8 hashes from 64-bytes to 64-bytes Yi ← X return ← Y0∥Y2∥...∥Y2r−2 ∥ Y1∥Y3∥...∥Y2r−1 Where ''Salsa20/8'' is the 8-round version of
Salsa20 Salsa20 and the closely related ChaCha are stream ciphers developed by Daniel J. Bernstein. Salsa20, the original cipher, was designed in 2005, then later submitted to the eSTREAM European Union cryptographic validation process by Bernstein. Ch ...
.


Cryptocurrency uses

Scrypt is used in many cryptocurrencies as a
proof-of-work Proof of work (PoW) is a form of cryptographic proof in which one party (the ''prover'') proves to others (the ''verifiers'') that a certain amount of a specific computational effort has been expended. Verifiers can subsequently confirm this expe ...
algorithm (more precisely, as the hash function in the Hashcash proof-of-work algorithm). It was first implemented for Tenebrix (released in September 2011) and served as the basis for
Litecoin Litecoin (Abbreviation: LTC; sign: Ł) is a decentralized peer-to-peer cryptocurrency and open-source software project released under the MIT/X11 license. Inspired by Bitcoin, Litecoin was among the earliest altcoins, starting in October 201 ...
and
Dogecoin Dogecoin ( or , Abbreviation: DOGE; sign: Ð) is a cryptocurrency created by software engineers Billy Markus and Jackson Palmer, who decided to create a payment system as a "joke", making fun of the wild speculation in cryptocurrencies at the ...
, which also adopted its scrypt algorithm. Mining of
cryptocurrencies A cryptocurrency, crypto-currency, or crypto is a digital currency designed to work as a medium of exchange through a computer network that is not reliant on any central authority, such as a government or bank, to uphold or maintain it. It ...
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. This led to shortages of high end GPUs due to the rising price of these currencies in the months of November and December 2013. As of May 2014, specialized
ASIC An application-specific integrated circuit (ASIC ) is an integrated circuit (IC) chip customized for a particular use, rather than intended for general-purpose use, such as a chip designed to run in a digital voice recorder or a high-efficie ...
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. It's available in most
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, whi ...
and BSD distributions.


See also

* Argon2 – winner of the Password Hashing Competition in 2015 *
bcrypt bcrypt is a password-hashing function designed by Niels Provos and David Mazières, based on the Blowfish cipher and presented at USENIX in 1999. Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive func ...
– blowfish-based password-hashing function *
bcrypt bcrypt is a password-hashing function designed by Niels Provos and David Mazières, based on the Blowfish cipher and presented at USENIX in 1999. Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive func ...
– blowfish-based cross-platform file encryption utility developed in 2002 *
crypt A crypt (from Latin '' crypta'' " vault") is a stone chamber beneath the floor of a church or other building. It typically contains coffins, sarcophagi, or religious relics. Originally, crypts were typically found below the main apse of a c ...
– Unix C library function *
crypt A crypt (from Latin '' crypta'' " vault") is a stone chamber beneath the floor of a church or other building. It typically contains coffins, sarcophagi, or religious relics. Originally, crypts were typically found below the main apse of a c ...
– Unix utility *
ccrypt ccrypt is a utility for the secure encryption and decryption of files and streams. It was designed as a replacement for the standard UNIX crypt utility, which is notorious for using a very weak encryption algorithm. ccrypt is based on the Rijnda ...
– utility *
Key derivation function In cryptography, a key derivation function (KDF) is a cryptographic algorithm that derives one or more secret keys from a secret value such as a master key, a password, or a passphrase using a pseudorandom function (which typically uses a cry ...
* 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 A space–time trade-off or time–memory trade-off in computer science is a case where an algorithm or program trades increased space usage with decreased time. Here, ''space'' refers to the data storage consumed in performing a given task (RA ...


References


External links


The scrypt page on the Tarsnap website.

The original scrypt paper.
* {{Cryptocurrencies Cryptographic algorithms Key derivation functions Articles with example pseudocode