-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Crypto: Add OpenSSL elliptic curve algorithm instances and consumers #19528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e7535b3
bbbdf89
d05d38f
3e54e4d
e5641ef
03a6e13
4309499
55119cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import cpp | ||
| private import experimental.quantum.Language | ||
| private import KnownAlgorithmConstants | ||
| private import OpenSSLAlgorithmInstanceBase | ||
| private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumerBase | ||
| private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.DirectAlgorithmValueConsumer | ||
| private import AlgToAVCFlow | ||
|
|
||
| class KnownOpenSSLEllipticCurveConstantAlgorithmInstance extends OpenSSLAlgorithmInstance, | ||
| Crypto::EllipticCurveInstance instanceof KnownOpenSSLEllipticCurveAlgorithmConstant | ||
Check warningCode scanning / CodeQL Acronyms should be PascalCase/camelCase. Warning
Acronyms in KnownOpenSSLEllipticCurveConstantAlgorithmInstance should be PascalCase/camelCase.
|
||
| { | ||
| OpenSSLAlgorithmValueConsumer getterCall; | ||
|
|
||
| KnownOpenSSLEllipticCurveConstantAlgorithmInstance() { | ||
| // Two possibilities: | ||
| // 1) The source is a literal and flows to a getter, then we know we have an instance | ||
| // 2) The source is a KnownOpenSSLAlgorithm is call, and we know we have an instance immediately from that | ||
| // Possibility 1: | ||
| this instanceof Literal and | ||
| exists(DataFlow::Node src, DataFlow::Node sink | | ||
| // Sink is an argument to a CipherGetterCall | ||
| sink = getterCall.getInputNode() and | ||
| // Source is `this` | ||
| src.asExpr() = this and | ||
| // This traces to a getter | ||
| KnownOpenSSLAlgorithmToAlgorithmValueConsumerFlow::flow(src, sink) | ||
| ) | ||
| or | ||
| // Possibility 2: | ||
| this instanceof DirectAlgorithmValueConsumer and getterCall = this | ||
| } | ||
|
|
||
| override OpenSSLAlgorithmValueConsumer getAVC() { result = getterCall } | ||
Check warningCode scanning / CodeQL Acronyms should be PascalCase/camelCase. Warning
Acronyms in getAVC should be PascalCase/camelCase.
|
||
|
|
||
| override string getRawEllipticCurveName() { result = this.(Literal).getValue().toString() } | ||
|
|
||
| override Crypto::TEllipticCurveType getEllipticCurveType() { | ||
| Crypto::ellipticCurveNameToKeySizeAndFamilyMapping(this.(KnownOpenSSLEllipticCurveAlgorithmConstant) | ||
| .getNormalizedName(), _, result) | ||
| } | ||
|
|
||
| override int getKeySize() { | ||
| Crypto::ellipticCurveNameToKeySizeAndFamilyMapping(this.(KnownOpenSSLEllipticCurveAlgorithmConstant) | ||
| .getNormalizedName(), result, _) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ import CipherAlgorithmInstance | |
| import PaddingAlgorithmInstance | ||
| import BlockAlgorithmInstance | ||
| import HashAlgorithmInstance | ||
| import EllipticCurveAlgorithmInstance | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommend going through all of these and doing a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushed |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,36 @@ | ||||||||||||||||||||||||||
| import cpp | ||||||||||||||||||||||||||
| private import experimental.quantum.Language | ||||||||||||||||||||||||||
| private import experimental.quantum.OpenSSL.LibraryDetector | ||||||||||||||||||||||||||
| private import experimental.quantum.OpenSSL.AlgorithmInstances.KnownAlgorithmConstants | ||||||||||||||||||||||||||
| private import experimental.quantum.OpenSSL.AlgorithmValueConsumers.OpenSSLAlgorithmValueConsumerBase | ||||||||||||||||||||||||||
| private import experimental.quantum.OpenSSL.AlgorithmInstances.OpenSSLAlgorithmInstances | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| /** | |
| * An abstract base class for consumers of elliptic curve algorithm values. | |
| * | |
| * This class is designed to be extended by specific implementations that | |
| * handle elliptic curve-related cryptographic operations in OpenSSL. | |
| * It provides a common interface and shared functionality for such consumers. | |
| * | |
| * Subclasses should implement the necessary methods to process elliptic curve | |
| * algorithm values and integrate with the OpenSSL cryptographic library. | |
| */ |
Check warning
Code scanning / CodeQL
Acronyms should be PascalCase/camelCase. Warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a generic algorithm class here, and why does the algorithm itself bind itself to the AVC as opposed to what is actually using/related to the algorithm consumed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I correct in my reasoning below?
"An algorithm instance exists if and only if it is a string literal that flows to a consumer. Consequently, the definition of an algorithm instance is inherently constrained by the consumer to which it flows, establishing a dependent relationship between the instance and its consuming context."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically a literal must flow to something that consumes it, if not, we aren't calling it an algorithm.
There is a flip side, the direct algorithms (functions like AES()), these... well we could say are algorithms in their own right, but I didn't model it that way. So if these don't flow to something, they also don't exist as an algorithm. We may need to re-address that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are indeed algorithms -- the instance where you define them would be be modeled by extending an algorithm, operation, and AVC (assuming AES() also performs some sort of operation using AES).
Check warning
Code scanning / CodeQL
Redundant import Warning