Skip to content

Commit

Permalink
Adding private key support
Browse files Browse the repository at this point in the history
  • Loading branch information
HovsepPapoyan committed Oct 9, 2024
1 parent 445bc39 commit 0fd0a56
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/PrivateKey.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ std::shared_ptr<PrivateKeyImpl>& PrivateKeyDCRTPoly::GetRef() noexcept
return m_privateKey;
}

std::unique_ptr<PrivateKeyDCRTPoly> DCRTPolyGenNullPrivateKey()
{
return std::make_unique<PrivateKeyDCRTPoly>();
}

} // openfhe
3 changes: 3 additions & 0 deletions src/PrivateKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PrivateKeyDCRTPoly final
{
std::shared_ptr<PrivateKeyImpl> m_privateKey;
public:
PrivateKeyDCRTPoly() = default;
PrivateKeyDCRTPoly(const std::shared_ptr<PrivateKeyImpl>& privateKey) noexcept;
PrivateKeyDCRTPoly(const PrivateKeyDCRTPoly&) = delete;
PrivateKeyDCRTPoly(PrivateKeyDCRTPoly&&) = delete;
Expand All @@ -22,4 +23,6 @@ class PrivateKeyDCRTPoly final
[[nodiscard]] std::shared_ptr<PrivateKeyImpl>& GetRef() noexcept;
};

[[nodiscard]] std::unique_ptr<PrivateKeyDCRTPoly> DCRTPolyGenNullPrivateKey();

} // openfhe
13 changes: 13 additions & 0 deletions src/SerialDeserial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "Ciphertext.h"
#include "CryptoContext.h"
#include "PrivateKey.h"
#include "PublicKey.h"

namespace openfhe
Expand Down Expand Up @@ -237,4 +238,16 @@ bool DCRTPolySerializePublicKeyToFile(const std::string& publicKeyLocation,
return Serial(publicKeyLocation, publicKey, serialMode);
}

bool DCRTPolyDeserializePrivateKeyFromFile(const std::string& privateKeyLocation,
PrivateKeyDCRTPoly& privateKey, const SerialMode serialMode)
{
return Deserial(privateKeyLocation, privateKey, serialMode);
}

bool DCRTPolySerializePrivateKeyToFile(const std::string& privateKeyLocation,
const PrivateKeyDCRTPoly& privateKey, const SerialMode serialMode)
{
return Serial(privateKeyLocation, privateKey, serialMode);
}

} // openfhe
6 changes: 6 additions & 0 deletions src/SerialDeserial.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace openfhe

class CiphertextDCRTPoly;
class CryptoContextDCRTPoly;
class PrivateKeyDCRTPoly;
class PublicKeyDCRTPoly;

// Ciphertext
Expand Down Expand Up @@ -55,4 +56,9 @@ class PublicKeyDCRTPoly;
[[nodiscard]] bool DCRTPolySerializePublicKeyToFile(const std::string& publicKeyLocation,
const PublicKeyDCRTPoly& publicKey, const SerialMode serialMode);

[[nodiscard]] bool DCRTPolyDeserializePrivateKeyFromFile(const std::string& privateKeyLocation,
PrivateKeyDCRTPoly& privateKey, const SerialMode serialMode);
[[nodiscard]] bool DCRTPolySerializePrivateKeyToFile(const std::string& privateKeyLocation,
const PrivateKeyDCRTPoly& cryptoContext, const SerialMode serialMode);

} // openfhe
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,13 @@ pub mod ffi
fn DCRTPolyGenNullPublicKey() -> UniquePtr<PublicKeyDCRTPoly>;
}

// PrivateKeyDCRTPoly
unsafe extern "C++"
{
// Generator functions
fn DCRTPolyGenNullPrivateKey() -> UniquePtr<PrivateKeyDCRTPoly>;
}

// Serialize / Deserialize
unsafe extern "C++"
{
Expand Down Expand Up @@ -1110,6 +1117,14 @@ pub mod ffi
fn DCRTPolySerializePublicKeyToFile(publicKeyLocation: &CxxString,
publicKey: &PublicKeyDCRTPoly,
serialMode: SerialMode) -> bool;

// PrivateKey
fn DCRTPolyDeserializePrivateKeyFromFile(privateKeyLocation: &CxxString,
privateKey: Pin<&mut PrivateKeyDCRTPoly>,
serialMode: SerialMode) -> bool;
fn DCRTPolySerializePrivateKeyToFile(privateKeyLocation: &CxxString,
privateKey: &PrivateKeyDCRTPoly,
serialMode: SerialMode) -> bool;
}
}

Expand Down

0 comments on commit 0fd0a56

Please sign in to comment.