SV.WEAK.KEYS.AES

Insufficient key length in Cryptographic Algorithm

Klocwork reports a SV.WEAK.KEYS.AES defect when the AES cryptographic algorithm is used with a key that is of insufficient size.

Vulnerability and risk

Small key size can lead to algorithm breaks that can then lead to the leakage of sensitive data. Algorithms need to be robust against the powerful computing techniques that are used to perform brute force attacks.

Mitigation and prevention

Avoid implementing AES algorithms with keys that are less than 128 bits.

Vulnerable code example

Copy
import javax.crypto.KeyGenerator;
 
class KeyGenAESTest {
  public static void main(String[] args) {
    KeyGenerator generatorAES = KeyGenerator.getInstance("AES");
    generatorAES.init(64);  // SV.WEAK.KEYS.AES (!)
  }
}

Klocwork reports an SV.WEAK.AES defect on line 6, indicating, "Cryptographic Algorithm uses key less than 128 bits". An AES algorithm needs a key that is at least 128 bits.

Fixed code example

Copy
import javax.crypto.KeyGenerator;
 
class KeyGenAESTest {
  public static void main(String[] args) {
    KeyGenerator generatorAES = KeyGenerator.getInstance("AES");
    generatorAES.init(128);  // no SV.WEAK.KEYS.AES
  }
}

Klocwork no longer reports a defect because the AES algorithm uses a key that is 128 bits.

Security training

Application security training materials provided by Secure Code Warrior.