{"record":{"id":"84b181983ebcdbdf","repo":"siyuan-note/siyuan","slug":"argon2id-parallelism-must-be-between-1-and-16","errorCode":null,"errorMessage":"Argon2id Parallelism must be between 1 and 16","messagePattern":"Argon2id Parallelism must be between 1 and 16","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/kdf.go","lineNumber":80,"sourceCode":"// 或过弱参数降低安全性。\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) {\n\treturn encryptGCM(key, plaintext, nil, \"Encrypt\")\n}\n\n// Decrypt 对应 Encrypt 的解密。密钥错误、格式无效或密文被篡改时返回错误。\nfunc Decrypt(key, ciphertext []byte) ([]byte, error) {\n\treturn decryptGCM(key, ciphertext, nil, \"Decrypt\")","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/kdf.go#L62-L98","documentation":"Raised by ValidateArgon2Params when p.Parallelism == 0 or > 16. Parallelism (lanes) must be between 1 and 16 inclusive; zero would make argon2.IDKey misbehave and very large values would spawn excessive goroutines/threads.","triggerScenarios":"KDFParams.Parallelism is 0 (unset/missing field) or > 16 in a loaded notebook crypto config.","commonSituations":"A deserialized config with the field absent (defaults to 0); a hand-edited value; a backup from a non-conforming client.","solutions":["Set KDFParams.Parallelism to a value in [1, 16] (DefaultArgon2Params uses 4).","Treat a zero Parallelism as missing and substitute the default before validating.","Regenerate params via the official change-password flow."],"exampleFix":"// before\nparams := util.Argon2Params{Memory: 64 * 1024, Iterations: 3, Parallelism: 0, KeyLength: 32}\n\n// after\nparams := util.Argon2Params{Memory: 64 * 1024, Iterations: 3, Parallelism: 4, KeyLength: 32}","handlingStrategy":"validation","validationCode":"if p.Parallelism == 0 {\n    p.Parallelism = 4 // DefaultArgon2Params value\n}\nif _, err := util.ValidateArgon2Params(p); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default Parallelism to 4 when the field is missing.","Keep Parallelism within [1, 16].","Validate after every config load."],"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"}