intel / pailliercryptolib

Intel Paillier Cryptosystem Library is an open-source library which provides accelerated performance of a partial homomorphic encryption (HE), named Paillier cryptosystem, by utilizing Intel® IPP-Crypto on AVX512IFMA instructions. Intel Paillier Cryptosystem Library is certified for ISO compliance.
Apache License 2.0
73 stars 18 forks source link

Segmentation fault occurs when serializing and deserializing a public key. #46

Closed xhuan28 closed 1 year ago

xhuan28 commented 1 year ago

The following snippet can reproduce this issue:

#include "ipcl/ipcl.hpp"
#include "cereal/archives/portable_binary.hpp"

using namespace ipcl;
int main(int argc, char** argv) {
  KeyPair kp = generateKeypair(2048, true);
  PublicKey pk_in = kp.pub_key;
  PublicKey pk_out;
  std::cout << "pk_in: " << *pk_in.getN() << std::endl;
  std::stringstream ss;
  {
    cereal::PortableBinaryOutputArchive archive(ss);
    archive(pk_in);
  }

  {
    cereal::PortableBinaryInputArchive archive(ss);
    archive(pk_out);
  }

  std::cout << "pk_out: " << *pk_out.getN() << std::endl;
  return 0;
}

The root cause is no adequate memory is allocated for BigNumber to load the serialized bytes (pub_key.hpp#L145)

xhuan28 commented 1 year ago

This PR(https://github.com/intel/pailliercryptolib/pull/47) may fix this issue.

justalittlenoob commented 1 year ago

Solved by PR #52