The scrypt parameters (2024)

The recommended scrypt parameters in the Go docs were recently brought up for discussion given they haven't changed since 2009.

Even if at this point I memorized the three numbers (N=16384, r=8, p=1) I only have a vague understanding of their meaning, so I took some time to read the scrypt paper.

It's an enjoyable and witty read, even if mathy at times, with lots of future predictions and reality modeling. Really drives across how scrypt is a fine piece of engineering. Also, it's single column with numbered pages, which earns it 100 points in my book.

The definitions are nested, each building on top of the previous one. In this post I summed up how each parameter impacts the whole scrypt algorithm. Finally, I had a look at what parameters you should use in 2017.

𝑟

𝑟 is the second parameter, but we start with it because it's used by the deepest nested function, BlockMix.

BlockMix turns a hash function with 𝑘-bit long inputs and outputs into a hash function with 2𝑟𝑘-bit long inputs and outputs. That is, it makes the core hash function in scrypt 2𝑟 wider.

It does that by iterating the hash function 2𝑟 times, so both memory usage (to store the hash values) and CPU time scale linearly with it. That is, if 𝑟 doubles the resources double.

That's useful because scrypt applies the hash to "random" memory positions. CPUs load memory in fixed-size blocks called cache lines. If the hash block size is smaller than the cache line, all the rest of the loaded line will be wasted memory bandwidth. Also, it dilutes the memory latency cost. Percival predicted both cache line sizes and memory latencies would increase over time, so made the hash size tunable to prevent scrypt from becoming latency-bound.

I have read that 𝑟 tunes memory usage, and believed it meant it is a memory-only work factor. That is incorrect because both CPU and memory scale with 𝑟. Also, while 𝑟 acts as a work factor, it's unclear increasing it provides the same security as 𝑁 (since there is no added randomization in memory accesses, see below), so it shouldn't be used as one.

𝑁

𝑁 is the one and only work factor.

Memory and CPU usage scale linearly with 𝑁. The mixing function, ROMix, stores 𝑁 sequential hash results in RAM, to then load them in a random order and sequentially xor and hash them.

The reason 𝑁 must be a power of two is that to randomly select one of the 𝑁 memory slots at each iteration, scrypt converts the hash output to an integer and reduces it mod 𝑁. If 𝑁 is a power of two, that operation can be optimized into simple (and fast) binary masking.

Estimating scrypt memory usage

scrypt requires 𝑁 times the hash block size memory. Because of BlockMix, the hash block size is 2𝑟 the underlying hash output size. In scrypt, that hash is the Salsa20 core, which operates on 64-bytes blocks.

So the minimum memory requirement of scrypt is:

𝑁 × 2𝑟 × 64 = 128 × 𝑁 × 𝑟 bytes

For 𝑁 = 16384 and 𝑟 = 8 that would be 16 MiB. It scales linearly with 𝑁 and 𝑟, and some implementations or APIs might cause internal copying doubling the requirement.

𝑝

𝑝 is used in the outmost function, MFcrypt. It is a parallelization parameter. 𝑝 instances of the mixing function are run independently and their outputs concatenated as salt for the final PBKDF2.

𝑝 > 1 can be handled in two ways: sequentially, which does not increase memory usage but requires 𝑝 times the CPU and wall clock time; or parallelly, which requires 𝑝 times the memory and effective CPU time, but does not increase wall clock time.

So 𝑝 can be used to increase CPU time without affecting memory requirements when handled sequentially, or without affecting wall clock time when handled parallelly. However, it offers attackers the same opportunity to optimize for processing or memory.

Parameters for 2017

We apply the same methodology of the paper to pick recommended 𝑁 values for interactive logins and file encryption: the biggest power of two that will run in less than 100ms and 5s respectively on "the CPU in the author's laptop" (a 3.1 GHz Intel Core i5).

func main() {for n := uint8(14); n < 22; n++ {b := testing.Benchmark(func(b *testing.B) {for i := 0; i < b.N; i++ {scrypt.Key([]byte("password"), []byte("salt"), 1<<n, 8, 1, 32)}})t := b.T / time.Duration(b.N)fmt.Printf("N = 2^%d\t%dms\n", n, t/time.Millisecond)}}
  • interactive logins: 2^15 — 1 << 15 — 32 768 — 86ms
  • file encryption: 2^20 — 1 << 20 — 1 048 576 — 3802ms

Curiously enough, the execution time of 𝑁 = 2^20 is exactly the same as in the paper's Table 1, while the sub-100ms value went from 2^14 to 2^15.

Cache line sizes have not significantly increased since 2009, so 8 should still be optimal for 𝑟.

If we really wanted to insist that CPUs have changed in 10 years we could say that more cores are now available, and increase the 𝑝 factor. However, common implementations don't spread the load of 𝑝 and instead compute each instance sequentially. Also, many use cases involve processing multiple parallel requests, so the available cores are not idle. So it seems ok to leave 𝑝 at 1.

Final miscellaneous notes

Colin Percival seems to agree [1] [2] on the new parameters.

Since the final output of scrypt is generated by PBKDF2(HMAC‑SHA256, Password, MixingOutput, 1), even if everything about scrypt were broken, it would still be a secure KDF as long as PBKDF2 with 1 iterations is. (While scrypt uses PBKDF2, it doesn't use it for its work factor.)

Best quote from the paper:

those few organizations which have the resources and inclination to design and fabricate custom circuits for password-cracking tend to be somewhat secretive

If you like digging into a cryptography paper now and then, you might enjoy following me on Twitter.

I never truly understood what the scrypt parameters 𝑁, 𝑟 and 𝑝 meant. So I read the paper and wrote it up for you. https://t.co/BL2a0BWAWH

— Filippo Valsorda (@FiloSottile) October 4, 2017

This post features my favourite Unicode points: U+2011 NON-BREAKING HYPHEN, U+202F NARROW NO-BREAK SPACE and the Mathematical Alphanumeric Symbols.

As an expert with a comprehensive understanding of the scrypt algorithm and its parameters, let me delve into the concepts mentioned in the article and provide an in-depth analysis.

  1. N (Iteration Count):

    • Definition: N is the iteration count or work factor that significantly influences both memory and CPU usage in the scrypt algorithm.
    • Impact: Memory and CPU usage scale linearly with N. The higher the N, the more resources are required.
    • Explanation: The mixing function, ROMix, involves storing N sequential hash results in RAM, loading them in a random order, and sequentially XOR and hashing them. N must be a power of two for optimization purposes.
  2. r (BlockMix Depth):

    • Definition: r is the second parameter in scrypt, affecting the depth of the BlockMix function.
    • Impact: BlockMix turns the core hash function in scrypt 2r wider. Both memory usage and CPU time scale linearly with r.
    • Explanation: BlockMix iterates the hash function 2r times, preventing scrypt from becoming latency-bound as it applies the hash to "random" memory positions. It addresses cache line sizes and memory latencies predicted to increase over time.
  3. p (Parallelization Factor):

    • Definition: p is the parallelization factor used in the outermost function, MFcrypt. It determines how many instances of the mixing function run independently.
    • Impact: p instances of the mixing function are run independently, affecting both CPU time and memory usage.
    • Explanation: p can be handled sequentially or parallelly. Sequential handling increases CPU time but does not affect memory requirements, while parallel handling increases both memory and CPU time. It can be used to adjust CPU time without impacting memory when handled sequentially or without affecting wall clock time when handled parallelly.
  4. Choosing Parameters for 2017:

    • The methodology from the scrypt paper is applied to pick recommended N values for interactive logins and file encryption.
    • The recommended N values are chosen based on the biggest power of two that runs in a specified time on the author's laptop CPU.
    • Parameters for interactive logins: 2^15 (32,768) with an execution time of 86ms.
    • Parameters for file encryption: 2^20 (1,048,576) with an execution time of 3802ms.
  5. Miscellaneous Notes:

    • Cache line sizes are kept at 8, as they have not significantly increased since 2009.
    • The author discusses the possibility of increasing the p factor due to the availability of more cores in modern CPUs but notes that common implementations compute each instance sequentially.

In summary, the scrypt parameters N, r, and p play crucial roles in determining the security, memory usage, and computational requirements of the algorithm. The article provides a detailed exploration of these parameters and their implications in the context of scrypt's design and functionality.

The scrypt parameters (2024)

FAQs

What are the best parameters for scrypt? ›

Scrypt Parameters
  • N – iterations count (affects memory and CPU usage), e.g. 16384 or 2048.
  • r – block size (affects memory and CPU usage), e.g. 8.
  • p – parallelism factor (threads to run in parallel - affects the memory, CPU usage), usually 1.
  • password – the input password (8-10 chars minimal length is recommended)
Jun 19, 2019

Is scrypt a good algorithm? ›

Scrypt is specifically designed to be memory-intensive, making it resistant to parallelization and specialized hardware attacks. Scrypt is highly adaptive and flexible, making it ideal for various applications. Scrypt is less complex and less energy-intensive than other PoW-based algorithms like SHA-256.

What is better, Bcrypt or scrypt? ›

bcrypt can deliver hashing times under 1 second long, but does not include parameters like threads, CPU, or memory hardness. scrypt (Stytch's personal choice!) is maximally hard against brute force attacks, but not quite as memory hard or time-intensive as Argon2.

What does scrypt stand for? ›

Scrypt is a password-based key derivation function (KDF). In cryptography, a KDF is a hash function 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. KDFs are generally efficient at preventing brute force password guessing attacks.

Is scrypt better than sha256? ›

What impact does the choice between Scrypt and SHA-256 have on security? The choice between Scrypt and SHA-256 affects the ecosystem's resistance to large-scale attacks using specialized hardware. By requiring significant memory for hashing, Scrypt is more resilient against brute-force attacks compared to SHA-256.

Which Cryptocurrency is based on scrypt? ›

Scrypt is a password-based key derivation function specifically designed to hinder large-scale custom hardware attacks by requiring large amounts of memory, making it a suitable ASCI-resistant hashing algorithm. The algorithm was popularized by Litecoin.

What is the easiest Scrypt coin to mine? ›

Best Cryptocurrencies to Mine
  • Monero (XMR) ...
  • Zcash (ZEC) ...
  • Ravencoin (RVN) ...
  • Vertcoin (VTC) Current Mining Rewards: 12.5 VTC/block. ...
  • Dash (DASH) Mining Rewards Per Block: 2.3097 DASH. ...
  • Ethereum Classic (ETC) Mining Rewards Per Block: 2.5 ETC. ...
  • Dogecoin (DOGE) Mining Rewards Per Block: 10,000 DOGE. ...
  • Litecoin (LTC)

What miners use Scrypt? ›

Top Scrypt Miners in 2024
  • Bitmain Antminer L7 (9.5Gh/s) Antminer L7 from Bitmain is finely optimized for the Scrypt algorithm with a maximum hash rate of 9.5Gh/s at a power consumption of 3425W. ...
  • Goldshell Mini-DOGE III. ...
  • Goldshell LT Lite. ...
  • Goldshell LT6. ...
  • Goldshell Mini-DOGE Pro.
Mar 29, 2024

Is bcrypt outdated? ›

bcrypt is just obsolete – this was to find a successor to it. yescrypt, one of the recommended finalists, is an improved/fixed version of scrypt. "Obsolete" is a very strong word for bcrypt.

Is scrypt slow? ›

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).

Is scrypt still secure? ›

Scrypt is a memory-hard function designed to protect against denial-of-service attacks and for metering clients' access. It is resistant to specialized hardware like ASICs and FPGAs, making it more secure than other algorithms.

How much memory does scrypt use? ›

The amount of RAM that scrypt requires for its computation is roughly (128 * N * r * p) bytes.

Can scrypt be decrypted? ›

The scrypt utility can be invoked as scrypt enc infile [outfile] to encrypt data (if outfile is not specified, the encrypted data is written to the standard output), or as scrypt dec infile [outfile] to decrypt data (if outfile is not specified, the decrypted data is written to the standard output).

Who created scrypt? ›

Scrypt is a key derivation function and password hashing algorithm created by Colin Percival. Scrypt was the first of the modern "memory hard" algorithms. The algorithm is standardized in RFC 7914, The scrypt Password-Based Key Derivation Function.

What are the optimal parameters for locality sensitive hashing? ›

The effectiveness of LSH depends on several important parameters:
  • Number of Hash Functions (K) More hash functions lead to a higher probability of similar items being hashed to the same bucket . ...
  • Length of Hash Codes (L) Longer hash codes provide more accurate results but also require more space to store.
Jul 30, 2023

What are the most important Hyperparameters for CNN? ›

In this article, we will discuss the key hyperparameters that need to be considered while designing a CNN and how to determine their optimal values.
  • Number of Layers. The number of layers in a CNN is a critical hyperparameter that determines the depth of the network. ...
  • Filter Size. ...
  • Stride. ...
  • Padding. ...
  • Learning Rate. ...
  • Batch Size.
May 21, 2023

What are the requirements for a good hashing algorithm? ›

Rules for choosing good hash function:
  • The hash function should be simple to compute.
  • Number of collisions should be less while placing the record in the hash table. ...
  • Hash function should produce such keys which will get distributed uniformly over an array.
  • The hash function should depend on every bit of the key.
Feb 21, 2023

What are the parameters of Feistel cipher network? ›

Strength depends on following parameters.
  • Block size – Larger block more security.
  • Key size – Larger key size more security.
  • Number of rounds – More rounds more security.
  • Subkey generation algorithm – complex algorithm- difficult for cryptanalysis to generate key.

Top Articles
Swissquote Introduces the TWINT App as a Client Payment Solution
What is DeFi? Everything you need to know about the future of decentralized finance
Regal Amc Near Me
Quick Pickling 101
Bloxburg Image Ids
Kent And Pelczar Obituaries
Tanger Outlets Sevierville Directory Map
Steve Strange - From Punk To New Romantic
Ap Chem Unit 8 Progress Check Mcq
Our Facility
Inside California's brutal underground market for puppies: Neglected dogs, deceived owners, big profits
How Many Slices Are In A Large Pizza? | Number Of Pizzas To Order For Your Next Party
Craigslist Pets Longview Tx
Https E24 Ultipro Com
What Happened To Anna Citron Lansky
Bnsf.com/Workforce Hub
London Ups Store
Kürtçe Doğum Günü Sözleri
Uky Linkblue Login
Khiara Keating: Manchester City and England goalkeeper convinced WSL silverware is on the horizon
Loves Employee Pay Stub
Mccain Agportal
Amih Stocktwits
Eine Band wie ein Baum
Yisd Home Access Center
Chime Ssi Payment 2023
Craigslist Dubuque Iowa Pets
Rugged Gentleman Barber Shop Martinsburg Wv
Sensual Massage Grand Rapids
Salemhex ticket show3
Yoshidakins
Ma Scratch Tickets Codes
Lake Dunson Robertson Funeral Home Lagrange Georgia Obituary
Roto-Rooter Plumbing and Drain Service hiring General Manager in Cincinnati Metropolitan Area | LinkedIn
Emerge Ortho Kronos
Page 5662 – Christianity Today
Bismarck Mandan Mugshots
Restored Republic May 14 2023
Nsav Investorshub
Thelemagick Library - The New Comment to Liber AL vel Legis
Walmart Car Service Near Me
Flappy Bird Cool Math Games
Sam's Club Gas Price Sioux City
Online College Scholarships | Strayer University
Suppress Spell Damage Poe
Craigslist Charles Town West Virginia
Read Love in Orbit - Chapter 2 - Page 974 | MangaBuddy
What Is The Gcf Of 44J5K4 And 121J2K6
Att Corporate Store Location
Ok-Selection9999
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated:

Views: 6012

Rating: 4.1 / 5 (72 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.