Skip to content

Commit 1d7e43a

Browse files
authored
Revert 'Adopt Swift 6' (#118)
1 parent cf5a7d7 commit 1d7e43a

File tree

12 files changed

+38
-28
lines changed

12 files changed

+38
-28
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
strategy:
3838
fail-fast: false
3939
matrix:
40-
swift: ["6.0"]
40+
swift: ["5.10", "6.0"]
4141
name: swift ${{ matrix.swift }} tests
4242
steps:
4343
- uses: slashmo/[email protected]

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 6.0
1+
// swift-tools-version: 5.10
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33
// Remember to update CI if changing
44

@@ -17,7 +17,9 @@
1717
// limitations under the License.
1818
import PackageDescription
1919

20-
let librarySettings: [SwiftSetting] = []
20+
let librarySettings: [SwiftSetting] = [
21+
.enableExperimentalFeature("StrictConcurrency"),
22+
]
2123

2224
let executableSettings: [SwiftSetting] =
2325
librarySettings +
@@ -271,9 +273,7 @@ package.targets += [
271273
]),
272274
]
273275

274-
#if canImport(Darwin)
275276
// Set the minimum macOS version for the package
276277
package.platforms = [
277-
.macOS(.v15), // Constrained by Swift 6 support for Xcode (https://developer.apple.com/support/xcode/)
278+
.macOS(.v14), // Constrained by Swift 5.10 support for Xcode (https://developer.apple.com/support/xcode/)
278279
]
279-
#endif

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The PNNS implementation in Swift Homomorphic Encryption uses homomorphic encrypt
7979
Swift Homomorphic Encryption requires:
8080
* 64-bit processor with little-endian memory representation
8181
* macOS or Linux operating system
82-
* [Swift](https://www.swift.org/) version 6.0 or later
82+
* [Swift](https://www.swift.org/) version 5.10 or later
8383

8484
> [!NOTE]
8585
> Swift Homomorphic Encryption relies on [SystemRandomNumberGenerator](https://developer.apple.com/documentation/swift/systemrandomnumbergenerator) as a cryptographically secure random number generator, which may have platform-dependent behavior.
@@ -134,7 +134,7 @@ swift run -c release EncryptionParametersSnippet
134134
## Developing Swift Homomorphic Encryption
135135
### Dependencies
136136
Building Swift Homomorphic Encryption requires:
137-
* [Swift](https://www.swift.org/) version 6.0 or later
137+
* [Swift](https://www.swift.org/) version 5.10 or later
138138

139139
Additionally, developing Swift Homomorphic Encryption requires:
140140
* [Nick Lockwood SwiftFormat](https://github.com/nicklockwood/SwiftFormat), v0.54.0

Sources/HomomorphicEncryption/DoubleWidthUInt.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,5 +717,6 @@ extension DoubleWidthUInt: UnsignedInteger where Base: FixedWidthInteger & Unsig
717717
}
718718
}
719719

720+
@usableFromInline typealias DWUInt128 = DoubleWidthUInt<UInt64>
720721
@usableFromInline typealias QuadWidth<T: FixedWidthInteger & UnsignedInteger> = DoubleWidthUInt<DoubleWidthUInt<T>>
721722
@usableFromInline typealias OctoWidth<T: FixedWidthInteger & UnsignedInteger> = DoubleWidthUInt<QuadWidth<T>>

Sources/HomomorphicEncryption/HomomorphicEncryption.docc/UsingSwiftHomomorphicEncryption.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Get started using Swift Homomorphic Encryption.
66
Swift Homomorphic Encryption requires:
77
* 64-bit processor with little-endian memory representation
88
* macOS or Linux operating system
9-
* [Swift](https://www.swift.org/) version 6.0 or later
9+
* [Swift](https://www.swift.org/) version 5.10 or later
1010

1111
> Note: Swift Homomorphic Encryption relies on [SystemRandomNumberGenerator](https://developer.apple.com/documentation/swift/systemrandomnumbergenerator) as a cryptographically secure random number generator, which may have platform-dependent behavior.
1212

Sources/HomomorphicEncryption/PolyRq/PolyRq+Randomize.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ extension PolyRq {
5353
@inlinable
5454
public mutating func randomizeUniform(using rng: inout some PseudoRandomNumberGenerator) {
5555
let chunkCount = min(degree, 1024)
56-
let uint128ByteCount = MemoryLayout<UInt128>.size
56+
let uint128ByteCount = MemoryLayout<DWUInt128>.size
5757
var randomBytes: [UInt8] = .init(repeating: 0, count: chunkCount * uint128ByteCount)
5858
// We can sample directly in Coeff or Eval domain
5959
for (rnsIndex, reduceModulus) in context.reduceModuliUInt64.enumerated() {
@@ -63,7 +63,7 @@ extension PolyRq {
6363
for index in 0..<chunkCount {
6464
// NOTE: for interoperability always ask rng for a UInt128 and reduces it
6565
let u128 =
66-
UInt128(littleEndianBytes: randomBytes[index * uint128ByteCount..<(index + 1) *
66+
DWUInt128(littleEndianBytes: randomBytes[index * uint128ByteCount..<(index + 1) *
6767
uint128ByteCount])
6868
let u64 = reduceModulus.reduce(u128)
6969
self[offset + index] = T(u64)
@@ -92,7 +92,7 @@ extension PolyRq {
9292
// consumed for each coefficient.
9393
let u64: UInt64 = rng.next()
9494
let u32: UInt32 = rng.next()
95-
let u128 = UInt128(u64) &<< 32 | UInt128(u32)
95+
let u128 = DWUInt128(u64) &<< 32 | DWUInt128(u32)
9696

9797
let val = T(reductionModulus.reduce(u128))
9898
for (index, modulus) in zip(rnsIndices(coeffIndex: coeffIndex), moduli) {

Sources/HomomorphicEncryption/Random/NistCtrDrbg.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,17 @@ import Foundation
2424
@usableFromInline
2525
package struct NistCtrDrbg {
2626
@usableFromInline static let ReseedInterval: Int64 = 1 << 48
27-
2827
@usableFromInline static let MaxByteCountPerRequest: Int = 1 << 16
29-
3028
/// Size of AES block.
3129
@usableFromInline static let BlockCount: Int = 16
32-
3330
/// Size of AES key.
3431
@usableFromInline static let KeyCount: Int = 16
35-
3632
/// Size of the seed.
3733
@usableFromInline static let SeedCount: Int = KeyCount + BlockCount
3834

3935
@usableFromInline var key: SymmetricKey
40-
4136
/// This is called `V` in the NIST specification.
42-
@usableFromInline var nonce: UInt128
43-
37+
@usableFromInline var nonce: DWUInt128
4438
@usableFromInline var reseedCounter: Int64
4539

4640
@usableFromInline var nonceBytes: [UInt8] {
@@ -76,7 +70,7 @@ package struct NistCtrDrbg {
7670

7771
let zeroes = [UInt8](repeating: 0, count: requestedByteCount)
7872
let output = try AES._CTR.encrypt(zeroes, using: key, nonce: .init(nonceBytes: nonceBytes))
79-
nonce &+= UInt128(requestedByteCount.dividingCeil(Self.BlockCount, variableTime: true))
73+
nonce &+= DWUInt128(requestedByteCount.dividingCeil(Self.BlockCount, variableTime: true))
8074

8175
let additionalInput = [UInt8](repeating: 0, count: Self.SeedCount)
8276
try ctrDrbgUpdate(providedData: additionalInput)

Sources/HomomorphicEncryption/Scalar.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ extension UInt32: ScalarType {
108108
}
109109

110110
extension UInt64: ScalarType {
111-
public typealias DoubleWidth = UInt128
111+
public typealias DoubleWidth = DoubleWidthUInt<UInt64>
112112
public typealias SignedScalar = Int64
113113

114114
public static var rnsCorrectionFactor: UInt64 {
@@ -161,7 +161,7 @@ extension UInt64: DoubleWidthType {
161161
public typealias Scalar = UInt32
162162
}
163163

164-
extension UInt128: DoubleWidthType {
164+
extension DWUInt128: DoubleWidthType {
165165
/// Single-width scalar, with bit-width half that of the ``DoubleWidthType``.
166166
public typealias Scalar = UInt64
167167
}

Sources/HomomorphicEncryption/Util.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ extension Sequence where Element: Hashable {
2525
}
2626
}
2727

28+
// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0220-count-where.md
29+
// introduced in swift 6
30+
#if swift(<6.0)
31+
extension Sequence {
32+
@inlinable
33+
package func count(where predicate: (Element) throws -> Bool) rethrows -> Int {
34+
var count = 0
35+
for element in self where try predicate(element) {
36+
count += 1
37+
}
38+
return count
39+
}
40+
}
41+
#endif
42+
2843
extension FixedWidthInteger {
2944
// not a constant time operation
3045
@inlinable

0 commit comments

Comments
 (0)