diff --git a/Benchmarks/PrivateNearestNeighborsSearchBenchmark/PrivateNearestNeighborsSearchBenchmark.swift b/Benchmarks/PrivateNearestNeighborsSearchBenchmark/PrivateNearestNeighborsSearchBenchmark.swift index 2aeb441b..3b92f0d7 100644 --- a/Benchmarks/PrivateNearestNeighborsSearchBenchmark/PrivateNearestNeighborsSearchBenchmark.swift +++ b/Benchmarks/PrivateNearestNeighborsSearchBenchmark/PrivateNearestNeighborsSearchBenchmark.swift @@ -118,7 +118,7 @@ struct ProcessBenchmarkContext { preferringSmall: false, nttDegree: parameterConfig.polyDegree) - let encryptionParams = try EncryptionParameters( + let encryptionParameters = try EncryptionParameters( polyDegree: parameterConfig.polyDegree, plaintextModulus: plaintextModuli[0], coefficientModuli: coefficientModuli, @@ -130,7 +130,7 @@ struct ProcessBenchmarkContext { plaintextMatrixDimensions: MatrixDimensions( rowCount: databaseConfig.rowCount, columnCount: databaseConfig.vectorDimension), - encryptionParameters: encryptionParams, + encryptionParameters: encryptionParameters, maxQueryCount: batchSize) let scalingFactor = ClientConfig .maxScalingFactor( @@ -138,7 +138,7 @@ struct ProcessBenchmarkContext { vectorDimension: databaseConfig.vectorDimension, plaintextModuli: Array(plaintextModuli[1...])) let clientConfig = try ClientConfig( - encryptionParams: encryptionParams, + encryptionParameters: encryptionParameters, scalingFactor: scalingFactor, queryPacking: .denseRow, vectorDimension: databaseConfig.vectorDimension, @@ -151,8 +151,8 @@ struct ProcessBenchmarkContext { self.serverConfig = serverConfig self.database = getDatabaseForTesting(config: databaseConfig) - self.contexts = try serverConfig.encryptionParameters.map { encryptionParams in - try Context(encryptionParameters: encryptionParams) + self.contexts = try serverConfig.encryptionParameters.map { encryptionParameters in + try Context(encryptionParameters: encryptionParameters) } } } @@ -224,7 +224,7 @@ struct PnnsBenchmarkContext { significantBitCounts: parameterConfig.coefficientModulusBits, preferringSmall: false, nttDegree: parameterConfig.polyDegree) - let encryptionParams = try EncryptionParameters( + let encryptionParameters = try EncryptionParameters( polyDegree: parameterConfig.polyDegree, plaintextModulus: plaintextModuli[0], coefficientModuli: coefficientModuli, @@ -235,7 +235,7 @@ struct PnnsBenchmarkContext { plaintextMatrixDimensions: MatrixDimensions( rowCount: databaseConfig.rowCount, columnCount: databaseConfig.vectorDimension), - encryptionParameters: encryptionParams, + encryptionParameters: encryptionParameters, maxQueryCount: queryCount) let scalingFactor = ClientConfig .maxScalingFactor( @@ -243,7 +243,7 @@ struct PnnsBenchmarkContext { vectorDimension: databaseConfig.vectorDimension, plaintextModuli: plaintextModuli) let clientConfig = try ClientConfig( - encryptionParams: encryptionParams, + encryptionParameters: encryptionParameters, scalingFactor: scalingFactor, queryPacking: .denseRow, vectorDimension: databaseConfig.vectorDimension, @@ -258,7 +258,7 @@ struct PnnsBenchmarkContext { let database = getDatabaseForTesting(config: databaseConfig) let contexts = try clientConfig.encryptionParameters - .map { encryptionParams in try Context(encryptionParameters: encryptionParams) } + .map { encryptionParameters in try Context(encryptionParameters: encryptionParameters) } self.processedDatabase = try database.process(config: serverConfig, contexts: contexts) self.client = try Client(config: clientConfig, contexts: contexts) self.server = try Server(database: processedDatabase) diff --git a/Sources/HomomorphicEncryption/Plaintext.swift b/Sources/HomomorphicEncryption/Plaintext.swift index b99616e7..a5f31217 100644 --- a/Sources/HomomorphicEncryption/Plaintext.swift +++ b/Sources/HomomorphicEncryption/Plaintext.swift @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + /// Plaintext type. public struct Plaintext: Equatable, Sendable { public typealias SignedScalar = Scheme.SignedScalar diff --git a/Sources/PNNSProcessDatabase/ProcessDatabase.swift b/Sources/PNNSProcessDatabase/ProcessDatabase.swift index 0b472738..76c78ec4 100644 --- a/Sources/PNNSProcessDatabase/ProcessDatabase.swift +++ b/Sources/PNNSProcessDatabase/ProcessDatabase.swift @@ -231,7 +231,7 @@ struct ProcessDatabase: ParsableCommand { let encryptionParameters = try EncryptionParameters(from: config.rlweParameters) let clientConfig = try ClientConfig( - encryptionParams: encryptionParameters, + encryptionParameters: encryptionParameters, scalingFactor: config.scalingFactor, queryPacking: config.queryPacking, vectorDimension: vectorDimension, diff --git a/Sources/PrivateNearestNeighborsSearch/CiphertextMatrix.swift b/Sources/PrivateNearestNeighborsSearch/CiphertextMatrix.swift index eccaf8f4..91e63815 100644 --- a/Sources/PrivateNearestNeighborsSearch/CiphertextMatrix.swift +++ b/Sources/PrivateNearestNeighborsSearch/CiphertextMatrix.swift @@ -62,12 +62,12 @@ public struct CiphertextMatrix: Equatable, guard let context = ciphertexts.first?.context else { throw PnnsError.emptyCiphertextArray } - let encryptionParams = context.encryptionParameters - guard let simdDimensions = encryptionParams.simdDimensions else { - throw PnnsError.simdEncodingNotSupported(for: encryptionParams) + let encryptionParameters = context.encryptionParameters + guard let simdDimensions = encryptionParameters.simdDimensions else { + throw PnnsError.simdEncodingNotSupported(for: encryptionParameters) } let expectedCiphertextCount = try PlaintextMatrix.plaintextCount( - encryptionParameters: encryptionParams, + encryptionParameters: encryptionParameters, dimensions: dimensions, packing: packing) guard ciphertexts.count == expectedCiphertextCount else { @@ -158,22 +158,22 @@ extension CiphertextMatrix { extension CiphertextMatrix { /// Computes the evaluation key configuration for calling `extractDenseRow`. /// - Parameters: - /// - encryptionParams: Encryption parameters; must support `.simd` encoding. + /// - encryptionParameters: Encryption parameters; must support `.simd` encoding. /// - dimensions: Dimensions of the matrix to call `extractDenseRow` on. /// - Returns: The evaluation key configuration. /// - Throws: Error upon failure to generate the evaluation key configuration. @inlinable - static func extractDenseRowConfig(for encryptionParams: EncryptionParameters, + static func extractDenseRowConfig(for encryptionParameters: EncryptionParameters, dimensions: MatrixDimensions) throws -> EvaluationKeyConfig { if dimensions.rowCount == 1 { // extractDenseRow is a No-op, so no evaluation key required return EvaluationKeyConfig() } - guard let simdDimensions = encryptionParams.simdDimensions else { - throw PnnsError.simdEncodingNotSupported(for: encryptionParams) + guard let simdDimensions = encryptionParameters.simdDimensions else { + throw PnnsError.simdEncodingNotSupported(for: encryptionParameters) } - let degree = encryptionParams.polyDegree + let degree = encryptionParameters.polyDegree var galoisElements = [GaloisElement.swappingRows(degree: degree)] let columnCountPowerOfTwo = dimensions.columnCount.nextPowerOfTwo if columnCountPowerOfTwo != simdDimensions.columnCount { diff --git a/Sources/PrivateNearestNeighborsSearch/Client.swift b/Sources/PrivateNearestNeighborsSearch/Client.swift index a98aab71..1a2fd790 100644 --- a/Sources/PrivateNearestNeighborsSearch/Client.swift +++ b/Sources/PrivateNearestNeighborsSearch/Client.swift @@ -48,8 +48,8 @@ public struct Client { var contexts = contexts if contexts.isEmpty { - contexts = try config.encryptionParameters.map { encryptionParams in - try Context(encryptionParameters: encryptionParams) + contexts = try config.encryptionParameters.map { encryptionParameters in + try Context(encryptionParameters: encryptionParameters) } } try config.validateContexts(contexts: contexts) diff --git a/Sources/PrivateNearestNeighborsSearch/Config.swift b/Sources/PrivateNearestNeighborsSearch/Config.swift index 652ac1c0..5885c547 100644 --- a/Sources/PrivateNearestNeighborsSearch/Config.swift +++ b/Sources/PrivateNearestNeighborsSearch/Config.swift @@ -60,7 +60,7 @@ public struct ClientConfig: Codable, Equatable, Hashable, Send public let distanceMetric: DistanceMetric /// For plaintext CRT, the list of extra plaintext moduli. /// - /// The first plaintext modulus will be the one in ``ClientConfig/encryptionParams``. + /// The first plaintext modulus will be the one in ``ClientConfig/encryptionParameters``. public let extraPlaintextModuli: [Scheme.Scalar] /// The plaintext CRT moduli. @@ -68,17 +68,17 @@ public struct ClientConfig: Codable, Equatable, Hashable, Send /// Creates a new ``ClientConfig``. /// - Parameters: - /// - encryptionParams: Encryption parameters. + /// - encryptionParameters: Encryption parameters. /// - scalingFactor: Factor by which to scale floating-point entries before rounding to integers. /// - queryPacking: Packing for the query. /// - vectorDimension: Number of entries in each vector. /// - evaluationKeyConfig: Evaluation key configuration for nearest neighbors computation. /// - distanceMetric: Metric for nearest neighbors computation /// - extraPlaintextModuli: For plaintext CRT, the list of extra plaintext moduli. The first plaintext modulus - /// will be the one in ``ClientConfig/encryptionParams``. + /// will be the one in ``ClientConfig/encryptionParameters``. /// - Throws: Error upon failure to create a new client config. public init( - encryptionParams: EncryptionParameters, + encryptionParameters: EncryptionParameters, scalingFactor: Int, queryPacking: MatrixPacking, vectorDimension: Int, @@ -88,13 +88,13 @@ public struct ClientConfig: Codable, Equatable, Hashable, Send { let extraEncryptionParams = try extraPlaintextModuli.map { plaintextModulus in try EncryptionParameters( - polyDegree: encryptionParams.polyDegree, + polyDegree: encryptionParameters.polyDegree, plaintextModulus: plaintextModulus, - coefficientModuli: encryptionParams.coefficientModuli, - errorStdDev: encryptionParams.errorStdDev, - securityLevel: encryptionParams.securityLevel) + coefficientModuli: encryptionParameters.coefficientModuli, + errorStdDev: encryptionParameters.errorStdDev, + securityLevel: encryptionParameters.securityLevel) } - self.encryptionParameters = [encryptionParams] + extraEncryptionParams + self.encryptionParameters = [encryptionParameters] + extraEncryptionParams self.scalingFactor = scalingFactor self.queryPacking = queryPacking self.vectorDimension = vectorDimension @@ -145,7 +145,7 @@ public struct ServerConfig: Codable, Equatable, Hashable, Send /// For plaintext CRT, the list of extra plaintext moduli. /// - /// The first plaintext modulus will be the one in ``ClientConfig/encryptionParams``. + /// The first plaintext modulus will be the one in ``ClientConfig/encryptionParameters``. public var extraPlaintextModuli: [Scheme.Scalar] { clientConfig.extraPlaintextModuli } diff --git a/Sources/PrivateNearestNeighborsSearch/PlaintextMatrix.swift b/Sources/PrivateNearestNeighborsSearch/PlaintextMatrix.swift index beddaa0f..e5887f7e 100644 --- a/Sources/PrivateNearestNeighborsSearch/PlaintextMatrix.swift +++ b/Sources/PrivateNearestNeighborsSearch/PlaintextMatrix.swift @@ -117,12 +117,12 @@ public struct PlaintextMatrix: Equatable, throw PnnsError.emptyPlaintextArray } let context = plaintexts[0].context - let encryptionParams = context.encryptionParameters - guard let simdDimensions = encryptionParams.simdDimensions else { - throw PnnsError.simdEncodingNotSupported(for: encryptionParams) + let encryptionParameters = context.encryptionParameters + guard let simdDimensions = encryptionParameters.simdDimensions else { + throw PnnsError.simdEncodingNotSupported(for: encryptionParameters) } let expectedPlaintextCount = try PlaintextMatrix.plaintextCount( - encryptionParameters: encryptionParams, + encryptionParameters: encryptionParameters, dimensions: dimensions, packing: packing) guard plaintexts.count == expectedPlaintextCount else { @@ -278,9 +278,9 @@ public struct PlaintextMatrix: Equatable, throw PnnsError.simdEncodingNotSupported(for: context.encryptionParameters) } - let encryptionParams = context.encryptionParameters + let encryptionParameters = context.encryptionParameters let expectedPlaintextCount = try PlaintextMatrix.plaintextCount( - encryptionParameters: encryptionParams, + encryptionParameters: encryptionParameters, dimensions: dimensions, packing: .denseColumn) var plaintexts: [Scheme.CoeffPlaintext] = [] diff --git a/Sources/PrivateNearestNeighborsSearch/ProcessedDatabase.swift b/Sources/PrivateNearestNeighborsSearch/ProcessedDatabase.swift index d450715b..589e51cd 100644 --- a/Sources/PrivateNearestNeighborsSearch/ProcessedDatabase.swift +++ b/Sources/PrivateNearestNeighborsSearch/ProcessedDatabase.swift @@ -55,8 +55,8 @@ public struct ProcessedDatabase: Equatable, Sendable { public init(from serialized: SerializedProcessedDatabase, contexts: [Context] = []) throws { var contexts = contexts if contexts.isEmpty { - contexts = try serialized.serverConfig.encryptionParameters.map { encryptionParams in - try Context(encryptionParameters: encryptionParams) + contexts = try serialized.serverConfig.encryptionParameters.map { encryptionParameters in + try Context(encryptionParameters: encryptionParameters) } } try serialized.serverConfig.validateContexts(contexts: contexts) @@ -195,8 +195,8 @@ extension Database { } var contexts = contexts if contexts.isEmpty { - contexts = try config.encryptionParameters.map { encryptionParams in - try Context(encryptionParameters: encryptionParams) + contexts = try config.encryptionParameters.map { encryptionParameters in + try Context(encryptionParameters: encryptionParameters) } } try config.validateContexts(contexts: contexts) diff --git a/Sources/PrivateNearestNeighborsSearchProtobuf/ConversionPnns.swift b/Sources/PrivateNearestNeighborsSearchProtobuf/ConversionPnns.swift index aa3b095c..1ab31255 100644 --- a/Sources/PrivateNearestNeighborsSearchProtobuf/ConversionPnns.swift +++ b/Sources/PrivateNearestNeighborsSearchProtobuf/ConversionPnns.swift @@ -121,7 +121,7 @@ extension Apple_SwiftHomomorphicEncryption_Pnns_V1_ClientConfig { throw ConversionError.unsetField(\Self.encryptionParameters, in: Self.self) } return try ClientConfig( - encryptionParams: encryptionParameters.native(), + encryptionParameters: encryptionParameters.native(), scalingFactor: Int(scalingFactor), queryPacking: queryPacking.native(), vectorDimension: Int(vectorDimension), diff --git a/Tests/HomomorphicEncryptionTests/HeAPITests.swift b/Tests/HomomorphicEncryptionTests/HeAPITests.swift index d6f39fa8..f84a820a 100644 --- a/Tests/HomomorphicEncryptionTests/HeAPITests.swift +++ b/Tests/HomomorphicEncryptionTests/HeAPITests.swift @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + @testable import HomomorphicEncryption import TestUtilities import XCTest @@ -1074,8 +1075,8 @@ class HeAPITests: XCTestCase { errorStdDev: ErrorStdDev.stdDev32, securityLevel: SecurityLevel.unchecked) - for encryptionParams in predefined + [custom] { - let context = try Context>(encryptionParameters: encryptionParams) + for encryptionParameters in predefined + [custom] { + let context = try Context>(encryptionParameters: encryptionParameters) try schemeEncodeDecodeTest(context: context) try schemeEncryptDecryptTest(context: context) try schemeEncryptZeroDecryptTest(context: context) diff --git a/Tests/PrivateInformationRetrievalTests/PirUtilTests.swift b/Tests/PrivateInformationRetrievalTests/PirUtilTests.swift index 59e25aad..be3260a2 100644 --- a/Tests/PrivateInformationRetrievalTests/PirUtilTests.swift +++ b/Tests/PrivateInformationRetrievalTests/PirUtilTests.swift @@ -23,7 +23,7 @@ class PirUtilTests: XCTestCase { _ keyCompression: PirKeyCompressionStrategy) throws { let degree = 32 - let encryptionParams = try EncryptionParameters( + let encryptionParameters = try EncryptionParameters( polyDegree: degree, plaintextModulus: Scheme.Scalar(17), coefficientModuli: Scheme.Scalar @@ -36,7 +36,7 @@ class PirUtilTests: XCTestCase { errorStdDev: ErrorStdDev.stdDev32, securityLevel: SecurityLevel.unchecked) - let context: Context = try Context(encryptionParameters: encryptionParams) + let context: Context = try Context(encryptionParameters: encryptionParameters) let plaintextModulus = context.plaintextModulus let logDegree = degree.log2 for logStep in 1...logDegree { diff --git a/Tests/PrivateNearestNeighborsSearchProtobufTests/ConversionTests.swift b/Tests/PrivateNearestNeighborsSearchProtobufTests/ConversionTests.swift index 16005487..37122f98 100644 --- a/Tests/PrivateNearestNeighborsSearchProtobufTests/ConversionTests.swift +++ b/Tests/PrivateNearestNeighborsSearchProtobufTests/ConversionTests.swift @@ -56,7 +56,7 @@ class ConversionTests: XCTestCase { func runTest(_: Scheme.Type) throws { let vectorDimension = 4 let clientConfig = try ClientConfig( - encryptionParams: EncryptionParameters( + encryptionParameters: EncryptionParameters( from: .insecure_n_8_logq_5x18_logt_5), scalingFactor: 123, queryPacking: .denseRow, @@ -97,13 +97,13 @@ class ConversionTests: XCTestCase { func testSerializedPlaintextMatrix() throws { func runTest(_: Scheme.Type) throws { - let encryptionParams = try EncryptionParameters(from: .insecure_n_8_logq_5x18_logt_5) - let context = try Context(encryptionParameters: encryptionParams) + let encryptionParameters = try EncryptionParameters(from: .insecure_n_8_logq_5x18_logt_5) + let context = try Context(encryptionParameters: encryptionParameters) let dimensions = try MatrixDimensions(rowCount: 5, columnCount: 4) let scalars: [[Scheme.Scalar]] = increasingData( dimensions: dimensions, - modulus: encryptionParams.plaintextModulus) + modulus: encryptionParameters.plaintextModulus) let plaintextMatrix = try PlaintextMatrix( context: context, dimensions: dimensions, @@ -114,7 +114,7 @@ class ConversionTests: XCTestCase { let deserialized = try PlaintextMatrix(deserialize: serialized, context: context) XCTAssertEqual(deserialized, plaintextMatrix) - for moduliCount in 1..(_: Scheme.Type) throws { - let encryptionParams = try EncryptionParameters(from: .insecure_n_8_logq_5x18_logt_5) - let context = try Context(encryptionParameters: encryptionParams) + let encryptionParameters = try EncryptionParameters(from: .insecure_n_8_logq_5x18_logt_5) + let context = try Context(encryptionParameters: encryptionParameters) let secretKey = try context.generateSecretKey() let dimensions = try MatrixDimensions(rowCount: 5, columnCount: 4) let scalars: [[Scheme.Scalar]] = increasingData( dimensions: dimensions, - modulus: encryptionParams.plaintextModulus) + modulus: encryptionParameters.plaintextModulus) let plaintextMatrix = try PlaintextMatrix( context: context, dimensions: dimensions, @@ -189,14 +189,14 @@ class ConversionTests: XCTestCase { func testQuery() throws { func runTest(_: Scheme.Type) throws { - let encryptionParams = try EncryptionParameters(from: .insecure_n_8_logq_5x18_logt_5) - let context = try Context(encryptionParameters: encryptionParams) + let encryptionParameters = try EncryptionParameters(from: .insecure_n_8_logq_5x18_logt_5) + let context = try Context(encryptionParameters: encryptionParameters) let secretKey = try context.generateSecretKey() let dimensions = try MatrixDimensions(rowCount: 5, columnCount: 4) let scalars: [[Scheme.Scalar]] = increasingData( dimensions: dimensions, - modulus: encryptionParams.plaintextModulus) + modulus: encryptionParameters.plaintextModulus) let plaintextMatrix = try PlaintextMatrix( context: context, dimensions: dimensions, @@ -216,7 +216,7 @@ class ConversionTests: XCTestCase { func testSerializedProcessedDatabase() throws { func runTest(_: Scheme.Type) throws { - let encryptionParams = try EncryptionParameters(from: .insecure_n_8_logq_5x18_logt_5) + let encryptionParameters = try EncryptionParameters(from: .insecure_n_8_logq_5x18_logt_5) let vectorDimension = 4 let rows = (0...10).map { rowIndex in @@ -231,7 +231,7 @@ class ConversionTests: XCTestCase { let database = Database(rows: rows) let clientConfig = try ClientConfig( - encryptionParams: encryptionParams, + encryptionParameters: encryptionParameters, scalingFactor: 123, queryPacking: .denseRow, vectorDimension: vectorDimension, @@ -241,7 +241,7 @@ class ConversionTests: XCTestCase { .generatePrimes( significantBitCounts: [7], preferringSmall: true, - nttDegree: encryptionParams.polyDegree)) + nttDegree: encryptionParameters.polyDegree)) let serverConfig = ServerConfig( clientConfig: clientConfig, databasePacking: MatrixPacking diff --git a/Tests/PrivateNearestNeighborsSearchTests/CiphertextMatrixTests.swift b/Tests/PrivateNearestNeighborsSearchTests/CiphertextMatrixTests.swift index fbdb8887..32cc3b92 100644 --- a/Tests/PrivateNearestNeighborsSearchTests/CiphertextMatrixTests.swift +++ b/Tests/PrivateNearestNeighborsSearchTests/CiphertextMatrixTests.swift @@ -36,9 +36,9 @@ final class CiphertextMatrixTests: XCTestCase { func testEncryptDecryptRoundTrip() throws { func runTest(for _: Scheme.Type) throws { let rlweParams = PredefinedRlweParameters.insecure_n_8_logq_5x18_logt_5 - let encryptionParams = try EncryptionParameters(from: rlweParams) - XCTAssert(encryptionParams.supportsSimdEncoding) - let context = try Context(encryptionParameters: encryptionParams) + let encryptionParameters = try EncryptionParameters(from: rlweParams) + XCTAssert(encryptionParameters.supportsSimdEncoding) + let context = try Context(encryptionParameters: encryptionParameters) let dimensions = try MatrixDimensions(rowCount: 10, columnCount: 4) let encodeValues: [[Scheme.Scalar]] = increasingData( dimensions: dimensions, @@ -68,9 +68,9 @@ final class CiphertextMatrixTests: XCTestCase { func testConvertRoundTrip() throws { func runTest(for _: Scheme.Type) throws { let rlweParams = PredefinedRlweParameters.insecure_n_8_logq_5x18_logt_5 - let encryptionParams = try EncryptionParameters(from: rlweParams) - XCTAssert(encryptionParams.supportsSimdEncoding) - let context = try Context(encryptionParameters: encryptionParams) + let encryptionParameters = try EncryptionParameters(from: rlweParams) + XCTAssert(encryptionParameters.supportsSimdEncoding) + let context = try Context(encryptionParameters: encryptionParameters) let dimensions = try MatrixDimensions(rowCount: 10, columnCount: 4) let encodeValues: [[Scheme.Scalar]] = increasingData( dimensions: dimensions, @@ -105,14 +105,14 @@ final class CiphertextMatrixTests: XCTestCase { count: 2), preferringSmall: false, nttDegree: degree) - let encryptionParams = try EncryptionParameters( + let encryptionParameters = try EncryptionParameters( polyDegree: degree, plaintextModulus: plaintextModulus, coefficientModuli: coefficientModuli, errorStdDev: .stdDev32, securityLevel: .unchecked) - XCTAssert(encryptionParams.supportsSimdEncoding) - let context = try Context(encryptionParameters: encryptionParams) + XCTAssert(encryptionParameters.supportsSimdEncoding) + let context = try Context(encryptionParameters: encryptionParameters) for rowCount in 1..<(2 * degree) { for columnCount in 1...extractDenseRowConfig( - for: encryptionParams, + for: encryptionParameters, dimensions: dimensions) let evaluationKey = try context.generateEvaluationKey( config: evaluationKeyConfig, diff --git a/Tests/PrivateNearestNeighborsSearchTests/ClientTests.swift b/Tests/PrivateNearestNeighborsSearchTests/ClientTests.swift index 233c8e23..6821417c 100644 --- a/Tests/PrivateNearestNeighborsSearchTests/ClientTests.swift +++ b/Tests/PrivateNearestNeighborsSearchTests/ClientTests.swift @@ -39,7 +39,8 @@ final class ClientTests: XCTestCase { XCTAssertNoThrow( try ClientConfig( - encryptionParams: EncryptionParameters(from: PredefinedRlweParameters.n_4096_logq_27_28_28_logt_17), + encryptionParameters: EncryptionParameters(from: PredefinedRlweParameters + .n_4096_logq_27_28_28_logt_17), scalingFactor: maxScalingFactor2, queryPacking: .denseRow, vectorDimension: 128, @@ -105,7 +106,7 @@ final class ClientTests: XCTestCase { func testQueryAsResponse() throws { func runTest(for _: Scheme.Type) throws { let degree = 512 - let encryptionParams = try EncryptionParameters( + let encryptionParameters = try EncryptionParameters( polyDegree: degree, plaintextModulus: Scheme.Scalar.generatePrimes( significantBitCounts: [16], @@ -117,8 +118,8 @@ final class ClientTests: XCTestCase { nttDegree: degree), errorStdDev: .stdDev32, securityLevel: .unchecked) - XCTAssert(encryptionParams.supportsSimdEncoding) - let context = try Context(encryptionParameters: encryptionParams) + XCTAssert(encryptionParameters.supportsSimdEncoding) + let context = try Context(encryptionParameters: encryptionParameters) let vectorDimension = 32 let queryDimensions = try MatrixDimensions(rowCount: 1, columnCount: vectorDimension) @@ -134,7 +135,7 @@ final class ClientTests: XCTestCase { preferringSmall: true, nttDegree: degree)] { let config = try ClientConfig( - encryptionParams: encryptionParams, + encryptionParameters: encryptionParameters, scalingFactor: scalingFactor, queryPacking: .denseRow, vectorDimension: vectorDimension, @@ -170,7 +171,7 @@ final class ClientTests: XCTestCase { func testClientServer() throws { func runSingleTest( - encryptionParams: EncryptionParameters, + encryptionParameters: EncryptionParameters, dimensions: MatrixDimensions, plaintextModuli: [Scheme.Scalar], queryCount: Int) throws @@ -182,10 +183,10 @@ final class ClientTests: XCTestCase { plaintextModuli: plaintextModuli) let evaluatonKeyConfig = try MatrixMultiplication.evaluationKeyConfig( plaintextMatrixDimensions: dimensions, - encryptionParameters: encryptionParams, + encryptionParameters: encryptionParameters, maxQueryCount: queryCount) let clientConfig = try ClientConfig( - encryptionParams: encryptionParams, + encryptionParameters: encryptionParameters, scalingFactor: scalingFactor, queryPacking: .denseRow, vectorDimension: vectorDimension, @@ -240,20 +241,20 @@ final class ClientTests: XCTestCase { count: 3), preferringSmall: false, nttDegree: degree) - let encryptionParams = try EncryptionParameters( + let encryptionParameters = try EncryptionParameters( polyDegree: degree, plaintextModulus: plaintextModuli[0], coefficientModuli: coefficientModuli, errorStdDev: .stdDev32, securityLevel: .unchecked) - XCTAssert(encryptionParams.supportsSimdEncoding) + XCTAssert(encryptionParameters.supportsSimdEncoding) let queryCount = 1 for rowCount in [degree / 2, degree, degree + 1, 3 * degree] { for dimensions in try [MatrixDimensions(rowCount: rowCount, columnCount: 16)] { for plaintextModuliCount in 1...maxPlaintextModuliCount { try runSingleTest( - encryptionParams: encryptionParams, + encryptionParameters: encryptionParameters, dimensions: dimensions, plaintextModuli: Array(plaintextModuli.prefix(plaintextModuliCount)), queryCount: queryCount) diff --git a/Tests/PrivateNearestNeighborsSearchTests/DatabaseTests.swift b/Tests/PrivateNearestNeighborsSearchTests/DatabaseTests.swift index e3a154d1..3a965ea8 100644 --- a/Tests/PrivateNearestNeighborsSearchTests/DatabaseTests.swift +++ b/Tests/PrivateNearestNeighborsSearchTests/DatabaseTests.swift @@ -20,7 +20,7 @@ import XCTest final class DatabaseTests: XCTestCase { func testSerializedProcessedDatabase() throws { func runTest(_: Scheme.Type) throws { - let encryptionParams = try EncryptionParameters(from: .insecure_n_8_logq_5x18_logt_5) + let encryptionParameters = try EncryptionParameters(from: .insecure_n_8_logq_5x18_logt_5) let vectorDimension = 4 let rows = (0...10).map { rowIndex in @@ -32,7 +32,7 @@ final class DatabaseTests: XCTestCase { let database = Database(rows: rows) let clientConfig = try ClientConfig( - encryptionParams: encryptionParams, + encryptionParameters: encryptionParameters, scalingFactor: 123, queryPacking: .denseRow, vectorDimension: vectorDimension, @@ -42,7 +42,7 @@ final class DatabaseTests: XCTestCase { .generatePrimes( significantBitCounts: [7], preferringSmall: true, - nttDegree: encryptionParams.polyDegree)) + nttDegree: encryptionParameters.polyDegree)) let serverConfig = ServerConfig( clientConfig: clientConfig, databasePacking: MatrixPacking diff --git a/Tests/PrivateNearestNeighborsSearchTests/MatrixMultiplicationTests.swift b/Tests/PrivateNearestNeighborsSearchTests/MatrixMultiplicationTests.swift index 5d9d3e79..657a7b6d 100644 --- a/Tests/PrivateNearestNeighborsSearchTests/MatrixMultiplicationTests.swift +++ b/Tests/PrivateNearestNeighborsSearchTests/MatrixMultiplicationTests.swift @@ -414,18 +414,18 @@ final class MatrixMultiplicationTests: XCTestCase { } func testEvaluationKeyContainment() throws { - let encryptionParams = try EncryptionParameters>(from: .insecure_n_512_logq_4x60_logt_20) + let encryptionParameters = try EncryptionParameters>(from: .insecure_n_512_logq_4x60_logt_20) let columnCount = 20 let plaintextDims = try MatrixDimensions(rowCount: 100, columnCount: columnCount) for maxQueryCount in 1..<(columnCount + 1) { let maxQueryCountConfig = try MatrixMultiplication.evaluationKeyConfig( plaintextMatrixDimensions: plaintextDims, - encryptionParameters: encryptionParams, + encryptionParameters: encryptionParameters, maxQueryCount: maxQueryCount) for queryCount in 1..(rlweParams: PredefinedRlweParameters, _: Scheme.Type) throws { - let encryptionParams = try EncryptionParameters(from: rlweParams) + let encryptionParameters = try EncryptionParameters(from: rlweParams) // Parameters with large polyDegree are slow in debug mode - guard encryptionParams.supportsSimdEncoding, encryptionParams.polyDegree <= 16 else { + guard encryptionParameters.supportsSimdEncoding, encryptionParameters.polyDegree <= 16 else { return } - let dims = try MatrixDimensions(rowCount: encryptionParams.polyDegree, columnCount: 2) + let dims = try MatrixDimensions(rowCount: encryptionParameters.polyDegree, columnCount: 2) let packing = MatrixPacking.denseRow - let context = try Context(encryptionParameters: encryptionParams) + let context = try Context(encryptionParameters: encryptionParameters) let values = TestUtils.getRandomPlaintextData( - count: encryptionParams.polyDegree, - in: 0.. = try context.encode( values: values, format: EncodeFormat.coefficient) @@ -80,12 +80,12 @@ final class PlaintextMatrixTests: XCTestCase { func testPlaintextMatrixDenseRowError() throws { func runTest(_: Scheme.Type) throws { let rlweParams = PredefinedRlweParameters.insecure_n_8_logq_5x18_logt_5 - let encryptionParams = try EncryptionParameters(from: rlweParams) - let context = try Context(encryptionParameters: encryptionParams) - let rowCount = encryptionParams.polyDegree + let encryptionParameters = try EncryptionParameters(from: rlweParams) + let context = try Context(encryptionParameters: encryptionParameters) + let rowCount = encryptionParameters.polyDegree let columnCount = 2 let values = TestUtils.getRandomPlaintextData( - count: encryptionParams.polyDegree, + count: encryptionParameters.polyDegree, in: 0..(for _: Scheme.Type) throws { - let encryptionParams = try EncryptionParameters( + let encryptionParameters = try EncryptionParameters( polyDegree: 8, plaintextModulus: 1153, coefficientModuli: Scheme.Scalar @@ -278,7 +278,7 @@ final class PlaintextMatrixTests: XCTestCase { nttDegree: 8), errorStdDev: .stdDev32, securityLevel: .unchecked) - let context = try Context(encryptionParameters: encryptionParams) + let context = try Context(encryptionParameters: encryptionParameters) for ((rowCount, columnCount), expected) in kats { let dimensions = try MatrixDimensions((rowCount, columnCount)) try runPlaintextMatrixInitTest( @@ -359,8 +359,8 @@ final class PlaintextMatrixTests: XCTestCase { func runTest(for _: Scheme.Type) throws { let rlweParams = PredefinedRlweParameters.insecure_n_8_logq_5x18_logt_5 - let encryptionParams = try EncryptionParameters(from: rlweParams) - let context = try Context(encryptionParameters: encryptionParams) + let encryptionParameters = try EncryptionParameters(from: rlweParams) + let context = try Context(encryptionParameters: encryptionParameters) for ((rowCount, columnCount), expected) in kats { let dimensions = try MatrixDimensions((rowCount, columnCount)) try runPlaintextMatrixInitTest( @@ -452,7 +452,7 @@ final class PlaintextMatrixTests: XCTestCase { ] func runTest(for _: Scheme.Type) throws { - let encryptionParams = try EncryptionParameters( + let encryptionParameters = try EncryptionParameters( polyDegree: 8, plaintextModulus: 1153, coefficientModuli: Scheme.Scalar @@ -462,7 +462,7 @@ final class PlaintextMatrixTests: XCTestCase { nttDegree: 8), errorStdDev: ErrorStdDev.stdDev32, securityLevel: SecurityLevel.unchecked) - let context = try Context(encryptionParameters: encryptionParams) + let context = try Context(encryptionParameters: encryptionParameters) for ((rowCount, columnCount), expected) in kats { let dimensions = try MatrixDimensions((rowCount, columnCount)) let bsgs = BabyStepGiantStep(vectorDimension: dimensions.columnCount.nextPowerOfTwo) @@ -480,7 +480,7 @@ final class PlaintextMatrixTests: XCTestCase { func testDiagonalRotation() throws { func runTest(for _: Scheme.Type) throws { - let encryptionParams = try EncryptionParameters( + let encryptionParameters = try EncryptionParameters( polyDegree: 16, plaintextModulus: 1153, coefficientModuli: Scheme.Scalar @@ -490,14 +490,14 @@ final class PlaintextMatrixTests: XCTestCase { nttDegree: 16), errorStdDev: ErrorStdDev.stdDev32, securityLevel: SecurityLevel.unchecked) - let context = try Context(encryptionParameters: encryptionParams) + let context = try Context(encryptionParameters: encryptionParameters) let dimensions = try MatrixDimensions(rowCount: 4, columnCount: 5) let bsgs = BabyStepGiantStep(vectorDimension: dimensions.columnCount) let values: [[Scheme.Scalar]] = increasingData( dimensions: dimensions, - modulus: encryptionParams.plaintextModulus) + modulus: encryptionParameters.plaintextModulus) let rotatedDiagonalPrefixes: [[Scheme.Scalar]] = [[1, 7, 13, 19], [2, 8, 14, 20], [3, 9, 15, 0], @@ -508,7 +508,7 @@ final class PlaintextMatrixTests: XCTestCase { [12, 18, 0, 0, 0, 0, 0, 6]] let expected: [[Scheme.Scalar]] = rotatedDiagonalPrefixes.map { diagonal in - diagonal + Array(repeating: 0, count: encryptionParams.polyDegree - diagonal.count) + diagonal + Array(repeating: 0, count: encryptionParameters.polyDegree - diagonal.count) } let plaintextMatrix = try PlaintextMatrix( @@ -529,9 +529,9 @@ final class PlaintextMatrixTests: XCTestCase { func testPlaintextMatrixConversion() throws { func runTest(for _: Scheme.Type) throws { let rlweParams = PredefinedRlweParameters.insecure_n_8_logq_5x18_logt_5 - let encryptionParams = try EncryptionParameters(from: rlweParams) - XCTAssert(encryptionParams.supportsSimdEncoding) - let context = try Context(encryptionParameters: encryptionParams) + let encryptionParameters = try EncryptionParameters(from: rlweParams) + XCTAssert(encryptionParameters.supportsSimdEncoding) + let context = try Context(encryptionParameters: encryptionParameters) let dimensions = try MatrixDimensions(rowCount: 10, columnCount: 4) let encodeValues: [[Scheme.Scalar]] = increasingData( dimensions: dimensions,