Skip to content

Commit d1c6b70

Browse files
authored
Avoid TSAN issue in _CryptoExtras/AES/CMAC (#402)
### Motivation: swift-crypto currently fails to compile with TSAN enabled in 5.10 and 6.0 due to a TSAN error stemming from the use of `consuming` in the `finalize()` method of `_CryptoExtras/AES/CMAC`. ### Modifications: Like #384, the `consuming finalize()` method in `_CryptoExtras/AES/CMAC` is now wrapped inside a `#if compiler(>=6.1)` condition. A non-consuming variant is used otherwise. ### Result: `swift-crypto` can successfully compile with TSAN enabled in 5.10 and 6.0.
1 parent b7c303d commit d1c6b70

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Sources/_CryptoExtras/AES/CMAC.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ extension AES {
6565
self.backing.update(bufferPointer)
6666
}
6767

68+
// This enhancement can only be present on 6.1 or later because of the
69+
// absence of https://github.com/swiftlang/swift/pull/76186 in older
70+
// compilers.
71+
#if compiler(>=6.1)
6872
/// Finalizes the message authentication computation and returns the
6973
/// computed code.
7074
///
@@ -77,6 +81,16 @@ extension AES {
7781
self.cowIfNeeded()
7882
return self.backing.finalize()
7983
}
84+
#else
85+
/// Finalizes the message authentication computation and returns the
86+
/// computed code.
87+
///
88+
/// - Returns: The message authentication code.
89+
public func finalize() -> AES.CMAC.MAC {
90+
var `self` = self
91+
return self.backing.finalize()
92+
}
93+
#endif
8094

8195
/// Updates the MAC with data.
8296
///

0 commit comments

Comments
 (0)