bindings.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 OPENFHE_BINDINGS_H
  22. #define OPENFHE_BINDINGS_H
  23. #include <cstdint>
  24. typedef std::uint32_t usint;
  25. typedef std::uint64_t FFIPlaintextModulus;
  26. // enums from constants.h
  27. enum FFIMultipartyMode {
  28. INVALID_MULTIPARTY_MODE = 0,
  29. FIXED_NOISE_MULTIPARTY,
  30. NOISE_FLOODING_MULTIPARTY,
  31. };
  32. enum FFIProxyReEncryptionMode {
  33. NOT_SET = 0,
  34. INDCPA,
  35. FIXED_NOISE_HRA,
  36. NOISE_FLOODING_HRA,
  37. DIVIDE_AND_ROUND_HRA,
  38. };
  39. enum FFIExecutionMode {
  40. EXEC_EVALUATION = 0,
  41. EXEC_NOISE_ESTIMATION,
  42. };
  43. enum FFIDecryptionNoiseMode {
  44. FIXED_NOISE_DECRYPT = 0,
  45. NOISE_FLOODING_DECRYPT,
  46. };
  47. enum FFIKeySwitchTechnique {
  48. INVALID_KS_TECH = 0,
  49. BV,
  50. HYBRID,
  51. };
  52. enum FFIScalingTechnique {
  53. FIXEDMANUAL = 0,
  54. FIXEDAUTO,
  55. FLEXIBLEAUTO,
  56. FLEXIBLEAUTOEXT,
  57. NORESCALE,
  58. INVALID_RS_TECHNIQUE, // TODO (dsuponit): make this the first value
  59. };
  60. enum FFIEncryptionTechnique {
  61. STANDARD = 0,
  62. EXTENDED,
  63. };
  64. enum FFIMultiplicationTechnique {
  65. BEHZ = 0,
  66. HPS,
  67. HPSPOVERQ,
  68. HPSPOVERQLEVELED,
  69. };
  70. enum FFICOMPRESSION_LEVEL {
  71. // we don't support 0 or 1 compression levels
  72. // do not change values here
  73. COMPACT = 2, // more efficient with stronger security assumption
  74. SLACK = 3 // less efficient with weaker security assumption
  75. };
  76. // enums from stdlatticeparms.h
  77. enum FFISecurityLevel {
  78. HEStd_128_classic,
  79. HEStd_192_classic,
  80. HEStd_256_classic,
  81. HEStd_128_quantum,
  82. HEStd_192_quantum,
  83. HEStd_256_quantum,
  84. HEStd_NotSet,
  85. };
  86. // enums from constants-lattice.h
  87. enum FFISecretKeyDist {
  88. GAUSSIAN = 0,
  89. UNIFORM_TERNARY = 1, // Default value, all schemes support this key distribution
  90. SPARSE_TERNARY = 2,
  91. // BINARY = 3, // Future implementation
  92. };
  93. // enums from scheme-id.h
  94. enum FFISCHEME {
  95. INVALID_SCHEME = 0,
  96. CKKSRNS_SCHEME,
  97. BFVRNS_SCHEME,
  98. BGVRNS_SCHEME,
  99. };
  100. enum CryptoContextType {
  101. BFVRNS,
  102. BGVRNS,
  103. // Add other types as needed
  104. };
  105. // Params FFI
  106. class FFIParams{
  107. protected:
  108. void* params_ptr;
  109. public:
  110. FFIParams();
  111. FFIParams(FFISCHEME scheme);
  112. virtual FFIPlaintextModulus GetPlaintextModulus() const;
  113. virtual FFISCHEME GetScheme() const;
  114. usint GetDigitSize() const;
  115. float GetStandardDeviation() const;
  116. FFISecretKeyDist GetSecretKeyDist() const;
  117. usint GetMaxRelinSkDeg() const;
  118. FFIProxyReEncryptionMode GetPREMode() const;
  119. FFIMultipartyMode GetMultipartyMode() const;
  120. FFIExecutionMode GetExecutionMode() const;
  121. FFIDecryptionNoiseMode GetDecryptionNoiseMode() const;
  122. double GetNoiseEstimate() const;
  123. double GetDesiredPrecision() const;
  124. double GetStatisticalSecurity() const;
  125. double GetNumAdversarialQueries() const;
  126. usint GetThresholdNumOfParties() const;
  127. FFIKeySwitchTechnique GetKeySwitchTechnique() const;
  128. FFIScalingTechnique GetScalingTechnique() const;
  129. usint GetBatchSize() const;
  130. usint GetFirstModSize() const;
  131. uint32_t GetNumLargeDigits() const;
  132. usint GetMultiplicativeDepth() const;
  133. usint GetScalingModSize() const;
  134. FFISecurityLevel GetSecurityLevel() const;
  135. usint GetRingDim() const;
  136. usint GetEvalAddCount() const;
  137. usint GetKeySwitchCount() const;
  138. FFIEncryptionTechnique GetEncryptionTechnique() const;
  139. FFIMultiplicationTechnique GetMultiplicationTechnique() const;
  140. usint GetMultiHopModSize() const;
  141. FFICOMPRESSION_LEVEL GetInteractiveBootCompressionLevel() const;
  142. void SetPlaintextModulus(FFIPlaintextModulus ptModulus);
  143. void SetDigitSize(usint digitSize);
  144. void SetStandardDeviation(float standardDeviation);
  145. void SetSecretKeyDist(FFISecretKeyDist secretKeyDist);
  146. void SetMaxRelinSkDeg(usint maxRelinSkDeg);
  147. void SetPREMode(FFIProxyReEncryptionMode preMode);
  148. void SetMultipartyMode(FFIMultipartyMode multipartyMode);
  149. void SetExecutionMode(FFIExecutionMode executionMode);
  150. void SetDecryptionNoiseMode(FFIDecryptionNoiseMode decryptionNoiseMode);
  151. void SetNoiseEstimate(double noiseEstimate);
  152. void SetDesiredPrecision(double desiredPrecision);
  153. void SetStatisticalSecurity(uint32_t statisticalSecurity);
  154. void SetNumAdversarialQueries(uint32_t numAdversarialQueries);
  155. void SetThresholdNumOfParties(uint32_t thresholdNumOfParties);
  156. void SetKeySwitchTechnique(FFIKeySwitchTechnique keySwitchTechnique);
  157. void SetScalingTechnique(FFIScalingTechnique scalingTechnique);
  158. void SetBatchSize(usint batchSize);
  159. void SetFirstModSize(usint firstModSize);
  160. void SetNumLargeDigits(uint32_t numLargeDigits);
  161. void SetMultiplicativeDepth(usint multiplicativeDepth);
  162. void SetScalingModSize(usint scalingModSize);
  163. void SetSecurityLevel(FFISecurityLevel securityLevel);
  164. void SetRingDim(usint ringDim);
  165. void SetEvalAddCount(usint evalAddCount);
  166. void SetKeySwitchCount(usint keySwitchCount);
  167. void SetEncryptionTechnique(FFIEncryptionTechnique encryptionTechnique);
  168. void SetMultiplicationTechnique(FFIMultiplicationTechnique multiplicationTechnique);
  169. void SetMultiHopModSize(usint multiHopModSize);
  170. void SetInteractiveBootCompressionLevel(FFICOMPRESSION_LEVEL interactiveBootCompressionLevel);
  171. // std::stream str();
  172. };
  173. class CryptoContextBFVRNSCCParams : public FFIParams {
  174. public:
  175. // CryptoContextBFVRNSCCParams();
  176. CryptoContextBFVRNSCCParams():FFIParams(BFVRNS_SCHEME){};
  177. };
  178. class CryptoContextBGVRNSCCParams : public FFIParams {
  179. public:
  180. // CryptoContextBGVRNSCCParams();
  181. CryptoContextBGVRNSCCParams():FFIParams(BGVRNS_SCHEME){};
  182. };
  183. // };
  184. #endif // OPENFHE_BINDINGS_H