Skip to content

Commit 5ceefbe

Browse files
author
Bram
committed
Appended XTS
* Implemented XTS mode
1 parent 67c170a commit 5ceefbe

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Sources/CCSwift/Cryptor.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ public final class AES: BlockCipherSuite {
172172
public static func CCM(key: Data, iv: Data, aad: Data) -> AESCCM {
173173
AESCCM(key: key, iv: iv, aad: aad)
174174
}
175+
176+
public static func XTS(key: Data, tweak: Data) throws -> AESXTS {
177+
try AESXTS(key: key, tweak: tweak)
178+
}
175179
}
176180

177181
public final class AESGCM {
@@ -333,3 +337,19 @@ public final class AESCCM {
333337
try Self.Cryptor.init(key: key, iv: iv, aad: aad, size: size, macSize: macSize, mac: mac)
334338
}
335339
}
340+
341+
public final class AESXTS {
342+
internal var cryptor: CCCryptorRef?
343+
344+
internal init(key: Data, tweak: Data) throws {
345+
try CCCryptorCreateWithMode(op: .both, mode: .xts, alg: .aes, padding: .none, iv: nil, key: key, tweak: tweak, reference: &cryptor)
346+
}
347+
348+
public final func encrypt(block: Data, iv: Data) throws -> Data {
349+
try CCCryptorEncryptDataBlock(cryptor, iv: iv, data: block)
350+
}
351+
352+
public final func decrypt(block: Data, iv: Data) throws -> Data {
353+
try CCCryptorDecryptDataBlock(cryptor, iv: iv, data: block)
354+
}
355+
}

0 commit comments

Comments
 (0)