Skip to content

Commit e81a30b

Browse files
committed
Update default configuration for SCryptPasswordEncoder
The recommended minimums for scrypt, as per OWASP Cheat Sheet Series (https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html), are: Use scrypt with a minimum CPU/memory cost parameter of (2^16), a minimum block size of 8 (1024 bytes), and a parallelization parameter of 1. Previous default configuration: cpuCost=16384, memoryCost=8, parallelism=1 New default configuration: cpuCost=65536, memoryCost=8, parallelism=1 The default salt length was also updated from 64 to 16. Issue gh-10506
1 parent e0c49a4 commit e81a30b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

crypto/src/main/java/org/springframework/security/crypto/scrypt/SCryptPasswordEncoder.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,6 +58,16 @@
5858
*/
5959
public class SCryptPasswordEncoder implements PasswordEncoder {
6060

61+
private static final int DEFAULT_CPU_COST = 65536;
62+
63+
private static final int DEFAULT_MEMORY_COST = 8;
64+
65+
private static final int DEFAULT_PARALLELISM = 1;
66+
67+
private static final int DEFAULT_KEY_LENGTH = 32;
68+
69+
private static final int DEFAULT_SALT_LENGTH = 16;
70+
6171
private final Log logger = LogFactory.getLog(getClass());
6272

6373
private final int cpuCost;
@@ -71,7 +81,7 @@ public class SCryptPasswordEncoder implements PasswordEncoder {
7181
private final BytesKeyGenerator saltGenerator;
7282

7383
public SCryptPasswordEncoder() {
74-
this(16384, 8, 1, 32, 64);
84+
this(DEFAULT_CPU_COST, DEFAULT_MEMORY_COST, DEFAULT_PARALLELISM, DEFAULT_KEY_LENGTH, DEFAULT_SALT_LENGTH);
7585
}
7686

7787
/**

0 commit comments

Comments
 (0)