# VNX-326: Inadequate Encryption Strength (undersized DSA, DH, EC or symmetric key)

Reports keys generated too small: DSA and Diffie-Hellman below 2048 bits, AES keys below 128 bits, elliptic curves under 224 bits.

| Field | Value |
|---|---|
| Rule ID | `VNX-326` |
| Severity | High |
| SARIF level | `error` |
| Kind | `sast` |
| Languages | Go, Java, Kotlin, JavaScript / TypeScript, PHP, Python, Ruby |
| CWE | [CWE-326](https://cwe.mitre.org/data/definitions/326.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:H/AP:A/AL:A/IC:N/FC:LT/RP:N/RL:A/AV:I/AS:N/IN:A/SC:A/BI:H/DI:H/EX:H/EC:N/P:H` |
| Tags | `crypto` `key-size` `cwe-326` |
| Source | [`internal/sast/rules/vnx-326.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-326.rego) |

## Overview

VNX-326 maps to [CWE-326: Inadequate Encryption Strength](https://cwe.mitre.org/data/definitions/326.html). It reports key generation with a literal size or named parameter set below current minimums.

## Why this matters

A 1024-bit DSA or Diffie-Hellman group is within reach of a well-funded attacker (Logjam precomputed the common 512 and 1024-bit groups), and curves under 224 bits give less than 112 bits of security. NIST SP 800-131A disallows both for new keys.

## What gets flagged

```java
// FLAGGED: a DSA generator initialised below 2048 bits
KeyPairGenerator g = KeyPairGenerator.getInstance("DSA");
g.initialize(1024);
// FLAGGED: a 192-bit curve
g.initialize(new ECGenParameterSpec("secp192r1"));
```

```python
# FLAGGED
dsa.generate_private_key(key_size=1024)
dh.generate_parameters(generator=2, key_size=512)
ec.generate_private_key(ec.SECP192R1())
```

```go
// FLAGGED
dsa.GenerateParameters(&params, rand.Reader, dsa.L1024N160)
```

```javascript
// FLAGGED
crypto.generateKeyPairSync('dsa', { modulusLength: 1024 });
crypto.getDiffieHellman('modp2');
```

```php
// FLAGGED
openssl_pkey_new(['private_key_bits' => 1024]);
```

```ruby
# FLAGGED
OpenSSL::PKey::RSA.new(1024)
```

## What is not flagged

- Sizes of 2048 bits and above (128 bits and above for AES), and sizes from a variable or configuration.
- `init()`/`initialize()` on objects that are not a DSA/DH key-pair generator or an AES key generator.
- RSA in Python, Go, Java and Node.js, which [VNX-CRYPTO-006](/sast/rules/vnx-crypto-006.md) reports; broken ciphers such as DES and RC4, which [VNX-CRYPTO-004](/sast/rules/vnx-crypto-004.md) reports.
- Comments, string literals and test files.

## Remediation

1. Use 3072-bit DSA, DH or RSA keys, or move to elliptic curves (P-256, X25519, Ed25519).
2. Use AES-128 or AES-256 keys.
3. Use `modp14` (2048-bit) or larger groups, or ECDH.

## References

- [CWE-326: Inadequate Encryption Strength](https://cwe.mitre.org/data/definitions/326.html)
- [NIST SP 800-131A Rev. 2](https://csrc.nist.gov/publications/detail/sp/800-131a/rev-2/final)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-326
// nosec vnx-326
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-326 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
