Browse Source

KeyPair method is_allocated and CryptoContext method KeyGen marked const.

nkaskov 1 year ago
parent
commit
57d27ec6f4
3 changed files with 21 additions and 26 deletions
  1. 2 3
      cpp/include/bindings.hpp
  2. 6 9
      cpp/src/bindings.cpp
  3. 13 14
      src/lib.rs

+ 2 - 3
cpp/include/bindings.hpp

@@ -202,8 +202,7 @@ public:
 
     explicit FFIKeyPair(const FFIPublicKeyImpl& publicKey, const FFIPrivateKeyImpl& privateKey);
     
-    // TODO make it a const method
-    bool is_good() ;
+    bool is_allocated() const;
 
     FFIPublicKeyImpl GetPublicKey() const;
 
@@ -384,7 +383,7 @@ public:
 
     void Enable(FFIPKESchemeFeature feature);
 
-    FFIKeyPair KeyGen();
+    FFIKeyPair KeyGen() const;
 
     void EvalMultKeyGen(const FFIPrivateKeyImpl key);
 

+ 6 - 9
cpp/src/bindings.cpp

@@ -476,10 +476,9 @@ void FFICryptoContextImpl::Enable(FFIPKESchemeFeature feature) {
     cc->Enable(PKESchemeFeature(feature));
 }
 
-FFIKeyPair FFICryptoContextImpl::KeyGen(){
-    // TODO make it const method
-    // std::shared_ptr<const CryptoContextImpl<DCRTPoly>> cc =
-    std::shared_ptr<CryptoContextImpl<DCRTPoly>> cc =
+FFIKeyPair FFICryptoContextImpl::KeyGen() const{
+    std::shared_ptr<const CryptoContextImpl<DCRTPoly>> cc =
+    // std::shared_ptr<CryptoContextImpl<DCRTPoly>> cc =
         reinterpret_cast<CryptoContextImplHolder*>(cc_ptr)->ptr;
     cc->KeyGen();
     void* keypair_ptr = reinterpret_cast<void*>(
@@ -1327,12 +1326,10 @@ FFIKeyPair::FFIKeyPair(const FFIPublicKeyImpl& pubkey, const FFIPrivateKeyImpl&
             reinterpret_cast<PrivkeyHolder*>(privkey.privkey_ptr)->ptr)});
 }
 
-bool FFIKeyPair::is_good() {
-    // TODO make it const method
-    // std::shared_ptr<const KeyPair<DCRTPoly>> keypair =
-    std::shared_ptr<KeyPair<DCRTPoly>> keypair =
+bool FFIKeyPair::is_allocated() const{
+    std::shared_ptr<const KeyPair<DCRTPoly>> keypair =
         reinterpret_cast<KeyPairHolder*>(keypair_ptr)->ptr;
-    return keypair->good();
+    return keypair->is_allocated();
 }
 
 FFIPublicKeyImpl FFIKeyPair::GetPublicKey() const{

+ 13 - 14
src/lib.rs

@@ -7,32 +7,31 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
 #[cfg(test)]
 mod tests {
     use super::*;
-    use std::mem;
 
     #[test]
     fn testCryptoContextBFVRNSCCParams() {
         unsafe {
-            let bfv_params = FFIParams::new1(FFISCHEME_BFVRNS_SCHEME);
+            let ccparams = FFIParams::new1(FFISCHEME_CKKSRNS_SCHEME);
 
-            println!("bfv_params numofparties{}", bfv_params.GetThresholdNumOfParties())
-        }
-    }
+            let mut ccontext = GenCryptoContext(ccparams);
 
-    #[test]
-    fn testCryptoContext() {
-        unsafe {
-            let mut ccontext = FFICryptoContextImpl::new();
-            ccontext.SetKeyGenLevel(10);
-            println!("crypto_context keygenlevel: {:?}", ccontext.GetKeyGenLevel());
-            // println!("crypto_context ringdimension: {:?}", ccontext.GetRingDimension())
+            ccontext.Enable(FFIPKESchemeFeature_PKE);
+            ccontext.Enable(FFIPKESchemeFeature_KEYSWITCH);
+            ccontext.Enable(FFIPKESchemeFeature_LEVELEDSHE);
+
+            let key_pair = ccontext.KeyGen();
+
+            println!("keypair is_allocated: {:?}", key_pair.is_allocated());
+             
+            ccontext.EvalMultKeyGen(key_pair.GetPrivateKey());
         }
     }
 
     #[test]
     fn testKeyPair() {
         unsafe {
-            let mut key_pair = FFIKeyPair::new();
-            println!("keypair is_good: {:?}", key_pair.is_good());
+            let key_pair = FFIKeyPair::new();
+            println!("keypair is_allocated: {:?}", key_pair.is_allocated());
         }
     }
 }