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 Format suffix to PolyRq/ConvertTo{Coeff,Eval} #90

Merged
merged 1 commit into from
Sep 4, 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
2 changes: 1 addition & 1 deletion Sources/HomomorphicEncryption/Bfv/Bfv+Keys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ extension Bfv {
var ciphertextProd: EvalCiphertext = Ciphertext(context: context,
polys: polys,
correctionFactor: 1)
let targetCoeff = try target.convertToCoeff()
let targetCoeff = try target.convertToCoeffFormat()

let keyCiphers = keySwitchingKey.ciphers
for rnsIndex in 0..<rnsModuliCount {
Expand Down
2 changes: 1 addition & 1 deletion Sources/HomomorphicEncryption/Plaintext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ extension Plaintext {
return plaintext
}
let rnsTool = context.getRnsTool(moduliCount: moduli.count)
var plaintextData = try poly.convertToCoeff().data
var plaintextData = try poly.convertToCoeffFormat().data
for index in plaintextData.rowIndices(row: 0) {
let condition = plaintextData[index].constantTimeGreaterThanOrEqual(rnsTool.tThreshold)
plaintextData[index] = Scheme.Scalar.constantTimeSelect(
Expand Down
8 changes: 4 additions & 4 deletions Sources/HomomorphicEncryption/PolyRq/PolyRq.swift
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ extension PolyRq {
/// If the polynomial is already in ``Coeff`` format, the input polynomial is returned with no conversion.
/// - Returns: The polynomial in ``Coeff`` format.
@inlinable
public func convertToCoeff() throws -> PolyRq<T, Coeff> {
public func convertToCoeffFormat() throws -> PolyRq<T, Coeff> {
switch F.self {
case is Coeff.Type:
guard let poly = self as? PolyRq<T, Coeff> else {
Expand All @@ -453,7 +453,7 @@ extension PolyRq {
/// If the polynomial is already in ``Eval`` format, the input polynomial is returned with no conversion.
/// - Returns: The polynomial in ``Eval`` format.
@inlinable
public func convertToEval() throws -> PolyRq<T, Eval> {
public func convertToEvalFormat() throws -> PolyRq<T, Eval> {
switch F.self {
case is Coeff.Type:
guard let poly = self as? PolyRq<T, Coeff> else {
Expand All @@ -476,12 +476,12 @@ extension PolyRq {
public func convertFormat<Format: PolyFormat>() throws -> PolyRq<T, Format> {
switch Format.self {
case is Coeff.Type:
guard let poly = try convertToCoeff() as? PolyRq<T, Format> else {
guard let poly = try convertToCoeffFormat() as? PolyRq<T, Format> else {
throw HeError.errorCastingPolyFormat(from: F.self, to: Format.self)
}
return poly
case is Eval.Type:
guard let poly = try convertToEval() as? PolyRq<T, Format> else {
guard let poly = try convertToEvalFormat() as? PolyRq<T, Format> else {
throw HeError.errorCastingPolyFormat(from: F.self, to: Format.self)
}
return poly
Expand Down
8 changes: 4 additions & 4 deletions Tests/HomomorphicEncryptionTests/NttTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ final class NttTests: XCTestCase {

XCTAssertEqual(try polyCoeff.forwardNtt(), polyEval)
XCTAssertEqual(try polyEval.inverseNtt(), polyCoeff)
XCTAssertEqual(try polyEval.convertToCoeff(), polyCoeff)
XCTAssertEqual(try polyCoeff.convertToCoeff(), polyCoeff)
XCTAssertEqual(try polyEval.convertToEval(), polyEval)
XCTAssertEqual(try polyCoeff.convertToEval(), polyEval)
XCTAssertEqual(try polyEval.convertToCoeffFormat(), polyCoeff)
XCTAssertEqual(try polyCoeff.convertToCoeffFormat(), polyCoeff)
XCTAssertEqual(try polyEval.convertToEvalFormat(), polyEval)
XCTAssertEqual(try polyCoeff.convertToEvalFormat(), polyEval)
}

func testNtt2() throws {
Expand Down
Loading