cryptocontext_docs.h 40 KB

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