Skip to content

Commit

Permalink
Add Format suffix to PolyRq/ConvertTo{Coeff,Eval} (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
fboemer authored Sep 4, 2024
1 parent 9b101fd commit 562dd5f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
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

0 comments on commit 562dd5f

Please sign in to comment.