diff --git a/shared/mad/codeql/mad/ModelValidation.qll b/shared/mad/codeql/mad/ModelValidation.qll index a5e64c434992..073701a18355 100644 --- a/shared/mad/codeql/mad/ModelValidation.qll +++ b/shared/mad/codeql/mad/ModelValidation.qll @@ -40,9 +40,10 @@ module KindValidation { "xslt-injection", // JavaScript-only currently, but may be shared in the future "cors-origin", "mongodb.sink", "system-prompt-injection", "user-prompt-injection", - // Swift-only currently, but may be shared in the future + // Swift / Unified Swift only currently, but may be shared in the future "database-store", "format-string", "hash-iteration-count", "predicate-injection", "preferences-store", "tls-protocol-version", "transmission", "webview-fetch", "xxe", + "encryption-block-mode", // Go-only currently, but may be shared in the future "jwt", // CPP-only currently @@ -134,7 +135,9 @@ module KindValidation { // JavaScript "database-access-result", "response", "request", "browser", "browser-url-query", "browser-url-fragment", "browser-url-path", "browser-url", "browser-window-name", - "browser-message-event" + "browser-message-event", + // Unified Swift + "ecb-block-mode" ] or this.matches([ diff --git a/unified/ql/lib/ext/crypto.model.json b/unified/ql/lib/ext/crypto.model.json new file mode 100644 index 000000000000..b2078d6d9b16 --- /dev/null +++ b/unified/ql/lib/ext/crypto.model.json @@ -0,0 +1,26 @@ +{ + "extensions": [ + { + "addsTo": { + "pack": "codeql/unified-all", + "extensible": "legacySourceModel" + }, + "data": [ + // namespace, type, subtypes, name, signature, ext, output, kind, provenance + ["", "ECB", true, "init()", "", "", "ReturnValue", "ecb-block-mode", "manual"] + ] + }, + { + "addsTo": { + "pack": "codeql/unified-all", + "extensible": "legacySinkModel" + }, + "data": [ + // namespace, type, subtypes, name, signature, ext, input, kind, provenance + ["", "AES", true, "init(key:blockMode:)", "", "", "Argument[blockMode:]", "encryption-block-mode", "manual"], + ["", "AES", true, "init(key:blockMode:padding:)", "", "", "Argument[blockMode:]", "encryption-block-mode", "manual"], + ["", "Blowfish", true, "init(key:blockMode:padding:)", "", "", "Argument[blockMode:]", "encryption-block-mode", "manual"] + ] + } + ] +} diff --git a/unified/ql/lib/ext/legacy-swift.model.json b/unified/ql/lib/ext/legacy-swift.model.json index 7719aa749f20..139a92f4ebb2 100644 --- a/unified/ql/lib/ext/legacy-swift.model.json +++ b/unified/ql/lib/ext/legacy-swift.model.json @@ -176,10 +176,7 @@ ["", "NSMutableString", true, "character(at:)", "", "", "Argument[at:]", "nsstring-length", "manual"], ["", "NSMutableString", true, "substring(from:)", "", "", "Argument[from:]", "nsstring-length", "manual"], ["", "NSMutableString", true, "substring(to:)", "", "", "Argument[to:]", "nsstring-length", "manual"], - ["", "AES", true, "init(key:blockMode:)", "", "", "Argument[blockMode:]", "encryption-block-mode", "manual"], - ["", "AES", true, "init(key:blockMode:padding:)", "", "", "Argument[blockMode:]", "encryption-block-mode", "manual"], ["", "NSRegularExpression", true, "init(pattern:options:)", "", "", "Argument[pattern:]", "regex-use", "manual"], - ["", "Blowfish", true, "init(key:blockMode:padding:)", "", "", "Argument[blockMode:]", "encryption-block-mode", "manual"], ["", "URLSessionConfiguration", false, "tlsMaximumSupportedProtocol", "", "", "PostUpdate", "tls-protocol-version", "manual"], ["", "URLSessionConfiguration", false, "tlsMinimumSupportedProtocol", "", "", "PostUpdate", "tls-protocol-version", "manual"], ["", "URLSessionConfiguration", false, "tlsMaximumSupportedProtocolVersion", "", "", "PostUpdate", "tls-protocol-version", "manual"], diff --git a/unified/ql/src/queries/security/CWE-327/ECBEncryption.qhelp b/unified/ql/src/queries/security/CWE-327/ECBEncryption.qhelp new file mode 100644 index 000000000000..576ca422bff2 --- /dev/null +++ b/unified/ql/src/queries/security/CWE-327/ECBEncryption.qhelp @@ -0,0 +1,21 @@ + + + +

ECB should not be used as a mode for encryption. With a fixed key, identical plaintext blocks always produce identical ciphertext blocks. This can expose sensitive information by revealing patterns in the plaintext.

+
+ + +

Use an authenticated encryption mode such as GCM where available. If CBC is used, generate a fresh, unpredictable initialization vector for each encryption and use a separate message authentication mechanism to protect ciphertext integrity.

+
+ + +

The following example shows six cases of instantiating a cipher with different block modes. In the 'BAD' cases, the encryption mode is ECB, which reveals patterns in the plaintext. In the 'GOOD' cases, the encryption mode is CBC with a randomly generated initialization vector, avoiding this issue. Authentication of the ciphertext is not shown.

+ +
+ + +
  • Wikipedia, block cipher modes of operation, Electronic codebook (ECB).
  • +
    +
    diff --git a/unified/ql/src/queries/security/CWE-327/ECBEncryption.ql b/unified/ql/src/queries/security/CWE-327/ECBEncryption.ql new file mode 100644 index 000000000000..cf8da678412f --- /dev/null +++ b/unified/ql/src/queries/security/CWE-327/ECBEncryption.ql @@ -0,0 +1,34 @@ +/** + * @name Encryption using ECB + * @description Using the ECB encryption mode can reveal patterns in encrypted data. + * @kind path-problem + * @problem.severity warning + * @security-severity 7.5 + * @precision high + * @id unified/swift/ecb-encryption + * @tags security + * external/cwe/cwe-327 + */ + +import unified + +/** + * A data flow configuration from a creation of an ECB mode instance to expressions that use + * it to initialize a cipher. + */ +module EcbEncryptionConfig implements DataFlow::ConfigSig { + predicate isSource(DataFlow::Node node) { Models::isSource(node, "ecb-block-mode") } + + predicate isSink(DataFlow::Node node) { Models::isSink(node, "encryption-block-mode") } +} + +module EcbEncryptionFlow = DataFlow::Global; + +import EcbEncryptionFlow::PathGraph + +from EcbEncryptionFlow::PathNode sourceNode, EcbEncryptionFlow::PathNode sinkNode +where EcbEncryptionFlow::flowPath(sourceNode, sinkNode) +select sinkNode.getNode(), sourceNode, sinkNode, + "The initialization of the cipher '" + sinkNode.getNode().toString() + + "' uses the insecure ECB block mode from $@.", sourceNode.getNode(), + sourceNode.getNode().toString() diff --git a/unified/ql/src/queries/security/CWE-327/ECBEncryption.swift b/unified/ql/src/queries/security/CWE-327/ECBEncryption.swift new file mode 100644 index 000000000000..12c7fdf0ac5a --- /dev/null +++ b/unified/ql/src/queries/security/CWE-327/ECBEncryption.swift @@ -0,0 +1,16 @@ + +func encrypt(key : Key, padding : Padding) { + // ... + + // BAD: ECB is used for block mode + _ = try AES(key: key, blockMode: ECB(), padding: padding) + _ = try AES(key: key, blockMode: ECB()) + _ = try Blowfish(key: key, blockMode: ECB(), padding: padding) + + // GOOD: ECB is not used for block mode + _ = try AES(key: key, blockMode: CBC(iv: AES.randomIV(AES.blockSize)), padding: padding) + _ = try AES(key: key, blockMode: CBC(iv: AES.randomIV(AES.blockSize))) + _ = try Blowfish(key: key, blockMode: CBC(iv: Blowfish.randomIV(Blowfish.blockSize), padding: padding) + + // ... +} diff --git a/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/ECBEncryption.expected b/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/ECBEncryption.expected new file mode 100644 index 000000000000..bfd54bef4e9a --- /dev/null +++ b/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/ECBEncryption.expected @@ -0,0 +1,32 @@ +#select +| test.swift:56:37:56:39 | ecb | test.swift:50:12:50:16 | ECB(...) | test.swift:56:37:56:39 | ecb | The initialization of the cipher 'ecb' uses the insecure ECB block mode from $@. | test.swift:50:12:50:16 | ECB(...) | ECB(...) | +| test.swift:57:37:57:39 | ecb | test.swift:50:12:50:16 | ECB(...) | test.swift:57:37:57:39 | ecb | The initialization of the cipher 'ecb' uses the insecure ECB block mode from $@. | test.swift:50:12:50:16 | ECB(...) | ECB(...) | +| test.swift:58:37:58:41 | ECB(...) | test.swift:58:37:58:41 | ECB(...) | test.swift:58:37:58:41 | ECB(...) | The initialization of the cipher 'ECB(...)' uses the insecure ECB block mode from $@. | test.swift:58:37:58:41 | ECB(...) | ECB(...) | +| test.swift:59:37:59:41 | ECB(...) | test.swift:59:37:59:41 | ECB(...) | test.swift:59:37:59:41 | ECB(...) | The initialization of the cipher 'ECB(...)' uses the insecure ECB block mode from $@. | test.swift:59:37:59:41 | ECB(...) | ECB(...) | +| test.swift:60:37:60:53 | getECBBlockMode(...) | test.swift:39:9:39:13 | ECB(...) | test.swift:60:37:60:53 | getECBBlockMode(...) | The initialization of the cipher 'getECBBlockMode(...)' uses the insecure ECB block mode from $@. | test.swift:39:9:39:13 | ECB(...) | ECB(...) | +| test.swift:61:37:61:53 | getECBBlockMode(...) | test.swift:39:9:39:13 | ECB(...) | test.swift:61:37:61:53 | getECBBlockMode(...) | The initialization of the cipher 'getECBBlockMode(...)' uses the insecure ECB block mode from $@. | test.swift:39:9:39:13 | ECB(...) | ECB(...) | +| test.swift:71:42:71:44 | ecb | test.swift:50:12:50:16 | ECB(...) | test.swift:71:42:71:44 | ecb | The initialization of the cipher 'ecb' uses the insecure ECB block mode from $@. | test.swift:50:12:50:16 | ECB(...) | ECB(...) | +| test.swift:72:42:72:46 | ECB(...) | test.swift:72:42:72:46 | ECB(...) | test.swift:72:42:72:46 | ECB(...) | The initialization of the cipher 'ECB(...)' uses the insecure ECB block mode from $@. | test.swift:72:42:72:46 | ECB(...) | ECB(...) | +| test.swift:73:42:73:58 | getECBBlockMode(...) | test.swift:39:9:39:13 | ECB(...) | test.swift:73:42:73:58 | getECBBlockMode(...) | The initialization of the cipher 'getECBBlockMode(...)' uses the insecure ECB block mode from $@. | test.swift:39:9:39:13 | ECB(...) | ECB(...) | +edges +| test.swift:39:9:39:13 | ECB(...) | test.swift:60:37:60:53 | getECBBlockMode(...) | provenance | | +| test.swift:39:9:39:13 | ECB(...) | test.swift:61:37:61:53 | getECBBlockMode(...) | provenance | | +| test.swift:39:9:39:13 | ECB(...) | test.swift:73:42:73:58 | getECBBlockMode(...) | provenance | | +| test.swift:50:6:50:8 | ecb | test.swift:56:37:56:39 | ecb | provenance | | +| test.swift:50:6:50:8 | ecb | test.swift:57:37:57:39 | ecb | provenance | | +| test.swift:50:6:50:8 | ecb | test.swift:71:42:71:44 | ecb | provenance | | +| test.swift:50:12:50:16 | ECB(...) | test.swift:50:6:50:8 | ecb | provenance | | +nodes +| test.swift:39:9:39:13 | ECB(...) | semmle.label | ECB(...) | +| test.swift:50:6:50:8 | ecb | semmle.label | ecb | +| test.swift:50:12:50:16 | ECB(...) | semmle.label | ECB(...) | +| test.swift:56:37:56:39 | ecb | semmle.label | ecb | +| test.swift:57:37:57:39 | ecb | semmle.label | ecb | +| test.swift:58:37:58:41 | ECB(...) | semmle.label | ECB(...) | +| test.swift:59:37:59:41 | ECB(...) | semmle.label | ECB(...) | +| test.swift:60:37:60:53 | getECBBlockMode(...) | semmle.label | getECBBlockMode(...) | +| test.swift:61:37:61:53 | getECBBlockMode(...) | semmle.label | getECBBlockMode(...) | +| test.swift:71:42:71:44 | ecb | semmle.label | ecb | +| test.swift:72:42:72:46 | ECB(...) | semmle.label | ECB(...) | +| test.swift:73:42:73:58 | getECBBlockMode(...) | semmle.label | getECBBlockMode(...) | +subpaths diff --git a/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/ECBEncryption.qlref b/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/ECBEncryption.qlref new file mode 100644 index 000000000000..ae476329e7a5 --- /dev/null +++ b/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/ECBEncryption.qlref @@ -0,0 +1,3 @@ +query: queries/security/CWE-327/ECBEncryption.ql +postprocess: + - utils/test/InlineExpectationsTestQuery.ql diff --git a/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/test.swift b/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/test.swift new file mode 100644 index 000000000000..4e47ae924c66 --- /dev/null +++ b/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/test.swift @@ -0,0 +1,78 @@ + +// --- stubs --- + +// These stubs roughly follows the same structure as classes from CryptoSwift +class AES +{ + init(key: Array, blockMode: BlockMode, padding: Padding) { } + init(key: Array, blockMode: BlockMode) { } +} + +class Blowfish +{ + init(key: Array, blockMode: BlockMode, padding: Padding) { } +} + +protocol BlockMode { } + +struct ECB: BlockMode { + init() { } +} + +struct CBC: BlockMode { + init(iv: Array) { } +} + +protocol PaddingProtocol { } + +enum Padding: PaddingProtocol { + case noPadding, zeroPadding, pkcs7, pkcs5, eme_pkcs1v15, emsa_pkcs1v15, iso78164, iso10126 +} + +// Create some inter-procedural dependencies + +func getRandomArray() -> Array { + (0..<10).map({ _ in UInt8.random(in: 0...UInt8.max) }) +} + +func getECBBlockMode() -> BlockMode { + return ECB() // $ Source +} + +func getCBCBlockMode() -> BlockMode { + return CBC(iv: getRandomArray()) +} + +// --- tests --- + +func test1() { + let key: Array = [0x2a, 0x3a, 0x80, 0x05, 0xaf, 0x46, 0x58, 0x2d, 0x66, 0x52, 0x10, 0xae, 0x86, 0xd3, 0x8e, 0x8f] + let ecb = ECB() // $ Source[unified/swift/ecb-encryption] + let iv = getRandomArray() + let cbc = CBC(iv: iv) + let padding = Padding.noPadding + + // AES test cases + let ab1 = AES(key: key, blockMode: ecb, padding: padding) // $ Alert[unified/swift/ecb-encryption] + let ab2 = AES(key: key, blockMode: ecb) // $ Alert[unified/swift/ecb-encryption] + let ab3 = AES(key: key, blockMode: ECB(), padding: padding) // $ Alert[unified/swift/ecb-encryption] + let ab4 = AES(key: key, blockMode: ECB()) // $ Alert[unified/swift/ecb-encryption] + let ab5 = AES(key: key, blockMode: getECBBlockMode(), padding: padding) // $ Alert[unified/swift/ecb-encryption] + let ab6 = AES(key: key, blockMode: getECBBlockMode()) // $ Alert[unified/swift/ecb-encryption] + + let ag1 = AES(key: key, blockMode: cbc, padding: padding) // GOOD + let ag2 = AES(key: key, blockMode: cbc) // GOOD + let ag3 = AES(key: key, blockMode: CBC(iv: iv), padding: padding) // GOOD + let ag4 = AES(key: key, blockMode: CBC(iv: iv)) // GOOD + let ag5 = AES(key: key, blockMode: getCBCBlockMode(), padding: padding) // GOOD + let ag6 = AES(key: key, blockMode: getCBCBlockMode()) // GOOD + + // Blowfish test cases + let bb1 = Blowfish(key: key, blockMode: ecb, padding: padding) // $ Alert[unified/swift/ecb-encryption] + let bb2 = Blowfish(key: key, blockMode: ECB(), padding: padding) // $ Alert[unified/swift/ecb-encryption] + let bb3 = Blowfish(key: key, blockMode: getECBBlockMode(), padding: padding) // $ Alert[unified/swift/ecb-encryption] + + let bg1 = Blowfish(key: key, blockMode: cbc, padding: padding) // GOOD + let bg2 = Blowfish(key: key, blockMode: CBC(iv: iv), padding: padding) // GOOD + let bg3 = Blowfish(key: key, blockMode: getCBCBlockMode(), padding: padding) // GOOD +} diff --git a/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/test_commoncrypto.swift b/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/test_commoncrypto.swift new file mode 100644 index 000000000000..c99cb8d3cdda --- /dev/null +++ b/unified/ql/test/query-tests/security/CWE-327/ECBEncryption/test_commoncrypto.swift @@ -0,0 +1,217 @@ +// --- stubs --- + +struct Data { + func withUnsafeBytes( + _ body: (UnsafeRawBufferPointer) throws -> ResultType + ) rethrows -> ResultType { return 0 as! ResultType } + mutating func withUnsafeMutableBytes( + _ body: (UnsafeMutableRawBufferPointer) throws -> ResultType + ) rethrows -> ResultType { return 0 as! ResultType } +} + +// --- CommonCryptor --- +// (real world projects will import the CommonCryptor headers which get +// converted to Swift by the compiler; the following is an approximation +// of that derived from QL queries and the CommonCryptor header files) + +var kCCSuccess : Int = 0 +typealias CCCryptorStatus = Int32 + +typealias CCCryptorRef = OpaquePointer + +var kCCEncrypt : Int = 0 +var kCCDecrypt : Int = 1 +typealias CCOperation = UInt32 + +var kCCAlgorithmAES128 : Int = 0 +var kCCAlgorithmAES : Int = 0 +var kCCAlgorithmDES : Int = 1 +var kCCAlgorithm3DES : Int = 2 +var kCCAlgorithmCAST : Int = 3 +var kCCAlgorithmRC4 : Int = 4 +var kCCAlgorithmRC2 : Int = 5 +var kCCAlgorithmBlowfish : Int = 6 +typealias CCAlgorithm = UInt32 + +var kCCOptionPKCS7Padding : Int = 1 +var kCCOptionECBMode : Int = 2 +typealias CCOptions = UInt32 + +var kCCModeECB : Int = 1 +var kCCModeCBC : Int = 2 +var kCCModeCFB : Int = 3 +var kCCModeCTR : Int = 4 +var kCCModeOFB : Int = 7 +var kCCModeRC4 : Int = 9 +var kCCModeCFB8 : Int = 10 +typealias CCMode = UInt32 + +typealias CCPadding = UInt32 + +typealias CCModeOptions = UInt32 + +func CCCryptorCreate( + _ op: CCOperation, + _ alg: CCAlgorithm, + _ options: CCOptions, + _ key: UnsafeRawPointer?, + _ keyLength: Int, + _ iv: UnsafeRawPointer?, + _ cryptorRef: UnsafeMutablePointer? + ) -> CCCryptorStatus { return 0 } + +func CCCryptorCreateFromData( + _ op: CCOperation, + _ alg: CCAlgorithm, + _ options: CCOptions, + _ key: UnsafeRawPointer?, + _ keyLength: Int, + _ iv: UnsafeRawPointer?, + _ data: UnsafeRawPointer?, + _ dataLength: Int, + _ cryptorRef: UnsafeMutablePointer?, + _ dataUsed: UnsafeMutablePointer? + ) -> CCCryptorStatus { return 0 } + +func CCCryptorCreateWithMode( + _ op: CCOperation, + _ mode: CCMode, + _ alg: CCAlgorithm, + _ padding: CCPadding, + _ iv: UnsafeRawPointer?, + _ key: UnsafeRawPointer?, + _ keyLength: Int, + _ tweak: UnsafeRawPointer?, + _ tweakLength: Int, + _ numRounds: Int32, + _ options: CCModeOptions, + _ cryptorRef: UnsafeMutablePointer? + ) -> CCCryptorStatus { return 0 } + +func CCCryptorUpdate( + _ cryptorRef: CCCryptorRef?, + _ dataIn: UnsafeRawPointer?, + _ dataInLength: Int, + _ dataOut: UnsafeMutableRawPointer?, + _ dataOutAvailable: Int, + _ dataOutMoved: UnsafeMutablePointer? + ) -> CCCryptorStatus { return 0 } + +func CCCryptorFinal( + _ cryptorRef: CCCryptorRef?, + _ dataOut: UnsafeMutableRawPointer?, + _ dataOutAvailable: Int, + _ dataOutMoved: UnsafeMutablePointer? + ) -> CCCryptorStatus { return 0 } + +func CCCrypt( + _ op: CCOperation, + _ alg: CCAlgorithm, + _ options: CCOptions, + _ key: UnsafeRawPointer?, + _ keyLength: Int, + _ iv: UnsafeRawPointer?, + _ dataIn: UnsafeRawPointer?, + _ dataInLength: Int, + _ dataOut: UnsafeMutableRawPointer?, + _ dataOutAvailable: Int, + _ dataOutMoved: UnsafeMutablePointer? + ) -> CCCryptorStatus { return 0 } + +// --- tests --- + +func cond() -> Bool { return true } + +func test_commoncrypto1(key: Data, iv: Data, dataIn: Data, dataOut: inout Data) { + // semi-realistic test case + var myCryptor: CCCryptorRef? + var dataOutWritten = 0 + + key.withUnsafeBytes({ + keyPtr in + iv.withUnsafeBytes({ + // create the cryptor object + ivPtr in + let result1 = CCCryptorCreate( + CCOperation(kCCEncrypt), + CCAlgorithm(kCCAlgorithm3DES), // weak-cryptographic-algorithm + CCOptions(0), + keyPtr.baseAddress!, + keyPtr.count, + ivPtr.baseAddress!, + &myCryptor + ) + guard result1 == CCCryptorStatus(kCCSuccess) else { + return // fail + } + + dataIn.withUnsafeBytes({ + dataInPtr in + dataOut.withUnsafeMutableBytes({ + dataOutPtr in + // encrypt data + while (cond()) { + let result2 = CCCryptorUpdate( + myCryptor, + dataInPtr.baseAddress!, + dataInPtr.count, + dataOutPtr.baseAddress!, + dataOutPtr.count, + &dataOutWritten) + guard result2 == CCCryptorStatus(kCCSuccess) else { + return // fail + } + } + + // finish + let result3 = CCCryptorFinal( + myCryptor, + dataOutPtr.baseAddress!, + dataOutPtr.count, + &dataOutWritten) + guard result3 == CCCryptorStatus(kCCSuccess) else { + return // fail + } + }) + }) + }) + }) +} + +func test_commoncrypto2( + key: UnsafeRawPointer, keyLen: Int, + iv: UnsafeRawPointer, + dataIn: UnsafeRawPointer, dataInLen: Int, + dataOut: UnsafeMutableRawPointer, dataOutAvail: Int) { + var myCryptor: CCCryptorRef? + var dataOutWritten = 0 + + // algorithms + _ = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmAES128), 0, key, keyLen, iv, dataIn, dataInLen, dataOut, dataOutAvail, nil) + _ = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmAES), 0, key, keyLen, iv, dataIn, dataInLen, dataOut, dataOutAvail, nil) + _ = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmDES), 0, key, keyLen, iv, dataIn, dataInLen, dataOut, dataOutAvail, nil) // weak-cryptographic-algorithm + _ = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithm3DES), 0, key, keyLen, iv, dataIn, dataInLen, dataOut, dataOutAvail, nil) // weak-cryptographic-algorithm + _ = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmCAST), 0, key, keyLen, iv, dataIn, dataInLen, dataOut, dataOutAvail, nil) + _ = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmRC4), 0, key, keyLen, iv, dataIn, dataInLen, dataOut, dataOutAvail, nil) // weak-cryptographic-algorithm + _ = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmRC2), 0, key, keyLen, iv, dataIn, dataInLen, dataOut, dataOutAvail, nil) // weak-cryptographic-algorithm + _ = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmBlowfish), 0, key, keyLen, iv, dataIn, dataInLen, dataOut, dataOutAvail, nil) + _ = CCCryptorCreate(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithm3DES), 0, key, keyLen, iv, &myCryptor) // weak-cryptographic-algorithm + _ = CCCryptorCreateFromData(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithm3DES), 0, key, keyLen, iv, dataIn, dataInLen, &myCryptor, &dataOutWritten) // weak-cryptographic-algorithm + _ = CCCryptorCreateFromData(CCOperation(kCCDecrypt), CCAlgorithm(kCCAlgorithm3DES), 0, key, keyLen, iv, dataIn, dataInLen, &myCryptor, &dataOutWritten) // weak-cryptographic-algorithm + + // block modes (the default is CBC) + _ = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmAES), CCOptions(0), key, keyLen, iv, dataIn, dataInLen, dataOut, dataOutAvail, nil) + _ = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmAES), CCOptions(kCCOptionPKCS7Padding), key, keyLen, iv, dataIn, dataInLen, dataOut, dataOutAvail, nil) + _ = CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmAES), CCOptions(kCCOptionECBMode), key, keyLen, iv, dataIn, dataInLen, dataOut, dataOutAvail, nil) // $ MISSING: Alert[unified/swift/ecb-encryption] + _ = CCCryptorCreate(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithm3DES), CCOptions(kCCOptionECBMode), key, keyLen, iv, &myCryptor) // $ MISSING: Alert[unified/swift/ecb-encryption] + _ = CCCryptorCreateFromData(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithm3DES), CCOptions(kCCOptionECBMode), key, keyLen, iv, dataIn, dataInLen, &myCryptor, &dataOutWritten) // $ MISSING: Alert[unified/swift/ecb-encryption] + + // modes + _ = CCCryptorCreateWithMode(CCOperation(kCCAlgorithmAES), CCMode(kCCModeECB), CCAlgorithm(kCCAlgorithm3DES), CCPadding(0), iv, key, keyLen, nil, 0, 0, CCModeOptions(0), &myCryptor) // $ MISSING: Alert[unified/swift/ecb-encryption] + _ = CCCryptorCreateWithMode(CCOperation(kCCAlgorithmAES), CCMode(kCCModeCBC), CCAlgorithm(kCCAlgorithm3DES), CCPadding(0), iv, key, keyLen, nil, 0, 0, CCModeOptions(0), &myCryptor) + _ = CCCryptorCreateWithMode(CCOperation(kCCAlgorithmAES), CCMode(kCCModeCFB), CCAlgorithm(kCCAlgorithm3DES), CCPadding(0), iv, key, keyLen, nil, 0, 0, CCModeOptions(0), &myCryptor) + _ = CCCryptorCreateWithMode(CCOperation(kCCAlgorithmAES), CCMode(kCCModeCTR), CCAlgorithm(kCCAlgorithm3DES), CCPadding(0), iv, key, keyLen, nil, 0, 0, CCModeOptions(0), &myCryptor) + _ = CCCryptorCreateWithMode(CCOperation(kCCAlgorithmAES), CCMode(kCCModeOFB), CCAlgorithm(kCCAlgorithm3DES), CCPadding(0), iv, key, keyLen, nil, 0, 0, CCModeOptions(0), &myCryptor) + _ = CCCryptorCreateWithMode(CCOperation(kCCAlgorithmAES), CCMode(kCCModeRC4), CCAlgorithm(kCCAlgorithm3DES), CCPadding(0), iv, key, keyLen, nil, 0, 0, CCModeOptions(0), &myCryptor) + _ = CCCryptorCreateWithMode(CCOperation(kCCAlgorithmAES), CCMode(kCCModeCFB8), CCAlgorithm(kCCAlgorithm3DES), CCPadding(0), iv, key, keyLen, nil, 0, 0, CCModeOptions(0), &myCryptor) +}