Browse Source

Plaintext done

Hovsep Papoyan 11 months ago
parent
commit
e7709ab3bc
3 changed files with 139 additions and 0 deletions
  1. 84 0
      src/Plaintext.cc
  2. 26 0
      src/Plaintext.h
  3. 29 0
      src/lib.rs

+ 84 - 0
src/Plaintext.cc

@@ -23,6 +23,22 @@ void Plaintext::SetLength(const size_t newSize) const
 {
     m_plaintext->SetLength(newSize);
 }
+void Plaintext::SetLevel(const size_t l) const
+{
+    m_plaintext->SetLevel(l);
+}
+bool Plaintext::IsEncoded() const
+{
+    return m_plaintext->IsEncoded();
+}
+int64_t Plaintext::HighBound() const
+{
+    return m_plaintext->HighBound();
+}
+int64_t Plaintext::LowBound() const
+{
+    return m_plaintext->LowBound();
+}
 double Plaintext::GetLogPrecision() const
 {
     return m_plaintext->GetLogPrecision();
@@ -33,6 +49,62 @@ rust::String Plaintext::GetString() const
     stream << *m_plaintext;
     return rust::String(stream.str());
 }
+size_t Plaintext::GetLength() const
+{
+    return m_plaintext->GetLength();
+}
+size_t Plaintext::GetLevel() const
+{
+    return m_plaintext->GetLevel();
+}
+double Plaintext::GetLogError() const
+{
+    return m_plaintext->GetLogError();
+}
+size_t Plaintext::GetNoiseScaleDeg() const
+{
+    return m_plaintext->GetNoiseScaleDeg();
+}
+double Plaintext::GetScalingFactor() const
+{
+    return m_plaintext->GetScalingFactor();
+}
+SCHEME Plaintext::GetSchemeID() const
+{
+    return m_plaintext->GetSchemeID();
+}
+uint32_t Plaintext::GetSlots() const
+{
+    return m_plaintext->GetSlots();
+}
+bool Plaintext::Encode() const
+{
+    return m_plaintext->Encode();
+}
+bool Plaintext::Decode() const
+{
+    return m_plaintext->Decode();
+}
+void Plaintext::SetFormat(const Format fmt) const
+{
+    m_plaintext->SetFormat(fmt);
+}
+void Plaintext::SetIntVectorValue(const std::vector<int64_t>& val) const
+{
+    m_plaintext->SetIntVectorValue(val);
+}
+void Plaintext::SetNoiseScaleDeg(const size_t nsd) const
+{
+    m_plaintext->SetNoiseScaleDeg(nsd);
+}
+void Plaintext::SetScalingFactor(const double sf) const
+{
+    m_plaintext->SetScalingFactor(sf);
+}
+void Plaintext::SetSlots(const uint32_t s) const
+{
+    m_plaintext->SetSlots(s);
+}
 std::unique_ptr<std::vector<ComplexPair>> Plaintext::GetCopyOfCKKSPackedValue() const
 {
     const std::vector<std::complex<double>>& v = m_plaintext->GetCKKSPackedValue();
@@ -44,6 +116,18 @@ std::unique_ptr<std::vector<ComplexPair>> Plaintext::GetCopyOfCKKSPackedValue()
     }
     return std::make_unique<std::vector<ComplexPair>>(std::move(result));
 }
+std::unique_ptr<std::vector<int64_t>> Plaintext::GetCopyOfPackedValue() const
+{
+    return std::make_unique<std::vector<int64_t>>(m_plaintext->GetPackedValue());
+}
+std::unique_ptr<std::vector<double>> Plaintext::GetCopyOfRealPackedValue() const
+{
+    return std::make_unique<std::vector<double>>(m_plaintext->GetRealPackedValue());
+}
+std::unique_ptr<std::vector<int64_t>> Plaintext::GetCopyOfCoefPackedValue() const
+{
+    return std::make_unique<std::vector<int64_t>>(m_plaintext->GetCoefPackedValue());
+}
 std::unique_ptr<Plaintext> GenEmptyPlainText()
 {
     return std::make_unique<Plaintext>();

+ 26 - 0
src/Plaintext.h

@@ -1,6 +1,8 @@
 #pragma once
 
+#include "openfhe/core/utils/inttypes.h" // Format
 #include "openfhe/pke/encoding/plaintext-fwd.h"
+#include "openfhe/pke/scheme/scheme-id.h"
 
 #include "rust/cxx.h" // rust::String
 
@@ -8,6 +10,8 @@ namespace openfhe
 {
 
 using PlaintextImpl = lbcrypto::PlaintextImpl;
+using SCHEME = lbcrypto::SCHEME;
+using Format = ::Format;
 struct ComplexPair;
 
 class Plaintext final
@@ -24,9 +28,31 @@ public:
 
     [[nodiscard]] std::shared_ptr<PlaintextImpl> GetInternal() const;
     void SetLength(const size_t newSize) const;
+    void SetLevel(const size_t l) const;
+    [[nodiscard]] bool IsEncoded() const;
+    [[nodiscard]] int64_t HighBound() const;
+    [[nodiscard]] int64_t LowBound() const;
     [[nodiscard]] double GetLogPrecision() const;
     [[nodiscard]] rust::String GetString() const;
+    [[nodiscard]] size_t GetLength() const;
+    [[nodiscard]] size_t GetLevel() const;
+    [[nodiscard]] double GetLogError() const;
+    [[nodiscard]] size_t GetNoiseScaleDeg() const;
+    [[nodiscard]] double GetScalingFactor() const;
+    [[nodiscard]] SCHEME GetSchemeID() const;
+    [[nodiscard]] uint32_t GetSlots() const;
+    [[nodiscard]] bool Encode() const;
+    [[nodiscard]] bool Decode() const;
+    void SetFormat(const Format fmt) const;
+    void SetIntVectorValue(const std::vector<int64_t>& val) const;
+    void SetNoiseScaleDeg(const size_t nsd) const;
+    void SetScalingFactor(const double sf) const;
+    void SetSlots(const uint32_t s) const;
+
     [[nodiscard]] std::unique_ptr<std::vector<ComplexPair>> GetCopyOfCKKSPackedValue() const;
+    [[nodiscard]] std::unique_ptr<std::vector<int64_t>> GetCopyOfPackedValue() const;
+    [[nodiscard]] std::unique_ptr<std::vector<double>> GetCopyOfRealPackedValue() const;
+    [[nodiscard]] std::unique_ptr<std::vector<int64_t>> GetCopyOfCoefPackedValue() const;
 };
 [[nodiscard]] std::unique_ptr<Plaintext> GenEmptyPlainText();
 

+ 29 - 0
src/lib.rs

@@ -131,6 +131,13 @@ pub mod ffi
         JSON = 1,
     }
 
+    #[repr(i32)]
+    enum Format
+    {
+        EVALUATION = 0,
+        COEFFICIENT = 1
+    }
+
     struct ComplexPair
     {
         re: f64,
@@ -161,6 +168,7 @@ pub mod ffi
         type SecretKeyDist;
         type SecurityLevel;
         type SerialMode;
+        type Format;
 
         type CiphertextDCRTPoly;
         type CryptoContextDCRTPoly;
@@ -487,6 +495,27 @@ pub mod ffi
         fn SetLength(self: &Plaintext, newSize: usize);
         fn GetString(self: &Plaintext) -> String;
         fn GetLogPrecision(self: &Plaintext) -> f64;
+        fn SetLevel(self: &Plaintext, l: usize);
+        fn IsEncoded(self: &Plaintext) -> bool;
+        fn HighBound(self: &Plaintext) -> i64;
+        fn LowBound(self: &Plaintext) -> i64;
+        fn GetLength(self: &Plaintext) -> usize;
+        fn GetLevel(self: &Plaintext) -> usize;
+        fn GetLogError(self: &Plaintext) -> f64;
+        fn GetNoiseScaleDeg(self: &Plaintext) -> usize;
+        fn GetScalingFactor(self: &Plaintext) -> f64;
+        fn GetSchemeID(self: &Plaintext) -> SCHEME;
+        fn GetSlots(self: &Plaintext) -> u32;
+        fn Encode(self: &Plaintext) -> bool;
+        fn Decode(self: &Plaintext) -> bool;
+        fn SetFormat(self: &Plaintext, fmt: Format);
+        fn SetIntVectorValue(self: &Plaintext, val: &CxxVector<i64>);
+        fn SetNoiseScaleDeg(self: &Plaintext, nsd: usize);
+        fn SetScalingFactor(self: &Plaintext, sf: f64);
+        fn SetSlots(self: &Plaintext, s: u32);
+        fn GetCopyOfPackedValue(self: &Plaintext) -> UniquePtr<CxxVector<i64>>;
+        fn GetCopyOfRealPackedValue(self: &Plaintext) -> UniquePtr<CxxVector<f64>>;
+        fn GetCopyOfCoefPackedValue(self: &Plaintext) -> UniquePtr<CxxVector<i64>>;
         fn GetCopyOfCKKSPackedValue(self: &Plaintext) -> UniquePtr<CxxVector<ComplexPair>>;
     }