Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default implementation for swift 6 feature count-where #15

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ let executableSettings: [SwiftSetting] =
librarySettings +
[.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))]

let benchmarkSettings: [SwiftSetting] = [.unsafeFlags(["-cross-module-optimization"], .when(configuration: .release))]

let package = Package(
name: "swift-homomorphic-encryption",
products: [
Expand Down Expand Up @@ -174,7 +176,7 @@ package.targets += [
"HomomorphicEncryption",
],
path: "Benchmarks/PolyBenchmark",
swiftSettings: executableSettings,
swiftSettings: benchmarkSettings,
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
]),
Expand All @@ -185,7 +187,7 @@ package.targets += [
"HomomorphicEncryption",
],
path: "Benchmarks/RlweBenchmark",
swiftSettings: executableSettings,
swiftSettings: benchmarkSettings,
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
]),
Expand All @@ -199,7 +201,7 @@ package.targets += [
"PrivateInformationRetrievalProtobuf",
],
path: "Benchmarks/PrivateInformationRetrievalBenchmark",
swiftSettings: executableSettings,
swiftSettings: benchmarkSettings,
plugins: [
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
]),
Expand Down
4 changes: 2 additions & 2 deletions Sources/HomomorphicEncryption/PolyRq/PolyContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
public final class PolyContext<T: ScalarType>: Sendable {
/// Number `N` of coefficients in the polynomial, must be a power of two.
@usableFromInline let degree: Int
/// CRT-representation of the modulus `Q = q_0 * q_2 * ... * q_{L-1}`.
/// CRT-representation of the modulus `Q = product_{i=0}^{L-1} q_i`.
@usableFromInline let moduli: [T]
/// Next context, typically formed by dropping `q_{L-1}`.
@usableFromInline let next: PolyContext<T>?
/// Operations mod `q_0, ..., q_{L-1}`.`
/// Operations mod `q_0` up to `q_{L-1}`.
@usableFromInline let reduceModuli: [Modulus<T>]
/// Operations mod `UInt64(q_0), ..., UInt64(q_{L-1})`.
@usableFromInline let reduceModuliUInt64: [Modulus<UInt64>]
Expand Down
2 changes: 1 addition & 1 deletion Sources/HomomorphicEncryption/RnsTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct RnsTool<T: ScalarType>: Sendable {
@usableFromInline let tIncrement: [T]
/// i'th entry stores `\tilde{m} mod qi`.
@usableFromInline let mTildeModQ: [T]
/// `-(Q^{-1}) mod {t, gamma}`.`
/// `-(Q^{-1}) mod {t, gamma}`.
@usableFromInline let negInverseQModTGamma: [T]
/// `|gamma * t|_qi``.
@usableFromInline let prodGammaTModQ: [T]
Expand Down
15 changes: 15 additions & 0 deletions Sources/HomomorphicEncryption/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ extension Sequence where Element: Hashable {
}
}

// https://github.com/swiftlang/swift-evolution/blob/main/proposals/0220-count-where.md
// introduced in swift 6
#if swift(<6.0)
extension Sequence {
@inlinable
package func count(where predicate: (Element) throws -> Bool) rethrows -> Int {
fboemer marked this conversation as resolved.
Show resolved Hide resolved
var count = 0
for element in self where try predicate(element) {
count += 1
}
return count
}
}
#endif

extension FixedWidthInteger {
// not a constant time operation
@inlinable
Expand Down
4 changes: 3 additions & 1 deletion Sources/PrivateInformationRetrieval/PirUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ enum PirUtil<Scheme: HeScheme> {
}
}

/// Convert the MulPir indices (i.e. the index of non-zero results after expansion) into plaintext.
/// Convert the MulPir indices into a plaintext.
///
/// The MulPir indices are the indices of non-zero results after expansion
static func compressInputsForOneCiphertext(totalInputCount: Int, nonZeroInputs: [Int],
context: Context<Scheme>) throws -> Plaintext<Scheme, Coeff>
{
Expand Down