diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-06-29 16:16:03 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-06-29 16:16:03 +0800 |
commit | 828e955b9adde17f2eab158f2e83155655de0605 (patch) | |
tree | 4aeb2ad72ce19cfaafdea69853193e6a78009d6d | |
parent | c5121c66e8d7dc51cd4eae9747edd8e14b489f5d (diff) | |
download | tangerine-mcl-828e955b9adde17f2eab158f2e83155655de0605.tar.gz tangerine-mcl-828e955b9adde17f2eab158f2e83155655de0605.tar.zst tangerine-mcl-828e955b9adde17f2eab158f2e83155655de0605.zip |
add serialize and deserialize
-rw-r--r-- | sample/bgn_smpl.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/sample/bgn_smpl.cpp b/sample/bgn_smpl.cpp index 7028ed6..eaf772e 100644 --- a/sample/bgn_smpl.cpp +++ b/sample/bgn_smpl.cpp @@ -88,15 +88,15 @@ void usePrimitiveCipherText() int a1 = 1, a2 = 2; int b1 = 5, b2 = -4; - BGN::CipherTextG1 c1, c2; // sizeof(CipherTextG1) = N * 2 ; N = 256-bit for CurveFp254BNb - BGN::CipherTextG2 d1, d2; // sizeof(CipherTextG2) = N * 4 + BGN::CipherTextG1 c1, c2; // size of CipherTextG1 = N * 2 ; N = 256-bit for CurveFp254BNb + BGN::CipherTextG2 d1, d2; // size of CipherTextG2 = N * 4 pub.enc(c1, a1, g_rg); pub.enc(c2, a2, g_rg); pub.enc(d1, b1, g_rg); pub.enc(d2, b2, g_rg); c1.add(c2); // CipherTextG1 is additive HE d1.add(d2); // CipherTextG2 is additive HE - BGN::CipherTextM cm; // sizeof(CipherTextM) = N * 12 * 4 + BGN::CipherTextM cm; // size of CipherTextM = N * 12 * 4 BGN::CipherTextM::mul(cm, c1, d1); // cm = c1 * d1 cm.add(cm); // 2cm int m = sec.dec(cm); @@ -106,6 +106,23 @@ void usePrimitiveCipherText() } else { printf("err m=%d ok=%d\n", m, ok); } + std::string s; + s = c1.getStr(mcl::IoFixedSizeByteSeq); // serialize + printf("c1 data size %d byte\n", (int)s.size()); + + c2.setStr(s, mcl::IoFixedSizeByteSeq); + printf("deserialize %s\n", c1 == c2 ? "ok" : "ng"); + + s = d1.getStr(mcl::IoFixedSizeByteSeq); // serialize + printf("d1 data size %d byte\n", (int)s.size()); + d2.setStr(s, mcl::IoFixedSizeByteSeq); + printf("deserialize %s\n", d1 == d2 ? "ok" : "ng"); + + s = cm.getStr(mcl::IoFixedSizeByteSeq); // serialize + printf("cm data size %d byte\n", (int)s.size()); + BGN::CipherTextM cm2; + cm2.setStr(s, mcl::IoFixedSizeByteSeq); + printf("deserialize %s\n", cm == cm2 ? "ok" : "ng"); } int main() |