diff --git a/Pods b/Pods index 40bc969de..d2cc7e97d 160000 --- a/Pods +++ b/Pods @@ -1 +1 @@ -Subproject commit 40bc969de75f70d546256db090dec25fe4661120 +Subproject commit d2cc7e97d653ab30ffadedd8034f6d8d27c27775 diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index ea98f085f..4de2cfbc6 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -6,14 +6,10 @@ CarthageVersion 0.33.0 - DateTime - Thu Jul 18 04:53:39 UTC 2019 OSXVersion - 10.14.5 + 10.14.6 WebRTCCommit 1445d719bf05280270e9f77576f80f973fd847f8 M73 - XCodeVersion - 1000.1020 CFBundleDevelopmentRegion en diff --git a/SignalServiceKit/src/Loki/Crypto/DiffieHellman.swift b/SignalServiceKit/src/Loki/Crypto/DiffieHellman.swift new file mode 100644 index 000000000..4c6bbbb50 --- /dev/null +++ b/SignalServiceKit/src/Loki/Crypto/DiffieHellman.swift @@ -0,0 +1,43 @@ +import CryptoSwift +import Curve25519Kit + +public enum DiffieHellman { + // The length of the iv + public static let ivLength: Int32 = 16; + + public static func encrypt(plainText: Data, symmetricKey: Data) throws -> Data { + let iv = Randomness.generateRandomBytes(ivLength)! + let ivBytes = [UInt8](iv) + + let symmetricKeyBytes = [UInt8](symmetricKey) + let messageBytes = [UInt8](plainText) + + let blockMode = CBC(iv: ivBytes) + let aes = try AES(key: symmetricKeyBytes, blockMode: blockMode) + let cipherText = try aes.encrypt(messageBytes) + let ivAndCipher = ivBytes + cipherText + return Data(bytes: ivAndCipher, count: ivAndCipher.count) + } + + public static func encrypt(plainText: Data, publicKey: Data, privateKey: Data) throws -> Data { + let symmetricKey = try Curve25519.generateSharedSecret(fromPublicKey: publicKey, privateKey: privateKey) + return try encrypt(plainText: plainText, symmetricKey: symmetricKey) + } + + public static func decrypt(cipherText: Data, symmetricKey: Data) throws -> Data { + let symmetricKeyBytes = [UInt8](symmetricKey) + let ivBytes = [UInt8](cipherText[.. Data { + let symmetricKey = try Curve25519.generateSharedSecret(fromPublicKey: publicKey, privateKey: privateKey) + return try decrypt(cipherText: cipherText, symmetricKey: symmetricKey) + } +}