Go Insecure Scrypt Parameters

Description

This detector identifies vulnerable usage of Go's scrypt library with weak key derivation parameters. Scrypt is a password-based key derivation function where insufficient CPU/memory cost parameters make passwords vulnerable to brute-force attacks.

Weakness:

052 - Insecure encryption algorithm

Category: Information Collection

Detection Strategy

    Scans Go source code files that import the golang.org/x/crypto/scrypt library or use a scrypt alias

    Skips test files to avoid flagging legitimate weak parameters used in testing scenarios

    Analyzes function calls to scrypt methods and evaluates the cost parameters (N, r, p values)

    Reports violations when scrypt is called with parameters that fall below secure thresholds for computational cost and memory usage

    Triggers when the combination of CPU cost (N), block size (r), and parallelization (p) parameters are insufficient to resist modern brute-force attacks

Vulnerable code example

package main

import "golang.org/x/crypto/scrypt"

func deriveKeyWeak(password string, salt []byte) ([]byte, error) {
	return scrypt.Key([]byte(password), salt, 1024, 8, 1, 32) // Weak N parameter < 32768
}
...

✅ Secure code example

package main

import "golang.org/x/crypto/scrypt"

func deriveKeyWeak(password string, salt []byte) ([]byte, error) {
	return scrypt.Key([]byte(password), salt, 32768, 8, 1, 32) // N >= 32768 for secure scrypt
}
...