{"record":{"id":"fa4869daa872d71f","repo":"siyuan-note/siyuan","slug":"argon2id-iterations-too-low-minimum-3","errorCode":null,"errorMessage":"Argon2id Iterations too low (minimum 3)","messagePattern":"Argon2id Iterations too low \\(minimum 3\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/kdf.go","lineNumber":74,"sourceCode":"\t\tParallelism: 4,\n\t\tKeyLength:   32,\n\t}\n}\n\n// ValidateArgon2Params 校验 Argon2id 参数是否在合理范围内，防止恶意备份设置极大内存导致 OOM，\n// 或过弱参数降低安全性。\nfunc ValidateArgon2Params(p Argon2Params) (Argon2Params, error) {\n\tif p.KeyLength != 32 {\n\t\treturn p, errors.New(\"Argon2id KeyLength must be 32\")\n\t}\n\tif p.Memory < 64*1024 {\n\t\treturn p, errors.New(\"Argon2id Memory too low (minimum 64 MB)\")\n\t}\n\tif p.Memory > 256*1024 {\n\t\treturn p, errors.New(\"Argon2id Memory too high (maximum 256 MB)\")\n\t}\n\tif p.Iterations < 3 {\n\t\treturn p, errors.New(\"Argon2id Iterations too low (minimum 3)\")\n\t}\n\tif p.Iterations > 10 {\n\t\treturn p, errors.New(\"Argon2id Iterations too high (maximum 10)\")\n\t}\n\tif p.Parallelism == 0 || p.Parallelism > 16 {\n\t\treturn p, errors.New(\"Argon2id Parallelism must be between 1 and 16\")\n\t}\n\treturn p, nil\n}\n\n// DeriveKey 用 Argon2id 从密码派生密钥。同一 password+salt+params 多次调用结果一致。\nfunc DeriveKey(password string, salt []byte, p Argon2Params) []byte {\n\treturn argon2.IDKey([]byte(password), salt, p.Iterations, p.Memory, p.Parallelism, p.KeyLength)\n}\n\n// Encrypt 用 AES-256-GCM 加密。每次调用生成随机 nonce，因此同一明文多次加密结果不同。\n// 返回格式：magic(4B) || spec(1B) || algorithm(1B) || nonceLength(1B) || nonce || ciphertext || GCM tag(16B)。\nfunc Encrypt(key, plaintext []byte) ([]byte, error) {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/kdf.go#L56-L92","documentation":"ValidateArgon2Params requires at least 3 Argon2id iterations (passes over memory). Fewer passes make key derivation too cheap and weaken the KDF against brute force, so the library rejects them before deriving any key.","triggerScenarios":"Calling ValidateArgon2Params (directly or via EnableEncryptedNotebook, ImportNotebookCryptoBackup, deriveKEK, or backup-restore paths) with Argon2Params.Iterations < 3, e.g. a config saved with Iterations 1 or 2.","commonSituations":"Hand-editing notebook crypto settings to speed up unlock, importing a backup whose params were downgraded, or constructing Argon2Params partially so Iterations zero-values to 0.","solutions":["Set Argon2Params.Iterations to >= 3; use util.DefaultArgon2Params() (3 iterations) as the baseline","If unlock is too slow, reduce Memory within the allowed 64-256 MB range instead of dropping iterations below 3","Fix the source config JSON of the imported backup before importing"],"exampleFix":"// before\np := util.Argon2Params{Memory: 64 * 1024, Iterations: 2, Parallelism: 4, KeyLength: 32}\n\n// after\np := util.Argon2Params{Memory: 64 * 1024, Iterations: 3, Parallelism: 4, KeyLength: 32}","handlingStrategy":"validation","validationCode":"if p.Iterations < 3 || p.Iterations > 10 {\n    return fmt.Errorf(\"iterations must be 3-10, got %d\", p.Iterations)\n}","typeGuard":null,"tryCatchPattern":"if _, err := util.ValidateArgon2Params(p); err != nil {\n    return fmt.Errorf(\"invalid KDF params: %w\", err)\n}","preventionTips":["Never reduce iterations below 3 to speed up unlock; tune Memory instead","Pre-populate Argon2Params from DefaultArgon2Params to avoid zero values","Validate config JSON fields after unmarshal, before use"],"tags":["kdf","argon2id","validation","weak-parameters","security"],"backgroundTag":"value-out-of-range","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}