Auditing application hashing, MACs and key derivation
Cryptography needs an explicit security purpose, appropriate mechanisms and a safe lifecycle for keys and protected data. Understanding application hashing and macs and key derivation helps establish which security property the feature needs and where that property is actually enforced.
What does this involve?
Cryptographic protection depends on the whole operation: the algorithm, its parameters, key handling and the way results are verified. Different mechanisms provide confidentiality, integrity or evidence of origin. Substituting one property for another can leave the important business requirement unprotected.
Cryptographic hashes are used in a wide variety of cryptographic protocols, such as digital signatures, HMAC, key derivation functions (KDF), random bit generation, and password storage. The security of the cryptographic system is only as strong as the underlying hash functions used. This section outlines the requirements for using secure hash functions in cryptographic operations.
Why it matters
Consider a realistic failure: an application uses an encryption or verification API correctly in isolation but trusts the wrong key, content or operation.
A weakness can undermine trust in stored records or messages even when their appearance does not change. Assessment should connect the defect to the data or action it protects and the capabilities available to an attacker.
A code audit connects a stated requirement to the implementation responsible for enforcing it. Source review and targeted behavioural checks should explain the same boundary and any relevant exceptions.
How penetration testers check for it
Review the specific control expectations below against the code, deployment and observable application behaviour.
- Confirm that only approved hash functions are used for general cryptographic use cases, including digital signatures, HMAC, KDF, and random bit generation. Disallowed hash functions, such as MD5, must not be used for any cryptographic purpose.
- Confirm that passwords are stored using an approved, computationally intensive, key derivation function (also known as a "password hashing function"), with parameter settings configured based on current guidance. The settings should balance security and performance to make brute-force attacks sufficiently challenging for the required level of security.
- Confirm that hash functions used in digital signatures, as part of data authentication or data integrity are collision resistant and have appropriate bit-lengths. If collision resistance is required, the output length must be at least 256 bits. If only resistance to second pre-image attacks is required, the output length must be at least 128 bits.
- Confirm that the application uses approved key derivation functions with key stretching parameters when deriving secret keys from passwords. The parameters in use must balance security and performance to prevent brute-force attacks from compromising the resulting cryptographic key.
- Trace key generation, access, replacement and verification.
- Test invalid inputs and failure handling with controlled data.
How to fix it
Implement the required boundary in the component that actually performs the sensitive operation and retain focused regression coverage.
- Use maintained standard implementations and appropriate parameters.
- Protect keys throughout generation, use and retirement.
- Authenticate the content and identity that the operation actually relies on.
- Reject failed verification before trusting or processing the result.
An unusual cryptographic implementation is not enough to establish practical compromise. The report should explain the failed property and a defensible consequence.
Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.
Related issues
- Auditing public-key operations and trust decisions
- Auditing application cryptographic API use and key handling
- Implementing cryptographic key storage, rotation and revocation
Read about our methodology or contact pentested.com to discuss the security of your application code.