Skip to content

Commit

Permalink
[swift] cbc: don't reset iv
Browse files Browse the repository at this point in the history
  • Loading branch information
yretenai committed Dec 3, 2024
1 parent 459900d commit a64ee93
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions swift/Sources/Myna/Transforms/CBCTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ public struct CBCTransform: BlockCipherTransform {
private let algorithm: BlockCipher
private let padding: PaddingScheme
private var previousBlock: Data
private let iv: Data

init(algorithm: BlockCipher, iv: Data?, paddingMode: PaddingScheme?) {
self.algorithm = algorithm
self.iv = iv ?? Data(count: self.algorithm.blockSize)
self.previousBlock = self.iv
self.previousBlock = iv ?? Data(count: self.algorithm.blockSize)
self.padding = paddingMode ?? PKCS7Padding()
}

Expand Down Expand Up @@ -41,9 +39,6 @@ public struct CBCTransform: BlockCipherTransform {

result.append(try self.algorithm.encrypt(block: finalBlock.xor(other: previousBlock)))

// reset IV
previousBlock = iv

return result
}

Expand All @@ -67,9 +62,6 @@ public struct CBCTransform: BlockCipherTransform {
let finalBlock = try self.algorithm.decrypt(block: blocks.last!).xor(other: previousBlock)
result.append(try padding.unpad(data: finalBlock))

// reset IV
previousBlock = iv

return result
}
}

0 comments on commit a64ee93

Please sign in to comment.