cryptocontext_docs.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. // BSD 2-Clause License
  2. // Copyright (c) 2023, OpenFHE
  3. // All rights reserved.
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are met:
  6. // 1. Redistributions of source code must retain the above copyright notice, this
  7. // list of conditions and the following disclaimer.
  8. // 2. Redistributions in binary form must reproduce the above copyright notice,
  9. // this list of conditions and the following disclaimer in the documentation
  10. // and/or other materials provided with the distribution.
  11. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  12. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  13. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  14. // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  15. // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  16. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  17. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  18. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  19. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  20. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. #ifndef CRYPTOCONTEXT_DOCSTRINGS_H
  22. #define CRYPTOCONTEXT_DOCSTRINGS_H
  23. #include "pybind11/pybind11.h"
  24. #include "pybind11/attr.h"
  25. namespace py = pybind11;
  26. // const char* cc_docs = R"doc(
  27. // test
  28. // )doc";
  29. // auto cc_docs2 = py::doc(cc_docs);
  30. const char* cc_SetKeyGenLevel_docs = R"pbdoc(
  31. Set the level used for key generation
  32. :param level: the level to set the key generation to
  33. :type level: int
  34. )pbdoc";
  35. const char* cc_GetKeyGenLevel_docs = R"pbdoc(
  36. Get the level used for key generation
  37. :return: The level used for key generation
  38. :rtype: int
  39. )pbdoc";
  40. const char* cc_GetRingDimension_docs = R"pbdoc(
  41. Get the ring dimension used for this context
  42. :return: The ring dimension
  43. :rtype: int
  44. )pbdoc";
  45. const char* cc_Enable_docs = R"pbdoc(
  46. Enable a particular feature for use with this CryptoContext
  47. :param feature: the feature that should be enabled.
  48. The list of available features is defined in the PKESchemeFeature enum.
  49. :type feature: PKESchemeFeature
  50. )pbdoc";
  51. const char* cc_KeyGen_docs = R"pbdoc(
  52. Generate a public and private key pair
  53. :return: a public/secret key pair
  54. :rtype: KeyPair
  55. )pbdoc";
  56. const char* cc_EvalMultKeyGen_docs = R"pbdoc(
  57. EvalMultKeyGen creates a key that can be used with the OpenFHE EvalMult operator.
  58. The new evaluation key is stored in cryptocontext.
  59. :param privateKey: the private key
  60. :type privateKey: PrivateKey
  61. )pbdoc";
  62. const char* cc_EvalMultKeysGen_docs = R"pbdoc(
  63. EvalMultsKeyGen creates a vector evalmult keys that can be used with the OpenFHE EvalMult operator.
  64. The 1st key (for s^2) is used for multiplication of ciphertexts of depth 1.
  65. The 2nd key (for s^3) is used for multiplication of ciphertexts of depth 2, etc.
  66. A vector of new evaluation keys is stored in cryptocontext.
  67. :param privateKey: the private key
  68. :type privateKey: PrivateKey
  69. )pbdoc";
  70. const char* cc_EvalRotateKeyGen_docs = R"pbdoc(
  71. EvalRotateKeyGen generates evaluation keys for a list of indices
  72. :param privateKey: private key
  73. :type privateKey: PrivateKey
  74. :param indexList: list of integers representing the indices
  75. :type indexList: list
  76. :param publicKey: public key (used in NTRU schemes)
  77. :type publicKey: PublicKey
  78. )pbdoc";
  79. // MakeStringPlaintext
  80. const char* cc_MakeStringPlaintext_docs = R"pbdoc(
  81. MakeStringPlaintext constructs a StringEncoding in this context.
  82. :param str: the string to convert
  83. :type str: str
  84. :return: plaintext
  85. )pbdoc";
  86. const char* cc_MakePackedPlaintext_docs = R"pbdoc(
  87. MakePackedPlaintext constructs a PackedEncoding in this context
  88. :param value: the vector (of integers) to convert
  89. :type value: list
  90. :param depth: is the multiplicative depth to encode the plaintext at
  91. :type depth: int
  92. :param level: is the level to encode the plaintext at
  93. :type level: int
  94. :return: plaintext
  95. :rtype: Plaintext
  96. )pbdoc";
  97. const char* cc_MakeCoefPackedPlaintext_docs = R"pbdoc(
  98. MakeCoefPackedPlaintext constructs a CoefPackedEncoding in this context
  99. :param value: the vector (of integers) to convert
  100. :type value: list
  101. :param depth: is the multiplicative depth to encode the plaintext at
  102. :type depth: int
  103. :param level: is the level to encode the plaintext at
  104. :type level: int
  105. :return: plaintext
  106. :rtype: Plaintext
  107. )pbdoc";
  108. const char* cc_MakeCKKSPackedPlaintextComplex_docs = R"pbdoc(
  109. COMPLEX ARITHMETIC IS NOT AVAILABLE STARTING WITH OPENFHE 1.10.6, AND THIS METHOD BE DEPRECATED. USE THE REAL-NUMBER METHOD INSTEAD. MakeCKKSPackedPlaintext constructs a CKKSPackedEncoding in this context from a vector of complex numbers
  110. :param value: input vector (of complex numbers)
  111. :type value: list
  112. :param depth: depth used to encode the vector
  113. :type depth: int
  114. :param level: level at each the vector will get encrypted
  115. :type level: int
  116. :param params: parameters to be used for the ciphertext (Only accepting params = None in this version)
  117. :type params: openfhe.ParmType
  118. :param slots: number of slots
  119. :type slots: int
  120. :return: plaintext
  121. :rtype: Plaintext
  122. )pbdoc";
  123. const char* cc_MakeCKKSPlaintextReal_docs = R"pbdoc(
  124. MakeCKKSPlaintext constructs a CKKSPackedEncoding in this context from a vector of real numbers
  125. :param value: input vector (of floats)
  126. :type value: list
  127. :param depth: depth used to encode the vector
  128. :type depth: int
  129. :param level: level at each the vector will get encrypted
  130. :type level: int
  131. :param params: parameters to be used for the ciphertext (Only accepting params = None in this version)
  132. :type params: openfhe.ParmType
  133. :param slots: number of slots
  134. :type slots: int
  135. :return: plaintext
  136. :rtype: Plaintext
  137. )pbdoc";
  138. const char* cc_EvalRotate_docs = R"pbdoc(
  139. EvalRotate rotates a ciphertext by a given index
  140. :param ciphertext: the ciphertext to rotate
  141. :type ciphertext: Ciphertext
  142. :param index: the index of the rotation. Positive indices correspond to left rotations and negative indices correspond to right rotations.
  143. :type index: int
  144. :return: the rotated ciphertext
  145. :rtype: Ciphertext
  146. )pbdoc";
  147. const char* cc_EvalFastRotationPreCompute_docs = R"pbdoc(
  148. EvalFastRotationPrecompute implements the precomputation step of hoisted automorphisms.
  149. Please refer to Section 5 of Halevi and Shoup, "Faster Homomorphic
  150. linear transformations in HELib." for more details, link:
  151. https://eprint.iacr.org/2018/244.
  152. Generally, automorphisms are performed with three steps:
  153. (1) The automorphism is applied to the ciphertext.
  154. (2) The automorphed values are decomposed into digits.
  155. (3) Key switching is applied to enable further computations on the ciphertext.
  156. Hoisted automorphisms are a technique that performs the digit decomposition for the original ciphertext first,
  157. and then performs the automorphism and the key switching on the decomposed digits.
  158. The benefit of this is that the digit decomposition is independent of the automorphism rotation index,
  159. so it can be reused for multiple different indices.
  160. This can greatly improve performance when we have to compute many automorphisms on the same ciphertext.
  161. This routinely happens when we do permutations (EvalPermute).
  162. EvalFastRotationPrecompute implements the digit decomposition step of hoisted automorphisms.
  163. :param ciphertext: the input ciphertext on which to do the precomputation (digit decomposition)
  164. :type ciphertext: Ciphertext
  165. :return: the precomputed ciphertext created using the digit decomposition
  166. :rtype: Ciphertext
  167. )pbdoc";
  168. const char* cc_EvalFastRotation_docs = R"pbdoc(
  169. EvalFastRotation implements the automorphism and key switching step of hoisted automorphisms.
  170. Please refer to Section 5 of Halevi and Shoup, "Faster Homomorphic
  171. linear transformations in HELib." for more details, link:
  172. https://eprint.iacr.org/2018/244.
  173. Generally, automorphisms are performed with three steps:
  174. (1) The automorphism is applied to the ciphertext.
  175. (2) The automorphed values are decomposed into digits.
  176. (3) Key switching is applied to enable further computations on the ciphertext.
  177. Hoisted automorphisms are a technique that performs the digit decomposition for the original ciphertext first,
  178. and then performs the automorphism and the key switching on the decomposed digits.
  179. The benefit of this is that the digit decomposition is independent of the automorphism rotation index,
  180. so it can be reused for multiple different indices.
  181. This can greatly improve performance when we have to compute many automorphisms on the same ciphertext.
  182. This routinely happens when we do permutations (EvalPermute).
  183. EvalFastRotation implements the automorphism and key switching step of hoisted automorphisms.
  184. This method assumes that all required rotation keys exist.
  185. This may not be true if we are using baby-step/giant-step key switching.
  186. Please refer to Section 5.1 of the above reference and EvalPermuteBGStepHoisted to see how to deal with this issue.
  187. :param ciphertext: the input ciphertext to perform the automorphism on
  188. :type ciphertext: Ciphertext
  189. :param index: the index of the rotation. Positive indices correspond to left rotations and negative indices correspond to right rotations.
  190. :type index: int
  191. :param m: is the cyclotomic order
  192. :type m: int
  193. :param digits: the precomputed ciphertext created by EvalFastRotationPrecompute using the digit decomposition at the precomputation step
  194. :type digits: Ciphertext
  195. :return: the rotated ciphertext
  196. :rtype: Ciphertext
  197. )pbdoc";
  198. const char* cc_EvalFastRotationExt_docs = R"pbdoc(
  199. Only supported for hybrid key switching. Performs fast (hoisted) rotation and returns the results in the extended CRT basis P*Q
  200. :param ciphertext: input ciphertext
  201. :type ciphertext: Ciphertext
  202. :param index: the rotation index
  203. :type index: int
  204. :param digits: the precomputed ciphertext created by EvalFastRotationPrecompute
  205. :type digits: Ciphertext
  206. :param addFirst: if true, the first element c0 is also computed (otherwise ignored)
  207. :type addFirst: bool
  208. :return: resulting ciphertext
  209. :rtype: Ciphertext
  210. )pbdoc";
  211. const char* cc_EvalAtIndex_docs = R"pbdoc(
  212. Moves i-th slot to slot 0
  213. :param ciphertext: the ciphertext
  214. :type ciphertext: Ciphertext
  215. :param i: the index
  216. :type i: int
  217. :return: resulting ciphertext
  218. :rtype: Ciphertext
  219. )pbdoc";
  220. const char* cc_EvalAtIndexKeyGen_docs = R"pbdoc(
  221. EvalAtIndexKeyGen generates evaluation keys for a list of indices
  222. :param privateKey: the private key
  223. :type privateKey: PrivateKey
  224. :param indexList: list of indices
  225. :type indexList: list
  226. :param publicKey: the public key (used in NTRU schemes)
  227. :type publicKey: PublicKey
  228. :return: None
  229. )pbdoc";
  230. const char* cc_Encrypt_docs = R"doc(
  231. Encrypt a plaintext using a given public key
  232. :param plaintext: the plaintext to encrypt
  233. :type plaintext: Plaintext
  234. :param publicKey: the public key
  235. :type publicKey: PublicKey
  236. :return: ciphertext (or null on failure)
  237. :rtype: Ciphertext
  238. )doc";
  239. const char* cc_Decrypt_docs = R"pbdoc(
  240. Decrypt a single ciphertext into the appropriate plaintext
  241. :param ciphertext: ciphertext to decrypt
  242. :type ciphertext: Ciphertext
  243. :param privateKey: decryption key
  244. :type privateKey: PrivateKey
  245. :return: decrypted plaintext
  246. :rtype: Plaintext
  247. )pbdoc";
  248. const char* cc_EvalAdd_docs = R"pbdoc(
  249. Add two ciphertexts
  250. :param ct1: first ciphertext
  251. :type ct1: Ciphertext
  252. :param ct2: second ciphertext
  253. :type ct2: Ciphertext
  254. :return: resulting ciphertext
  255. :rtype: Ciphertext
  256. )pbdoc";
  257. const char* cc_EvalAddfloat_docs = R"pbdoc(
  258. EvalAdd - OpenFHE EvalAdd method for a ciphertext and constant
  259. :param ct: ciphertext
  260. :type ct: Ciphertext
  261. :param constant: constant to add
  262. :type constant: float
  263. :return: new ciphertext for ciphertext + constant
  264. :rtype: Ciphertext
  265. )pbdoc";
  266. const char* cc_EvalAddInPlace_docs = R"pbdoc(
  267. EvalAdd - OpenFHE EvalAddInPlace method for a pair of ciphertexts
  268. :param ct1: Input/output ciphertext
  269. :type ct1: Ciphertext
  270. :param ct2: Input ciphertext
  271. :type ct2: Ciphertext
  272. :return: ct1 contains ct1 + ct2
  273. )pbdoc";
  274. const char* cc_EvalAddInPlacePlaintext_docs = R"pbdoc(
  275. EvalAdd - OpenFHE EvalAddInPlace method for a ciphertext and plaintext
  276. :param ct: Input/output ciphertext
  277. :type ct: Ciphertext
  278. :param pt: Input plaintext
  279. :type pt: Plaintext
  280. :return: ct contains ct + pt
  281. )pbdoc";
  282. const char* cc_EvalAddMutable_docs = R"pbdoc(
  283. EvalAdd - OpenFHE EvalAddMutable method for a pair of ciphertexts. This is a mutable version - input ciphertexts may get automatically rescaled, or level-reduced.
  284. :param ct1: first ciphertext
  285. :type ct1: Ciphertext
  286. :param ct2: second ciphertext
  287. :type ct2: Ciphertext
  288. :return: new ciphertext for ct1 + ct2
  289. :rtype: Ciphertext
  290. )pbdoc";
  291. const char* cc_EvalAddMutablePlaintext_docs = R"pbdoc(
  292. EvalAdd - OpenFHE EvalAddMutable method for a ciphertext and plaintext. This is a mutable version - input ciphertexts may get automatically rescaled, or level-reduced.
  293. :param ciphertext: ciphertext
  294. :type ciphertext: Ciphertext
  295. :param plaintext: plaintext
  296. :type plaintext: Plaintext
  297. :return: new ciphertext for ciphertext + plaintext
  298. :rtype: Ciphertext
  299. )pbdoc";
  300. const char* cc_EvalAddMutableInPlace_docs = R"pbdoc(
  301. EvalAdd - Inplace version of EvalAddMutable
  302. :param ct1: Input/output ciphertext
  303. :type ct1: Ciphertext
  304. :param ct2: Input ciphertext
  305. :type ct2: Ciphertext
  306. :return: ct1 contains ct1 + ct2
  307. )pbdoc";
  308. const char* cc_EvalSub_docs = R"pbdoc(
  309. EvalSub - OpenFHE EvalSub method for a pair of ciphertexts
  310. :param ct1: first ciphertext
  311. :type ct1: Ciphertext
  312. :param ct2: second ciphertext
  313. :type ct2: Ciphertext
  314. :return: new ciphertext for ct1 - ct2
  315. :rtype: Ciphertext
  316. )pbdoc";
  317. const char* cc_EvalSubfloat_docs = R"pbdoc(
  318. EvalSub - OpenFHE EvalSub method for a ciphertext and constant
  319. :param ciphertext: ciphertext
  320. :type ciphertext: Ciphertext
  321. :param constant: constant to subtract
  322. :type constant: float
  323. :return: new ciphertext for ciphertext - constant
  324. :rtype: Ciphertext
  325. )pbdoc";
  326. const char* cc_EvalSubPlaintext_docs = R"pbdoc(
  327. EvalSub - OpenFHE EvalSub method for a ciphertext and plaintext
  328. :param ciphertext: ciphertext
  329. :type ciphertext: Ciphertext
  330. :param plaintext: plaintext
  331. :type plaintext: Plaintext
  332. :return: new ciphertext for ciphertext - plaintext
  333. :rtype: Ciphertext
  334. )pbdoc";
  335. const char* cc_EvalSubInPlace_docs = R"pbdoc(
  336. Inplace version of EvalSub for a pair of ciphertexts
  337. :param ct1: Input/output ciphertext
  338. :type ct1: Ciphertext
  339. :param ct2: Input ciphertext
  340. :type ct2: Ciphertext
  341. :return: ct1 contains ct1 - ct2
  342. )pbdoc";
  343. const char* cc_EvalSubInPlacefloat_docs = R"pbdoc(
  344. Inplace version of EvalSub for a ciphertext and constant
  345. :param ciphertext: Input/output ciphertext
  346. :type ciphertext: Ciphertext
  347. :param constant: constant to subtract
  348. :type constant: float
  349. :return: ciphertext contains ciphertext - constant
  350. )pbdoc";
  351. // EvalSubMutable
  352. const char* cc_EvalSubMutable_docs = R"pbdoc(
  353. EvalSub - OpenFHE EvalSubMutable method for a pair of ciphertexts. This is a mutable version - input ciphertexts may get automatically rescaled, or level-reduced.
  354. :param ct1: first ciphertext
  355. :type ct1: Ciphertext
  356. :param ct2: second ciphertext
  357. :type ct2: Ciphertext
  358. :return: new ciphertext for ct1 - ct2
  359. )pbdoc";
  360. // EvalSubMutableInPlace
  361. const char* cc_EvalSubMutableInPlace_docs = R"pbdoc(
  362. EvalSub - Inplace variant for EvalSubMutable.
  363. :param ct1: Input/output ciphertext
  364. :type ct1: Ciphertext
  365. :param ct2: Input ciphertext
  366. :type ct2: Ciphertext
  367. :return: ct1 contains ct1 - ct2
  368. )pbdoc";
  369. // EvalSubMutablePlaintext
  370. const char* cc_EvalSubMutablePlaintext_docs = R"pbdoc(
  371. EvalSub - OpenFHE EvalSubMutable method for a ciphertext and plaintext. This is a mutable version - input ciphertexts may get automatically rescaled, or level-reduced.
  372. :param ciphertext: ciphertext
  373. :type ciphertext: Ciphertext
  374. :param plaintext: plaintext
  375. :type plaintext: Plaintext
  376. :return: new ciphertext for ciphertext - plaintext
  377. )pbdoc";
  378. const char* cc_EvalMult_docs = R"pbdoc(
  379. EvalMult - OpenFHE EvalMult method for a pair of ciphertexts - with key switching
  380. :param ct1: first ciphertext
  381. :type ct1: Ciphertext
  382. :param ct2: second ciphertext
  383. :type ct2: Ciphertext
  384. :return: new ciphertext for ct1 * ct2
  385. :rtype: Ciphertext
  386. )pbdoc";
  387. const char* cc_EvalMultfloat_docs = R"pbdoc(
  388. EvalMult - OpenFHE EvalMult method for a ciphertext and constant
  389. :param ciphertext: the ciphertext
  390. :type ciphertext: Ciphertext
  391. :param constant: constant to multiply
  392. :type constant: float
  393. :return: new ciphertext for ciphertext * constant
  394. :rtype: Ciphertext
  395. )pbdoc";
  396. const char* cc_EvalMultPlaintext_docs = R"pbdoc(
  397. EvalMult - OpenFHE EvalMult method for a ciphertext and plaintext
  398. :param ciphertext: the ciphertext
  399. :type ciphertext: Ciphertext
  400. :param plaintext: the plaintext
  401. :type plaintext: Plaintext
  402. :return: new ciphertext for ciphertext * plaintext
  403. :rtype: Ciphertext
  404. )pbdoc";
  405. const char* cc_EvalMultMutable_docs = R"pbdoc(
  406. EvalMult - OpenFHE EvalMultMutable method for a pair of ciphertexts. This is a mutable version - input ciphertexts may get automatically rescaled, or level-reduced.
  407. :param ct1: first ciphertext
  408. :type ct1: Ciphertext
  409. :param ct2: second ciphertext
  410. :type ct2: Ciphertext
  411. :return: new ciphertext for ct1 * ct2
  412. :rtype: Ciphertext
  413. )pbdoc";
  414. const char* cc_EvalMultMutablePlaintext_docs = R"pbdoc(
  415. EvalMult - OpenFHE EvalMultMutable method for a ciphertext and plaintext. This is a mutable version - input ciphertexts may get automatically rescaled, or level-reduced.
  416. :param ciphertext: the ciphertext
  417. :type ciphertext: Ciphertext
  418. :param plaintext: the plaintext
  419. :type plaintext: Plaintext
  420. :return: new ciphertext for ciphertext * plaintext
  421. :rtype: Ciphertext
  422. )pbdoc";
  423. const char* cc_EvalMultMutableInPlace_docs = R"pbdoc(
  424. EvalMult - OpenFHE EvalMult method for a pair of ciphertexts - with key switching. This is a mutable version - input ciphertexts may get automatically rescaled, or level-reduced.
  425. :param ct1: Input/output ciphertext
  426. :type ct1: Ciphertext
  427. :param ct2: Input cipherext
  428. :type ct2: Ciphertext
  429. :return: ct1 contains ct1 * ct2
  430. )pbdoc";
  431. const char* cc_EvalSquare_docs = R"pbdoc(
  432. EvalSquare - OpenFHE EvalSquare method for a ciphertext
  433. :param ct: the ciphertext to square
  434. :type ct: Ciphertext
  435. :return: new ciphertext for ct^2 = ct * ct
  436. :rtype: Ciphertext
  437. )pbdoc";
  438. const char* cc_EvalSquareMutable_docs = R"pbdoc(
  439. EvalSquare - OpenFHE EvalSquareMutable method for a ciphertext. This is a mutable version - input ciphertexts may get automatically rescaled, or level-reduced.
  440. :param ct: the ciphertext to square
  441. :type ct: Ciphertext
  442. :return: new ciphertext for ct^2 = ct * ct
  443. :rtype: Ciphertext
  444. )pbdoc";
  445. const char* cc_EvalSquareInPlace_docs = R"pbdoc(
  446. EvalSquare - OpenFHE EvalSquare method for a ciphertext. This is a mutable version - input ciphertexts may get automatically rescaled, or level-reduced.
  447. :param ct: Input/output ciphertext
  448. :type ct: Ciphertext
  449. :return: ct contains ct^2 = ct * ct
  450. )pbdoc";
  451. const char* cc_EvalMultNoRelin_docs = R"pbdoc(
  452. EvalMultNoRelin - OpenFHE EvalMult method for a pair of ciphertexts - no key switching (relinearization)
  453. :param ct1: first ciphertext
  454. :type ct1: Ciphertext
  455. :param ct2: second ciphertext
  456. :type ct2: Ciphertext
  457. :return: new ciphertext for ct1 * ct2
  458. :rtype: Ciphertext
  459. )pbdoc";
  460. const char* cc_Relinearize_docs = R"pbdoc(
  461. Function for relinearization of a ciphertext.
  462. :param ct: input ciphertext
  463. :type ct: Ciphertext
  464. :return: relienarized ciphertext
  465. :rtype: Ciphertext
  466. )pbdoc";
  467. const char* cc_RelinearizeInPlace_docs = R"pbdoc(
  468. Function for inplace relinearization of a ciphertext.
  469. :param ct: input/output ciphertext
  470. :type ct: Ciphertext
  471. :return: ct contains relienarized ciphertext
  472. )pbdoc";
  473. const char* cc_EvalMultAndRelinearize_docs = R"pbdoc(
  474. Function for evaluating multiplication on ciphertext followed by relinearization operation. Currently it assumes that the input arguments have total depth smaller than the supported depth. Otherwise, it throws an error
  475. :param ct1: first input ciphertext
  476. :type ct1: Ciphertext
  477. :param ct2: second input ciphertext
  478. :type ct2: Ciphertext
  479. :return: new ciphertext
  480. :rtype: Ciphertext
  481. )pbdoc";
  482. const char* cc_EvalNegate_docs = R"pbdoc(
  483. EvalSub - OpenFHE Negate method for a ciphertext
  484. :param ct: input ciphertext
  485. :type ct: Ciphertext
  486. :return: new ciphertext -ct
  487. :rtype: Ciphertext
  488. )pbdoc";
  489. const char* cc_EvalNegateInPlace_docs = R"pbdoc(
  490. EvalSub - Inplace OpenFHE Negate method for a ciphertext
  491. :param ct: input/output ciphertext
  492. :type ct: Ciphertext
  493. :return: ct contains -ct
  494. )pbdoc";
  495. const char* cc_EvalChebyshevSeries_docs = R"pbdoc(
  496. Method for evaluating Chebyshev polynomial interpolation; first the range [a,b] is mapped to [-1,1] using linear transformation 1 + 2 (x-a)/(b-a) If the degree of the polynomial is less than 5, use EvalChebyshevSeriesLinear, otherwise, use EvalChebyshevSeriesPS.
  497. :param ciphertext: input ciphertext
  498. :type ciphertext: Ciphertext
  499. :param coefficients: list of coefficients in Chebyshev expansion
  500. :type coefficients: list
  501. :param a: lower bound of argument for which the coefficients were found
  502. :type a: float
  503. :param b: upper bound of argument for which the coefficients were found
  504. :type b: float
  505. :return: the result of polynomial evaluation
  506. :rtype: Ciphertext
  507. )pbdoc";
  508. const char* cc_EvalChebyshevSeriesLinear_docs = R"pbdoc(
  509. Evaluate Chebyshev polynomial of degree less than 5.
  510. :param ciphertext: input ciphertext
  511. :type ciphertext: Ciphertext
  512. :param coefficients: list of coefficients in Chebyshev expansion
  513. :type coefficients: list
  514. :param a: lower bound of argument for which the coefficients were found
  515. :type a: float
  516. :param b: upper bound of argument for which the coefficients were found
  517. :type b: float
  518. :return: the result of polynomial evaluation
  519. :rtype: Ciphertext
  520. )pbdoc";
  521. const char* cc_EvalChebyshevSeriesPS_docs = R"pbdoc(
  522. Evaluate Chebyshev polynomial of degree greater or equal to 5.
  523. :param ciphertext: input ciphertext
  524. :type ciphertext: Ciphertext
  525. :param coefficients: list of coefficients in Chebyshev expansion
  526. :type coefficients: list
  527. :param a: lower bound of argument for which the coefficients were found
  528. :type a: float
  529. :param b: upper bound of argument for which the coefficients were found
  530. :type b: float
  531. :return: the result of polynomial evaluation
  532. :rtype: Ciphertext
  533. )pbdoc";
  534. const char* cc_EvalChebyshevFunction_docs = R"pbdoc(
  535. Method for calculating Chebyshev evaluation on a ciphertext for a smooth input function over the range [a,b].
  536. :param func: the function to be approximated
  537. :type func: function
  538. :param ciphertext: input ciphertext
  539. :type ciphertext: Ciphertext
  540. :param a: lower bound of argument for which the coefficients were found
  541. :type a: float
  542. :param b: upper bound of argument for which the coefficients were found
  543. :type b: float
  544. :param degree: Desired degree of approximation
  545. :type degree: int
  546. :return: the coefficients of the Chebyshev approximation.
  547. :rtype: Ciphertext
  548. )pbdoc";
  549. const char* cc_EvalSin_docs = R"pbdoc(
  550. Evaluate approximate sine function on a ciphertext using the Chebyshev approximation.
  551. :param ciphertext: input ciphertext
  552. :type ciphertext: Ciphertext
  553. :param a: lower bound of argument for which the coefficients were found
  554. :type a: float
  555. :param b: upper bound of argument for which the coefficients were found
  556. :type b: float
  557. :param degree: Desired degree of approximation
  558. :type degree: int
  559. :return: the result of polynomial evaluation.
  560. :rtype: Ciphertext
  561. )pbdoc";
  562. const char* cc_EvalCos_docs = R"pbdoc(
  563. Evaluate approximate cosine function on a ciphertext using the Chebyshev approximation.
  564. :param ciphertext: input ciphertext
  565. :type ciphertext: Ciphertext
  566. :param a: lower bound of argument for which the coefficients were found
  567. :type a: float
  568. :param b: upper bound of argument for which the coefficients were found
  569. :type b: float
  570. :param degree: Desired degree of approximation
  571. :type degree: int
  572. :return: the result of polynomial evaluation.
  573. :rtype: Ciphertext
  574. )pbdoc";
  575. const char* cc_EvalLogistic_docs = R"pbdoc(
  576. Evaluate approximate logistic function 1/(1 + exp(-x)) on a ciphertext using the Chebyshev approximation.
  577. :param ciphertext: input ciphertext
  578. :type ciphertext: Ciphertext
  579. :param a: lower bound of argument for which the coefficients were found
  580. :type a: float
  581. :param b: upper bound of argument for which the coefficients were found
  582. :type b: float
  583. :param degree: Desired degree of approximation
  584. :type degree: int
  585. :return: the result of polynomial evaluation.
  586. :rtype: Ciphertext
  587. )pbdoc";
  588. const char* cc_EvalDivide_docs = R"pbdoc(
  589. Evaluate approximate division function 1/x where x >= 1 on a ciphertext using the Chebyshev approximation.
  590. :param ciphertext: input ciphertext
  591. :type ciphertext: Ciphertext
  592. :param a: lower bound of argument for which the coefficients were found
  593. :type a: float
  594. :param b: upper bound of argument for which the coefficients were found
  595. :type b: float
  596. :param degree: Desired degree of approximation
  597. :type degree: int
  598. :return: the result of polynomial evaluation.
  599. :rtype: Ciphertext
  600. )pbdoc";
  601. const char* cc_EvalSumKeyGen_docs = R"pbdoc(
  602. EvalSumKeyGen generates the key map to be used by evalsum
  603. :param privateKey: private key
  604. :type privateKey: PrivateKey
  605. :param publicKey: public key (used in NTRU schemes)
  606. :type publicKey: PublicKey
  607. :return: None
  608. )pbdoc";
  609. const char* cc_EvalSumRowsKeyGen_docs = R"pbdoc(
  610. EvalSumRowsKeyGen generates the key map to be used by EvalSumRows
  611. :param privateKey: private key
  612. :type privateKey: PrivateKey
  613. :param publicKey: public key (used in NTRU schemes)
  614. :type publicKey: PublicKey
  615. :param rowSize: number of rows
  616. :type rowSize: int
  617. :param subringDim: dimension of the subring
  618. :type subringDim: int
  619. :return: dict: Evaluation key map, where the keys being integer indexes and values being EvalKey objects
  620. )pbdoc";
  621. const char* cc_EvalSumColsKeyGen_docs = R"pbdoc(
  622. EvalSumColsKeyGen generates the key map to be used by EvalSumCols
  623. :param privateKey: private key
  624. :type privateKey: PrivateKey
  625. :param publicKey: public key (used in NTRU schemes)
  626. :type publicKey: PublicKey
  627. :return: dict: Evaluation key map, where the keys being integer indexes and values being EvalKey objects
  628. )pbdoc";
  629. const char* cc_EvalSumRows_docs = R"pbdoc(
  630. :param ciphertext: input ciphertext
  631. :type ciphertext: Ciphertext
  632. :param rowSize: number of rows
  633. :type rowSize: int
  634. :param evalSumKeyMap: evaluation key map, where the keys being integer indexes and values being EvalKey objects
  635. :type evalSumKeyMap: dict
  636. :param subringDim: dimension of the subring
  637. :type subringDim: int
  638. :return: Ciphertext: resulting ciphertext
  639. :rtype: Ciphertext
  640. )pbdoc";
  641. const char* cc_EvalSumCols_docs = R"pbdoc(
  642. :param ciphertext: input ciphertext
  643. :type ciphertext: Ciphertext
  644. :param rowSize: number of rows
  645. :type rowSize: int
  646. :param evalSumKeyMap: evaluation key map, where the keys being integer indexes and values being EvalKey objects
  647. :type evalSumKeyMap: dict
  648. :return: Ciphertext: resulting ciphertext
  649. :rtype: Ciphertext
  650. )pbdoc";
  651. const char* cc_EvalInnerProduct_docs = R"pbdoc(
  652. Evaluates inner product in batched encoding
  653. :param ciphertext1: first vector
  654. :type ciphertext1: Ciphertext
  655. :param ciphertext2: second vector
  656. :type ciphertext2: Ciphertext
  657. :param batchSize: size of the batch to be summed up
  658. :type batchSize: int
  659. :return: Ciphertext: resulting ciphertext
  660. :rtype: Ciphertext
  661. )pbdoc";
  662. const char* cc_EvalInnerProductPlaintext_docs = R"pbdoc(
  663. Evaluates inner product in batched encoding
  664. :param ciphertext: first vector - ciphertext
  665. :type ciphertext: Ciphertext
  666. :param plaintext: second vector - plaintext
  667. :type plaintext: Plaintext
  668. :param batchSize: size of the batch to be summed up
  669. :type batchSize: int
  670. :return: Ciphertext: resulting ciphertext
  671. :rtype: Ciphertext
  672. )pbdoc";
  673. const char* cc_EvalMerge_docs = R"pbdoc(
  674. Merges multiple ciphertexts with encrypted results in slot 0 into a single ciphertext The slot assignment is done based on the order of ciphertexts in the vector
  675. :param ciphertextVec: vector of ciphertexts to be merged.
  676. :type ciphertextVec: list
  677. :return: Ciphertext: resulting ciphertext
  678. :rtype: Ciphertext
  679. )pbdoc";
  680. const char* cc_EvalPoly_docs = R"pbdoc(
  681. Method for polynomial evaluation for polynomials represented as power series.
  682. :param ciphertext: input ciphertext
  683. :type ciphertext: Ciphertext
  684. :param coefficients: vector of coefficients in the polynomial; the size of the vector is the degree of the polynomial + 1
  685. :type coefficients: list
  686. :return: Ciphertext: the result of polynomial evaluation.
  687. :rtype: Ciphertext
  688. )pbdoc";
  689. const char* cc_EvalPolyLinear_docs = R"pbdoc(
  690. Method for polynomial evaluation for polynomials represented in the power series. This uses EvalPolyLinear, which uses a binary tree computation of the polynomial powers.
  691. :param ciphertext: input ciphertext
  692. :type ciphertext: Ciphertext
  693. :param coefficients: vector of coefficients in the polynomial; the size of the vector is the degree of the polynomial
  694. :type coefficients: list
  695. :return: Ciphertext: the result of polynomial evaluation.
  696. :rtype: Ciphertext
  697. )pbdoc";
  698. const char* cc_EvalPolyPS_docs = R"pbdoc(
  699. :param ciphertext: input ciphertext
  700. :type ciphertext: Ciphertext
  701. :param coefficients: vector of coefficients in the polynomial; the size of the vector is the degree of the polynomial
  702. :type coefficients: list
  703. :return: Ciphertext: the result of polynomial evaluation.
  704. :rtype: Ciphertext
  705. )pbdoc";
  706. const char* cc_Rescale_docs = R"pbdoc(
  707. Rescale - An alias for OpenFHE ModReduce method. This is because ModReduce is called Rescale in CKKS.
  708. :param ciphertext: ciphertext
  709. :type ciphertext: Ciphertext
  710. :return: Ciphertext: mod reduced ciphertext
  711. :rtype: Ciphertext
  712. )pbdoc";
  713. const char* cc_EvalBootstrapSetup_docs = R"pbdoc(
  714. Bootstrap functionality: There are three methods that have to be called in this specific order:
  715. 1. EvalBootstrapSetup: computes and encodes the coefficients for encoding and decoding and stores the necessary parameters
  716. 2. EvalBootstrapKeyGen: computes and stores the keys for rotations and conjugation
  717. 3. EvalBootstrap: refreshes the given ciphertext Sets all parameters for the linear method for the FFT-like method
  718. :param levelBudget: vector of budgets for the amount of levels in encoding and decoding
  719. :type levelBudget: list
  720. :param dim1: vector of inner dimension in the baby-step giant-step routine for encoding and decodingl
  721. :type dim1: list
  722. :param slots: number of slots to be bootstraped
  723. :type slots: int
  724. :param correctionFactor: alue to rescale message by to improve precision. If set to 0, we use the default logic. This value is only used when get_native_int()=64
  725. :type correctionFactor: int
  726. :return: None
  727. )pbdoc";
  728. const char* cc_EvalBootstrapKeyGen_docs = R"pbdoc(
  729. Generates all automorphism keys for EvalBT. EvalBootstrapKeyGen uses the baby-step/giant-step strategy.
  730. :param privateKey: private key.
  731. :type privateKey: PrivateKey
  732. :param slots: number of slots to support permutations on.
  733. :type slots: int
  734. :return: None
  735. )pbdoc";
  736. const char* cc_EvalBootstrap_docs = R"pbdoc(
  737. Defines the bootstrapping evaluation of ciphertext using either the FFT-like method or the linear method
  738. :param ciphertext: the input ciphertext
  739. :type ciphertext: Ciphertext
  740. :param numIterations: number of iterations to run iterative bootstrapping (Meta-BTS). Increasing the iterations increases the precision of bootstrapping
  741. :type numIterations: int
  742. :param precision: precision of initial bootstrapping algorithm. This value is determined by the user experimentally by first running EvalBootstrap with numIterations = 1 and precision = 0 (unused).
  743. :type precision: int
  744. :return: Ciphertext: the refreshed ciphertext
  745. :rtype: Ciphertext
  746. )pbdoc";
  747. const char* cc_EvalAutomorphismKeyGen_docs = R"pbdoc(
  748. Generate automophism keys for a given private key; Uses the private key for encryption
  749. :param privateKey: private key.
  750. :type privateKey: PrivateKey
  751. :param indexList: list of automorphism indices to be computed.
  752. :type indexList: list
  753. :return: dict: returns the evaluation key
  754. )pbdoc";
  755. const char* cc_EvalAutomorphismKeyGenPublic_docs = R"pbdoc(
  756. Generate automophism keys for a given private key.
  757. :param publicKey: original public key.
  758. :type publicKey: PublicKey
  759. :param privateKey: original private key.
  760. :type privateKey: PrivateKey
  761. :param indexList: list of automorphism indices to be computed.
  762. :type indexList: list
  763. :return: dict: returns the evaluation keys; index 0 of the vector corresponds to plaintext index 2, index 1 to plaintex index 3, etc.
  764. )pbdoc";
  765. const char* cc_FindAutomorphismIndex_docs = R"pbdoc(
  766. Find the automorphism index for a given plaintext index
  767. :param idx: plaintext index
  768. :type idx: int
  769. :return: int: automorphism index
  770. )pbdoc";
  771. const char* cc_FindAutomorphismIndices_docs = R"pbdoc(
  772. Find the automorphism indices for a given list of plaintext indices
  773. :param idxList: list of plaintext indices
  774. :type idxList: list
  775. :return: list: list of automorphism indices
  776. )pbdoc";
  777. const char* cc_ClearEvalMultKeys_docs = R"pbdoc(
  778. ClearEvalMultKeys - flush EvalMultKey cache
  779. )pbdoc";
  780. const char* cc_ClearEvalAutomorphismKeys_docs = R"pbdoc(
  781. ClearEvalAutomorphismKeys - flush EvalAutomorphismKey cache
  782. )pbdoc";
  783. const char* cc_SerializeEvalAutomorphismKey_docs = R"pbdoc(
  784. SerializeEvalAutomorphismKey for a single EvalAuto key or all of the EvalAuto keys
  785. :param filename: output file
  786. :type filename: str
  787. :param sertype: serialization type
  788. :type sertype: SERJSON, SERBINARY
  789. :param id: key to serialize; empty string means all keys
  790. :type id: str
  791. :return: bool: true on success
  792. )pbdoc";
  793. const char* cc_SerializeEvalMultKey_docs = R"pbdoc(
  794. SerializeEvalMultKey for a single EvalMult key or all of the EvalMult keys
  795. :param filename: output file
  796. :type filename: str
  797. :param sertype: type of serialization
  798. :type sertype: SERJSON, SERBINARY
  799. :param id: for key to serialize - if empty string, serialize them all
  800. :type id: str
  801. :return: bool: true on success
  802. )pbdoc";
  803. const char* cc_DeserializeEvalAutomorphismKey_docs = R"pbdoc(
  804. DeserializeEvalAutomorphismKey deserialize all keys in the serialization deserialized keys silently replace any existing matching keys deserialization will create CryptoContext if necessary
  805. :param filename: path for the file to deserialize from
  806. :type filename: str
  807. :param sertype: type of serialization
  808. :type sertype: SERJSON, SERBINARY
  809. :return: bool: true on success
  810. )pbdoc";
  811. const char* cc_DeserializeEvalMultKey_docs = R"pbdoc(
  812. DeserializeEvalMultKey deserialize all keys in the serialization deserialized keys silently replace any existing matching keys deserialization will create CryptoContext if necessary
  813. :param filename: path for the file to deserialize from
  814. :type filename: str
  815. :param sertype: type of serialization
  816. :type sertype: SERJSON, SERBINARY
  817. :return: bool: true on success
  818. )pbdoc";
  819. #endif //CRYPTOCONTEXT_DOCSTRINGS_H