{"record":{"id":"c3c9bef94e3dd441","repo":"siyuan-note/siyuan","slug":"argon2id-memory-too-low-minimum-64-mb","errorCode":null,"errorMessage":"Argon2id Memory too low (minimum 64 MB)","messagePattern":"Argon2id Memory too low \\(minimum 64 MB\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/kdf.go","lineNumber":68,"sourceCode":"\n// DefaultArgon2Params 返回 OWASP 2023 推荐的 Argon2id 参数。\nfunc DefaultArgon2Params() Argon2Params {\n\treturn Argon2Params{\n\t\tMemory:      64 * 1024,\n\t\tIterations:  3,\n\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 {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/kdf.go#L50-L86","documentation":"Raised by ValidateArgon2Params when p.Memory < 64*1024 (KiB), i.e. below the OWASP-2023 minimum of 64 MB for Argon2id. The guard prevents a weak KDF configuration from weakening notebook encryption; the default is 64 MB.","triggerScenarios":"KDFParams.Memory is loaded below 65536 (KiB) from a tampered or hand-edited notebook crypto config, or a backup generated by a non-conforming client. Caught during unlock/setup/change-password before DeriveKey runs.","commonSituations":"Editing conf JSON and shrinking memory to speed up unlock; a legacy or third-party backup with sub-minimum memory; a mis-typed value (e.g. entering MB instead of KiB).","solutions":["Set KDFParams.Memory to at least 64*1024 (KiB); DefaultArgon2Params uses 64*1024.","Re-derive the config through the official change-password flow, which always emits valid params.","Remember the unit is KiB, not bytes and not MiB."],"exampleFix":"// before (treated as < 64 MiB)\nparams := util.Argon2Params{Memory: 64, Iterations: 3, Parallelism: 4, KeyLength: 32}\n\n// after: 64 MiB expressed in KiB\nparams := util.Argon2Params{Memory: 64 * 1024, Iterations: 3, Parallelism: 4, KeyLength: 32}","handlingStrategy":"validation","validationCode":"if p.Memory < 64*1024 {\n    p.Memory = 64 * 1024 // clamp to OWASP minimum, expressed in KiB\n}\nif _, err := util.ValidateArgon2Params(p); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember Memory is in KiB; 64*1024 KiB == 64 MB.","Use DefaultArgon2Params as the baseline.","Validate immediately after loading config from disk or backup."],"tags":["crypto","argon2","encryption","validation","notebook-crypto"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}