Skip to content

Commit d57e576

Browse files
committed
fix(core): reduce hashing security for low-end routers compatibility
1 parent 1ba237a commit d57e576

4 files changed

Lines changed: 11 additions & 8 deletions

File tree

docs/content/docs/rest-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The REST API is available when:
2222
"listen": "0.0.0.0:12121",
2323
"authentication": {
2424
"enabled": true,
25-
"password_hash": "argon2id$v=19$m=19456,t=2,p=1$..."
25+
"password_hash": "argon2id$v=19$m=2048,t=2,p=1$..."
2626
},
2727
"cors": {
2828
"allowed_origins": ["https://panel.example.com"]

docs/content/docs/rest-api.ru.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ REST API доступен, если:
2222
"listen": "0.0.0.0:12121",
2323
"authentication": {
2424
"enabled": true,
25-
"password_hash": "argon2id$v=19$m=19456,t=2,p=1$..."
25+
"password_hash": "argon2id$v=19$m=2048,t=2,p=1$..."
2626
},
2727
"cors": {
2828
"allowed_origins": ["https://panel.example.com"]

src/auth/password.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ namespace {
1818
using Salt = std::array<std::uint8_t, 16>;
1919
using Digest = std::array<std::uint8_t, 32>;
2020

21-
constexpr std::uint32_t kArgon2MemoryBlocks = 19'456; // 19 MiB
21+
constexpr std::uint32_t kArgon2MemoryBlocks = 2'048; // 2 MiB
2222
constexpr std::uint32_t kArgon2Passes = 2;
2323
constexpr std::uint32_t kArgon2Lanes = 1;
24-
constexpr std::string_view kVerifierPrefix = "argon2id$v=19$m=19456,t=2,p=1$";
24+
constexpr std::string_view kVerifierPrefix = "argon2id$v=19$m=2048,t=2,p=1$";
2525
constexpr char kHex[] = "0123456789abcdef";
2626

2727
struct Argon2WorkArea {
28-
std::vector<std::uint64_t> words = std::vector<std::uint64_t>(
29-
static_cast<std::size_t>(kArgon2MemoryBlocks) * 1024 / sizeof(std::uint64_t));
28+
Argon2WorkArea()
29+
: words(static_cast<std::size_t>(kArgon2MemoryBlocks) * 1024 / sizeof(std::uint64_t)) {}
30+
31+
std::vector<std::uint64_t> words;
3032

3133
~Argon2WorkArea() {
3234
crypto_wipe(words.data(), words.size() * sizeof(std::uint64_t));

tests/test_api_auth.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ namespace keen_pbr3 {
1111

1212
TEST_CASE("Argon2id password verifiers validate and reject other passwords") {
1313
const auto verifier = auth::generate_password_hash("correct horse");
14-
CHECK(verifier.rfind("argon2id$v=19$m=19456,t=2,p=1$", 0) == 0);
14+
CHECK(verifier.rfind("argon2id$v=19$m=2048,t=2,p=1$", 0) == 0);
1515
CHECK(auth::valid_password_hash(verifier));
1616
CHECK(auth::verify_password("correct horse", verifier));
1717
CHECK_FALSE(auth::verify_password("wrong", verifier));
18+
CHECK_FALSE(auth::valid_password_hash("argon2id$v=19$m=19456,t=2,p=1$"));
1819
CHECK_FALSE(auth::valid_password_hash("sha256$invalid"));
1920
CHECK_FALSE(auth::valid_password_hash("pbkdf2-sha256$200000$legacy$verifier"));
2021
auto modified = verifier;
21-
modified.replace(modified.find("m=19456"), 7, "m=32768");
22+
modified.replace(modified.find("m=2048"), 6, "m=32768");
2223
CHECK_FALSE(auth::valid_password_hash(modified));
2324
}
2425

0 commit comments

Comments
 (0)