lib.rs 71 KB

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