siyuan-note/siyuan · error

Argon2id Parallelism must be between 1 and 16

Error message

Argon2id Parallelism must be between 1 and 16

What it means

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.

Source

Thrown at kernel/util/kdf.go:80

// 或过弱参数降低安全性。
func ValidateArgon2Params(p Argon2Params) (Argon2Params, error) {
	if p.KeyLength != 32 {
		return p, errors.New("Argon2id KeyLength must be 32")
	}
	if p.Memory < 64*1024 {
		return p, errors.New("Argon2id Memory too low (minimum 64 MB)")
	}
	if p.Memory > 256*1024 {
		return p, errors.New("Argon2id Memory too high (maximum 256 MB)")
	}
	if p.Iterations < 3 {
		return p, errors.New("Argon2id Iterations too low (minimum 3)")
	}
	if p.Iterations > 10 {
		return p, errors.New("Argon2id Iterations too high (maximum 10)")
	}
	if p.Parallelism == 0 || p.Parallelism > 16 {
		return p, errors.New("Argon2id Parallelism must be between 1 and 16")
	}
	return p, nil
}

// DeriveKey 用 Argon2id 从密码派生密钥。同一 password+salt+params 多次调用结果一致。
func DeriveKey(password string, salt []byte, p Argon2Params) []byte {
	return argon2.IDKey([]byte(password), salt, p.Iterations, p.Memory, p.Parallelism, p.KeyLength)
}

// Encrypt 用 AES-256-GCM 加密。每次调用生成随机 nonce,因此同一明文多次加密结果不同。
// 返回格式:magic(4B) || spec(1B) || algorithm(1B) || nonceLength(1B) || nonce || ciphertext || GCM tag(16B)。
func Encrypt(key, plaintext []byte) ([]byte, error) {
	return encryptGCM(key, plaintext, nil, "Encrypt")
}

// Decrypt 对应 Encrypt 的解密。密钥错误、格式无效或密文被篡改时返回错误。
func Decrypt(key, ciphertext []byte) ([]byte, error) {
	return decryptGCM(key, ciphertext, nil, "Decrypt")

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Set KDFParams.Parallelism to a value in [1, 16] (DefaultArgon2Params uses 4).
  2. Treat a zero Parallelism as missing and substitute the default before validating.
  3. Regenerate params via the official change-password flow.

Example fix

// before
params := util.Argon2Params{Memory: 64 * 1024, Iterations: 3, Parallelism: 0, KeyLength: 32}

// after
params := util.Argon2Params{Memory: 64 * 1024, Iterations: 3, Parallelism: 4, KeyLength: 32}
Defensive patterns

Strategy: validation

Validate before calling

if p.Parallelism == 0 {
    p.Parallelism = 4 // DefaultArgon2Params value
}
if _, err := util.ValidateArgon2Params(p); err != nil {
    return err
}

Prevention

When it happens

Trigger: KDFParams.Parallelism is 0 (unset/missing field) or > 16 in a loaded notebook crypto config.

Common situations: A deserialized config with the field absent (defaults to 0); a hand-edited value; a backup from a non-conforming client.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/84b181983ebcdbdf. Report an issue: GitHub.