Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0f874e4
Crypto: Adding initial openssl tests, fixing a bug in hash modeling f…
bdrodes May 22, 2025
10d8504
refactor EVP common classes
GrosQuildu May 23, 2025
8b96ec9
fix openssl outputs
GrosQuildu May 28, 2025
adb9c3b
Update cpp/ql/lib/experimental/quantum/OpenSSL/Operations/OpenSSLOper…
GrosQuildu May 29, 2025
408224a
Apply docs suggestions
GrosQuildu May 29, 2025
0c17cbf
rm one-shot class
GrosQuildu May 29, 2025
c3b384d
init work for openssl signatures
GrosQuildu May 28, 2025
c14fba5
openssl signatures - inputs, outputs and algorithms base
GrosQuildu May 29, 2025
b068833
start on openssl signature tests
GrosQuildu May 29, 2025
310469a
fix super/parent bug, use new SignatureOperationNode
GrosQuildu May 29, 2025
804bd89
flows for key from contexts
GrosQuildu May 29, 2025
02fb52c
make signature tests work for algorithms
GrosQuildu May 29, 2025
16c136e
openssl keygen & tracking of keys-contexts-algorithms
GrosQuildu May 29, 2025
3672358
signature algorithms are tracked from keys and contexts
GrosQuildu May 30, 2025
54a3e5c
fix cipher tests after adding new stubs
GrosQuildu May 30, 2025
0178bf3
more tests
GrosQuildu May 30, 2025
e618097
signature and keygen tests - expected
GrosQuildu May 30, 2025
c6b2165
change model.qll - KeyArtifactNode getAKnownAlgorithm fix
GrosQuildu May 30, 2025
a70cd60
key sizes basic support
GrosQuildu May 30, 2025
9b87f1f
rm redundant predicate
GrosQuildu May 30, 2025
5dbaf1b
merge main
GrosQuildu Jun 4, 2025
ca67e45
Merge branch 'main' into openssl-signatures
GrosQuildu Jun 4, 2025
30bc605
fix formatting
GrosQuildu Jun 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
key sizes basic support
  • Loading branch information
GrosQuildu committed May 30, 2025
commit a70cd60b37551552c8eac7a3f69a21b8e79c08ea
Original file line number Diff line number Diff line change
@@ -82,7 +82,12 @@ class KnownOpenSSLSignatureAlgorithmConstant extends KnownOpenSSLAlgorithmConsta
predicate resolveAlgorithmFromCall(Call c, string normalized, string algType) {
exists(string name, string parsedTargetName |
parsedTargetName =
c.getTarget().getName().replaceAll("EVP_", "").toLowerCase().replaceAll("_", "-") and
c.getTarget()
.getName()
.replaceAll("EVP_", "")
.replaceAll("_gen", "")
.toLowerCase()
.replaceAll("_", "-") and
name = resolveAlgorithmAlias(parsedTargetName) and
knownOpenSSLAlgorithmLiteral(name, _, normalized, algType)
)
Original file line number Diff line number Diff line change
@@ -69,7 +69,8 @@ class KnownOpenSSLSignatureConstantAlgorithmInstance extends OpenSSLAlgorithmIns
override string getRawAlgorithmName() { result = this.(Literal).getValue().toString() }

override int getKeySizeFixed() {
// this.(KnownOpenSSLSignatureAlgorithmConstant).getExplicitKeySize() = result
// TODO: use ellipticCurveNameToKeySizeAndFamilyMapping or KnownOpenSSLEllipticCurveConstantAlgorithmInstance
// TODO: maybe add getExplicitKeySize to KnownOpenSSLSignatureAlgorithmConstant and use it here
none()
}

@@ -83,11 +84,20 @@ class KnownOpenSSLSignatureConstantAlgorithmInstance extends OpenSSLAlgorithmIns
override OpenSSLAlgorithmValueConsumer getAVC() { result = getterCall }

override Crypto::ConsumerInputDataFlowNode getKeySizeConsumer() {
// TODO: trace to any key size initializer, symmetric and asymmetric
// TODO: trace to any key size initializer
// probably PKeyAlgorithmValueConsumer and SignatureAlgorithmValueConsumer
none()
}

/**
* No mode for signatures.
*/
override predicate shouldHaveModeOfOperation() { none() }

override predicate shouldHavePaddingScheme() { none() }
/**
* Padding only for RSA.
*/
override predicate shouldHavePaddingScheme() {
this.getAlgorithmType() instanceof KeyOpAlg::TAsymmetricCipher
}
}
Original file line number Diff line number Diff line change
@@ -15,18 +15,51 @@ class EVPKeyGenInitialize extends EVPInitialize {
override Expr getAlgorithmArg() { result = getAlgorithmFromCtx(this.getContextArg()) }
}

class EVPKeyGenOperation extends EVPOperation, Crypto::KeyGenerationOperationInstance {
/**
* All calls that can be tracked via ctx.
* For example calls used to set parameters like a key size.
*/
class EVPKeyGenUpdate extends EVPUpdate {
EVPKeyGenUpdate() {
this.(Call).getTarget().getName() in [
"EVP_PKEY_CTX_set_rsa_keygen_bits",
// TODO: "EVP_PKEY_CTX_set_params"
]
}

/**
* No input in our meaning.
*/
override Expr getInputArg() { none() }

/**
* No output in our meaning.
*/
override Expr getOutputArg() { none() }

Expr getKeySizeArg() {
this.(Call).getTarget().getName() = "EVP_PKEY_CTX_set_rsa_keygen_bits" and
result = this.(Call).getArgument(1)
}
}

class EVPKeyGenOperation extends EVPFinal, Crypto::KeyGenerationOperationInstance {
EVPKeyGenOperation() {
this.(Call).getTarget().getName() in [
"EVP_PKEY_generate", "EVP_PKEY_keygen", "EVP_PKEY_Q_keygen", "EVP_PKEY_paramgen"
// TODO: "EVP_PKEY_paramgen"
"EVP_PKEY_generate", "EVP_PKEY_keygen", "EVP_PKEY_Q_keygen", "EVP_PKEY_paramgen",
"EVP_RSA_gen"
// TODO: "EVP_PKEY_paramgen" may need special handling
// TODO: RSA_generate_key, RSA_generate_key_ex, etc
]
}

override Expr getAlgorithmArg() {
if this.(Call).getTarget().getName() = "EVP_PKEY_Q_keygen"
then result = this.(Call).getArgument(0)
else result = EVPOperation.super.getAlgorithmArg()
else
if this.(Call).getTarget().getName() = "EVP_RSA_gen"
then result = this
else result = EVPFinal.super.getAlgorithmArg()
}

override Crypto::KeyArtifactType getOutputKeyType() { result = Crypto::TAsymmetricKeyType() }
@@ -36,11 +69,16 @@ class EVPKeyGenOperation extends EVPOperation, Crypto::KeyGenerationOperationIns
override Expr getOutputArg() { result = this.(Call).getArgument(1) }

override Crypto::ArtifactOutputDataFlowNode getOutputKeyArtifact() {
result = EVPOperation.super.getOutputKeyArtifact()
result = EVPFinal.super.getOutputKeyArtifact()
}

override Crypto::ConsumerInputDataFlowNode getKeySizeConsumer() {
none() // TODO
if this.(Call).getTarget().getName() = "EVP_PKEY_Q_keygen"
then result = DataFlow::exprNode(this.(Call).getArgument(3)) // TODO: may be wrong for EC keys
else
if this.(Call).getTarget().getName() = "EVP_RSA_gen"
then result = DataFlow::exprNode(this.(Call).getArgument(0))
else result = DataFlow::exprNode(this.getUpdateCalls().(EVPKeyGenUpdate).getKeySizeArg())
}

override int getKeySizeFixed() {
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ abstract class OpenSSLOperation extends Crypto::OperationInstance instanceof Ope

/**
* Algorithm is either an argument and we track it to AlgorithmValueConsumer
* or we have the AlgorithmValueConsumer already and just return it.
* or we have the AlgorithmValueConsumer already tracked down and just return it.
*/
override Crypto::AlgorithmValueConsumer getAnAlgorithmValueConsumer() {
AlgGetterToAlgConsumerFlow::flow(result.(OpenSSLAlgorithmValueConsumer).getResultNode(),