Skip to content

Commit 45fa2c9

Browse files
committed
Crypto: Code review cleanup.
1 parent 1882db7 commit 45fa2c9

File tree

10 files changed

+15
-25
lines changed

10 files changed

+15
-25
lines changed

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/KeyAgreementAlgorithmInstance.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ predicate knownOpenSSLConstantToKeyAgreementFamilyType(
2222
)
2323
}
2424

25-
class KnownOpenSSLHashConstantAlgorithmInstance extends OpenSSLAlgorithmInstance,
25+
class KnownOpenSSLKeyAgreementConstantAlgorithmInstance extends OpenSSLAlgorithmInstance,
2626
Crypto::KeyAgreementAlgorithmInstance instanceof KnownOpenSSLKeyAgreementAlgorithmExpr
2727
{
2828
OpenSSLAlgorithmValueConsumer getterCall;
2929

30-
KnownOpenSSLHashConstantAlgorithmInstance() {
30+
KnownOpenSSLKeyAgreementConstantAlgorithmInstance() {
3131
// Two possibilities:
3232
// 1) The source is a literal and flows to a getter, then we know we have an instance
3333
// 2) The source is a KnownOpenSSLAlgorithm is call, and we know we have an instance immediately from that
@@ -44,7 +44,6 @@ class KnownOpenSSLHashConstantAlgorithmInstance extends OpenSSLAlgorithmInstance
4444
or
4545
// Possibility 2:
4646
this instanceof OpenSSLAlgorithmCall and
47-
this instanceof DirectAlgorithmValueConsumer and
4847
getterCall = this
4948
}
5049

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmInstances/MACAlgorithmInstance.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class KnownOpenSSLMACConstantAlgorithmInstance extends OpenSSLAlgorithmInstance,
1919
this instanceof OpenSSLAlgorithmLiteral and
2020
exists(DataFlow::Node src, DataFlow::Node sink |
2121
// Sink is an argument to a CipherGetterCall
22-
sink = getterCall.(OpenSSLAlgorithmValueConsumer).getInputNode() and
22+
sink = getterCall.getInputNode() and
2323
// Source is `this`
2424
src.asExpr() = this and
2525
// This traces to a getter

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/DirectAlgorithmValueConsumer.qll

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgor
1212
*/
1313
class DirectAlgorithmValueConsumer extends OpenSSLAlgorithmValueConsumer instanceof OpenSSLAlgorithmCall
1414
{
15-
DataFlow::Node resultNode;
16-
Expr resultExpr;
17-
1815
/**
1916
* These cases take in no explicit value (the value is implicit)
2017
*/

cpp/ql/lib/experimental/quantum/OpenSSL/AlgorithmValueConsumers/HashAlgorithmValueConsumer.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class EVP_Q_Digest_Algorithm_Consumer extends HashAlgorithmValueConsumer {
2828
}
2929

3030
/**
31-
* Instances from https://docs.openssl.org/3.0/man3/EVP_PKEY_CTX_ctrl/
31+
* An instance from https://docs.openssl.org/3.0/man3/EVP_PKEY_CTX_ctrl/
3232
* where the digest is directly consumed by name.
3333
* In these cases, the operation is not yet performed, but there is
3434
* these functions are treated as 'initializers' and track the algorithm through
@@ -71,7 +71,7 @@ class EVPDigestAlgorithmValueConsumer extends HashAlgorithmValueConsumer {
7171
] and
7272
valueArgNode.asExpr() = this.(Call).getArgument(0)
7373
or
74-
this.(Call).getTarget().getName() in ["EVP_MD_fetch"] and
74+
this.(Call).getTarget().getName() = "EVP_MD_fetch" and
7575
valueArgNode.asExpr() = this.(Call).getArgument(1)
7676
or
7777
this.(Call).getTarget().getName() = "EVP_DigestSignInit_ex" and

cpp/ql/lib/experimental/quantum/OpenSSL/AvcFlow.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import semmle.code.cpp.dataflow.new.DataFlow
2-
import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers
2+
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers
33

44
/**
55
* Flows from algorithm values to operations, specific to OpenSSL

cpp/ql/lib/experimental/quantum/OpenSSL/CtxFlow.qll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ class CtxPointerArgument extends CtxPointerExpr {
6666
/**
6767
* A call returning a CtxPointerExpr.
6868
*/
69-
private class CtxPointerReturn extends CtxPointerExpr {
70-
CtxPointerReturn() { exists(Call c | c = this) }
71-
72-
Call getCall() { result = this.(Call) }
69+
private class CtxPointerReturn extends CtxPointerExpr instanceof Call {
70+
Call getCall() { result = this }
7371
}
7472

7573
/**

cpp/ql/lib/experimental/quantum/OpenSSL/KeyFlow.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ module OpenSSLKeyFlowConfig implements DataFlow::ConfigSig {
1212
exists(Crypto::KeyCreationOperationInstance keygen | keygen.getOutputKeyArtifact() = source)
1313
}
1414

15-
predicate isSink(DataFlow::Node sink) {
16-
exists(Call call | call.(Call).getAnArgument() = sink.asExpr())
17-
}
15+
predicate isSink(DataFlow::Node sink) { exists(Call call | call.getAnArgument() = sink.asExpr()) }
1816
//TODO: consideration for additional flow steps? Can a key be copied for example?
1917
}
2018

cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPKeyGenOperation.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ private import experimental.quantum.Language
22
private import experimental.quantum.OpenSSL.CtxFlow
33
private import OpenSSLOperationBase
44
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers
5-
private import semmle.code.cpp.dataflow.new.DataFlow
65

76
class EVPKeyGenInitialize extends EvpPrimaryAlgorithmInitializer {
87
EVPKeyGenInitialize() {
@@ -13,7 +12,8 @@ class EVPKeyGenInitialize extends EvpPrimaryAlgorithmInitializer {
1312
}
1413

1514
/**
16-
* The algorithm is encoded through the context argument.
15+
* Gets the algorithm argument.
16+
* In this case the algorithm is encoded through the context argument.
1717
* The context may be directly created from an algorithm consumer,
1818
* or from a new operation off of a prior key. Either way,
1919
* we will treat this argument as the algorithm argument.
@@ -67,8 +67,8 @@ class EVPKeyGenOperation extends EvpOperation, Crypto::KeyGenerationOperationIns
6767
}
6868

6969
/**
70-
* Calls to `EVP_PKEY_new_mac_key` create a new MAC key.
71-
* EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key, int keylen);
70+
* A call to `EVP_PKEY_new_mac_key` that creatse a new generic MAC key.
71+
* Signature: EVP_PKEY *EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key, int keylen);
7272
*/
7373
class EvpNewMacKey extends EvpOperation, Crypto::KeyGenerationOperationInstance {
7474
DataFlow::Node keyResultNode;

cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPPKeyCtxInitializer.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import cpp
99
private import experimental.quantum.OpenSSL.CtxFlow
1010
private import OpenSSLOperations
11-
private import OpenSSLOperationBase
1211

1312
/**
1413
* A call to `EVP_PKEY_CTX_new` or `EVP_PKEY_CTX_new_from_pkey`.
@@ -17,7 +16,7 @@ private import OpenSSLOperationBase
1716
* parameters set (e.g., `EVP_PKEY_paramgen`).
1817
* NOTE: for the case of `EVP_PKEY_paramgen`, these calls
1918
* are encoded as context passthroughs, and any operation
20-
* will get all associated initializers for teh paramgen
19+
* will get all associated initializers for the paramgen
2120
* at the final keygen operation automatically.
2221
*/
2322
class EVPNewKeyCtx extends EvpKeyInitializer {

cpp/ql/lib/experimental/quantum/OpenSSL/Operations/EVPSignatureOperation.qll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
private import experimental.quantum.Language
6-
private import OpenSSLOperationBase
76
private import experimental.quantum.OpenSSL.AvcFlow
87
private import experimental.quantum.OpenSSL.CtxFlow
98
private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumers
@@ -87,7 +86,7 @@ private Expr signatureOperationOutputArg(Call call) {
8786
}
8887

8988
/**
90-
* Base configuration for all EVP signature operations.
89+
* The base configuration for all EVP signature operations.
9190
*/
9291
abstract class EvpSignatureOperation extends EvpOperation, Crypto::SignatureOperationInstance {
9392
EvpSignatureOperation() {

0 commit comments

Comments
 (0)