@@ -12,14 +12,24 @@ signature module InputSig<LocationSig Location> {
1212 string toString ( ) ;
1313 }
1414
15+ class DataFlowNode {
16+ Location getLocation ( ) ;
17+
18+ string toString ( ) ;
19+ }
20+
1521 class UnknownLocation instanceof Location ;
22+
23+ predicate rngToIvFlow ( DataFlowNode rng , DataFlowNode iv ) ;
1624}
1725
1826module CryptographyBase< LocationSig Location, InputSig< Location > Input> {
1927 final class LocatableElement = Input:: LocatableElement ;
2028
2129 final class UnknownLocation = Input:: UnknownLocation ;
2230
31+ final class DataFlowNode = Input:: DataFlowNode ;
32+
2333 final class UnknownPropertyValue extends string {
2434 UnknownPropertyValue ( ) { this = "<unknown>" }
2535 }
@@ -93,12 +103,15 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
93103
94104 abstract class NonceArtifactInstance extends LocatableElement { }
95105
106+ abstract class RandomNumberGenerationInstance extends LocatableElement { }
107+
96108 newtype TNode =
97109 // Artifacts (data that is not an operation or algorithm, e.g., a key)
98110 TDigest ( DigestArtifactInstance e ) or
99111 TKey ( KeyArtifactInstance e ) or
100112 TInitializationVector ( InitializationVectorArtifactInstance e ) or
101113 TNonce ( NonceArtifactInstance e ) or
114+ TRandomNumberGeneration ( RandomNumberGenerationInstance e ) or
102115 // Operations (e.g., hashing, encryption)
103116 THashOperation ( HashOperationInstance e ) or
104117 TKeyDerivationOperation ( KeyDerivationOperationInstance e ) or
@@ -115,7 +128,7 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
115128 TPaddingAlgorithm ( PaddingAlgorithmInstance e ) or
116129 // Composite and hybrid cryptosystems (e.g., RSA-OAEP used with AES, post-quantum hybrid cryptosystems)
117130 // These nodes are always parent nodes and are not modeled but rather defined via library-agnostic patterns.
118- TKemDemHybridCryptosystem ( EncryptionAlgorithmInstance dem ) or // TODO, change this relation and the below ones
131+ TKemDemHybridCryptosystem ( EncryptionAlgorithm dem ) or // TODO, change this relation and the below ones
119132 TKeyAgreementHybridCryptosystem ( EncryptionAlgorithmInstance ka ) or
120133 TAsymmetricEncryptionMacHybridCryptosystem ( EncryptionAlgorithmInstance enc ) or
121134 TPostQuantumHybridCryptosystem ( EncryptionAlgorithmInstance enc )
@@ -127,9 +140,9 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
127140 */
128141 abstract class NodeBase extends TNode {
129142 /**
130- * Returns a string representation of this node, usually the name of the operation/algorithm/property .
143+ * Returns a string representation of this node.
131144 */
132- abstract string toString ( ) ;
145+ string toString ( ) { result = this . getInternalType ( ) }
133146
134147 /**
135148 * Returns a string representation of the internal type of this node, usually the name of the class.
@@ -172,15 +185,48 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
172185
173186 class Asset = NodeBase ;
174187
175- class Artifact = NodeBase ;
188+ abstract class Artifact extends NodeBase {
189+ abstract DataFlowNode asOutputData ( ) ;
190+
191+ abstract DataFlowNode getInputData ( ) ;
192+ }
176193
177194 /**
178195 * An initialization vector
179196 */
180- abstract class InitializationVector extends Asset , TInitializationVector {
197+ abstract class InitializationVector extends Artifact , TInitializationVector {
181198 final override string getInternalType ( ) { result = "InitializationVector" }
182199
183- final override string toString ( ) { result = this .getInternalType ( ) }
200+ RandomNumberGeneration getRNGSource ( ) {
201+ Input:: rngToIvFlow ( result .asOutputData ( ) , this .getInputData ( ) )
202+ }
203+ }
204+
205+ newtype TRNGSourceSecurity =
206+ RNGSourceSecure ( ) or // Secure RNG source (unrelated to seed)
207+ RNGSourceInsecure ( ) // Insecure RNG source (unrelated to seed)
208+
209+ class RNGSourceSecurity extends TRNGSourceSecurity {
210+ string toString ( ) {
211+ this instanceof RNGSourceSecure and result = "Secure RNG Source"
212+ or
213+ this instanceof RNGSourceInsecure and result = "Insecure RNG Source"
214+ }
215+ }
216+
217+ newtype TRNGSeedSecurity =
218+ RNGSeedSecure ( ) or
219+ RNGSeedInsecure ( )
220+
221+ /**
222+ * A source of random number generation
223+ */
224+ abstract class RandomNumberGeneration extends Artifact , TRandomNumberGeneration {
225+ final override string getInternalType ( ) { result = "RandomNumberGeneration" }
226+
227+ abstract RNGSourceSecurity getSourceSecurity ( ) ;
228+
229+ abstract TRNGSeedSecurity getSeedSecurity ( Location location ) ;
184230 }
185231
186232 /**
@@ -197,8 +243,6 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
197243 */
198244 abstract string getOperationType ( ) ;
199245
200- final override string toString ( ) { result = this .getOperationType ( ) }
201-
202246 final override string getInternalType ( ) { result = this .getOperationType ( ) }
203247
204248 override NodeBase getChild ( string edgeName ) {
@@ -210,8 +254,6 @@ module CryptographyBase<LocationSig Location, InputSig<Location> Input> {
210254 }
211255
212256 abstract class Algorithm extends Asset {
213- final override string toString ( ) { result = this .getAlgorithmType ( ) }
214-
215257 final override string getInternalType ( ) { result = this .getAlgorithmType ( ) }
216258
217259 /**
0 commit comments