@@ -1376,34 +1376,68 @@ public enum HeAPITestHelpers {
13761376
13771377 /// Testing multiply inverse power of x.
13781378 @inlinable
1379- public static func multiplyInverseTest < Scheme: HeScheme > (
1379+ public static func multiplyPowerOfXTest < Scheme: HeScheme > (
13801380 context: Scheme . Context ,
13811381 scheme _: Scheme . Type ) async throws
13821382 {
13831383 let testEnv = try HeAPITestHelpers . TestEnv< Scheme> ( context: context, format: . coefficient)
13841384
1385- var coeffCiphertext1 = try await testEnv. ciphertext1. convertToCoeffFormat ( )
1386- var coeffCiphertext2 = coeffCiphertext1
1387- var coeffCiphertext3 = coeffCiphertext1
1388- var coeffCiphertext4 = coeffCiphertext1
1385+ var coeffCiphertext = try await testEnv. ciphertext1. convertToCoeffFormat ( )
1386+ var coeffCiphertexts = Array ( repeating: coeffCiphertext, count: 8 )
13891387 let degree = context. degree
13901388 let plaintextModulus = context. plaintextModulus
1389+
1390+ try Scheme . multiplyPowerOfX ( & coeffCiphertext, power: 0 )
1391+ try testEnv. checkDecryptsDecodes ( ciphertext: coeffCiphertext, format: . coefficient, expected: testEnv. data1)
1392+
13911393 let power1 = Int . random ( in: 0 ..< degree)
1394+ try Scheme . multiplyPowerOfX ( & coeffCiphertexts[ 0 ] , power: power1)
1395+ try await Scheme . multiplyPowerOfXAsync ( & coeffCiphertexts[ 1 ] , power: power1)
1396+
1397+ try Scheme . multiplyPowerOfX ( & coeffCiphertexts[ 2 ] , power: - power1)
1398+ try await Scheme . multiplyPowerOfXAsync ( & coeffCiphertexts[ 3 ] , power: - power1)
1399+
13921400 let power2 = Int . random ( in: degree..< ( degree << 1 ) )
1393- try Scheme . multiplyInversePowerOfX ( & coeffCiphertext1, power: power1)
1394- try Scheme . multiplyInversePowerOfX ( & coeffCiphertext2, power: power2)
1395- try await Scheme . multiplyInversePowerOfXAsync ( & coeffCiphertext3, power: power1)
1396- try await Scheme . multiplyInversePowerOfXAsync ( & coeffCiphertext4, power: power2)
13971401
1398- let expectedData1 = Array ( testEnv. data1 [ power1..< degree] + testEnv. data1 [ 0 ..< power1]
1402+ try Scheme . multiplyPowerOfX ( & coeffCiphertexts[ 4 ] , power: power2)
1403+ try await Scheme . multiplyPowerOfXAsync ( & coeffCiphertexts[ 5 ] , power: power2)
1404+
1405+ try Scheme . multiplyPowerOfX ( & coeffCiphertexts[ 6 ] , power: - power2)
1406+ try await Scheme . multiplyPowerOfXAsync ( & coeffCiphertexts[ 7 ] , power: - power2)
1407+
1408+ let expectedData1 = Array ( testEnv. data1 [ degree - power1..< degree]
1409+ . map { $0. negateMod ( modulus: plaintextModulus) } +
1410+ testEnv. data1 [ 0 ..< degree - power1] )
1411+
1412+ let expectedDataNeg1 = Array ( testEnv. data1 [ power1..< degree] + testEnv. data1 [ 0 ..< power1]
13991413 . map { $0. negateMod ( modulus: plaintextModulus) } )
1400- let expectedData2 = Array ( testEnv. data1 [ ( power2 - degree) ..< degree]
1414+
1415+ let expectedData2 = Array ( testEnv. data1 [ ( 2 * degree - power2) ..< degree] +
1416+ testEnv. data1 [ 0 ..< ( 2 * degree - power2) ] . map { $0. negateMod ( modulus: plaintextModulus) } )
1417+
1418+ let expectedDataNeg2 = Array ( testEnv. data1 [ ( power2 - degree) ..< degree]
14011419 . map { $0. negateMod ( modulus: plaintextModulus) } + testEnv. data1 [ 0 ..< ( power2 - degree) ] )
14021420
1403- try testEnv. checkDecryptsDecodes ( ciphertext: coeffCiphertext1, format: . coefficient, expected: expectedData1)
1404- try testEnv. checkDecryptsDecodes ( ciphertext: coeffCiphertext2, format: . coefficient, expected: expectedData2)
1405- try testEnv. checkDecryptsDecodes ( ciphertext: coeffCiphertext3, format: . coefficient, expected: expectedData1)
1406- try testEnv. checkDecryptsDecodes ( ciphertext: coeffCiphertext4, format: . coefficient, expected: expectedData2)
1421+ try testEnv. checkDecryptsDecodes ( ciphertext: coeffCiphertexts [ 0 ] , format: . coefficient, expected: expectedData1)
1422+ try testEnv. checkDecryptsDecodes ( ciphertext: coeffCiphertexts [ 1 ] , format: . coefficient, expected: expectedData1)
1423+ try testEnv. checkDecryptsDecodes (
1424+ ciphertext: coeffCiphertexts [ 2 ] ,
1425+ format: . coefficient,
1426+ expected: expectedDataNeg1)
1427+ try testEnv. checkDecryptsDecodes (
1428+ ciphertext: coeffCiphertexts [ 3 ] ,
1429+ format: . coefficient,
1430+ expected: expectedDataNeg1)
1431+ try testEnv. checkDecryptsDecodes ( ciphertext: coeffCiphertexts [ 4 ] , format: . coefficient, expected: expectedData2)
1432+ try testEnv. checkDecryptsDecodes ( ciphertext: coeffCiphertexts [ 5 ] , format: . coefficient, expected: expectedData2)
1433+ try testEnv. checkDecryptsDecodes (
1434+ ciphertext: coeffCiphertexts [ 6 ] ,
1435+ format: . coefficient,
1436+ expected: expectedDataNeg2)
1437+ try testEnv. checkDecryptsDecodes (
1438+ ciphertext: coeffCiphertexts [ 7 ] ,
1439+ format: . coefficient,
1440+ expected: expectedDataNeg2)
14071441 }
14081442
14091443 /// Testing ntt and intt on ciphertexts.
0 commit comments