Scrypt | Practical Cryptography for Developers (2024)

Scrypt (RFC 7914) is a strong cryptographic key-derivation function (KDF). It is memory-intensive, designed to prevent GPU, ASIC and FPGA attacks (highly efficient password cracking hardware).

The Scrypt algorithm takes several input parameters and produces the derived key as output:

key = Scrypt(password, salt, N, r, p, derived-key-len)

Scrypt Parameters

The Scrypt config parameters are:

The memory in Scrypt is accessed in strongly dependent order at each step, so the memory access speed is the algorithm's bottleneck. The memory required to compute Scrypt key derivation is calculated as follows:

Memory required = 128 * N * r * p bytes

Example: e.g. 128 * N * r * p = 128 * 16384 * 8 * 1 = 16 MB(or 128 * N * r * p = 128 * 2048 * 8 * 1 = 2 MB)

Choosing parameters depends on how much you want to wait and what level of security (password cracking resistance) do you want to achieve:

  • Sample parameters for interactive login: N=16384, r=8, p=1 (RAM = 2 MB). For interactive login you most probably do not want to wait more than a 0.5 seconds, so the computations should be very slow. Also at the server side, it is usual that many users can login in the same time, so slow Scrypt computation will slow down the entire system.

  • Sample parameters for file encryption: N=1048576, r=8, p=1 (RAM = 1 GB). When you encrypt your hard drive, you will unlock the encrypted data in rare cases, usually not more than 2-3 times per day, so you may want to wait for 2-3 seconds to increase the security.

You can perform tests and choose the Scrypt parameters yourself during the design and development of your app or system. Always try to use the fastest possible implementation of Scrypt for your language and platform, because crackers will definitely use it. Some implementations (e.g. in Python) may be 100 times slower than the fastest ones!

In the MyEtherWallet crypto wallet, the default Scrypt parameters are N=8192, r=8, p=1. These settings are not strong enough for crypto wallets, but this is how it works. The solution is to use long and complex password to avoid password cracking attacks.

Scrypt - Example

You can play with Scrypt key derivation online here: https://8gwifi.org/scrypt.jsp.

Scrypt Calculation in Python - Example

Now, we shall write some code in Python to derive a key from a password using the Scrypt algorithm.

First, install the Python package scrypt using the command:

pip install scrypt

Note that the scrypt package depends on OpenSSL, so first install it in its default location (e.g. in C:\OpenSSL-Win64 in Windows), then install the scrypt Python package.

Now, after the scrypt package is successfully installed, write the Python code to calculate a Scrypt hash:(Note, we have chosen smaller number for iterations count. We did that just to increase the following example execution speed. In common usage, a higher iterations count is recommended, e.g. 16384 - see above.)

import pyscryptsalt = b'aa1f2d3f4d23ac44e9c5a6c3d8f9ee8c'passwd = b'p@$Sw0rD~7'key = pyscrypt.hash(passwd, salt, 2048, 8, 1, 32)print("Derived key:", key.hex())

Run the above code example: https://repl.it/@nakov/Scrypt-in-Python.

The Scrypt calculation function takes several input parameters: the password (bytes sequence), the salt (bytes sequence), iterations count, block size for each iteration, parallelism factor and the output key length (number of bytes for the derived key).

The output from the above code execution is the following:

Derived key: b'e813a6f6ccc4e9110193bf9efb7c0a489d76655f9e36629dccbeaf2a73bc0c6f'

Try to change the number of iterations or the block size and see how they affect the execution time. Have in mind that the above Python implementation is not very fast. You may find fast Scrypt implementation in Internet.

Storing Algorithm Settings + Salt + Hash Together

In many applications, frameworks and tools, Scrypt encrypted passwords are stored together with the algorithm settings and salt, into a single string (in certain format), consisting of several parts, separated by $ character. For example, the password p@ss~123 can be stored in the Scrypt standard format like this (several examples are given, to make the pattern apparent):

16384$8$1$kytG1MHY1KU=$afc338d494dc89be40e317788e3cd9166d066709db0e6481f0801bd918710f4616384$8$1$5gFGlElztY0=$560f6229356c281a525fad4e2fc4c209bb55c21dec789381335a32bb84888a5a32768$8$4$VGhlIHF1aWo=$54d657cec8b3aaca675b407e790bccf1dddb0a23665cd5f994820a736d4b58ba

When to Use Scrypt?

When configured properly Scrypt is considered a highly secure KDF function, so you can use it as general purpose password to key derivation algorithm, e.g. when encrypting wallets, files or app passwords.

Scrypt | Practical Cryptography for Developers (2024)

FAQs

Is scrypt a good algorithm? ›

Why Use Scrypt? Scrypt is efficient without compromising security. The hashing function is also less complex than alternatives. Adopting networks also enjoy relatively lower trading fees than ledgers adopting other hashing functions like SHA-256.

How much memory does scrypt use? ›

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

Can you decrypt scrypt? ›

SCrypt File Encrypter

SCrypt is a Java based program to encrypt and decrypt files. It can only process one file at a time.

What is the difference between sha256 and scrypt? ›

Known for its robust security measures, SHA-256 converts input data into a unique 256-bit (32-byte) hash, making it extremely resistant to attacks. Scrypt: Scrypt, on the other hand, is a memory-hard algorithm that was initially designed to limit large-scale custom hardware attacks.

Top Articles
Sort & filter your data - Computer
Titanswap (TITAN) Price Prediction 2024, 2025–2030 | CoinCodex
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Aron Pacocha

Last Updated:

Views: 6350

Rating: 4.8 / 5 (48 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Aron Pacocha

Birthday: 1999-08-12

Address: 3808 Moen Corner, Gorczanyport, FL 67364-2074

Phone: +393457723392

Job: Retail Consultant

Hobby: Jewelry making, Cooking, Gaming, Reading, Juggling, Cabaret, Origami

Introduction: My name is Aron Pacocha, I am a happy, tasty, innocent, proud, talented, courageous, magnificent person who loves writing and wants to share my knowledge and understanding with you.