lib.rs 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478
  1. #![allow(dead_code)]
  2. #![allow(non_snake_case)]
  3. #![allow(unused_imports)]
  4. use cxx::{CxxVector, let_cxx_string};
  5. pub use cxx;
  6. #[cxx::bridge(namespace = "openfhe")]
  7. pub mod ffi
  8. {
  9. #[repr(i32)]
  10. enum COMPRESSION_LEVEL
  11. {
  12. COMPACT = 2,
  13. SLACK = 3,
  14. }
  15. #[repr(i32)]
  16. enum DecryptionNoiseMode
  17. {
  18. FIXED_NOISE_DECRYPT = 0,
  19. NOISE_FLOODING_DECRYPT,
  20. }
  21. #[repr(i32)]
  22. enum EncryptionTechnique
  23. {
  24. STANDARD = 0,
  25. EXTENDED,
  26. }
  27. #[repr(i32)]
  28. enum ExecutionMode
  29. {
  30. EXEC_EVALUATION = 0,
  31. EXEC_NOISE_ESTIMATION,
  32. }
  33. #[repr(i32)]
  34. enum Format
  35. {
  36. EVALUATION = 0,
  37. COEFFICIENT = 1
  38. }
  39. #[repr(i32)]
  40. enum KeySwitchTechnique
  41. {
  42. INVALID_KS_TECH = 0,
  43. BV,
  44. HYBRID,
  45. }
  46. #[repr(i32)]
  47. enum MultipartyMode
  48. {
  49. INVALID_MULTIPARTY_MODE = 0,
  50. FIXED_NOISE_MULTIPARTY,
  51. NOISE_FLOODING_MULTIPARTY,
  52. }
  53. #[repr(i32)]
  54. enum MultiplicationTechnique
  55. {
  56. BEHZ = 0,
  57. HPS,
  58. HPSPOVERQ,
  59. HPSPOVERQLEVELED,
  60. }
  61. #[repr(i32)]
  62. enum PKESchemeFeature
  63. {
  64. PKE = 0x01,
  65. KEYSWITCH = 0x02,
  66. PRE = 0x04,
  67. LEVELEDSHE = 0x08,
  68. ADVANCEDSHE = 0x10,
  69. MULTIPARTY = 0x20,
  70. FHE = 0x40,
  71. SCHEMESWITCH = 0x80,
  72. }
  73. #[repr(i32)]
  74. enum PlaintextEncodings
  75. {
  76. INVALID_ENCODING = 0,
  77. COEF_PACKED_ENCODING,
  78. PACKED_ENCODING,
  79. STRING_ENCODING,
  80. CKKS_PACKED_ENCODING,
  81. }
  82. #[repr(i32)]
  83. enum ProxyReEncryptionMode
  84. {
  85. NOT_SET = 0,
  86. INDCPA,
  87. FIXED_NOISE_HRA,
  88. NOISE_FLOODING_HRA,
  89. }
  90. #[repr(i32)]
  91. enum ScalingTechnique
  92. {
  93. FIXEDMANUAL = 0,
  94. FIXEDAUTO,
  95. FLEXIBLEAUTO,
  96. FLEXIBLEAUTOEXT,
  97. NORESCALE,
  98. INVALID_RS_TECHNIQUE,
  99. }
  100. #[repr(i32)]
  101. enum SCHEME
  102. {
  103. INVALID_SCHEME = 0,
  104. CKKSRNS_SCHEME,
  105. BFVRNS_SCHEME,
  106. BGVRNS_SCHEME,
  107. }
  108. #[repr(i32)]
  109. enum SecretKeyDist
  110. {
  111. GAUSSIAN = 0,
  112. UNIFORM_TERNARY = 1,
  113. SPARSE_TERNARY = 2,
  114. }
  115. #[repr(i32)]
  116. enum SecurityLevel
  117. {
  118. HEStd_128_classic,
  119. HEStd_192_classic,
  120. HEStd_256_classic,
  121. HEStd_128_quantum,
  122. HEStd_192_quantum,
  123. HEStd_256_quantum,
  124. HEStd_NotSet,
  125. }
  126. #[repr(i32)]
  127. enum SerialMode
  128. {
  129. BINARY = 0,
  130. JSON = 1,
  131. }
  132. struct ComplexPair
  133. {
  134. re: f64,
  135. im: f64,
  136. }
  137. unsafe extern "C++"
  138. {
  139. // includes
  140. include!("openfhe/src/AssociativeContainers.h");
  141. include!("openfhe/src/Ciphertext.h");
  142. include!("openfhe/src/CryptoContext.h");
  143. include!("openfhe/src/CryptoParametersBase.h");
  144. include!("openfhe/src/DCRTPoly.h");
  145. include!("openfhe/src/DecryptResult.h");
  146. include!("openfhe/src/EncodingParams.h");
  147. include!("openfhe/src/EvalKey.h");
  148. include!("openfhe/src/KeyPair.h");
  149. include!("openfhe/src/LWEPrivateKey.h");
  150. include!("openfhe/src/Params.h");
  151. include!("openfhe/src/Plaintext.h");
  152. include!("openfhe/src/PrivateKey.h");
  153. include!("openfhe/src/PublicKey.h");
  154. include!("openfhe/src/SchemeBase.h");
  155. include!("openfhe/src/SequenceContainers.h");
  156. include!("openfhe/src/SerialDeserial.h");
  157. include!("openfhe/src/Trapdoor.h");
  158. // enums
  159. type COMPRESSION_LEVEL;
  160. type DecryptionNoiseMode;
  161. type EncryptionTechnique;
  162. type ExecutionMode;
  163. type Format;
  164. type KeySwitchTechnique;
  165. type MultipartyMode;
  166. type MultiplicationTechnique;
  167. type PKESchemeFeature;
  168. type PlaintextEncodings;
  169. type ProxyReEncryptionMode;
  170. type ScalingTechnique;
  171. type SCHEME;
  172. type SecretKeyDist;
  173. type SecurityLevel;
  174. type SerialMode;
  175. // types
  176. type CiphertextDCRTPoly;
  177. type CryptoContextDCRTPoly;
  178. type CryptoParametersBaseDCRTPoly;
  179. type DCRTPoly;
  180. type DCRTPolyImpl;
  181. type DCRTPolyParams;
  182. type DecryptResult;
  183. type EncodingParams;
  184. type EvalKeyDCRTPoly;
  185. type KeyPairDCRTPoly;
  186. type ILDCRTParams;
  187. type LWEPrivateKey;
  188. type MapFromIndexToEvalKey;
  189. type MapFromStringToMapFromIndexToEvalKey;
  190. type MapFromStringToVectorOfEvalKeys;
  191. type Params;
  192. type ParamsBFVRNS;
  193. type ParamsBGVRNS;
  194. type ParamsCKKSRNS;
  195. type Plaintext;
  196. type PrivateKeyDCRTPoly;
  197. type PublicKeyDCRTPoly;
  198. type SchemeBaseDCRTPoly;
  199. type SetOfUints;
  200. type UnorderedMapFromIndexToDCRTPoly;
  201. type VectorOfCiphertexts;
  202. type VectorOfDCRTPolys;
  203. type VectorOfEvalKeys;
  204. type VectorOfLWECiphertexts;
  205. type VectorOfPrivateKeys;
  206. type VectorOfVectorOfCiphertexts;
  207. type TrapdoorOutput;
  208. }
  209. // CiphertextDCRTPoly
  210. unsafe extern "C++"
  211. {
  212. // Generator functions
  213. fn DCRTPolyGenNullCiphertext() -> UniquePtr<CiphertextDCRTPoly>;
  214. }
  215. // CryptoContextDCRTPoly
  216. unsafe extern "C++"
  217. {
  218. fn ComposedEvalMult(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly,
  219. ciphertext2: &CiphertextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>;
  220. fn Compress(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  221. towersLeft: /* 1 */ u32) -> UniquePtr<CiphertextDCRTPoly>;
  222. fn DecryptByCiphertextAndPrivateKey(self: &CryptoContextDCRTPoly,
  223. ciphertext: &CiphertextDCRTPoly,
  224. privateKey: &PrivateKeyDCRTPoly,
  225. plaintext: Pin<&mut Plaintext>)
  226. -> UniquePtr<DecryptResult>;
  227. fn DecryptByPrivateKeyAndCiphertext(self: &CryptoContextDCRTPoly,
  228. privateKey: &PrivateKeyDCRTPoly,
  229. ciphertext: &CiphertextDCRTPoly,
  230. plaintext: Pin<&mut Plaintext>)
  231. -> UniquePtr<DecryptResult>;
  232. fn EnableByFeature(self: &CryptoContextDCRTPoly, feature: PKESchemeFeature);
  233. fn EnableByMask(self: &CryptoContextDCRTPoly, featureMask: u32);
  234. fn EncryptByPrivateKey(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  235. plaintext: &Plaintext) -> UniquePtr<CiphertextDCRTPoly>;
  236. fn EncryptByPublicKey(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly,
  237. plaintext: &Plaintext) -> UniquePtr<CiphertextDCRTPoly>;
  238. fn EvalAddByCiphertextAndConst(self: &CryptoContextDCRTPoly,
  239. ciphertext: &CiphertextDCRTPoly, constant: f64)
  240. -> UniquePtr<CiphertextDCRTPoly>;
  241. fn EvalAddByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly,
  242. ciphertext: &CiphertextDCRTPoly, plaintext: &Plaintext)
  243. -> UniquePtr<CiphertextDCRTPoly>;
  244. fn EvalAddByCiphertexts(self: &CryptoContextDCRTPoly,
  245. ciphertext1: &CiphertextDCRTPoly,ciphertext2: &CiphertextDCRTPoly)
  246. -> UniquePtr<CiphertextDCRTPoly>;
  247. fn EvalAddByConstAndCiphertext(self: &CryptoContextDCRTPoly,
  248. constant: f64, ciphertext: &CiphertextDCRTPoly)
  249. -> UniquePtr<CiphertextDCRTPoly>;
  250. fn EvalAddByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly,
  251. plaintext: &Plaintext, ciphertext: &CiphertextDCRTPoly)
  252. -> UniquePtr<CiphertextDCRTPoly>;
  253. fn EvalAddInPlaceByCiphertextAndConst(self: &CryptoContextDCRTPoly,
  254. ciphertext: Pin<&mut CiphertextDCRTPoly>,
  255. constant: f64);
  256. fn EvalAddInPlaceByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly,
  257. ciphertext: Pin<&mut CiphertextDCRTPoly>,
  258. plaintext: &Plaintext);
  259. fn EvalAddInPlaceByCiphertexts(self: &CryptoContextDCRTPoly,
  260. ciphertext1: Pin<&mut CiphertextDCRTPoly>,
  261. ciphertext2: &CiphertextDCRTPoly);
  262. fn EvalAddInPlaceByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64,
  263. ciphertext: Pin<&mut CiphertextDCRTPoly>);
  264. fn EvalAddInPlaceByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly,
  265. plaintext: &Plaintext,
  266. ciphertext: Pin<&mut CiphertextDCRTPoly>);
  267. fn EvalAddMany(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts)
  268. -> UniquePtr<CiphertextDCRTPoly>;
  269. fn EvalAddManyInPlace(self: &CryptoContextDCRTPoly,
  270. ciphertextVec: Pin<&mut VectorOfCiphertexts>)
  271. -> UniquePtr<CiphertextDCRTPoly>;
  272. fn EvalAddMutableByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly,
  273. ciphertext: Pin<&mut CiphertextDCRTPoly>,
  274. plaintext: &Plaintext)
  275. -> UniquePtr<CiphertextDCRTPoly>;
  276. fn EvalAddMutableByCiphertexts(self: &CryptoContextDCRTPoly,
  277. ciphertext1: Pin<&mut CiphertextDCRTPoly>,
  278. ciphertext2: Pin<&mut CiphertextDCRTPoly>)
  279. -> UniquePtr<CiphertextDCRTPoly>;
  280. fn EvalAddMutableByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly,
  281. plaintext: &Plaintext,
  282. ciphertext: Pin<&mut CiphertextDCRTPoly>)
  283. -> UniquePtr<CiphertextDCRTPoly>;
  284. fn EvalAddMutableInPlace(self: &CryptoContextDCRTPoly,
  285. ciphertext1: Pin<&mut CiphertextDCRTPoly>,
  286. ciphertext2: Pin<&mut CiphertextDCRTPoly>);
  287. fn EvalAtIndex(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, index: u32)
  288. -> UniquePtr<CiphertextDCRTPoly>;
  289. fn EvalAtIndexKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  290. indexList: &CxxVector<i32>,
  291. publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly);
  292. fn EvalAutomorphism(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, i: u32,
  293. evalKeyMap: &MapFromIndexToEvalKey) -> UniquePtr<CiphertextDCRTPoly>;
  294. fn EvalAutomorphismKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  295. indexList: &CxxVector<u32>) -> UniquePtr<MapFromIndexToEvalKey>;
  296. fn EvalBootstrap(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  297. numIterations: /* 1 */ u32, precision: /* 0 */ u32)
  298. -> UniquePtr<CiphertextDCRTPoly>;
  299. fn EvalBootstrapKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  300. slots: u32);
  301. fn EvalBootstrapPrecompute(self: &CryptoContextDCRTPoly, slots: /* 0 */ u32);
  302. fn EvalBootstrapSetup(self: &CryptoContextDCRTPoly,
  303. levelBudget: /* {5, 4} */ &CxxVector<u32>,
  304. dim1: /* {0, 0} */ &CxxVector<u32>, slots: /* 0 */ u32,
  305. correctionFactor: /* 0 */ u32, precompute: /* true */ bool);
  306. fn EvalCKKStoFHEW(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  307. numCtxts: /* 0 */ u32) -> UniquePtr<VectorOfLWECiphertexts>;
  308. fn EvalCKKStoFHEWKeyGen(self: &CryptoContextDCRTPoly, keyPair: &KeyPairDCRTPoly,
  309. lwesk: &LWEPrivateKey);
  310. fn EvalCKKStoFHEWPrecompute(self: &CryptoContextDCRTPoly, scale: /* 1.0 */ f64);
  311. fn EvalChebyshevFunction(self: &CryptoContextDCRTPoly, func: fn(f64, ret: &mut f64),
  312. ciphertext: &CiphertextDCRTPoly, a: f64, b: f64, degree: u32)
  313. -> UniquePtr<CiphertextDCRTPoly>;
  314. fn EvalChebyshevSeries(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  315. coefficients: &CxxVector<f64>, a: f64, b: f64)
  316. -> UniquePtr<CiphertextDCRTPoly>;
  317. fn EvalChebyshevSeriesLinear(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  318. coefficients: &CxxVector<f64>, a: f64, b: f64)
  319. -> UniquePtr<CiphertextDCRTPoly>;
  320. fn EvalChebyshevSeriesPS(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  321. coefficients: &CxxVector<f64>, a: f64, b: f64)
  322. -> UniquePtr<CiphertextDCRTPoly>;
  323. fn EvalCompareSchemeSwitching(self: &CryptoContextDCRTPoly,
  324. ciphertext1: &CiphertextDCRTPoly,
  325. ciphertext2: &CiphertextDCRTPoly, numCtxts: /* 0 */ u32,
  326. numSlots: /* 0 */ u32, pLWE: /* 0 */ u32,
  327. scaleSign: /* 1.0 */ f64, unit: /* false */ bool)
  328. -> UniquePtr<CiphertextDCRTPoly>;
  329. fn EvalCompareSwitchPrecompute(self: &CryptoContextDCRTPoly, pLWE: u32, scaleSign: f64,
  330. unit: bool);
  331. fn EvalCos(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64, b: f64,
  332. degree: u32) -> UniquePtr<CiphertextDCRTPoly>;
  333. fn EvalDivide(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64,
  334. b: f64, degree: u32) -> UniquePtr<CiphertextDCRTPoly>;
  335. fn EvalFHEWtoCKKS(self: &CryptoContextDCRTPoly,
  336. LWECiphertexts: Pin<&mut VectorOfLWECiphertexts>, numCtxts: /* 0 */ u32,
  337. numSlots: /* 0 */ u32, p: /* 4 */ u32, pmin: /* 0.0 */ f64,
  338. pmax: /* 2.0 */ f64, dim1: /* 0 */ u32) -> UniquePtr<CiphertextDCRTPoly>;
  339. fn EvalFHEWtoCKKSKeyGen(self: &CryptoContextDCRTPoly, keyPair: &KeyPairDCRTPoly,
  340. lwesk: &LWEPrivateKey, numSlots: /* 0 */ u32,
  341. numCtxts: /* 0 */ u32, dim1: /* 0 */ u32, L: /* 0 */ u32);
  342. fn EvalFastRotation(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  343. index: u32, m: u32, digits: &VectorOfDCRTPolys)
  344. -> UniquePtr<CiphertextDCRTPoly>;
  345. fn EvalFastRotationExt(self: &CryptoContextDCRTPoly,
  346. ciphertext: &CiphertextDCRTPoly, index: u32,
  347. digits: &VectorOfDCRTPolys, addFirst: bool)
  348. -> UniquePtr<CiphertextDCRTPoly>;
  349. fn EvalFastRotationPrecompute(self: &CryptoContextDCRTPoly,
  350. ciphertext: &CiphertextDCRTPoly)
  351. -> UniquePtr<VectorOfDCRTPolys>;
  352. fn EvalInnerProductByCiphertexts(self: &CryptoContextDCRTPoly,
  353. ciphertext1: &CiphertextDCRTPoly,
  354. ciphertext2: &CiphertextDCRTPoly, batchSize: u32)
  355. -> UniquePtr<CiphertextDCRTPoly>;
  356. fn EvalInnerProductByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly,
  357. ciphertext: &CiphertextDCRTPoly,
  358. plaintext: &Plaintext, batchSize: u32)
  359. -> UniquePtr<CiphertextDCRTPoly>;
  360. fn EvalInnerProductByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly,
  361. plaintext: &Plaintext,
  362. ciphertext: &CiphertextDCRTPoly,
  363. batchSize: u32)
  364. -> UniquePtr<CiphertextDCRTPoly>;
  365. fn EvalLinearWSumMutableByConstantsAndVectorOfCiphertexts(self: &CryptoContextDCRTPoly,
  366. constantsVec: &CxxVector<f64>,
  367. ciphertextVec:
  368. Pin<&mut VectorOfCiphertexts>)
  369. -> UniquePtr<CiphertextDCRTPoly>;
  370. fn EvalLinearWSumMutableByVectorOfCiphertextsAndConstants(self: &CryptoContextDCRTPoly,
  371. ciphertextVec:
  372. Pin<&mut VectorOfCiphertexts>,
  373. constantsVec: &CxxVector<f64>)
  374. -> UniquePtr<CiphertextDCRTPoly>;
  375. fn EvalLogistic(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64,
  376. b: f64, degree: u32) -> UniquePtr<CiphertextDCRTPoly>;
  377. fn EvalMaxSchemeSwitching(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  378. publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32,
  379. numSlots: /* 0 */ u32, pLWE: /* 0 */ u32,
  380. scaleSign: /* 1.0 */ f64) -> UniquePtr<VectorOfCiphertexts>;
  381. fn EvalMaxSchemeSwitchingAlt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  382. publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32,
  383. numSlots: /* 0 */ u32, pLWE: /* 0 */ u32,
  384. scaleSign: /* 1.0 */ f64) -> UniquePtr<VectorOfCiphertexts>;
  385. fn EvalMerge(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts)
  386. -> UniquePtr<CiphertextDCRTPoly>;
  387. fn EvalMinSchemeSwitching(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  388. publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32,
  389. numSlots: /* 0 */ u32, pLWE: /* 0 */ u32,
  390. scaleSign: /* 1.0 */ f64) -> UniquePtr<VectorOfCiphertexts>;
  391. fn EvalMinSchemeSwitchingAlt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  392. publicKey: &PublicKeyDCRTPoly, numValues: /* 0 */ u32,
  393. numSlots: /* 0 */ u32, pLWE: /* 0 */ u32,
  394. scaleSign: /* 1.0 */ f64) -> UniquePtr<VectorOfCiphertexts>;
  395. fn EvalMultAndRelinearize(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly,
  396. ciphertext2: &CiphertextDCRTPoly)
  397. -> UniquePtr<CiphertextDCRTPoly>;
  398. fn EvalMultByCiphertextAndConst(self: &CryptoContextDCRTPoly,
  399. ciphertext: &CiphertextDCRTPoly, constant: f64)
  400. -> UniquePtr<CiphertextDCRTPoly>;
  401. fn EvalMultByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly,
  402. ciphertext: &CiphertextDCRTPoly, plaintext: &Plaintext)
  403. -> UniquePtr<CiphertextDCRTPoly>;
  404. fn EvalMultByCiphertexts(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly,
  405. ciphertext2: &CiphertextDCRTPoly)
  406. -> UniquePtr<CiphertextDCRTPoly>;
  407. fn EvalMultByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64,
  408. ciphertext: &CiphertextDCRTPoly)
  409. -> UniquePtr<CiphertextDCRTPoly>;
  410. fn EvalMultByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly, plaintext: &Plaintext,
  411. ciphertext: &CiphertextDCRTPoly)
  412. -> UniquePtr<CiphertextDCRTPoly>;
  413. fn EvalMultInPlaceByCiphertextAndConst(self: &CryptoContextDCRTPoly,
  414. ciphertext: Pin<&mut CiphertextDCRTPoly>,
  415. constant: f64);
  416. fn EvalMultInPlaceByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64,
  417. ciphertext: Pin<&mut CiphertextDCRTPoly>);
  418. fn EvalMultKeyGen(self: &CryptoContextDCRTPoly, key: &PrivateKeyDCRTPoly);
  419. fn EvalMultKeysGen(self: &CryptoContextDCRTPoly, key: &PrivateKeyDCRTPoly);
  420. fn EvalMultMany(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts)
  421. -> UniquePtr<CiphertextDCRTPoly>;
  422. fn EvalMultMutableByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly,
  423. ciphertext: Pin<&mut CiphertextDCRTPoly>,
  424. plaintext: &Plaintext)
  425. -> UniquePtr<CiphertextDCRTPoly>;
  426. fn EvalMultMutableByCiphertexts(self: &CryptoContextDCRTPoly,
  427. ciphertext1: Pin<&mut CiphertextDCRTPoly>,
  428. ciphertext2: Pin<&mut CiphertextDCRTPoly>)
  429. -> UniquePtr<CiphertextDCRTPoly>;
  430. fn EvalMultMutableByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly,
  431. plaintext: &Plaintext,
  432. ciphertext: Pin<&mut CiphertextDCRTPoly>)
  433. -> UniquePtr<CiphertextDCRTPoly>;
  434. fn EvalMultMutableInPlace(self: &CryptoContextDCRTPoly,
  435. ciphertext1: Pin<&mut CiphertextDCRTPoly>,
  436. ciphertext2: Pin<&mut CiphertextDCRTPoly>);
  437. fn EvalMultNoRelin(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly,
  438. ciphertext2: &CiphertextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>;
  439. fn EvalNegate(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
  440. -> UniquePtr<CiphertextDCRTPoly>;
  441. fn EvalNegateInPlace(self: &CryptoContextDCRTPoly,
  442. ciphertext: Pin<&mut CiphertextDCRTPoly>);
  443. fn EvalPoly(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  444. coefficients: &CxxVector<f64>) -> UniquePtr<CiphertextDCRTPoly>;
  445. fn EvalPolyLinear(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  446. coefficients: &CxxVector<f64>)-> UniquePtr<CiphertextDCRTPoly>;
  447. fn EvalPolyPS(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  448. coefficients: &CxxVector<f64>) -> UniquePtr<CiphertextDCRTPoly>;
  449. fn EvalRotate(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, index: i32)
  450. -> UniquePtr<CiphertextDCRTPoly>;
  451. fn EvalRotateKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  452. indexList: &CxxVector<i32>,
  453. publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly);
  454. fn EvalSchemeSwitchingKeyGen(self: &CryptoContextDCRTPoly, keyPair: &KeyPairDCRTPoly,
  455. lwesk: &LWEPrivateKey);
  456. fn EvalSin(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, a: f64, b: f64,
  457. degree: u32) -> UniquePtr<CiphertextDCRTPoly>;
  458. fn EvalSquare(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
  459. -> UniquePtr<CiphertextDCRTPoly>;
  460. fn EvalSquareInPlace(self: &CryptoContextDCRTPoly,
  461. ciphertext: Pin<&mut CiphertextDCRTPoly>);
  462. fn EvalSquareMutable(self: &CryptoContextDCRTPoly,
  463. ciphertext: Pin<&mut CiphertextDCRTPoly>)
  464. -> UniquePtr<CiphertextDCRTPoly>;
  465. fn EvalSubByCiphertextAndConst(self: &CryptoContextDCRTPoly,
  466. ciphertext: &CiphertextDCRTPoly, constant: f64)
  467. -> UniquePtr<CiphertextDCRTPoly>;
  468. fn EvalSubByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly,
  469. ciphertext: &CiphertextDCRTPoly, plaintext: &Plaintext)
  470. -> UniquePtr<CiphertextDCRTPoly>;
  471. fn EvalSubByCiphertexts(self: &CryptoContextDCRTPoly, ciphertext1: &CiphertextDCRTPoly,
  472. ciphertext2: &CiphertextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>;
  473. fn EvalSubByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64,
  474. ciphertext: &CiphertextDCRTPoly)
  475. -> UniquePtr<CiphertextDCRTPoly>;
  476. fn EvalSubByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly,
  477. plaintext: &Plaintext, ciphertext: &CiphertextDCRTPoly)
  478. -> UniquePtr<CiphertextDCRTPoly>;
  479. fn EvalSubInPlaceByCiphertextAndConst(self: &CryptoContextDCRTPoly,
  480. ciphertext: Pin<&mut CiphertextDCRTPoly>,
  481. constant: f64);
  482. fn EvalSubInPlaceByCiphertexts(self: &CryptoContextDCRTPoly,
  483. ciphertext1: Pin<&mut CiphertextDCRTPoly>,
  484. ciphertext2: &CiphertextDCRTPoly);
  485. fn EvalSubInPlaceByConstAndCiphertext(self: &CryptoContextDCRTPoly, constant: f64,
  486. ciphertext: Pin<&mut CiphertextDCRTPoly>);
  487. fn EvalSubMutableByCiphertextAndPlaintext(self: &CryptoContextDCRTPoly,
  488. ciphertext: Pin<&mut CiphertextDCRTPoly>,
  489. plaintext: &Plaintext)
  490. -> UniquePtr<CiphertextDCRTPoly>;
  491. fn EvalSubMutableByCiphertexts(self: &CryptoContextDCRTPoly,
  492. ciphertext1: Pin<&mut CiphertextDCRTPoly>,
  493. ciphertext2: Pin<&mut CiphertextDCRTPoly>)
  494. -> UniquePtr<CiphertextDCRTPoly>;
  495. fn EvalSubMutableByPlaintextAndCiphertext(self: &CryptoContextDCRTPoly,
  496. plaintext: &Plaintext,
  497. ciphertext: Pin<&mut CiphertextDCRTPoly>)
  498. -> UniquePtr<CiphertextDCRTPoly>;
  499. fn EvalSubMutableInPlace(self: &CryptoContextDCRTPoly,
  500. ciphertext1: Pin<&mut CiphertextDCRTPoly>,
  501. ciphertext2: Pin<&mut CiphertextDCRTPoly>);
  502. fn EvalSum(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, batchSize: u32)
  503. -> UniquePtr<CiphertextDCRTPoly>;
  504. fn EvalSumCols(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, rowSize: u32,
  505. evalSumKeyMap: &MapFromIndexToEvalKey) -> UniquePtr<CiphertextDCRTPoly>;
  506. fn EvalSumColsKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  507. publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly)
  508. -> UniquePtr<MapFromIndexToEvalKey>;
  509. fn EvalSumKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  510. publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly);
  511. fn EvalSumRows(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly, rowSize: u32,
  512. evalSumKeyMap: &MapFromIndexToEvalKey, subringDim: /* 0 */ u32)
  513. -> UniquePtr<CiphertextDCRTPoly>;
  514. fn EvalSumRowsKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  515. publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly,
  516. rowSize: /* 0 */ u32, subringDim: /* 0 */ u32)
  517. -> UniquePtr<MapFromIndexToEvalKey>;
  518. fn FindAutomorphismIndex(self: &CryptoContextDCRTPoly, idx: u32) -> u32;
  519. fn FindAutomorphismIndices(self: &CryptoContextDCRTPoly, idxList: &CxxVector<u32>)
  520. -> UniquePtr<CxxVector<u32>>;
  521. fn GetCryptoParameters(self: &CryptoContextDCRTPoly)
  522. -> UniquePtr<CryptoParametersBaseDCRTPoly>;
  523. fn GetCyclotomicOrder(self: &CryptoContextDCRTPoly) -> u32;
  524. fn GetElementParams(self: &CryptoContextDCRTPoly) -> UniquePtr<DCRTPolyParams>;
  525. fn GetEncodingParams(self: &CryptoContextDCRTPoly) -> UniquePtr<EncodingParams>;
  526. fn GetKeyGenLevel(self: &CryptoContextDCRTPoly) -> usize;
  527. fn GetModulus(self: &CryptoContextDCRTPoly) -> u64;
  528. fn GetRingDimension(self: &CryptoContextDCRTPoly) -> u32;
  529. fn GetRootOfUnity(self: &CryptoContextDCRTPoly) -> u64;
  530. fn GetScheme(self: &CryptoContextDCRTPoly) -> UniquePtr<SchemeBaseDCRTPoly>;
  531. fn GetSchemeId(self: &CryptoContextDCRTPoly) -> SCHEME;
  532. fn GetSwkFC(self: &CryptoContextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>;
  533. fn IntMPBootAdd(self: &CryptoContextDCRTPoly,
  534. sharesPairVec: Pin<&mut VectorOfVectorOfCiphertexts>)
  535. -> UniquePtr<VectorOfCiphertexts>;
  536. fn IntMPBootAdjustScale(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
  537. -> UniquePtr<CiphertextDCRTPoly>;
  538. fn IntMPBootDecrypt(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  539. ciphertext: &CiphertextDCRTPoly, a: &CiphertextDCRTPoly)
  540. -> UniquePtr<VectorOfCiphertexts>;
  541. fn IntMPBootEncrypt(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly,
  542. sharesPair: &VectorOfCiphertexts, a: &CiphertextDCRTPoly,
  543. ciphertext: &CiphertextDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>;
  544. fn IntMPBootRandomElementGen(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly)
  545. -> UniquePtr<CiphertextDCRTPoly>;
  546. fn KeyGen(self: &CryptoContextDCRTPoly) -> UniquePtr<KeyPairDCRTPoly>;
  547. fn KeySwitch(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  548. evalKey: &EvalKeyDCRTPoly) -> UniquePtr<CiphertextDCRTPoly>;
  549. fn KeySwitchDown(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
  550. -> UniquePtr<CiphertextDCRTPoly>;
  551. fn KeySwitchDownFirstElement(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
  552. -> UniquePtr<DCRTPoly>;
  553. fn KeySwitchExt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  554. addFirst: bool) -> UniquePtr<CiphertextDCRTPoly>;
  555. fn KeySwitchGen(self: &CryptoContextDCRTPoly, oldPrivateKey: &PrivateKeyDCRTPoly,
  556. newPrivateKey: &PrivateKeyDCRTPoly) -> UniquePtr<EvalKeyDCRTPoly>;
  557. fn KeySwitchInPlace(self: &CryptoContextDCRTPoly, ciphertext: Pin<&mut CiphertextDCRTPoly>,
  558. evalKey: &EvalKeyDCRTPoly);
  559. fn LevelReduce(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  560. evalKey: &EvalKeyDCRTPoly, levels: /* 1 */ usize)
  561. -> UniquePtr<CiphertextDCRTPoly>;
  562. fn LevelReduceInPlace(self: &CryptoContextDCRTPoly,
  563. ciphertext: Pin<&mut CiphertextDCRTPoly>, evalKey: &EvalKeyDCRTPoly,
  564. levels: /* 1 */ usize);
  565. fn MakeCKKSPackedPlaintextByVectorOfDouble(self: &CryptoContextDCRTPoly,
  566. value: &CxxVector<f64>,
  567. scaleDeg: /* 1 */ usize, level: /* 0 */ u32,
  568. params:
  569. /* DCRTPolyGenNullParams() */ &DCRTPolyParams,
  570. slots: /* 0 */ u32) -> UniquePtr<Plaintext>;
  571. fn MakeCKKSPackedPlaintextByVectorOfComplex(self: &CryptoContextDCRTPoly,
  572. value: &CxxVector<ComplexPair>,
  573. scaleDeg: /* 1 */ usize, level: /* 0 */ u32,
  574. params:
  575. /* DCRTPolyGenNullParams() */ &DCRTPolyParams,
  576. slots: /* 0 */ u32) -> UniquePtr<Plaintext>;
  577. fn MakeCoefPackedPlaintext(self: &CryptoContextDCRTPoly, value: &CxxVector<i64>,
  578. noiseScaleDeg: /* 1 */ usize, level: /* 0 */ u32)
  579. -> UniquePtr<Plaintext>;
  580. fn MakePackedPlaintext(self: &CryptoContextDCRTPoly, value: &CxxVector<i64>,
  581. noiseScaleDeg: /* 1 */ usize, level: /* 0 */ u32)
  582. -> UniquePtr<Plaintext>;
  583. fn MakeStringPlaintext(self: &CryptoContextDCRTPoly, s: &CxxString)
  584. -> UniquePtr<Plaintext>;
  585. fn ModReduce(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
  586. -> UniquePtr<CiphertextDCRTPoly>;
  587. fn ModReduceInPlace(self: &CryptoContextDCRTPoly,
  588. ciphertext: Pin<&mut CiphertextDCRTPoly>);
  589. fn MultiAddEvalAutomorphismKeys(self: &CryptoContextDCRTPoly,
  590. evalKeyMap1: &MapFromIndexToEvalKey,
  591. evalKeyMap2: &MapFromIndexToEvalKey,
  592. keyId: /* "" */ &CxxString)
  593. -> UniquePtr<MapFromIndexToEvalKey>;
  594. fn MultiAddEvalKeys(self: &CryptoContextDCRTPoly, evalKey1: &EvalKeyDCRTPoly,
  595. evalKey2: &EvalKeyDCRTPoly, keyId: /* "" */ &CxxString)
  596. -> UniquePtr<EvalKeyDCRTPoly>;
  597. fn MultiAddEvalMultKeys(self: &CryptoContextDCRTPoly, evalKey1: &EvalKeyDCRTPoly,
  598. evalKey2: &EvalKeyDCRTPoly, keyId: /* "" */ &CxxString)
  599. -> UniquePtr<EvalKeyDCRTPoly>;
  600. fn MultiAddEvalSumKeys(self: &CryptoContextDCRTPoly, evalKeyMap1: &MapFromIndexToEvalKey,
  601. evalKeyMap2: &MapFromIndexToEvalKey, keyId: /* "" */ &CxxString)
  602. -> UniquePtr<MapFromIndexToEvalKey>;
  603. fn MultiAddPubKeys(self: &CryptoContextDCRTPoly, publicKey1: &PublicKeyDCRTPoly,
  604. publicKey2: &PublicKeyDCRTPoly, keyId: /* "" */ &CxxString)
  605. -> UniquePtr<PublicKeyDCRTPoly>;
  606. fn MultiEvalAtIndexKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  607. evalKeyMap: &MapFromIndexToEvalKey, indexList: &CxxVector<i32>,
  608. keyId: /* "" */ &CxxString) -> UniquePtr<MapFromIndexToEvalKey>;
  609. fn MultiEvalAutomorphismKeyGen(self: &CryptoContextDCRTPoly,
  610. privateKey: &PrivateKeyDCRTPoly,
  611. evalKeyMap: &MapFromIndexToEvalKey,
  612. indexList: &CxxVector<u32>, keyId: /* "" */ &CxxString)
  613. -> UniquePtr<MapFromIndexToEvalKey>;
  614. fn MultiEvalSumKeyGen(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  615. evalKeyMap: &MapFromIndexToEvalKey, keyId: /* "" */ &CxxString)
  616. -> UniquePtr<MapFromIndexToEvalKey>;
  617. fn MultiKeySwitchGen(self: &CryptoContextDCRTPoly,
  618. originalPrivateKey: &PrivateKeyDCRTPoly,
  619. newPrivateKey: &PrivateKeyDCRTPoly, evalKey: &EvalKeyDCRTPoly)
  620. -> UniquePtr<EvalKeyDCRTPoly>;
  621. fn MultiMultEvalKey(self: &CryptoContextDCRTPoly, privateKey: &PrivateKeyDCRTPoly,
  622. evalKey: &EvalKeyDCRTPoly, keyId: /* "" */ &CxxString)
  623. -> UniquePtr<EvalKeyDCRTPoly>;
  624. fn MultipartyDecryptFusion(self: &CryptoContextDCRTPoly,
  625. partialCiphertextVec: &VectorOfCiphertexts,
  626. plaintext: Pin<&mut Plaintext>) -> UniquePtr<DecryptResult>;
  627. fn MultipartyDecryptLead(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts,
  628. privateKey: &PrivateKeyDCRTPoly)
  629. -> UniquePtr<VectorOfCiphertexts>;
  630. fn MultipartyDecryptMain(self: &CryptoContextDCRTPoly, ciphertextVec: &VectorOfCiphertexts,
  631. privateKey: &PrivateKeyDCRTPoly)
  632. -> UniquePtr<VectorOfCiphertexts>;
  633. fn MultipartyKeyGenByPublicKey(self: &CryptoContextDCRTPoly, publicKey: &PublicKeyDCRTPoly,
  634. makeSparse: /* false */ bool, fresh: /* false */ bool)
  635. -> UniquePtr<KeyPairDCRTPoly>;
  636. fn MultipartyKeyGenByVectorOfPrivateKeys(self: &CryptoContextDCRTPoly,
  637. privateKeyVec: &VectorOfPrivateKeys)
  638. -> UniquePtr<KeyPairDCRTPoly>;
  639. fn ReEncrypt(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly,
  640. evalKey: &EvalKeyDCRTPoly,
  641. publicKey: /* DCRTPolyGenNullPublicKey() */ &PublicKeyDCRTPoly)
  642. -> UniquePtr<CiphertextDCRTPoly>;
  643. fn ReKeyGen(self: &CryptoContextDCRTPoly, oldPrivateKey: &PrivateKeyDCRTPoly,
  644. newPublicKey: &PublicKeyDCRTPoly) -> UniquePtr<EvalKeyDCRTPoly>;
  645. fn RecoverSharedKey(self: &CryptoContextDCRTPoly, sk: Pin<&mut PrivateKeyDCRTPoly>,
  646. sk_shares: Pin<&mut UnorderedMapFromIndexToDCRTPoly>, N: u32,
  647. threshold: u32, shareType: &CxxString);
  648. fn Relinearize(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
  649. -> UniquePtr<CiphertextDCRTPoly>;
  650. fn RelinearizeInPlace(self: &CryptoContextDCRTPoly,
  651. ciphertext: Pin<&mut CiphertextDCRTPoly>);
  652. fn Rescale(self: &CryptoContextDCRTPoly, ciphertext: &CiphertextDCRTPoly)
  653. -> UniquePtr<CiphertextDCRTPoly>;
  654. fn RescaleInPlace(self: &CryptoContextDCRTPoly, ciphertext: Pin<&mut CiphertextDCRTPoly>);
  655. fn SetKeyGenLevel(self: &CryptoContextDCRTPoly, level: usize);
  656. fn SetSchemeId(self: &CryptoContextDCRTPoly, schemeTag: SCHEME);
  657. fn SetSwkFC(self: &CryptoContextDCRTPoly, FHEWtoCKKSswk: &CiphertextDCRTPoly);
  658. fn ShareKeys(self: &CryptoContextDCRTPoly, sk: &PrivateKeyDCRTPoly, N: u32, threshold: u32,
  659. index: u32, shareType: &CxxString)
  660. -> UniquePtr<UnorderedMapFromIndexToDCRTPoly>;
  661. fn SparseKeyGen(self: &CryptoContextDCRTPoly) -> UniquePtr<KeyPairDCRTPoly>;
  662. // cxx currently does not support static class methods
  663. fn DCRTPolyClearEvalAutomorphismKeys();
  664. fn DCRTPolyClearEvalAutomorphismKeysByCryptoContext(cryptoContext: &CryptoContextDCRTPoly);
  665. fn DCRTPolyClearEvalAutomorphismKeysById(id: &CxxString);
  666. fn DCRTPolyClearEvalMultKeys();
  667. fn DCRTPolyClearEvalMultKeysByCryptoContext(cryptoContext: &CryptoContextDCRTPoly);
  668. fn DCRTPolyClearEvalMultKeysById(id: &CxxString);
  669. fn DCRTPolyClearEvalSumKeys();
  670. fn DCRTPolyClearEvalSumKeysByCryptoContext(cryptoContext: &CryptoContextDCRTPoly);
  671. fn DCRTPolyClearEvalSumKeysById(id: &CxxString);
  672. fn DCRTPolyGetCopyOfAllEvalAutomorphismKeys()
  673. -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>;
  674. fn DCRTPolyGetCopyOfAllEvalMultKeys() -> UniquePtr<MapFromStringToVectorOfEvalKeys>;
  675. fn DCRTPolyGetCopyOfAllEvalSumKeys() -> UniquePtr<MapFromStringToMapFromIndexToEvalKey>;
  676. fn DCRTPolyGetCopyOfEvalAutomorphismKeyMap(keyID: &CxxString)
  677. -> UniquePtr<MapFromIndexToEvalKey>;
  678. fn DCRTPolyGetCopyOfEvalMultKeyVector(keyID: &CxxString) -> UniquePtr<VectorOfEvalKeys>;
  679. fn DCRTPolyGetCopyOfEvalSumKeyMap(id: &CxxString) -> UniquePtr<MapFromIndexToEvalKey>;
  680. fn DCRTPolyGetExistingEvalAutomorphismKeyIndices(keyTag: &CxxString)
  681. -> UniquePtr<SetOfUints>;
  682. fn DCRTPolyGetPlaintextForDecrypt(pte: PlaintextEncodings, evp: &DCRTPolyParams,
  683. ep: &EncodingParams) -> UniquePtr<Plaintext>;
  684. fn DCRTPolyGetUniqueValues(oldValues: &SetOfUints, newValues: &SetOfUints)
  685. -> UniquePtr<SetOfUints>;
  686. fn DCRTPolyInsertEvalAutomorphismKey(evalKeyMap: &MapFromIndexToEvalKey,
  687. keyTag: /* "" */ &CxxString);
  688. fn DCRTPolyInsertEvalMultKey(evalKeyVec: &VectorOfEvalKeys);
  689. fn DCRTPolyInsertEvalSumKey(mapToInsert: &MapFromIndexToEvalKey,
  690. keyTag: /* "" */ &CxxString);
  691. // Generator functions
  692. fn DCRTPolyGenCryptoContextByParamsCKKSRNS(params: &ParamsCKKSRNS)
  693. -> UniquePtr<CryptoContextDCRTPoly>;
  694. fn DCRTPolyGenCryptoContextByParamsBFVRNS(params: &ParamsBFVRNS)
  695. -> UniquePtr<CryptoContextDCRTPoly>;
  696. fn DCRTPolyGenCryptoContextByParamsBGVRNS(params: &ParamsBGVRNS)
  697. -> UniquePtr<CryptoContextDCRTPoly>;
  698. fn DCRTPolyGenNullCryptoContext() -> UniquePtr<CryptoContextDCRTPoly>;
  699. }
  700. // DCRTPolyParams
  701. unsafe extern "C++"
  702. {
  703. // Generator functions
  704. fn DCRTPolyGenNullParams() -> UniquePtr<DCRTPolyParams>;
  705. }
  706. // DCRTPolyImpl
  707. unsafe extern "C++"
  708. {
  709. fn DCRTPolyGenFromDug(params: &ILDCRTParams) -> UniquePtr<DCRTPolyImpl>;
  710. }
  711. // KeyPairDCRTPoly
  712. unsafe extern "C++"
  713. {
  714. fn GetPrivateKey(self: &KeyPairDCRTPoly) -> UniquePtr<PrivateKeyDCRTPoly>;
  715. fn GetPublicKey(self: &KeyPairDCRTPoly) -> UniquePtr<PublicKeyDCRTPoly>;
  716. }
  717. // ILDCRTParams
  718. unsafe extern "C++"
  719. {
  720. fn GenILDCRTParamsByOrderSizeBits(corder: u32, depth: u32, bits: u32) -> UniquePtr<ILDCRTParams>;
  721. }
  722. // Params
  723. unsafe extern "C++"
  724. {
  725. fn GetBatchSize(self: &Params) -> u32;
  726. fn GetDecryptionNoiseMode(self: &Params) -> DecryptionNoiseMode;
  727. fn GetDesiredPrecision(self: &Params) -> f64;
  728. fn GetDigitSize(self: &Params) -> u32;
  729. fn GetEncryptionTechnique(self: &Params) -> EncryptionTechnique;
  730. fn GetEvalAddCount(self: &Params) -> u32;
  731. fn GetExecutionMode(self: &Params) -> ExecutionMode;
  732. fn GetFirstModSize(self: &Params) -> u32;
  733. fn GetInteractiveBootCompressionLevel(self: &Params) -> COMPRESSION_LEVEL;
  734. fn GetKeySwitchCount(self: &Params) -> u32;
  735. fn GetKeySwitchTechnique(self: &Params) -> KeySwitchTechnique;
  736. fn GetMaxRelinSkDeg(self: &Params) -> u32;
  737. fn GetMultipartyMode(self: &Params) -> MultipartyMode;
  738. fn GetMultiplicationTechnique(self: &Params) -> MultiplicationTechnique;
  739. fn GetMultiplicativeDepth(self: &Params) -> u32;
  740. fn GetNoiseEstimate(self: &Params) -> f64;
  741. fn GetNumAdversarialQueries(self: &Params) -> f64;
  742. fn GetNumLargeDigits(self: &Params) -> u32;
  743. fn GetPREMode(self: &Params) -> ProxyReEncryptionMode;
  744. fn GetPlaintextModulus(self: &Params) -> u64;
  745. fn GetRingDim(self: &Params) -> u32;
  746. fn GetScalingModSize(self: &Params) -> u32;
  747. fn GetScalingTechnique(self: &Params) -> ScalingTechnique;
  748. fn GetScheme(self: &Params) -> SCHEME;
  749. fn GetSecretKeyDist(self: &Params) -> SecretKeyDist;
  750. fn GetSecurityLevel(self: &Params) -> SecurityLevel;
  751. fn GetStandardDeviation(self: &Params) -> f32;
  752. fn GetStatisticalSecurity(self: &Params) -> f64;
  753. fn GetThresholdNumOfParties(self: &Params) -> u32;
  754. fn SetBatchSize(self: Pin<&mut Params>, batchSize0: u32);
  755. fn SetDecryptionNoiseMode(self: Pin<&mut Params>,
  756. decryptionNoiseMode0: DecryptionNoiseMode);
  757. fn SetDesiredPrecision(self: Pin<&mut Params>, desiredPrecision0: f64);
  758. fn SetDigitSize(self: Pin<&mut Params>, digitSize0: u32);
  759. fn SetEncryptionTechnique(self: Pin<&mut Params>,
  760. encryptionTechnique0: EncryptionTechnique);
  761. fn SetEvalAddCount(self: Pin<&mut Params>, evalAddCount0: u32);
  762. fn SetExecutionMode(self: Pin<&mut Params>, executionMode0: ExecutionMode);
  763. fn SetFirstModSize(self: Pin<&mut Params>, firstModSize0: u32);
  764. fn SetInteractiveBootCompressionLevel(self: Pin<&mut Params>,
  765. interactiveBootCompressionLevel0: COMPRESSION_LEVEL);
  766. fn SetKeySwitchCount(self: Pin<&mut Params>, keySwitchCount0: u32);
  767. fn SetKeySwitchTechnique(self: Pin<&mut Params>, ksTech0: KeySwitchTechnique);
  768. fn SetMaxRelinSkDeg(self: Pin<&mut Params>, maxRelinSkDeg0: u32);
  769. fn SetMultipartyMode(self: Pin<&mut Params>, multipartyMode0: MultipartyMode);
  770. fn SetMultiplicationTechnique(self: Pin<&mut Params>,
  771. multiplicationTechnique0: MultiplicationTechnique);
  772. fn SetMultiplicativeDepth(self: Pin<&mut Params>, multiplicativeDepth0: u32);
  773. fn SetNoiseEstimate(self: Pin<&mut Params>, noiseEstimate0: f64);
  774. fn SetNumAdversarialQueries(self: Pin<&mut Params>, numAdversarialQueries0: u32);
  775. fn SetNumLargeDigits(self: Pin<&mut Params>, numLargeDigits0: u32);
  776. fn SetPREMode(self: Pin<&mut Params>, PREMode0: ProxyReEncryptionMode);
  777. fn SetPlaintextModulus(self: Pin<&mut Params>, ptModulus0: u64);
  778. fn SetRingDim(self: Pin<&mut Params>, ringDim0: u32);
  779. fn SetScalingModSize(self: Pin<&mut Params>, scalingModSize0: u32);
  780. fn SetScalingTechnique(self: Pin<&mut Params>, scalTech0: ScalingTechnique);
  781. fn SetSecretKeyDist(self: Pin<&mut Params>, secretKeyDist0: SecretKeyDist);
  782. fn SetSecurityLevel(self: Pin<&mut Params>, securityLevel0: SecurityLevel);
  783. fn SetStandardDeviation(self: Pin<&mut Params>, standardDeviation0: f32);
  784. fn SetStatisticalSecurity(self: Pin<&mut Params>, statisticalSecurity0: u32);
  785. fn SetThresholdNumOfParties(self: Pin<&mut Params>, thresholdNumOfParties0: u32);
  786. // Generator functions
  787. fn GenParamsByScheme(scheme: SCHEME) -> UniquePtr<Params>;
  788. fn GenParamsByVectorOfString(vals: &CxxVector<CxxString>) -> UniquePtr<Params>;
  789. }
  790. // ParamsBFVRNS
  791. unsafe extern "C++"
  792. {
  793. fn GetBatchSize(self: &ParamsBFVRNS) -> u32;
  794. fn GetDecryptionNoiseMode(self: &ParamsBFVRNS) -> DecryptionNoiseMode;
  795. fn GetDesiredPrecision(self: &ParamsBFVRNS) -> f64;
  796. fn GetDigitSize(self: &ParamsBFVRNS) -> u32;
  797. fn GetEncryptionTechnique(self: &ParamsBFVRNS) -> EncryptionTechnique;
  798. fn GetEvalAddCount(self: &ParamsBFVRNS) -> u32;
  799. fn GetExecutionMode(self: &ParamsBFVRNS) -> ExecutionMode;
  800. fn GetFirstModSize(self: &ParamsBFVRNS) -> u32;
  801. fn GetInteractiveBootCompressionLevel(self: &ParamsBFVRNS) -> COMPRESSION_LEVEL;
  802. fn GetKeySwitchCount(self: &ParamsBFVRNS) -> u32;
  803. fn GetKeySwitchTechnique(self: &ParamsBFVRNS) -> KeySwitchTechnique;
  804. fn GetMaxRelinSkDeg(self: &ParamsBFVRNS) -> u32;
  805. fn GetMultipartyMode(self: &ParamsBFVRNS) -> MultipartyMode;
  806. fn GetMultiplicationTechnique(self: &ParamsBFVRNS) -> MultiplicationTechnique;
  807. fn GetMultiplicativeDepth(self: &ParamsBFVRNS) -> u32;
  808. fn GetNoiseEstimate(self: &ParamsBFVRNS) -> f64;
  809. fn GetNumAdversarialQueries(self: &ParamsBFVRNS) -> f64;
  810. fn GetNumLargeDigits(self: &ParamsBFVRNS) -> u32;
  811. fn GetPREMode(self: &ParamsBFVRNS) -> ProxyReEncryptionMode;
  812. fn GetPlaintextModulus(self: &ParamsBFVRNS) -> u64;
  813. fn GetRingDim(self: &ParamsBFVRNS) -> u32;
  814. fn GetScalingModSize(self: &ParamsBFVRNS) -> u32;
  815. fn GetScalingTechnique(self: &ParamsBFVRNS) -> ScalingTechnique;
  816. fn GetScheme(self: &ParamsBFVRNS) -> SCHEME;
  817. fn GetSecretKeyDist(self: &ParamsBFVRNS) -> SecretKeyDist;
  818. fn GetSecurityLevel(self: &ParamsBFVRNS) -> SecurityLevel;
  819. fn GetStandardDeviation(self: &ParamsBFVRNS) -> f32;
  820. fn GetStatisticalSecurity(self: &ParamsBFVRNS) -> f64;
  821. fn GetThresholdNumOfParties(self: &ParamsBFVRNS) -> u32;
  822. fn SetBatchSize(self: Pin<&mut ParamsBFVRNS>, batchSize0: u32);
  823. fn SetDecryptionNoiseMode(self: Pin<&mut ParamsBFVRNS>,
  824. decryptionNoiseMode0: DecryptionNoiseMode);
  825. fn SetDesiredPrecision(self: Pin<&mut ParamsBFVRNS>, desiredPrecision0: f64);
  826. fn SetDigitSize(self: Pin<&mut ParamsBFVRNS>, digitSize0: u32);
  827. fn SetEncryptionTechnique(self: Pin<&mut ParamsBFVRNS>,
  828. encryptionTechnique0: EncryptionTechnique);
  829. fn SetEvalAddCount(self: Pin<&mut ParamsBFVRNS>, evalAddCount0: u32);
  830. fn SetExecutionMode(self: Pin<&mut ParamsBFVRNS>, executionMode0: ExecutionMode);
  831. fn SetFirstModSize(self: Pin<&mut ParamsBFVRNS>, firstModSize0: u32);
  832. fn SetInteractiveBootCompressionLevel(self: Pin<&mut ParamsBFVRNS>,
  833. interactiveBootCompressionLevel0: COMPRESSION_LEVEL);
  834. fn SetKeySwitchCount(self: Pin<&mut ParamsBFVRNS>, keySwitchCount0: u32);
  835. fn SetKeySwitchTechnique(self: Pin<&mut ParamsBFVRNS>, ksTech0: KeySwitchTechnique);
  836. fn SetMaxRelinSkDeg(self: Pin<&mut ParamsBFVRNS>, maxRelinSkDeg0: u32);
  837. fn SetMultipartyMode(self: Pin<&mut ParamsBFVRNS>, multipartyMode0: MultipartyMode);
  838. fn SetMultiplicationTechnique(self: Pin<&mut ParamsBFVRNS>,
  839. multiplicationTechnique0: MultiplicationTechnique);
  840. fn SetMultiplicativeDepth(self: Pin<&mut ParamsBFVRNS>, multiplicativeDepth0: u32);
  841. fn SetNoiseEstimate(self: Pin<&mut ParamsBFVRNS>, noiseEstimate0: f64);
  842. fn SetNumAdversarialQueries(self: Pin<&mut ParamsBFVRNS>, numAdversarialQueries0: u32);
  843. fn SetNumLargeDigits(self: Pin<&mut ParamsBFVRNS>, numLargeDigits0: u32);
  844. fn SetPREMode(self: Pin<&mut ParamsBFVRNS>, PREMode0: ProxyReEncryptionMode);
  845. fn SetPlaintextModulus(self: Pin<&mut ParamsBFVRNS>, ptModulus0: u64);
  846. fn SetRingDim(self: Pin<&mut ParamsBFVRNS>, ringDim0: u32);
  847. fn SetScalingModSize(self: Pin<&mut ParamsBFVRNS>, scalingModSize0: u32);
  848. fn SetScalingTechnique(self: Pin<&mut ParamsBFVRNS>, scalTech0: ScalingTechnique);
  849. fn SetSecretKeyDist(self: Pin<&mut ParamsBFVRNS>, secretKeyDist0: SecretKeyDist);
  850. fn SetSecurityLevel(self: Pin<&mut ParamsBFVRNS>, securityLevel0: SecurityLevel);
  851. fn SetStandardDeviation(self: Pin<&mut ParamsBFVRNS>, standardDeviation0: f32);
  852. fn SetStatisticalSecurity(self: Pin<&mut ParamsBFVRNS>, statisticalSecurity0: u32);
  853. fn SetThresholdNumOfParties(self: Pin<&mut ParamsBFVRNS>, thresholdNumOfParties0: u32);
  854. // Generator functions
  855. fn GenParamsBFVRNS() -> UniquePtr<ParamsBFVRNS>;
  856. fn GenParamsBFVRNSbyVectorOfString(vals: &CxxVector<CxxString>) -> UniquePtr<ParamsBFVRNS>;
  857. }
  858. // ParamsBGVRNS
  859. unsafe extern "C++"
  860. {
  861. fn GetBatchSize(self: &ParamsBGVRNS) -> u32;
  862. fn GetDecryptionNoiseMode(self: &ParamsBGVRNS) -> DecryptionNoiseMode;
  863. fn GetDesiredPrecision(self: &ParamsBGVRNS) -> f64;
  864. fn GetDigitSize(self: &ParamsBGVRNS) -> u32;
  865. fn GetEncryptionTechnique(self: &ParamsBGVRNS) -> EncryptionTechnique;
  866. fn GetEvalAddCount(self: &ParamsBGVRNS) -> u32;
  867. fn GetExecutionMode(self: &ParamsBGVRNS) -> ExecutionMode;
  868. fn GetFirstModSize(self: &ParamsBGVRNS) -> u32;
  869. fn GetInteractiveBootCompressionLevel(self: &ParamsBGVRNS) -> COMPRESSION_LEVEL;
  870. fn GetKeySwitchCount(self: &ParamsBGVRNS) -> u32;
  871. fn GetKeySwitchTechnique(self: &ParamsBGVRNS) -> KeySwitchTechnique;
  872. fn GetMaxRelinSkDeg(self: &ParamsBGVRNS) -> u32;
  873. fn GetMultipartyMode(self: &ParamsBGVRNS) -> MultipartyMode;
  874. fn GetMultiplicationTechnique(self: &ParamsBGVRNS) -> MultiplicationTechnique;
  875. fn GetMultiplicativeDepth(self: &ParamsBGVRNS) -> u32;
  876. fn GetNoiseEstimate(self: &ParamsBGVRNS) -> f64;
  877. fn GetNumAdversarialQueries(self: &ParamsBGVRNS) -> f64;
  878. fn GetNumLargeDigits(self: &ParamsBGVRNS) -> u32;
  879. fn GetPREMode(self: &ParamsBGVRNS) -> ProxyReEncryptionMode;
  880. fn GetPlaintextModulus(self: &ParamsBGVRNS) -> u64;
  881. fn GetRingDim(self: &ParamsBGVRNS) -> u32;
  882. fn GetScalingModSize(self: &ParamsBGVRNS) -> u32;
  883. fn GetScalingTechnique(self: &ParamsBGVRNS) -> ScalingTechnique;
  884. fn GetScheme(self: &ParamsBGVRNS) -> SCHEME;
  885. fn GetSecretKeyDist(self: &ParamsBGVRNS) -> SecretKeyDist;
  886. fn GetSecurityLevel(self: &ParamsBGVRNS) -> SecurityLevel;
  887. fn GetStandardDeviation(self: &ParamsBGVRNS) -> f32;
  888. fn GetStatisticalSecurity(self: &ParamsBGVRNS) -> f64;
  889. fn GetThresholdNumOfParties(self: &ParamsBGVRNS) -> u32;
  890. fn SetBatchSize(self: Pin<&mut ParamsBGVRNS>, batchSize0: u32);
  891. fn SetDecryptionNoiseMode(self: Pin<&mut ParamsBGVRNS>,
  892. decryptionNoiseMode0: DecryptionNoiseMode);
  893. fn SetDesiredPrecision(self: Pin<&mut ParamsBGVRNS>, desiredPrecision0: f64);
  894. fn SetDigitSize(self: Pin<&mut ParamsBGVRNS>, digitSize0: u32);
  895. fn SetEncryptionTechnique(self: Pin<&mut ParamsBGVRNS>,
  896. encryptionTechnique0: EncryptionTechnique);
  897. fn SetEvalAddCount(self: Pin<&mut ParamsBGVRNS>, evalAddCount0: u32);
  898. fn SetExecutionMode(self: Pin<&mut ParamsBGVRNS>, executionMode0: ExecutionMode);
  899. fn SetFirstModSize(self: Pin<&mut ParamsBGVRNS>, firstModSize0: u32);
  900. fn SetInteractiveBootCompressionLevel(self: Pin<&mut ParamsBGVRNS>,
  901. interactiveBootCompressionLevel0: COMPRESSION_LEVEL);
  902. fn SetKeySwitchCount(self: Pin<&mut ParamsBGVRNS>, keySwitchCount0: u32);
  903. fn SetKeySwitchTechnique(self: Pin<&mut ParamsBGVRNS>, ksTech0: KeySwitchTechnique);
  904. fn SetMaxRelinSkDeg(self: Pin<&mut ParamsBGVRNS>, maxRelinSkDeg0: u32);
  905. fn SetMultipartyMode(self: Pin<&mut ParamsBGVRNS>, multipartyMode0: MultipartyMode);
  906. fn SetMultiplicationTechnique(self: Pin<&mut ParamsBGVRNS>,
  907. multiplicationTechnique0: MultiplicationTechnique);
  908. fn SetMultiplicativeDepth(self: Pin<&mut ParamsBGVRNS>, multiplicativeDepth0: u32);
  909. fn SetNoiseEstimate(self: Pin<&mut ParamsBGVRNS>, noiseEstimate0: f64);
  910. fn SetNumAdversarialQueries(self: Pin<&mut ParamsBGVRNS>, numAdversarialQueries0: u32);
  911. fn SetNumLargeDigits(self: Pin<&mut ParamsBGVRNS>, numLargeDigits0: u32);
  912. fn SetPREMode(self: Pin<&mut ParamsBGVRNS>, PREMode0: ProxyReEncryptionMode);
  913. fn SetPlaintextModulus(self: Pin<&mut ParamsBGVRNS>, ptModulus0: u64);
  914. fn SetRingDim(self: Pin<&mut ParamsBGVRNS>, ringDim0: u32);
  915. fn SetScalingModSize(self: Pin<&mut ParamsBGVRNS>, scalingModSize0: u32);
  916. fn SetScalingTechnique(self: Pin<&mut ParamsBGVRNS>, scalTech0: ScalingTechnique);
  917. fn SetSecretKeyDist(self: Pin<&mut ParamsBGVRNS>, secretKeyDist0: SecretKeyDist);
  918. fn SetSecurityLevel(self: Pin<&mut ParamsBGVRNS>, securityLevel0: SecurityLevel);
  919. fn SetStandardDeviation(self: Pin<&mut ParamsBGVRNS>, standardDeviation0: f32);
  920. fn SetStatisticalSecurity(self: Pin<&mut ParamsBGVRNS>, statisticalSecurity0: u32);
  921. fn SetThresholdNumOfParties(self: Pin<&mut ParamsBGVRNS>, thresholdNumOfParties0: u32);
  922. // Generator functions
  923. fn GenParamsBGVRNS() -> UniquePtr<ParamsBGVRNS>;
  924. fn GenParamsBGVRNSbyVectorOfString(vals: &CxxVector<CxxString>) -> UniquePtr<ParamsBGVRNS>;
  925. }
  926. // ParamsCKKSRNS
  927. unsafe extern "C++"
  928. {
  929. fn GetBatchSize(self: &ParamsCKKSRNS) -> u32;
  930. fn GetDecryptionNoiseMode(self: &ParamsCKKSRNS) -> DecryptionNoiseMode;
  931. fn GetDesiredPrecision(self: &ParamsCKKSRNS) -> f64;
  932. fn GetDigitSize(self: &ParamsCKKSRNS) -> u32;
  933. fn GetEncryptionTechnique(self: &ParamsCKKSRNS) -> EncryptionTechnique;
  934. fn GetEvalAddCount(self: &ParamsCKKSRNS) -> u32;
  935. fn GetExecutionMode(self: &ParamsCKKSRNS) -> ExecutionMode;
  936. fn GetFirstModSize(self: &ParamsCKKSRNS) -> u32;
  937. fn GetInteractiveBootCompressionLevel(self: &ParamsCKKSRNS) -> COMPRESSION_LEVEL;
  938. fn GetKeySwitchCount(self: &ParamsCKKSRNS) -> u32;
  939. fn GetKeySwitchTechnique(self: &ParamsCKKSRNS) -> KeySwitchTechnique;
  940. fn GetMaxRelinSkDeg(self: &ParamsCKKSRNS) -> u32;
  941. fn GetMultipartyMode(self: &ParamsCKKSRNS) -> MultipartyMode;
  942. fn GetMultiplicationTechnique(self: &ParamsCKKSRNS) -> MultiplicationTechnique;
  943. fn GetMultiplicativeDepth(self: &ParamsCKKSRNS) -> u32;
  944. fn GetNoiseEstimate(self: &ParamsCKKSRNS) -> f64;
  945. fn GetNumAdversarialQueries(self: &ParamsCKKSRNS) -> f64;
  946. fn GetNumLargeDigits(self: &ParamsCKKSRNS) -> u32;
  947. fn GetPREMode(self: &ParamsCKKSRNS) -> ProxyReEncryptionMode;
  948. fn GetPlaintextModulus(self: &ParamsCKKSRNS) -> u64;
  949. fn GetRingDim(self: &ParamsCKKSRNS) -> u32;
  950. fn GetScalingModSize(self: &ParamsCKKSRNS) -> u32;
  951. fn GetScalingTechnique(self: &ParamsCKKSRNS) -> ScalingTechnique;
  952. fn GetScheme(self: &ParamsCKKSRNS) -> SCHEME;
  953. fn GetSecretKeyDist(self: &ParamsCKKSRNS) -> SecretKeyDist;
  954. fn GetSecurityLevel(self: &ParamsCKKSRNS) -> SecurityLevel;
  955. fn GetStandardDeviation(self: &ParamsCKKSRNS) -> f32;
  956. fn GetStatisticalSecurity(self: &ParamsCKKSRNS) -> f64;
  957. fn GetThresholdNumOfParties(self: &ParamsCKKSRNS) -> u32;
  958. fn SetBatchSize(self: Pin<&mut ParamsCKKSRNS>, batchSize0: u32);
  959. fn SetDecryptionNoiseMode(self: Pin<&mut ParamsCKKSRNS>,
  960. decryptionNoiseMode0: DecryptionNoiseMode);
  961. fn SetDesiredPrecision(self: Pin<&mut ParamsCKKSRNS>, desiredPrecision0: f64);
  962. fn SetDigitSize(self: Pin<&mut ParamsCKKSRNS>, digitSize0: u32);
  963. fn SetEncryptionTechnique(self: Pin<&mut ParamsCKKSRNS>,
  964. encryptionTechnique0: EncryptionTechnique);
  965. fn SetEvalAddCount(self: Pin<&mut ParamsCKKSRNS>, evalAddCount0: u32);
  966. fn SetExecutionMode(self: Pin<&mut ParamsCKKSRNS>, executionMode0: ExecutionMode);
  967. fn SetFirstModSize(self: Pin<&mut ParamsCKKSRNS>, firstModSize0: u32);
  968. fn SetInteractiveBootCompressionLevel(self: Pin<&mut ParamsCKKSRNS>,
  969. interactiveBootCompressionLevel0: COMPRESSION_LEVEL);
  970. fn SetKeySwitchCount(self: Pin<&mut ParamsCKKSRNS>, keySwitchCount0: u32);
  971. fn SetKeySwitchTechnique(self: Pin<&mut ParamsCKKSRNS>, ksTech0: KeySwitchTechnique);
  972. fn SetMaxRelinSkDeg(self: Pin<&mut ParamsCKKSRNS>, maxRelinSkDeg0: u32);
  973. fn SetMultipartyMode(self: Pin<&mut ParamsCKKSRNS>, multipartyMode0: MultipartyMode);
  974. fn SetMultiplicationTechnique(self: Pin<&mut ParamsCKKSRNS>,
  975. multiplicationTechnique0: MultiplicationTechnique);
  976. fn SetMultiplicativeDepth(self: Pin<&mut ParamsCKKSRNS>, multiplicativeDepth0: u32);
  977. fn SetNoiseEstimate(self: Pin<&mut ParamsCKKSRNS>, noiseEstimate0: f64);
  978. fn SetNumAdversarialQueries(self: Pin<&mut ParamsCKKSRNS>, numAdversarialQueries0: u32);
  979. fn SetNumLargeDigits(self: Pin<&mut ParamsCKKSRNS>, numLargeDigits0: u32);
  980. fn SetPREMode(self: Pin<&mut ParamsCKKSRNS>, PREMode0: ProxyReEncryptionMode);
  981. fn SetPlaintextModulus(self: Pin<&mut ParamsCKKSRNS>, ptModulus0: u64);
  982. fn SetRingDim(self: Pin<&mut ParamsCKKSRNS>, ringDim0: u32);
  983. fn SetScalingModSize(self: Pin<&mut ParamsCKKSRNS>, scalingModSize0: u32);
  984. fn SetScalingTechnique(self: Pin<&mut ParamsCKKSRNS>, scalTech0: ScalingTechnique);
  985. fn SetSecretKeyDist(self: Pin<&mut ParamsCKKSRNS>, secretKeyDist0: SecretKeyDist);
  986. fn SetSecurityLevel(self: Pin<&mut ParamsCKKSRNS>, securityLevel0: SecurityLevel);
  987. fn SetStandardDeviation(self: Pin<&mut ParamsCKKSRNS>, standardDeviation0: f32);
  988. fn SetStatisticalSecurity(self: Pin<&mut ParamsCKKSRNS>, statisticalSecurity0: u32);
  989. fn SetThresholdNumOfParties(self: Pin<&mut ParamsCKKSRNS>, thresholdNumOfParties0: u32);
  990. // Generator functions
  991. fn GenParamsCKKSRNS() -> UniquePtr<ParamsCKKSRNS>;
  992. fn GenParamsCKKSRNSbyVectorOfString(vals: &CxxVector<CxxString>)
  993. -> UniquePtr<ParamsCKKSRNS>;
  994. }
  995. // Plaintext
  996. unsafe extern "C++"
  997. {
  998. fn Decode(self: &Plaintext) -> bool;
  999. fn Encode(self: &Plaintext) -> bool;
  1000. fn GetCoefPackedValue(self: &Plaintext) -> &CxxVector<i64>;
  1001. fn GetCopyOfCKKSPackedValue(self: &Plaintext) -> UniquePtr<CxxVector<ComplexPair>>;
  1002. fn GetLength(self: &Plaintext) -> usize;
  1003. fn GetLevel(self: &Plaintext) -> usize;
  1004. fn GetLogError(self: &Plaintext) -> f64;
  1005. fn GetLogPrecision(self: &Plaintext) -> f64;
  1006. fn GetNoiseScaleDeg(self: &Plaintext) -> usize;
  1007. fn GetPackedValue(self: &Plaintext) -> &CxxVector<i64>;
  1008. fn GetRealPackedValue(self: &Plaintext) -> UniquePtr<CxxVector<f64>>;
  1009. fn GetScalingFactor(self: &Plaintext) -> f64;
  1010. fn GetSchemeID(self: &Plaintext) -> SCHEME;
  1011. fn GetSlots(self: &Plaintext) -> u32;
  1012. fn GetString(self: &Plaintext) -> String;
  1013. fn GetStringValue(self: &Plaintext) -> &CxxString;
  1014. fn HighBound(self: &Plaintext) -> i64;
  1015. fn IsEncoded(self: &Plaintext) -> bool;
  1016. fn LowBound(self: &Plaintext) -> i64;
  1017. fn SetFormat(self: &Plaintext, fmt: Format);
  1018. fn SetIntVectorValue(self: &Plaintext, val: &CxxVector<i64>);
  1019. fn SetLength(self: &Plaintext, newSize: usize);
  1020. fn SetLevel(self: &Plaintext, l: usize);
  1021. fn SetNoiseScaleDeg(self: &Plaintext, nsd: usize);
  1022. fn SetScalingFactor(self: &Plaintext, sf: f64);
  1023. fn SetSlots(self: &Plaintext, s: u32);
  1024. fn SetStringValue(self: &Plaintext, value: &CxxString);
  1025. // Generator functions
  1026. fn GenNullPlainText() -> UniquePtr<Plaintext>;
  1027. }
  1028. // PublicKeyDCRTPoly
  1029. unsafe extern "C++"
  1030. {
  1031. // Generator functions
  1032. fn DCRTPolyGenNullPublicKey() -> UniquePtr<PublicKeyDCRTPoly>;
  1033. }
  1034. // PrivateKeyDCRTPoly
  1035. unsafe extern "C++"
  1036. {
  1037. // Generator functions
  1038. fn DCRTPolyGenNullPrivateKey() -> UniquePtr<PrivateKeyDCRTPoly>;
  1039. }
  1040. // Serialize / Deserialize
  1041. unsafe extern "C++"
  1042. {
  1043. // Ciphertext
  1044. fn DCRTPolyDeserializeCiphertextFromFile(ciphertextLocation: &CxxString,
  1045. ciphertext: Pin<&mut CiphertextDCRTPoly>,
  1046. serialMode: SerialMode) -> bool;
  1047. fn DCRTPolySerializeCiphertextToFile(ciphertextLocation: &CxxString,
  1048. ciphertext: &CiphertextDCRTPoly,
  1049. serialMode: SerialMode) -> bool;
  1050. // CryptoContextDCRTPoly
  1051. fn DCRTPolyDeserializeCryptoContextFromFile(ccLocation: &CxxString,
  1052. cryptoContext: Pin<&mut CryptoContextDCRTPoly>,
  1053. serialMode: SerialMode) -> bool;
  1054. fn DCRTPolySerializeCryptoContextToFile(ccLocation: &CxxString,
  1055. cryptoContext: &CryptoContextDCRTPoly,
  1056. serialMode: SerialMode) -> bool;
  1057. // EvalAutomorphismKey
  1058. fn DCRTPolyDeserializeEvalAutomorphismKeyFromFile(automorphismKeyLocation: &CxxString,
  1059. serialMode: SerialMode) -> bool;
  1060. fn DCRTPolySerializeEvalAutomorphismKeyByIdToFile(automorphismKeyLocation: &CxxString,
  1061. serialMode: SerialMode, id: &CxxString)
  1062. -> bool;
  1063. fn DCRTPolySerializeEvalAutomorphismKeyToFile(automorphismKeyLocation: &CxxString,
  1064. cryptoContext: &CryptoContextDCRTPoly,
  1065. serialMode: SerialMode) -> bool;
  1066. // EvalMultKey
  1067. fn DCRTPolyDeserializeEvalMultKeyFromFile(multKeyLocation: &CxxString,
  1068. serialMode: SerialMode) -> bool;
  1069. fn DCRTPolySerializeEvalMultKeyByIdToFile(multKeyLocation: &CxxString,
  1070. serialMode: SerialMode, id: &CxxString) -> bool;
  1071. fn DCRTPolySerializeEvalMultKeyToFile(multKeyLocation: &CxxString,
  1072. cryptoContext: &CryptoContextDCRTPoly,
  1073. serialMode: SerialMode) -> bool;
  1074. // EvalSumKey
  1075. fn DCRTPolyDeserializeEvalSumKeyFromFile(sumKeyLocation: &CxxString,
  1076. serialMode: SerialMode) -> bool;
  1077. fn DCRTPolySerializeEvalSumKeyByIdToFile(sumKeyLocation: &CxxString,
  1078. serialMode: SerialMode, id: &CxxString) -> bool;
  1079. fn DCRTPolySerializeEvalSumKeyToFile(sumKeyLocation: &CxxString,
  1080. cryptoContext: &CryptoContextDCRTPoly,
  1081. serialMode: SerialMode) -> bool;
  1082. // PublicKey
  1083. fn DCRTPolyDeserializePublicKeyFromFile(publicKeyLocation: &CxxString,
  1084. publicKey: Pin<&mut PublicKeyDCRTPoly>,
  1085. serialMode: SerialMode) -> bool;
  1086. fn DCRTPolySerializePublicKeyToFile(publicKeyLocation: &CxxString,
  1087. publicKey: &PublicKeyDCRTPoly,
  1088. serialMode: SerialMode) -> bool;
  1089. // PrivateKey
  1090. fn DCRTPolyDeserializePrivateKeyFromFile(privateKeyLocation: &CxxString,
  1091. privateKey: Pin<&mut PrivateKeyDCRTPoly>,
  1092. serialMode: SerialMode) -> bool;
  1093. fn DCRTPolySerializePrivateKeyToFile(privateKeyLocation: &CxxString,
  1094. privateKey: &PrivateKeyDCRTPoly,
  1095. serialMode: SerialMode) -> bool;
  1096. }
  1097. // Trapdoor
  1098. unsafe extern "C++"
  1099. {
  1100. // Generator functions
  1101. fn DCRTPolyTrapdoorGen(params: &ILDCRTParams, stddev: f64, base: i64, balanced: bool) -> UniquePtr<TrapdoorOutput>;
  1102. }
  1103. }
  1104. #[cfg(test)]
  1105. mod tests
  1106. {
  1107. use super::*;
  1108. // TODO: add more tests
  1109. #[test]
  1110. fn SimpleIntegersExample()
  1111. {
  1112. let mut _cc_params_bfvrns = ffi::GenParamsBFVRNS();
  1113. _cc_params_bfvrns.pin_mut().SetPlaintextModulus(65537);
  1114. _cc_params_bfvrns.pin_mut().SetMultiplicativeDepth(2);
  1115. let _cc = ffi::DCRTPolyGenCryptoContextByParamsBFVRNS(&_cc_params_bfvrns);
  1116. _cc.EnableByFeature(ffi::PKESchemeFeature::PKE);
  1117. _cc.EnableByFeature(ffi::PKESchemeFeature::KEYSWITCH);
  1118. _cc.EnableByFeature(ffi::PKESchemeFeature::LEVELEDSHE);
  1119. let _key_pair = _cc.KeyGen();
  1120. _cc.EvalMultKeyGen(&_key_pair.GetPrivateKey());
  1121. let mut _index_list = CxxVector::<i32>::new();
  1122. _index_list.pin_mut().push(1);
  1123. _index_list.pin_mut().push(2);
  1124. _index_list.pin_mut().push(-1);
  1125. _index_list.pin_mut().push(-2);
  1126. _cc.EvalRotateKeyGen(&_key_pair.GetPrivateKey(), &_index_list, &ffi::DCRTPolyGenNullPublicKey());
  1127. let mut _vector_of_ints_1 = CxxVector::<i64>::new();
  1128. _vector_of_ints_1.pin_mut().push(1);
  1129. _vector_of_ints_1.pin_mut().push(2);
  1130. _vector_of_ints_1.pin_mut().push(3);
  1131. _vector_of_ints_1.pin_mut().push(4);
  1132. _vector_of_ints_1.pin_mut().push(5);
  1133. _vector_of_ints_1.pin_mut().push(6);
  1134. _vector_of_ints_1.pin_mut().push(7);
  1135. _vector_of_ints_1.pin_mut().push(8);
  1136. _vector_of_ints_1.pin_mut().push(9);
  1137. _vector_of_ints_1.pin_mut().push(10);
  1138. _vector_of_ints_1.pin_mut().push(11);
  1139. _vector_of_ints_1.pin_mut().push(12);
  1140. let _plain_text_1 = _cc.MakePackedPlaintext(&_vector_of_ints_1, 1, 0);
  1141. let mut _vector_of_ints_2 = CxxVector::<i64>::new();
  1142. _vector_of_ints_2.pin_mut().push(3);
  1143. _vector_of_ints_2.pin_mut().push(2);
  1144. _vector_of_ints_2.pin_mut().push(1);
  1145. _vector_of_ints_2.pin_mut().push(4);
  1146. _vector_of_ints_2.pin_mut().push(5);
  1147. _vector_of_ints_2.pin_mut().push(6);
  1148. _vector_of_ints_2.pin_mut().push(7);
  1149. _vector_of_ints_2.pin_mut().push(8);
  1150. _vector_of_ints_2.pin_mut().push(9);
  1151. _vector_of_ints_2.pin_mut().push(10);
  1152. _vector_of_ints_2.pin_mut().push(11);
  1153. _vector_of_ints_2.pin_mut().push(12);
  1154. let _plain_text_2 = _cc.MakePackedPlaintext(&_vector_of_ints_2, 1, 0);
  1155. let mut _vector_of_ints_3 = CxxVector::<i64>::new();
  1156. _vector_of_ints_3.pin_mut().push(1);
  1157. _vector_of_ints_3.pin_mut().push(2);
  1158. _vector_of_ints_3.pin_mut().push(5);
  1159. _vector_of_ints_3.pin_mut().push(2);
  1160. _vector_of_ints_3.pin_mut().push(5);
  1161. _vector_of_ints_3.pin_mut().push(6);
  1162. _vector_of_ints_3.pin_mut().push(7);
  1163. _vector_of_ints_3.pin_mut().push(8);
  1164. _vector_of_ints_3.pin_mut().push(9);
  1165. _vector_of_ints_3.pin_mut().push(10);
  1166. _vector_of_ints_3.pin_mut().push(11);
  1167. _vector_of_ints_3.pin_mut().push(12);
  1168. let _plain_text_3 = _cc.MakePackedPlaintext(&_vector_of_ints_3, 1, 0);
  1169. let _cipher_text_1 = _cc.EncryptByPublicKey(&_key_pair.GetPublicKey(), &_plain_text_1);
  1170. let _cipher_text_2 = _cc.EncryptByPublicKey(&_key_pair.GetPublicKey(), &_plain_text_2);
  1171. let _cipher_text_3 = _cc.EncryptByPublicKey(&_key_pair.GetPublicKey(), &_plain_text_3);
  1172. let _cipher_text_add_1_2 = _cc.EvalAddByCiphertexts(&_cipher_text_1, &_cipher_text_2);
  1173. let _cipher_text_add_result = _cc.EvalAddByCiphertexts(&_cipher_text_add_1_2, &_cipher_text_3);
  1174. let _cipher_text_mul_1_2 = _cc.EvalMultByCiphertexts(&_cipher_text_1, &_cipher_text_2);
  1175. let _cipher_text_mult_result = _cc.EvalMultByCiphertexts(&_cipher_text_mul_1_2, &_cipher_text_3);
  1176. let _cipher_text_rot_1 = _cc.EvalRotate(&_cipher_text_1, 1);
  1177. let _cipher_text_rot_2 = _cc.EvalRotate(&_cipher_text_1, 2);
  1178. let _cipher_text_rot_3 = _cc.EvalRotate(&_cipher_text_1, -1);
  1179. let _cipher_text_rot_4 = _cc.EvalRotate(&_cipher_text_1, -2);
  1180. let mut _plain_text_add_result = ffi::GenNullPlainText();
  1181. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_add_result, _plain_text_add_result.pin_mut());
  1182. let mut _plain_text_mult_result = ffi::GenNullPlainText();
  1183. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_mult_result, _plain_text_mult_result.pin_mut());
  1184. let mut _plain_text_rot_1 = ffi::GenNullPlainText();
  1185. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_1, _plain_text_rot_1.pin_mut());
  1186. let mut _plain_text_rot_2 = ffi::GenNullPlainText();
  1187. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_2, _plain_text_rot_2.pin_mut());
  1188. let mut _plain_text_rot_3 = ffi::GenNullPlainText();
  1189. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_3, _plain_text_rot_3.pin_mut());
  1190. let mut _plain_text_rot_4 = ffi::GenNullPlainText();
  1191. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_cipher_text_rot_4, _plain_text_rot_4.pin_mut());
  1192. _plain_text_rot_1.SetLength(_vector_of_ints_1.len());
  1193. _plain_text_rot_2.SetLength(_vector_of_ints_1.len());
  1194. _plain_text_rot_3.SetLength(_vector_of_ints_1.len());
  1195. _plain_text_rot_4.SetLength(_vector_of_ints_1.len());
  1196. println!("Plaintext #1: {}", _plain_text_1.GetString());
  1197. println!("Plaintext #2: {}", _plain_text_2.GetString());
  1198. println!("Plaintext #3: {}", _plain_text_3.GetString());
  1199. println!("\nResults of homomorphic computations");
  1200. println!("#1 + #2 + #3: {}", _plain_text_add_result.GetString());
  1201. println!("#1 * #2 * #3: {}", _plain_text_mult_result.GetString());
  1202. println!("Left rotation of #1 by 1: {}", _plain_text_rot_1.GetString());
  1203. println!("Left rotation of #1 by 2: {}", _plain_text_rot_2.GetString());
  1204. println!("Right rotation of #1 by -1: {}", _plain_text_rot_3.GetString());
  1205. println!("Right rotation of #1 by -2: {}", _plain_text_rot_4.GetString());
  1206. }
  1207. #[test]
  1208. fn SimpleRealNumbersExample()
  1209. {
  1210. let _mult_depth: u32 = 1;
  1211. let _scale_mod_size: u32 = 50;
  1212. let _batch_size: u32 = 8;
  1213. let mut _cc_params_ckksrns = ffi::GenParamsCKKSRNS();
  1214. _cc_params_ckksrns.pin_mut().SetMultiplicativeDepth(_mult_depth);
  1215. _cc_params_ckksrns.pin_mut().SetScalingModSize(_scale_mod_size);
  1216. _cc_params_ckksrns.pin_mut().SetBatchSize(_batch_size);
  1217. let _cc = ffi::DCRTPolyGenCryptoContextByParamsCKKSRNS(&_cc_params_ckksrns);
  1218. _cc.EnableByFeature(ffi::PKESchemeFeature::PKE);
  1219. _cc.EnableByFeature(ffi::PKESchemeFeature::KEYSWITCH);
  1220. _cc.EnableByFeature(ffi::PKESchemeFeature::LEVELEDSHE);
  1221. println!("CKKS scheme is using ring dimension {}\n", _cc.GetRingDimension());
  1222. let _key_pair = _cc.KeyGen();
  1223. _cc.EvalMultKeyGen(&_key_pair.GetPrivateKey());
  1224. let mut _index_list = CxxVector::<i32>::new();
  1225. _index_list.pin_mut().push(1);
  1226. _index_list.pin_mut().push(-2);
  1227. _cc.EvalRotateKeyGen(&_key_pair.GetPrivateKey(), &_index_list, &ffi::DCRTPolyGenNullPublicKey());
  1228. let mut _x_1 = CxxVector::<f64>::new();
  1229. _x_1.pin_mut().push(0.25);
  1230. _x_1.pin_mut().push(0.5);
  1231. _x_1.pin_mut().push(0.75);
  1232. _x_1.pin_mut().push(1.0);
  1233. _x_1.pin_mut().push(2.0);
  1234. _x_1.pin_mut().push(3.0);
  1235. _x_1.pin_mut().push(4.0);
  1236. _x_1.pin_mut().push(5.0);
  1237. let mut _x_2 = CxxVector::<f64>::new();
  1238. _x_2.pin_mut().push(5.0);
  1239. _x_2.pin_mut().push(4.0);
  1240. _x_2.pin_mut().push(3.0);
  1241. _x_2.pin_mut().push(2.0);
  1242. _x_2.pin_mut().push(1.0);
  1243. _x_2.pin_mut().push(0.75);
  1244. _x_2.pin_mut().push(0.5);
  1245. _x_2.pin_mut().push(0.25);
  1246. let _dcrt_poly_params = ffi::DCRTPolyGenNullParams();
  1247. let _p_txt_1 = _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_1, 1, 0, &_dcrt_poly_params, 0);
  1248. let _p_txt_2 = _cc.MakeCKKSPackedPlaintextByVectorOfDouble(&_x_2, 1, 0, &_dcrt_poly_params, 0);
  1249. println!("Input x1: {}", _p_txt_1.GetString());
  1250. println!("Input x2: {}", _p_txt_2.GetString());
  1251. let _c1 = _cc.EncryptByPublicKey(&_key_pair.GetPublicKey(), &_p_txt_1);
  1252. let _c2 = _cc.EncryptByPublicKey(&_key_pair.GetPublicKey(), &_p_txt_2);
  1253. let _c_add = _cc.EvalAddByCiphertexts(&_c1, &_c2);
  1254. let _c_sub = _cc.EvalSubByCiphertexts(&_c1, &_c2);
  1255. let _c_scalar = _cc.EvalMultByCiphertextAndConst(&_c1, 4.0);
  1256. let _c_mul = _cc.EvalMultByCiphertexts(&_c1, &_c2);
  1257. let _c_rot_1 = _cc.EvalRotate(&_c1, 1);
  1258. let _c_rot_2 = _cc.EvalRotate(&_c1, -2);
  1259. let mut _result = ffi::GenNullPlainText();
  1260. println!("\nResults of homomorphic computations:");
  1261. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c1, _result.pin_mut());
  1262. _result.SetLength(_batch_size.try_into().unwrap());
  1263. println!("x1 = {}Estimated precision in bits: {}", _result.GetString(), _result.GetLogPrecision());
  1264. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_add, _result.pin_mut());
  1265. _result.SetLength(_batch_size.try_into().unwrap());
  1266. println!("x1 + x2 = {}Estimated precision in bits: {}",_result.GetString(), _result.GetLogPrecision());
  1267. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_sub, _result.pin_mut());
  1268. _result.SetLength(_batch_size.try_into().unwrap());
  1269. println!("x1 - x2 = {}", _result.GetString());
  1270. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_scalar, _result.pin_mut());
  1271. _result.SetLength(_batch_size.try_into().unwrap());
  1272. println!("4 * x1 = {}", _result.GetString());
  1273. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_mul, _result.pin_mut());
  1274. _result.SetLength(_batch_size.try_into().unwrap());
  1275. println!("x1 * x2 = {}", _result.GetString());
  1276. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_rot_1, _result.pin_mut());
  1277. _result.SetLength(_batch_size.try_into().unwrap());
  1278. println!("\nIn rotations, very small outputs (~10^-10 here) correspond to 0's:");
  1279. println!("x1 rotate by 1 = {}", _result.GetString());
  1280. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_c_rot_2, _result.pin_mut());
  1281. _result.SetLength(_batch_size.try_into().unwrap());
  1282. println!("x1 rotate by -2 = {}", _result.GetString());
  1283. }
  1284. #[test]
  1285. fn PolynomialEvaluationExample()
  1286. {
  1287. use std::time::Instant;
  1288. println!("\n======EXAMPLE FOR EVALPOLY========\n");
  1289. let mut _cc_params_ckksrns = ffi::GenParamsCKKSRNS();
  1290. _cc_params_ckksrns.pin_mut().SetMultiplicativeDepth(6);
  1291. _cc_params_ckksrns.pin_mut().SetScalingModSize(50);
  1292. let _cc = ffi::DCRTPolyGenCryptoContextByParamsCKKSRNS(&_cc_params_ckksrns);
  1293. _cc.EnableByFeature(ffi::PKESchemeFeature::PKE);
  1294. _cc.EnableByFeature(ffi::PKESchemeFeature::KEYSWITCH);
  1295. _cc.EnableByFeature(ffi::PKESchemeFeature::LEVELEDSHE);
  1296. _cc.EnableByFeature(ffi::PKESchemeFeature::ADVANCEDSHE);
  1297. let mut _input = CxxVector::<ffi::ComplexPair>::new();
  1298. _input.pin_mut().push(ffi::ComplexPair{re: 0.5, im: 0.0});
  1299. _input.pin_mut().push(ffi::ComplexPair{re: 0.7, im: 0.0});
  1300. _input.pin_mut().push(ffi::ComplexPair{re: 0.9, im: 0.0});
  1301. _input.pin_mut().push(ffi::ComplexPair{re: 0.95, im: 0.0});
  1302. _input.pin_mut().push(ffi::ComplexPair{re: 0.93, im: 0.0});
  1303. let _encoded_length = _input.len();
  1304. let mut _coefficients_1 = CxxVector::<f64>::new();
  1305. _coefficients_1.pin_mut().push(0.15);
  1306. _coefficients_1.pin_mut().push(0.75);
  1307. _coefficients_1.pin_mut().push(0.0);
  1308. _coefficients_1.pin_mut().push(1.25);
  1309. _coefficients_1.pin_mut().push(0.0);
  1310. _coefficients_1.pin_mut().push(0.0);
  1311. _coefficients_1.pin_mut().push(1.0);
  1312. _coefficients_1.pin_mut().push(0.0);
  1313. _coefficients_1.pin_mut().push(1.0);
  1314. _coefficients_1.pin_mut().push(2.0);
  1315. _coefficients_1.pin_mut().push(0.0);
  1316. _coefficients_1.pin_mut().push(1.0);
  1317. _coefficients_1.pin_mut().push(0.0);
  1318. _coefficients_1.pin_mut().push(0.0);
  1319. _coefficients_1.pin_mut().push(0.0);
  1320. _coefficients_1.pin_mut().push(0.0);
  1321. _coefficients_1.pin_mut().push(1.0);
  1322. let mut _coefficients_2 = CxxVector::<f64>::new();
  1323. _coefficients_2.pin_mut().push(1.0);
  1324. _coefficients_2.pin_mut().push(2.0);
  1325. _coefficients_2.pin_mut().push(3.0);
  1326. _coefficients_2.pin_mut().push(4.0);
  1327. _coefficients_2.pin_mut().push(5.0);
  1328. _coefficients_2.pin_mut().push(-1.0);
  1329. _coefficients_2.pin_mut().push(-2.0);
  1330. _coefficients_2.pin_mut().push(-3.0);
  1331. _coefficients_2.pin_mut().push(-4.0);
  1332. _coefficients_2.pin_mut().push(-5.0);
  1333. _coefficients_2.pin_mut().push(0.1);
  1334. _coefficients_2.pin_mut().push(0.2);
  1335. _coefficients_2.pin_mut().push(0.3);
  1336. _coefficients_2.pin_mut().push(0.4);
  1337. _coefficients_2.pin_mut().push(0.5);
  1338. _coefficients_2.pin_mut().push(-0.1);
  1339. _coefficients_2.pin_mut().push(-0.2);
  1340. _coefficients_2.pin_mut().push(-0.3);
  1341. _coefficients_2.pin_mut().push(-0.4);
  1342. _coefficients_2.pin_mut().push(-0.5);
  1343. _coefficients_2.pin_mut().push(0.1);
  1344. _coefficients_2.pin_mut().push(0.2);
  1345. _coefficients_2.pin_mut().push(0.3);
  1346. _coefficients_2.pin_mut().push(0.4);
  1347. _coefficients_2.pin_mut().push(0.5);
  1348. _coefficients_2.pin_mut().push(-0.1);
  1349. _coefficients_2.pin_mut().push(-0.2);
  1350. _coefficients_2.pin_mut().push(-0.3);
  1351. _coefficients_2.pin_mut().push(-0.4);
  1352. _coefficients_2.pin_mut().push(-0.5);
  1353. let _dcrt_poly_params = ffi::DCRTPolyGenNullParams();
  1354. let _plain_text_1 = _cc.MakeCKKSPackedPlaintextByVectorOfComplex(&_input, 1, 0, &_dcrt_poly_params, 0);
  1355. let _key_pair = _cc.KeyGen();
  1356. print!("Generating evaluation key for homomorphic multiplication...");
  1357. _cc.EvalMultKeyGen(&_key_pair.GetPrivateKey());
  1358. println!("Completed.\n");
  1359. let _cipher_text_1 = _cc.EncryptByPublicKey(&_key_pair.GetPublicKey(), &_plain_text_1);
  1360. let mut _start = Instant::now();
  1361. let _result = _cc.EvalPoly(&_cipher_text_1, &_coefficients_1);
  1362. let _time_eval_poly_1 = _start.elapsed();
  1363. _start = Instant::now();
  1364. let _result_2 = _cc.EvalPoly(&_cipher_text_1, &_coefficients_2);
  1365. let _time_eval_poly_2 = _start.elapsed();
  1366. let mut _plain_text_dec = ffi::GenNullPlainText();
  1367. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_result, _plain_text_dec.pin_mut());
  1368. _plain_text_dec.SetLength(_encoded_length);
  1369. let mut _plain_text_dec_2 = ffi::GenNullPlainText();
  1370. _cc.DecryptByPrivateKeyAndCiphertext(&_key_pair.GetPrivateKey(), &_result_2, _plain_text_dec_2.pin_mut());
  1371. _plain_text_dec_2.SetLength(_encoded_length);
  1372. println!("\n Original Plaintext #1:");
  1373. println!("{}", _plain_text_1.GetString());
  1374. println!("\n Result of evaluating a polynomial with coefficients [{} ]", _coefficients_1.iter().fold(String::new(), |acc, &arg| acc + " " + &arg.to_string()));
  1375. println!("{}", _plain_text_dec.GetString());
  1376. println!("\n Expected result: (0.70519107, 1.38285078, 3.97211180, 5.60215665, 4.86357575)");
  1377. println!("\n Evaluation time: {:.0?}", _time_eval_poly_1);
  1378. println!("\n Result of evaluating a polynomial with coefficients [{} ]", _coefficients_2.iter().fold(String::new(), |acc, &arg| acc + " " + &arg.to_string()));
  1379. println!("{}\n", _plain_text_dec_2.GetString());
  1380. println!(" Expected result: (3.4515092326, 5.3752765397, 4.8993108833, 3.2495023573, 4.0485229982)");
  1381. print!("\n Evaluation time: {:.0?}\n", _time_eval_poly_2);
  1382. }
  1383. }