| 1 |
Optimal yescrypt configuration. |
| 2 |
|
| 3 |
yescrypt is very flexible, but configuring it optimally is complicated. |
| 4 |
Here are some guidelines to simplify near-optimal configuration. We |
| 5 |
start by listing the parameters and their typical values, and then give |
| 6 |
currently recommended parameter sets by use case. |
| 7 |
|
| 8 |
|
| 9 |
Parameters and their typical values. |
| 10 |
|
| 11 |
Set flags (yescrypt flavor) to YESCRYPT_DEFAULTS to use the currently |
| 12 |
recommended flavor. (Other flags values exist for compatibility and for |
| 13 |
specialized cases where you think you know what you're doing.) |
| 14 |
|
| 15 |
Set N (block count) based on target memory usage and running time, as |
| 16 |
well as on the value of r (block size in 128 byte units). N must be a |
| 17 |
power of two. |
| 18 |
|
| 19 |
Set r (block size) to 8 (so that N is in KiB, which is convenient) or to |
| 20 |
another small value (if more optimal or for fine-tuning of the total |
| 21 |
size and/or running time). Reasonable values for r are from 8 to 96. |
| 22 |
|
| 23 |
Set p (parallelism) to 1 meaning no thread-level parallelism within one |
| 24 |
computation of yescrypt. (Use of thread-level parallelism within |
| 25 |
yescrypt makes sense for ROM initialization and for key derivation at |
| 26 |
high memory usage, but usually not for password hashing where |
| 27 |
parallelism is available through concurrent authentication attempts. |
| 28 |
Don't use p > 1 unnecessarily.) |
| 29 |
|
| 30 |
Set t (time) to 0 to use the optimal running time for a given memory |
| 31 |
usage. This will allow you to maximize the memory usage (the value of |
| 32 |
N*r) while staying within your running time constraints. (Non-zero t |
| 33 |
makes sense in specialized cases where you can't afford higher memory |
| 34 |
usage but can afford more time.) |
| 35 |
|
| 36 |
Set g (upgrades) to 0 because there have been no hash upgrades yet. |
| 37 |
|
| 38 |
Set NROM (block count of ROM) to 0 unless you use a ROM (see below). |
| 39 |
NROM must be a power of two. |
| 40 |
|
| 41 |
|
| 42 |
Password hashing for user authentication, no ROM. |
| 43 |
|
| 44 |
Small and fast (memory usage 2 MiB, performance like bcrypt cost 2^5 - |
| 45 |
latency 2-3 ms and throughput 10,000+ per second on a 16-core server): |
| 46 |
|
| 47 |
flags = YESCRYPT_DEFAULTS, N = 2048, r = 8, p = 1, t = 0, g = 0, NROM = 0 |
| 48 |
|
| 49 |
Large and slow (memory usage 16 MiB, performance like bcrypt cost 2^8 - |
| 50 |
latency 10-30 ms and throughput 1000+ per second on a 16-core server): |
| 51 |
|
| 52 |
flags = YESCRYPT_DEFAULTS, N = 4096, r = 32, p = 1, t = 0, g = 0, NROM = 0 |
| 53 |
|
| 54 |
Of course, even heavier and slower settings are possible, if affordable. |
| 55 |
Simply double the value of N as many times as needed. Since N must be a |
| 56 |
power of two, you may use r (in the range of 8 to 32) or/and t (in the |
| 57 |
range of 0 to 2) for fine-tuning the running time, but first bring N to |
| 58 |
the maximum you can afford. If this feels too complicated, just use one |
| 59 |
of the two parameter sets given above (preferably the second) as-is. |
| 60 |
|
| 61 |
|
| 62 |
Password hashing for user authentication, with ROM. |
| 63 |
|
| 64 |
It's similar to the above, except that you need to adjust r, set NROM, |
| 65 |
and initialize the ROM. |
| 66 |
|
| 67 |
First decide on a ROM size, such as making it a large portion of your |
| 68 |
dedicated authentication servers' RAM sizes. Since NROM (block count) |
| 69 |
must be a power of two, you might need to choose r (block size) based on |
| 70 |
how your desired ROM size corresponds to a power of two. Also tuning |
| 71 |
for performance on current hardware, you'll likely end up with r in the |
| 72 |
range from slightly below 16 to 32. For example, to use 15/16 of a |
| 73 |
server's 256 GiB RAM as ROM (thus, making it 240 GiB), you could use |
| 74 |
r=15 or r=30. To use 23/24 of a server's 384 GiB RAM as ROM (thus, |
| 75 |
making it 368 GiB), you'd use r=23. Then set NROM to your desired ROM |
| 76 |
size in KiB divided by 128*r. Note that these examples might (or might |
| 77 |
not) be too extreme, leaving little memory for the rest of the system. |
| 78 |
You could as well opt for 7/8 with r=14 or 11/12 with r=11 or r=22. |
| 79 |
|
| 80 |
Note that higher r may make placing of ROM in e.g. NVMe flash memory |
| 81 |
instead of in RAM more reasonable (or less unreasonable) than it would |
| 82 |
have been with a lower r. If this is a concern as it relates to |
| 83 |
possible attacks and you do not intend to ever do it defensively, you |
| 84 |
might want to keep r lower (e.g., prefer r=15 over r=30 in the example |
| 85 |
above, even if 30 performs slightly faster). |
| 86 |
|
| 87 |
Your adjustments to r, if you deviate from powers of two, will also |
| 88 |
result in weirder memory usage per hash. Like 1.75 MiB at r=14 instead |
| 89 |
of 2 MiB at r=8 that you would have used without a ROM. That's OK. |
| 90 |
|
| 91 |
For ROM initialization, which you do with yescrypt_init_shared(), use |
| 92 |
the same r and NROM that you'd later use for password hashing, choose p |
| 93 |
based on your servers' physical and/or logical CPU count (maybe |
| 94 |
considering eventual upgrades as you won't be able to change this later, |
| 95 |
but without going unnecessarily high - e.g., p=28, p=56, or p=112 make |
| 96 |
sense on servers that currently have 28 physical / 56 logical CPUs), and |
| 97 |
set the rest of the parameters to: |
| 98 |
|
| 99 |
flags = YESCRYPT_DEFAULTS, N = 0, t = 0, g = 0 |
| 100 |
|
| 101 |
N is set to 0 because it isn't relevant during ROM initialization (you |
| 102 |
can use different values of N for hashing passwords with the same ROM). |
| 103 |
|
| 104 |
To keep the ROM in e.g. SysV shared memory and reuse it across your |
| 105 |
authentication service restarts, you'd need to allocate the memory and |
| 106 |
set the flags to "YESCRYPT_DEFAULTS | YESCRYPT_SHARED_PREALLOCATED". |
| 107 |
|
| 108 |
For actual password hashing, you'd use your chosen values for N, r, |
| 109 |
NROM, and set the rest of the parameters to: |
| 110 |
|
| 111 |
flags = YESCRYPT_DEFAULTS, p = 1, t = 0, g = 0 |
| 112 |
|
| 113 |
Note that although you'd use a large p for ROM initialization, you |
| 114 |
should use p=1 for actual password hashing like you would without a ROM. |
| 115 |
|
| 116 |
Do not forget to pass the ROM into the actual password hashing (and keep |
| 117 |
r and NROM set accordingly). |
| 118 |
|
| 119 |
Since N must be a power of two and r is dependent on ROM size, you may |
| 120 |
use t (in the range of 0 to 2) for fine-tuning the running time, but |
| 121 |
first bring N to the maximum you can afford. |
| 122 |
|
| 123 |
If this feels too complicated, or even if it doesn't, please consider |
| 124 |
engaging Openwall for your yescrypt deployment. We'd be happy to help. |
| 125 |
|
| 126 |
|
| 127 |
Password-based key derivation. |
| 128 |
|
| 129 |
(Or rather passphrase-based.) |
| 130 |
|
| 131 |
Use settings similar to those for password hashing without a ROM, but |
| 132 |
adjusted for higher memory usage and running time, and optionally with |
| 133 |
thread-level parallelism. |
| 134 |
|
| 135 |
Small and fast (memory usage 128 MiB, running time under 100 ms on a |
| 136 |
fast desktop): |
| 137 |
|
| 138 |
flags = YESCRYPT_DEFAULTS, N = 32768, r = 32, p = 1, t = 0, g = 0, NROM = 0 |
| 139 |
|
| 140 |
Large and fast (memory usage 1 GiB, running time under 200 ms on a fast |
| 141 |
quad-core desktop not including memory allocation overhead, under 250 ms |
| 142 |
with the overhead included), but requires build with OpenMP support (or |
| 143 |
otherwise will run as slow as yet be weaker than its p=1 alternative): |
| 144 |
|
| 145 |
flags = YESCRYPT_DEFAULTS, N = 262144, r = 32, p = 4, t = 0, g = 0, NROM = 0 |
| 146 |
|
| 147 |
Large and slower (memory usage 1 GiB, running time under 300 ms on a |
| 148 |
fast quad-core desktop not including memory allocation overhead, under |
| 149 |
350 ms with the overhead included), also requires build with OpenMP |
| 150 |
support (or otherwise will run slower than the p=1 alternative below): |
| 151 |
|
| 152 |
flags = YESCRYPT_DEFAULTS, N = 262144, r = 32, p = 4, t = 2, g = 0, NROM = 0 |
| 153 |
|
| 154 |
Large and slow (memory usage 1 GiB, running time under 600 ms on a fast |
| 155 |
desktop not including memory allocation overhead, under 650 ms with the |
| 156 |
overhead included): |
| 157 |
|
| 158 |
flags = YESCRYPT_DEFAULTS, N = 262144, r = 32, p = 1, t = 0, g = 0, NROM = 0 |
| 159 |
|
| 160 |
Just like with password hashing, even heavier and slower settings are |
| 161 |
possible, if affordable, and you achieve them by adjusting N, r, t in |
| 162 |
the same way and in the same preferred ranges (please see the section on |
| 163 |
password hashing without a ROM, above). Unlike with password hashing, |
| 164 |
it makes some sense to go above t=2 if you expect that your users might |
| 165 |
not be able to afford more memory but can afford more time. However, |
| 166 |
increasing the memory usage provides better protection, and we don't |
| 167 |
recommend forcing your users to wait for more than 1 second as they |
| 168 |
could as well type more characters in that time. If this feels too |
| 169 |
complicated, just use one of the above parameter sets as-is. |
| 170 |
|
| 171 |
|
| 172 |
Amortization of memory allocation overhead. |
| 173 |
|
| 174 |
It takes a significant fraction of yescrypt's total running time to |
| 175 |
allocate memory from the operating system, especially considering that |
| 176 |
the kernel zeroizes the memory before handing it over to your program. |
| 177 |
|
| 178 |
Unless you naturally need to compute yescrypt just once per process, you |
| 179 |
may achieve greater efficiency by fully using advanced yescrypt APIs |
| 180 |
that let you preserve and reuse the memory allocation across yescrypt |
| 181 |
invocations. This is done by reusing the structure pointed to by the |
| 182 |
"yescrypt_local_t *local" argument of yescrypt_r() or yescrypt_kdf() |
| 183 |
without calling yescrypt_free_local() inbetween the repeated invocations |
| 184 |
of yescrypt. |
| 185 |
|
| 186 |
|
| 187 |
YESCRYPT_DEFAULTS macro. |
| 188 |
|
| 189 |
Please note that the value of the YESCRYPT_DEFAULTS macro might change |
| 190 |
later, so if you use the macro like it's recommended here then for |
| 191 |
results reproducible across versions you might need to store its value |
| 192 |
somewhere along with the hashes or the encrypted data. |
| 193 |
|
| 194 |
If you use yescrypt's standard hash string encoding, then yescrypt |
| 195 |
already encodes and decodes this value for you, so you don't need to |
| 196 |
worry about this. |