802
cryptographic algorithms. They will likely be exposed to attacks that are well-understood
by cryptographers. Reverse engineering techniques are mature. If the algorithm can be
compromised if attackers find out how it works, then it is especially weak. Periodically ensure that
the cryptography has not become obsolete. Some older algorithms, once thought to require a
billion years of computing time, can now be broken in days or hours. This includes MD4, MD5,
SHA1, DES, and other algorithms that were once regarded as strong. [REF-267]
Phase: Architecture and Design
Ensure that the design allows one cryptographic algorithm to be replaced with another in the
next generation or version. Where possible, use wrappers to make the interfaces uniform. This
will make it easier to upgrade to stronger algorithms. With hardware, design the product at the
Intellectual Property (IP) level so that one cryptographic algorithm can be replaced with another
in the next generation of the hardware product.
Effectiveness = Defense in Depth
Phase: Architecture and Design
Carefully manage and protect cryptographic keys (see CWE-320). If the keys can be guessed or
stolen, then the strength of the cryptography itself is irrelevant.
Phase: Architecture and Design
Strategy = Libraries or Frameworks
Use a vetted library or framework that does not allow this weakness to occur or provides
constructs that make this weakness easier to avoid. Industry-standard implementations will save
development time and may be more likely to avoid errors that can occur during implementation of
cryptographic algorithms. Consider the ESAPI Encryption feature.
Phase: Implementation
Phase: Architecture and Design
When using industry-approved techniques, use them correctly. Don't cut corners by skipping
resource-intensive steps (CWE-325). These steps are often essential for preventing common
attacks.
Demonstrative Examples
Example 1:
These code examples use the Data Encryption Standard (DES).
Example Language: C (Bad)
EVP_des_ecb();
Example Language: Java (Bad)
Cipher des=Cipher.getInstance("DES...");
des.initEncrypt(key2);
Example Language: PHP (Bad)
function encryptPassword($password){
$iv_size = mcrypt_get_iv_size(MCRYPT_DES, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key = "This is a password encryption key";
$encryptedPassword = mcrypt_encrypt(MCRYPT_DES, $key, $password, MCRYPT_MODE_ECB, $iv);
return $encryptedPassword;
}
Once considered a strong algorithm, DES now regarded as insufficient for many applications. It has
been replaced by Advanced Encryption Standard (AES).
CWE Version 4.14
CWE-327: Use of a Broken or Risky Cryptographic Algorithm
CWE-327: Use of a Broken or Risky Cryptographic Algorithm