Skip to content

Commit 51b3cf6

Browse files
security(scrypt): Force Scrypt parameters to have salt and dklen as well
1 parent ab08837 commit 51b3cf6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Keystore/ScryptParameters.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ static const auto r = "r";
8787
} // namespace CodingKeys::SP
8888

8989
ScryptParameters::ScryptParameters(const nlohmann::json& json) {
90-
salt = parse_hex(json[CodingKeys::SP::salt].get<std::string>());
91-
desiredKeyLength = json[CodingKeys::SP::desiredKeyLength];
9290
if (json.count(CodingKeys::SP::n) == 0
9391
|| json.count(CodingKeys::SP::p) == 0
94-
|| json.count(CodingKeys::SP::r) == 0) {
95-
throw std::invalid_argument("Missing required scrypt parameters n, p, or r");
92+
|| json.count(CodingKeys::SP::r) == 0
93+
|| json.count(CodingKeys::SP::salt) == 0
94+
|| json.count(CodingKeys::SP::desiredKeyLength) == 0) {
95+
throw std::invalid_argument("Missing required scrypt parameters n, p, r, salt, or dklen");
9696
}
97+
98+
salt = parse_hex(json[CodingKeys::SP::salt].get<std::string>());
99+
desiredKeyLength = json[CodingKeys::SP::desiredKeyLength];
97100
n = json[CodingKeys::SP::n];
98101
p = json[CodingKeys::SP::p];
99102
r = json[CodingKeys::SP::r];

0 commit comments

Comments
 (0)