소스 검색

AEAD refactor.
Expose keySize instance property for Cipher.

Marcin Krzyżanowski 7 년 전
부모
커밋
b3d65e5ca1

+ 17 - 9
CryptoSwift.xcodeproj/project.pbxproj

@@ -7,16 +7,16 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		14156CE320111B5C00DDCFBC /* ChaCha20Poly1305.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14156CE220111B5C00DDCFBC /* ChaCha20Poly1305.swift */; };
-		14156CE52011422400DDCFBC /* ChaCha20Poly1305Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14156CE42011422400DDCFBC /* ChaCha20Poly1305Tests.swift */; };
-		1467460F2017BB3600DF04ED /* AEAD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1467460E2017BB3600DF04ED /* AEAD.swift */; };
 		0EE73E71204D598100110E11 /* CMAC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE73E70204D598100110E11 /* CMAC.swift */; };
 		0EE73E74204D59C200110E11 /* CMACTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE73E72204D599C00110E11 /* CMACTests.swift */; };
+		14156CE52011422400DDCFBC /* ChaCha20Poly1305Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14156CE42011422400DDCFBC /* ChaCha20Poly1305Tests.swift */; };
+		1467460F2017BB3600DF04ED /* AEAD.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1467460E2017BB3600DF04ED /* AEAD.swift */; };
 		674A736F1BF5D85B00866C5B /* RabbitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 674A736E1BF5D85B00866C5B /* RabbitTests.swift */; };
 		750509991F6BEF2A00394A1B /* PKCS7.swift in Sources */ = {isa = PBXBuildFile; fileRef = 750509981F6BEF2A00394A1B /* PKCS7.swift */; };
 		750CC3EB1DC0CACE0096BE6E /* BlowfishTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 750CC3EA1DC0CACE0096BE6E /* BlowfishTests.swift */; };
 		75100F8F19B0BC890005C5F5 /* Poly1305Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75100F8E19B0BC890005C5F5 /* Poly1305Tests.swift */; };
 		751EE9781F93996100161FFC /* AES.Cryptors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 751EE9771F93996100161FFC /* AES.Cryptors.swift */; };
+		7529366A20683DFC00195874 /* AEADChaCha20Poly1305.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7529366920683DFC00195874 /* AEADChaCha20Poly1305.swift */; };
 		753B33011DAB84D600D06422 /* RandomBytesSequenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 753B33001DAB84D600D06422 /* RandomBytesSequenceTests.swift */; };
 		754310442050111A003FB1DF /* CompactMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 754310432050111A003FB1DF /* CompactMap.swift */; };
 		75482EA41CB310B7001F66A5 /* PBKDF.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75482EA31CB310B7001F66A5 /* PBKDF.swift */; };
@@ -160,16 +160,16 @@
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
-		14156CE220111B5C00DDCFBC /* ChaCha20Poly1305.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChaCha20Poly1305.swift; sourceTree = "<group>"; };
-		14156CE42011422400DDCFBC /* ChaCha20Poly1305Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChaCha20Poly1305Tests.swift; sourceTree = "<group>"; };
-		1467460E2017BB3600DF04ED /* AEAD.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AEAD.swift; sourceTree = "<group>"; };
 		0EE73E70204D598100110E11 /* CMAC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CMAC.swift; sourceTree = "<group>"; };
 		0EE73E72204D599C00110E11 /* CMACTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CMACTests.swift; sourceTree = "<group>"; };
+		14156CE42011422400DDCFBC /* ChaCha20Poly1305Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChaCha20Poly1305Tests.swift; sourceTree = "<group>"; };
+		1467460E2017BB3600DF04ED /* AEAD.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AEAD.swift; sourceTree = "<group>"; };
 		674A736E1BF5D85B00866C5B /* RabbitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RabbitTests.swift; sourceTree = "<group>"; };
 		750509981F6BEF2A00394A1B /* PKCS7.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKCS7.swift; sourceTree = "<group>"; };
 		750CC3EA1DC0CACE0096BE6E /* BlowfishTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlowfishTests.swift; sourceTree = "<group>"; };
 		75100F8E19B0BC890005C5F5 /* Poly1305Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Poly1305Tests.swift; sourceTree = "<group>"; };
 		751EE9771F93996100161FFC /* AES.Cryptors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AES.Cryptors.swift; sourceTree = "<group>"; };
+		7529366920683DFC00195874 /* AEADChaCha20Poly1305.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AEADChaCha20Poly1305.swift; sourceTree = "<group>"; };
 		753B33001DAB84D600D06422 /* RandomBytesSequenceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RandomBytesSequenceTests.swift; sourceTree = "<group>"; };
 		754310432050111A003FB1DF /* CompactMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompactMap.swift; sourceTree = "<group>"; };
 		75482EA31CB310B7001F66A5 /* PBKDF.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PBKDF.swift; sourceTree = "<group>"; };
@@ -278,6 +278,15 @@
 			name = Frameworks;
 			sourceTree = "<group>";
 		};
+		7529366820683DFC00195874 /* AEAD */ = {
+			isa = PBXGroup;
+			children = (
+				1467460E2017BB3600DF04ED /* AEAD.swift */,
+				7529366920683DFC00195874 /* AEADChaCha20Poly1305.swift */,
+			);
+			path = AEAD;
+			sourceTree = "<group>";
+		};
 		754BE44B19693E190098E6F3 = {
 			isa = PBXGroup;
 			children = (
@@ -345,6 +354,7 @@
 		75EC52371EE8B6CA0048EB3B /* CryptoSwift */ = {
 			isa = PBXGroup;
 			children = (
+				7529366820683DFC00195874 /* AEAD */,
 				75EC52381EE8B6CA0048EB3B /* AES.swift */,
 				751EE9771F93996100161FFC /* AES.Cryptors.swift */,
 				75EC52391EE8B6CA0048EB3B /* Array+Extension.swift */,
@@ -388,8 +398,6 @@
 				75EC52771EE8B6CA0048EB3B /* Updatable.swift */,
 				75EC52781EE8B6CA0048EB3B /* Utils.swift */,
 				75EC52791EE8B6CA0048EB3B /* ZeroPadding.swift */,
-				14156CE220111B5C00DDCFBC /* ChaCha20Poly1305.swift */,
-				1467460E2017BB3600DF04ED /* AEAD.swift */,
 				754310432050111A003FB1DF /* CompactMap.swift */,
 			);
 			path = CryptoSwift;
@@ -565,6 +573,7 @@
 				E6200E141FB9A7AE00258382 /* HKDF.swift in Sources */,
 				75EC529F1EE8B8230048EB3B /* HMAC.swift in Sources */,
 				75EC52B91EE8B83D0048EB3B /* ZeroPadding.swift in Sources */,
+				7529366A20683DFC00195874 /* AEADChaCha20Poly1305.swift in Sources */,
 				75EC529E1EE8B8230048EB3B /* Generics.swift in Sources */,
 				75EC52AA1EE8B83D0048EB3B /* Poly1305.swift in Sources */,
 				75EC52AC1EE8B83D0048EB3B /* RandomAccessCryptor.swift in Sources */,
@@ -591,7 +600,6 @@
 				750509991F6BEF2A00394A1B /* PKCS7.swift in Sources */,
 				75EC52B51EE8B83D0048EB3B /* UInt64+Extension.swift in Sources */,
 				75EC52AF1EE8B83D0048EB3B /* SHA1.swift in Sources */,
-				14156CE320111B5C00DDCFBC /* ChaCha20Poly1305.swift in Sources */,
 				75EC52801EE8B8130048EB3B /* Bit.swift in Sources */,
 				75EC52971EE8B8200048EB3B /* ChaCha20+Foundation.swift in Sources */,
 				75EC52871EE8B8170048EB3B /* CTR.swift in Sources */,

+ 3 - 3
README.md

@@ -77,7 +77,7 @@ Good mood
 - No padding
 
 #### Authenticated Encryption with Associated Data (AEAD)
-- [ChaCha20/Poly1305](https://tools.ietf.org/html/rfc7539)
+- [AEAD_CHACHA20_POLY1305](https://tools.ietf.org/html/rfc7539#section-2.8)
 
 ## Why
 [Why?](https://github.com/krzyzanowskim/CryptoSwift/issues/5) [Because I can](https://github.com/krzyzanowskim/CryptoSwift/issues/5#issuecomment-53379391).
@@ -415,8 +415,8 @@ let decrypted = try! encrypted.decrypt(ChaCha20(key: key, iv: iv))
 ##### AEAD
 
 ```swift
-let encrypt = try ChaCha20Poly1305.encrypt(message: message, header: header, key: key, nonce: nonce)
-let decrypt = try ChaCha20Poly1305.decrypt(cipher: cipher, header: header, key: key, nonce: nonce, tag: tag)
+let encrypt = try AEADChaCha20Poly1305.encrypt(plaintext, key: key, iv: nonce, authenticationHeader: header)
+let decrypt = try AEADChaCha20Poly1305.decrypt(ciphertext, key: key, iv: nonce, authenticationHeader: header, authenticationTag: tagArr: tag)
 ```
 
 ## Author

+ 0 - 22
Sources/CryptoSwift/AEAD.swift

@@ -1,22 +0,0 @@
-//
-//  AEAD.swift
-//  CryptoSwift
-//
-//  Copyright (C) 2014-2017 Marcin Krzyżanowski <marcin@krzyzanowskim.com>
-//  This software is provided 'as-is', without any express or implied warranty.
-//
-//  In no event will the authors be held liable for any damages arising from the use of this software.
-//
-//  Permission is granted to anyone to use this software for any purpose,including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
-//
-//  - The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation is required.
-//  - Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-//  - This notice may not be removed or altered from any source or binary distribution.
-//
-//
-
-public protocol AEAD {
-    static func encrypt( message:Array<UInt8>, header:Array<UInt8>, key:Array<UInt8>, nonce:Array<UInt8> ) throws -> (cipher:Array<UInt8>, tag:Array<UInt8>)
-    
-    static func decrypt( cipher:Array<UInt8>, header:Array<UInt8>, key:Array<UInt8>, nonce:Array<UInt8>, tag:Array<UInt8> ) throws -> (message:Array<UInt8>, success:Bool)
-}

+ 40 - 0
Sources/CryptoSwift/AEAD/AEAD.swift

@@ -0,0 +1,40 @@
+//
+//  AEAD.swift
+//  CryptoSwift
+//
+//  Copyright (C) 2014-2017 Marcin Krzyżanowski <marcin@krzyzanowskim.com>
+//  This software is provided 'as-is', without any express or implied warranty.
+//
+//  In no event will the authors be held liable for any damages arising from the use of this software.
+//
+//  Permission is granted to anyone to use this software for any purpose,including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
+//
+//  - The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation is required.
+//  - Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+//  - This notice may not be removed or altered from any source or binary distribution.
+//
+//
+
+// https://www.iana.org/assignments/aead-parameters/aead-parameters.xhtml
+
+/// Authenticated Encryption with Associated Data (AEAD)
+public protocol AEAD {
+    static var kLen: Int { get } // key length
+    static var ivRange: Range<Int> { get } // nonce length
+}
+
+extension AEAD {
+    static func calculateAuthenticationTag(authenticator: Authenticator, cipherText: Array<UInt8>, authenticationHeader: Array<UInt8>) throws -> Array<UInt8> {
+        let headerPadding = ((16 - (authenticationHeader.count & 0xf)) & 0xf)
+        let cipherPadding = ((16 - (cipherText.count & 0xf)) & 0xf)
+
+        var mac = authenticationHeader
+        mac += Array<UInt8>(repeating: 0, count: headerPadding)
+        mac += cipherText
+        mac += Array<UInt8>(repeating: 0, count: cipherPadding)
+        mac += UInt64(bigEndian: UInt64(authenticationHeader.count)).bytes()
+        mac += UInt64(bigEndian: UInt64(cipherText.count)).bytes()
+
+        return try authenticator.authenticate(mac)
+    }
+}

+ 59 - 0
Sources/CryptoSwift/AEAD/AEADChaCha20Poly1305.swift

@@ -0,0 +1,59 @@
+//
+//  ChaCha20Poly1305.swift
+//  CryptoSwift
+//
+//  Copyright (C) 2014-2017 Marcin Krzyżanowski <marcin@krzyzanowskim.com>
+//  This software is provided 'as-is', without any express or implied warranty.
+//
+//  In no event will the authors be held liable for any damages arising from the use of this software.
+//
+//  Permission is granted to anyone to use this software for any purpose,including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
+//
+//  - The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation is required.
+//  - Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+//  - This notice may not be removed or altered from any source or binary distribution.
+//
+//
+//  https://tools.ietf.org/html/rfc7539#section-2.8.1
+
+/// AEAD_CHACHA20_POLY1305
+public final class AEADChaCha20Poly1305: AEAD {
+    public static let kLen = 32 // key length
+    public static var ivRange = Range<Int>(12...12)
+
+    /// Authenticated encryption
+    public static func encrypt(_ plainText: Array<UInt8>, key: Array<UInt8>, iv: Array<UInt8>, authenticationHeader: Array<UInt8>) throws -> (cipherText: Array<UInt8>, authenticationTag: Array<UInt8>) {
+        let cipher = try ChaCha20(key: key, iv: iv)
+
+        var polykey = Array<UInt8>(repeating: 0, count: kLen)
+        var toEncrypt = polykey
+        polykey = try cipher.encrypt(polykey)
+        toEncrypt += polykey
+        toEncrypt += plainText
+
+        let fullCipherText = try cipher.encrypt(toEncrypt)
+        let cipherText = Array(fullCipherText.dropFirst(64))
+
+        let tag = try calculateAuthenticationTag(authenticator: Poly1305(key: polykey), cipherText: cipherText, authenticationHeader: authenticationHeader)
+        return (cipherText, tag)
+    }
+
+    /// Authenticated decryption
+    public static func decrypt(_ cipherText: Array<UInt8>, key: Array<UInt8>, iv: Array<UInt8>, authenticationHeader: Array<UInt8>, authenticationTag: Array<UInt8>) throws -> (plainText: Array<UInt8>, success: Bool) {
+        let chacha = try ChaCha20(key: key, iv: iv)
+
+        let polykey = try chacha.encrypt(Array<UInt8>(repeating: 0, count: kLen))
+        let mac = try calculateAuthenticationTag(authenticator: Poly1305(key: polykey), cipherText: cipherText, authenticationHeader: authenticationHeader)
+        guard mac == authenticationTag else {
+            return (cipherText, false)
+        }
+
+        var toDecrypt = Array<UInt8>(reserveCapacity: cipherText.count + 64)
+        toDecrypt += polykey
+        toDecrypt += polykey
+        toDecrypt += cipherText
+        let fullPlainText = try chacha.decrypt(toDecrypt)
+        let plainText = Array(fullPlainText.dropFirst(64))
+        return (plainText, true)
+    }
+}

+ 3 - 1
Sources/CryptoSwift/AES.swift

@@ -46,9 +46,10 @@ public final class AES: BlockCipher {
     private lazy var variantNk: Int = self.variant.Nk
 
     public static let blockSize: Int = 16 // 128 /8
+    public let keySize: Int
 
     public var variant: Variant {
-        switch key.count * 8 {
+        switch keySize * 8 {
         case 128:
             return .aes128
         case 192:
@@ -123,6 +124,7 @@ public final class AES: BlockCipher {
         self.key = Key(bytes: key)
         self.blockMode = blockMode
         self.padding = padding
+        keySize = self.key.count
     }
 
     internal func encrypt(block: ArraySlice<UInt8>) -> Array<UInt8>? {

+ 5 - 2
Sources/CryptoSwift/Blowfish.swift

@@ -28,8 +28,10 @@ public final class Blowfish {
     }
 
     public static let blockSize: Int = 8 // 64 bit
-    fileprivate let blockMode: BlockMode
-    fileprivate let padding: Padding
+    public let keySize: Int
+
+    private let blockMode: BlockMode
+    private let padding: Padding
     private var decryptWorker: BlockModeWorker!
     private var encryptWorker: BlockModeWorker!
 
@@ -315,6 +317,7 @@ public final class Blowfish {
 
         self.blockMode = blockMode
         self.padding = padding
+        keySize = key.count
 
         S = origS
         P = origP

+ 2 - 0
Sources/CryptoSwift/ChaCha20.swift

@@ -22,6 +22,7 @@ public final class ChaCha20: BlockCipher {
     }
 
     public static let blockSize = 64 // 512 / 8
+    public let keySize: Int
 
     fileprivate let key: Key
     fileprivate var counter: Array<UInt8>
@@ -34,6 +35,7 @@ public final class ChaCha20: BlockCipher {
         }
 
         self.key = Key(bytes: key)
+        keySize = self.key.count
 
         if nonce.count == 8 {
             counter = [0, 0, 0, 0, 0, 0, 0, 0] + nonce

+ 0 - 72
Sources/CryptoSwift/ChaCha20Poly1305.swift

@@ -1,72 +0,0 @@
-//
-//  ChaCha20Poly1305.swift
-//  CryptoSwift
-//
-//  Copyright (C) 2014-2017 Marcin Krzyżanowski <marcin@krzyzanowskim.com>
-//  This software is provided 'as-is', without any express or implied warranty.
-//
-//  In no event will the authors be held liable for any damages arising from the use of this software.
-//
-//  Permission is granted to anyone to use this software for any purpose,including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
-//
-//  - The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation is required.
-//  - Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-//  - This notice may not be removed or altered from any source or binary distribution.
-//
-//
-//  https://tools.ietf.org/html/rfc7539#section-2.8.1
-
-public final class ChaCha20Poly1305: AEAD {
-    public static func encrypt(message: Array<UInt8>, header: Array<UInt8>, key: Array<UInt8>, nonce: Array<UInt8>) throws -> (cipher: Array<UInt8>, tag: Array<UInt8>) {
-        let chacha = try ChaCha20(key: key, iv: nonce)
-
-        var polykey = Array<UInt8>(repeating: 0, count: 32)
-        var toEncrypt = Array<UInt8>(reserveCapacity: message.count + 64)
-
-        toEncrypt += polykey
-        polykey = try chacha.encrypt(polykey)
-        toEncrypt += polykey
-        toEncrypt += message
-
-        let fullCipher = try chacha.encrypt(toEncrypt)
-        let cipher = Array(fullCipher.dropFirst(64))
-
-        let tag = try ChaCha20Poly1305.calculateTag(cipher: cipher, header: header, encodedKey: polykey)
-
-        return (cipher, tag)
-    }
-
-    public static func decrypt(cipher: Array<UInt8>, header: Array<UInt8>, key: Array<UInt8>, nonce: Array<UInt8>, tag: Array<UInt8>) throws -> (message: Array<UInt8>, success: Bool) {
-        let chacha = try ChaCha20(key: key, iv: nonce)
-
-        var polykey = Array<UInt8>(repeating: 0, count: 32)
-        polykey = try chacha.encrypt(polykey)
-
-        let mac = try ChaCha20Poly1305.calculateTag(cipher: cipher, header: header, encodedKey: polykey)
-
-        guard mac == tag else { return (cipher, false) }
-
-        var toDecrypt = Array<UInt8>(reserveCapacity: cipher.count + 64)
-        toDecrypt += polykey
-        toDecrypt += polykey
-        toDecrypt += cipher
-        let decrypted = try chacha.decrypt(toDecrypt)
-        let message = Array(decrypted.dropFirst(64))
-        return (message, true)
-    }
-
-    private class func calculateTag(cipher: Array<UInt8>, header: Array<UInt8>, encodedKey: Array<UInt8>) throws -> Array<UInt8> {
-        let poly1305 = Poly1305(key: encodedKey)
-        var mac = Array<UInt8>()
-        mac += header
-        let headerPadding = ((16 - (header.count & 0xf)) & 0xf)
-        mac += Array<UInt8>(repeating: 0, count: headerPadding)
-        mac += cipher
-        let cipherPadding = ((16 - (cipher.count & 0xf)) & 0xf)
-        mac += Array<UInt8>(repeating: 0, count: cipherPadding)
-        mac += UInt64(bigEndian: UInt64(header.count)).bytes()
-        mac += UInt64(bigEndian: UInt64(cipher.count)).bytes()
-
-        return try poly1305.authenticate(mac)
-    }
-}

+ 2 - 0
Sources/CryptoSwift/Cipher.swift

@@ -19,6 +19,8 @@ public enum CipherError: Error {
 }
 
 public protocol Cipher: class {
+    var keySize: Int { get }
+
     /// Encrypt given bytes at once
     ///
     /// - parameter bytes: Plaintext data

+ 4 - 0
Sources/CryptoSwift/Rabbit.swift

@@ -27,6 +27,10 @@ public final class Rabbit: BlockCipher {
     /// Size of block in bytes
     public static let blockSize = 128 / 8
 
+    public var keySize: Int {
+        return key.count
+    }
+
     /// Key
     private let key: Key
 

+ 5 - 5
Tests/CryptoSwiftTests/ChaCha20Poly1305Tests.swift

@@ -64,19 +64,19 @@ class ChaCha20Poly1305Tests: XCTestCase {
         let tagArr = Array<UInt8>(hex: tag)
 
         do {
-            let encryptResult = try ChaCha20Poly1305.encrypt(message: messageArr, header: headerArr, key: keyArr, nonce: nonceArr)
+            let encryptResult = try AEADChaCha20Poly1305.encrypt(messageArr, key: keyArr, iv: nonceArr, authenticationHeader: headerArr)
 
-            XCTAssertEqual(encryptResult.cipher, cipherArr, "cipher not equal")
-            XCTAssertEqual(encryptResult.tag, tagArr, "tag not equal")
+            XCTAssertEqual(encryptResult.cipherText, cipherArr, "cipher not equal")
+            XCTAssertEqual(encryptResult.authenticationTag, tagArr, "tag not equal")
         } catch {
             XCTAssert(false, "Encryption Failed with error: \(error.localizedDescription)")
         }
 
         do {
-            let decryptResult = try ChaCha20Poly1305.decrypt(cipher: cipherArr, header: headerArr, key: keyArr, nonce: nonceArr, tag: tagArr)
+            let decryptResult = try AEADChaCha20Poly1305.decrypt(cipherArr, key: keyArr, iv: nonceArr, authenticationHeader: headerArr, authenticationTag: tagArr)
 
             XCTAssertEqual(decryptResult.success, true, "decrypt mac check failed")
-            XCTAssertEqual(decryptResult.message, messageArr, "message not equal")
+            XCTAssertEqual(decryptResult.plainText, messageArr, "message not equal")
         } catch {
             XCTAssert(false, "Encryption Failed with error: \(error.localizedDescription)")
         }