Skip to content

Commit 6cb205d

Browse files
authored
Params -> Parameters (#113)
1 parent b593b9a commit 6cb205d

File tree

17 files changed

+113
-110
lines changed

17 files changed

+113
-110
lines changed

Benchmarks/PrivateNearestNeighborsSearchBenchmark/PrivateNearestNeighborsSearchBenchmark.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct ProcessBenchmarkContext<Scheme: HeScheme> {
118118
preferringSmall: false,
119119
nttDegree: parameterConfig.polyDegree)
120120

121-
let encryptionParams = try EncryptionParameters<Scheme>(
121+
let encryptionParameters = try EncryptionParameters<Scheme>(
122122
polyDegree: parameterConfig.polyDegree,
123123
plaintextModulus: plaintextModuli[0],
124124
coefficientModuli: coefficientModuli,
@@ -130,15 +130,15 @@ struct ProcessBenchmarkContext<Scheme: HeScheme> {
130130
plaintextMatrixDimensions: MatrixDimensions(
131131
rowCount: databaseConfig.rowCount,
132132
columnCount: databaseConfig.vectorDimension),
133-
encryptionParameters: encryptionParams,
133+
encryptionParameters: encryptionParameters,
134134
maxQueryCount: batchSize)
135135
let scalingFactor = ClientConfig<Scheme>
136136
.maxScalingFactor(
137137
distanceMetric: .cosineSimilarity,
138138
vectorDimension: databaseConfig.vectorDimension,
139139
plaintextModuli: Array(plaintextModuli[1...]))
140140
let clientConfig = try ClientConfig(
141-
encryptionParams: encryptionParams,
141+
encryptionParameters: encryptionParameters,
142142
scalingFactor: scalingFactor,
143143
queryPacking: .denseRow,
144144
vectorDimension: databaseConfig.vectorDimension,
@@ -151,8 +151,8 @@ struct ProcessBenchmarkContext<Scheme: HeScheme> {
151151
self.serverConfig = serverConfig
152152

153153
self.database = getDatabaseForTesting(config: databaseConfig)
154-
self.contexts = try serverConfig.encryptionParameters.map { encryptionParams in
155-
try Context(encryptionParameters: encryptionParams)
154+
self.contexts = try serverConfig.encryptionParameters.map { encryptionParameters in
155+
try Context(encryptionParameters: encryptionParameters)
156156
}
157157
}
158158
}
@@ -224,7 +224,7 @@ struct PnnsBenchmarkContext<Scheme: HeScheme> {
224224
significantBitCounts: parameterConfig.coefficientModulusBits,
225225
preferringSmall: false,
226226
nttDegree: parameterConfig.polyDegree)
227-
let encryptionParams = try EncryptionParameters<Scheme>(
227+
let encryptionParameters = try EncryptionParameters<Scheme>(
228228
polyDegree: parameterConfig.polyDegree,
229229
plaintextModulus: plaintextModuli[0],
230230
coefficientModuli: coefficientModuli,
@@ -235,15 +235,15 @@ struct PnnsBenchmarkContext<Scheme: HeScheme> {
235235
plaintextMatrixDimensions: MatrixDimensions(
236236
rowCount: databaseConfig.rowCount,
237237
columnCount: databaseConfig.vectorDimension),
238-
encryptionParameters: encryptionParams,
238+
encryptionParameters: encryptionParameters,
239239
maxQueryCount: queryCount)
240240
let scalingFactor = ClientConfig<Scheme>
241241
.maxScalingFactor(
242242
distanceMetric: .cosineSimilarity,
243243
vectorDimension: databaseConfig.vectorDimension,
244244
plaintextModuli: plaintextModuli)
245245
let clientConfig = try ClientConfig(
246-
encryptionParams: encryptionParams,
246+
encryptionParameters: encryptionParameters,
247247
scalingFactor: scalingFactor,
248248
queryPacking: .denseRow,
249249
vectorDimension: databaseConfig.vectorDimension,
@@ -258,7 +258,7 @@ struct PnnsBenchmarkContext<Scheme: HeScheme> {
258258

259259
let database = getDatabaseForTesting(config: databaseConfig)
260260
let contexts = try clientConfig.encryptionParameters
261-
.map { encryptionParams in try Context(encryptionParameters: encryptionParams) }
261+
.map { encryptionParameters in try Context(encryptionParameters: encryptionParameters) }
262262
self.processedDatabase = try database.process(config: serverConfig, contexts: contexts)
263263
self.client = try Client(config: clientConfig, contexts: contexts)
264264
self.server = try Server(database: processedDatabase)

Sources/HomomorphicEncryption/Plaintext.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
/// Plaintext type.
1516
public struct Plaintext<Scheme: HeScheme, Format: PolyFormat>: Equatable, Sendable {
1617
public typealias SignedScalar = Scheme.SignedScalar

Sources/PNNSProcessDatabase/ProcessDatabase.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ struct ProcessDatabase: ParsableCommand {
231231

232232
let encryptionParameters = try EncryptionParameters<Scheme>(from: config.rlweParameters)
233233
let clientConfig = try ClientConfig<Scheme>(
234-
encryptionParams: encryptionParameters,
234+
encryptionParameters: encryptionParameters,
235235
scalingFactor: config.scalingFactor,
236236
queryPacking: config.queryPacking,
237237
vectorDimension: vectorDimension,

Sources/PrivateNearestNeighborsSearch/CiphertextMatrix.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ public struct CiphertextMatrix<Scheme: HeScheme, Format: PolyFormat>: Equatable,
6262
guard let context = ciphertexts.first?.context else {
6363
throw PnnsError.emptyCiphertextArray
6464
}
65-
let encryptionParams = context.encryptionParameters
66-
guard let simdDimensions = encryptionParams.simdDimensions else {
67-
throw PnnsError.simdEncodingNotSupported(for: encryptionParams)
65+
let encryptionParameters = context.encryptionParameters
66+
guard let simdDimensions = encryptionParameters.simdDimensions else {
67+
throw PnnsError.simdEncodingNotSupported(for: encryptionParameters)
6868
}
6969
let expectedCiphertextCount = try PlaintextMatrix<Scheme, Format>.plaintextCount(
70-
encryptionParameters: encryptionParams,
70+
encryptionParameters: encryptionParameters,
7171
dimensions: dimensions,
7272
packing: packing)
7373
guard ciphertexts.count == expectedCiphertextCount else {
@@ -158,22 +158,22 @@ extension CiphertextMatrix {
158158
extension CiphertextMatrix {
159159
/// Computes the evaluation key configuration for calling `extractDenseRow`.
160160
/// - Parameters:
161-
/// - encryptionParams: Encryption parameters; must support `.simd` encoding.
161+
/// - encryptionParameters: Encryption parameters; must support `.simd` encoding.
162162
/// - dimensions: Dimensions of the matrix to call `extractDenseRow` on.
163163
/// - Returns: The evaluation key configuration.
164164
/// - Throws: Error upon failure to generate the evaluation key configuration.
165165
@inlinable
166-
static func extractDenseRowConfig(for encryptionParams: EncryptionParameters<Scheme>,
166+
static func extractDenseRowConfig(for encryptionParameters: EncryptionParameters<Scheme>,
167167
dimensions: MatrixDimensions) throws -> EvaluationKeyConfig
168168
{
169169
if dimensions.rowCount == 1 {
170170
// extractDenseRow is a No-op, so no evaluation key required
171171
return EvaluationKeyConfig()
172172
}
173-
guard let simdDimensions = encryptionParams.simdDimensions else {
174-
throw PnnsError.simdEncodingNotSupported(for: encryptionParams)
173+
guard let simdDimensions = encryptionParameters.simdDimensions else {
174+
throw PnnsError.simdEncodingNotSupported(for: encryptionParameters)
175175
}
176-
let degree = encryptionParams.polyDegree
176+
let degree = encryptionParameters.polyDegree
177177
var galoisElements = [GaloisElement.swappingRows(degree: degree)]
178178
let columnCountPowerOfTwo = dimensions.columnCount.nextPowerOfTwo
179179
if columnCountPowerOfTwo != simdDimensions.columnCount {

Sources/PrivateNearestNeighborsSearch/Client.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public struct Client<Scheme: HeScheme> {
4848

4949
var contexts = contexts
5050
if contexts.isEmpty {
51-
contexts = try config.encryptionParameters.map { encryptionParams in
52-
try Context(encryptionParameters: encryptionParams)
51+
contexts = try config.encryptionParameters.map { encryptionParameters in
52+
try Context(encryptionParameters: encryptionParameters)
5353
}
5454
}
5555
try config.validateContexts(contexts: contexts)

Sources/PrivateNearestNeighborsSearch/Config.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,25 @@ public struct ClientConfig<Scheme: HeScheme>: Codable, Equatable, Hashable, Send
6060
public let distanceMetric: DistanceMetric
6161
/// For plaintext CRT, the list of extra plaintext moduli.
6262
///
63-
/// The first plaintext modulus will be the one in ``ClientConfig/encryptionParams``.
63+
/// The first plaintext modulus will be the one in ``ClientConfig/encryptionParameters``.
6464
public let extraPlaintextModuli: [Scheme.Scalar]
6565

6666
/// The plaintext CRT moduli.
6767
public var plaintextModuli: [Scheme.Scalar] { encryptionParameters.map(\.plaintextModulus) }
6868

6969
/// Creates a new ``ClientConfig``.
7070
/// - Parameters:
71-
/// - encryptionParams: Encryption parameters.
71+
/// - encryptionParameters: Encryption parameters.
7272
/// - scalingFactor: Factor by which to scale floating-point entries before rounding to integers.
7373
/// - queryPacking: Packing for the query.
7474
/// - vectorDimension: Number of entries in each vector.
7575
/// - evaluationKeyConfig: Evaluation key configuration for nearest neighbors computation.
7676
/// - distanceMetric: Metric for nearest neighbors computation
7777
/// - extraPlaintextModuli: For plaintext CRT, the list of extra plaintext moduli. The first plaintext modulus
78-
/// will be the one in ``ClientConfig/encryptionParams``.
78+
/// will be the one in ``ClientConfig/encryptionParameters``.
7979
/// - Throws: Error upon failure to create a new client config.
8080
public init(
81-
encryptionParams: EncryptionParameters<Scheme>,
81+
encryptionParameters: EncryptionParameters<Scheme>,
8282
scalingFactor: Int,
8383
queryPacking: MatrixPacking,
8484
vectorDimension: Int,
@@ -88,13 +88,13 @@ public struct ClientConfig<Scheme: HeScheme>: Codable, Equatable, Hashable, Send
8888
{
8989
let extraEncryptionParams = try extraPlaintextModuli.map { plaintextModulus in
9090
try EncryptionParameters<Scheme>(
91-
polyDegree: encryptionParams.polyDegree,
91+
polyDegree: encryptionParameters.polyDegree,
9292
plaintextModulus: plaintextModulus,
93-
coefficientModuli: encryptionParams.coefficientModuli,
94-
errorStdDev: encryptionParams.errorStdDev,
95-
securityLevel: encryptionParams.securityLevel)
93+
coefficientModuli: encryptionParameters.coefficientModuli,
94+
errorStdDev: encryptionParameters.errorStdDev,
95+
securityLevel: encryptionParameters.securityLevel)
9696
}
97-
self.encryptionParameters = [encryptionParams] + extraEncryptionParams
97+
self.encryptionParameters = [encryptionParameters] + extraEncryptionParams
9898
self.scalingFactor = scalingFactor
9999
self.queryPacking = queryPacking
100100
self.vectorDimension = vectorDimension
@@ -145,7 +145,7 @@ public struct ServerConfig<Scheme: HeScheme>: Codable, Equatable, Hashable, Send
145145

146146
/// For plaintext CRT, the list of extra plaintext moduli.
147147
///
148-
/// The first plaintext modulus will be the one in ``ClientConfig/encryptionParams``.
148+
/// The first plaintext modulus will be the one in ``ClientConfig/encryptionParameters``.
149149
public var extraPlaintextModuli: [Scheme.Scalar] {
150150
clientConfig.extraPlaintextModuli
151151
}

Sources/PrivateNearestNeighborsSearch/PlaintextMatrix.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ public struct PlaintextMatrix<Scheme: HeScheme, Format: PolyFormat>: Equatable,
117117
throw PnnsError.emptyPlaintextArray
118118
}
119119
let context = plaintexts[0].context
120-
let encryptionParams = context.encryptionParameters
121-
guard let simdDimensions = encryptionParams.simdDimensions else {
122-
throw PnnsError.simdEncodingNotSupported(for: encryptionParams)
120+
let encryptionParameters = context.encryptionParameters
121+
guard let simdDimensions = encryptionParameters.simdDimensions else {
122+
throw PnnsError.simdEncodingNotSupported(for: encryptionParameters)
123123
}
124124
let expectedPlaintextCount = try PlaintextMatrix.plaintextCount(
125-
encryptionParameters: encryptionParams,
125+
encryptionParameters: encryptionParameters,
126126
dimensions: dimensions,
127127
packing: packing)
128128
guard plaintexts.count == expectedPlaintextCount else {
@@ -278,9 +278,9 @@ public struct PlaintextMatrix<Scheme: HeScheme, Format: PolyFormat>: Equatable,
278278
throw PnnsError.simdEncodingNotSupported(for: context.encryptionParameters)
279279
}
280280

281-
let encryptionParams = context.encryptionParameters
281+
let encryptionParameters = context.encryptionParameters
282282
let expectedPlaintextCount = try PlaintextMatrix.plaintextCount(
283-
encryptionParameters: encryptionParams,
283+
encryptionParameters: encryptionParameters,
284284
dimensions: dimensions,
285285
packing: .denseColumn)
286286
var plaintexts: [Scheme.CoeffPlaintext] = []

Sources/PrivateNearestNeighborsSearch/ProcessedDatabase.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public struct ProcessedDatabase<Scheme: HeScheme>: Equatable, Sendable {
5555
public init(from serialized: SerializedProcessedDatabase<Scheme>, contexts: [Context<Scheme>] = []) throws {
5656
var contexts = contexts
5757
if contexts.isEmpty {
58-
contexts = try serialized.serverConfig.encryptionParameters.map { encryptionParams in
59-
try Context(encryptionParameters: encryptionParams)
58+
contexts = try serialized.serverConfig.encryptionParameters.map { encryptionParameters in
59+
try Context(encryptionParameters: encryptionParameters)
6060
}
6161
}
6262
try serialized.serverConfig.validateContexts(contexts: contexts)
@@ -195,8 +195,8 @@ extension Database {
195195
}
196196
var contexts = contexts
197197
if contexts.isEmpty {
198-
contexts = try config.encryptionParameters.map { encryptionParams in
199-
try Context(encryptionParameters: encryptionParams)
198+
contexts = try config.encryptionParameters.map { encryptionParameters in
199+
try Context(encryptionParameters: encryptionParameters)
200200
}
201201
}
202202
try config.validateContexts(contexts: contexts)

Sources/PrivateNearestNeighborsSearchProtobuf/ConversionPnns.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ extension Apple_SwiftHomomorphicEncryption_Pnns_V1_ClientConfig {
121121
throw ConversionError.unsetField(\Self.encryptionParameters, in: Self.self)
122122
}
123123
return try ClientConfig<Scheme>(
124-
encryptionParams: encryptionParameters.native(),
124+
encryptionParameters: encryptionParameters.native(),
125125
scalingFactor: Int(scalingFactor),
126126
queryPacking: queryPacking.native(),
127127
vectorDimension: Int(vectorDimension),

Tests/HomomorphicEncryptionTests/HeAPITests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
1415
@testable import HomomorphicEncryption
1516
import TestUtilities
1617
import XCTest
@@ -1074,8 +1075,8 @@ class HeAPITests: XCTestCase {
10741075
errorStdDev: ErrorStdDev.stdDev32,
10751076
securityLevel: SecurityLevel.unchecked)
10761077

1077-
for encryptionParams in predefined + [custom] {
1078-
let context = try Context<Bfv<T>>(encryptionParameters: encryptionParams)
1078+
for encryptionParameters in predefined + [custom] {
1079+
let context = try Context<Bfv<T>>(encryptionParameters: encryptionParameters)
10791080
try schemeEncodeDecodeTest(context: context)
10801081
try schemeEncryptDecryptTest(context: context)
10811082
try schemeEncryptZeroDecryptTest(context: context)

0 commit comments

Comments
 (0)