Crypto: Update JCA PBKDF2 modeling: 1) add further inheritance structures to make the inheritance decomposition and caveats clearer, and 2) use getConsumer to establish the hash and hmac consumer. Update the Model to expect hash node types specifically for HMAC getHashALgorithmOrUnknown.

This commit is contained in:
REDMOND\brodes
2025-10-02 11:45:13 -04:00
parent 850c1ec12d
commit 704a06e1fa
2 changed files with 28 additions and 12 deletions

View File

@@ -1265,23 +1265,39 @@ module JCAModel {
override int getFixedDigestLength() { exists(hash_name_to_type_known(hashName, result)) }
}
//TODO: handle PBE
class Pbkdf2AlgorithmStringLiteral extends KdfAlgorithmStringLiteral,
Crypto::Pbkdf2AlgorithmInstance, Crypto::HmacAlgorithmInstance
//TODO: handle PBE "with" cases
class Pbkdf2WithHmac_Pbkdf2AlgorithmInstance extends Crypto::Pbkdf2AlgorithmInstance,
KdfAlgorithmStringLiteral, // this is a parent already, but extending to have immediate access to 'getConsumer()'
Pbkdf2WithHmac_KeyOperationAlgorithmStringLiteral
{
Pbkdf2AlgorithmStringLiteral() { super.getKdfType() instanceof Crypto::PBKDF2 }
override Crypto::AlgorithmValueConsumer getHmacAlgorithmValueConsumer() {
result = this.getConsumer()
}
}
override Crypto::AlgorithmValueConsumer getHmacAlgorithmValueConsumer() { result = this }
// NOTE: must use instanceof to avoid non-monotonic recursion
class Pbkdf2WithHmac_HmacAlgorithmInstance extends Crypto::HmacAlgorithmInstance instanceof Pbkdf2WithHmac_KeyOperationAlgorithmStringLiteral
{
override Crypto::AlgorithmValueConsumer getHashAlgorithmValueConsumer() {
result = this.(KdfAlgorithmStringLiteral).getConsumer()
}
override Crypto::AlgorithmValueConsumer getHashAlgorithmValueConsumer() { result = this }
override int getKeySizeFixed() {
// already defined by parent key operation algorithm, but extending an instance
// still requires we override this method
result = super.getKeySizeFixed()
}
override int getKeySizeFixed() { none() }
override Crypto::ConsumerInputDataFlowNode getKeySizeConsumer() { none() }
override Crypto::ConsumerInputDataFlowNode getKeySizeConsumer() {
// already defined by parent key operation algorithm, but extending an instance
// still requires we override this method
result = super.getKeySizeConsumer()
}
override string getRawAlgorithmName() {
// Note: hard coding "hmac" since that should be the only option
result = "Hmac"
// already defined by parent key operation algorithm, but extending an instance
// still requires we override this method
result = super.getRawAlgorithmName()
}
override Crypto::KeyOpAlg::AlgorithmType getAlgorithmType() {

View File

@@ -1633,7 +1633,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
override string getInternalType() { result = "HMACAlgorithm" }
NodeBase getHashAlgorithmOrUnknown() {
HashAlgorithmNode getHashAlgorithmOrUnknown() {
result.asElement() = hmacInstance.getHashAlgorithmValueConsumer().getASource()
}