<commit_before>/*
	For secp384r1
	define this macro if using secp384r1
*/
// #define MCLBN_FP_UNIT_SIZE 6

/*
	For secp521r1
	1. rebuild libmcl.a
	make clean && make lib/libmcl.a MCL_MAX_BIT_SIZE=576
	2. define this macro if using secp521r1
*/
// #define MCLBN_FP_UNIT_SIZE 9
#include <mcl/she.hpp>
#include <cybozu/option.hpp>
#include <cybozu/benchmark.hpp>
#include <sstream>
#include <vector>
#include <omp.h>

using namespace mcl::she;

const int maxMsg = 10000;

typedef std::vector<CipherTextG1> CipherTextG1Vec;

template<class T>
void loadSaveTest(const char *msg, const T& x, bool compress)
{
	std::string s;
	// save
	{
		std::ostringstream oss; // you can use std::fstream
		if (compress) {
			cybozu::save(oss, x);
		} else {
			oss.write((const char*)&x, sizeof(x));
		}
		s = oss.str();
		printf("size=%zd\n", s.size());
	}
	// load
	{
		std::istringstream iss(s);
		T y;
		if (compress) {
			cybozu::load(y, iss);
		} else {
			iss.read((char*)&y, sizeof(y));
		}
		printf("save and load %s %s\n", msg, (x == y) ? "ok" : "err");
	}
}

void loadSave(const SecretKey& sec, const PublicKey& pub, bool compress)
{
	printf("loadSave compress=%d\n", compress);
	int m = 123;
	CipherTextG1 c;
	pub.enc(c, m);
	loadSaveTest("sec", sec, compress);
	loadSaveTest("pub", pub, compress);
	loadSaveTest("ciphertext", c, compress);
}

void benchEnc(const PrecomputedPublicKey& ppub, int vecN)
{
	cybozu::CpuClock clk;
	CipherTextG1Vec cv;
	cv.resize(vecN);
	const int C = 10;
	for (int k = 0; k < C; k++) {
		clk.begin();
		#pragma omp parallel for
		for (int i = 0; i < vecN; i++) {
			ppub.enc(cv[i], i);<commit_msg>[she] use load/save method<commit_after>/*
	For secp384r1
	define this macro if using secp384r1
*/
// #define MCLBN_FP_UNIT_SIZE 6

/*
	For secp521r1
	1. rebuild libmcl.a
	make clean && make lib/libmcl.a MCL_MAX_BIT_SIZE=576
	2. define this macro if using secp521r1
*/
// #define MCLBN_FP_UNIT_SIZE 9
#include <mcl/she.hpp>
#include <cybozu/option.hpp>
#include <cybozu/benchmark.hpp>
#include <sstream>
#include <vector>
#include <omp.h>

using namespace mcl::she;

const int maxMsg = 10000;

typedef std::vector<CipherTextG1> CipherTextG1Vec;

template<class T>
void loadSaveTest(const char *msg, const T& x, bool compress)
{
	std::string s;
	// save
	{
		std::ostringstream oss; // you can use std::fstream
		if (compress) {
//			cybozu::save(oss, x);
			x.save(oss);
		} else {
			oss.write((const char*)&x, sizeof(x));
		}
		s = oss.str();
		printf("size=%zd\n", s.size());
	}
	// load
	{
		std::istringstream iss(s);
		T y;
		if (compress) {
//			cybozu::load(y, iss);
			y.load(iss);
		} else {
			iss.read((char*)&y, sizeof(y));
		}
		printf("save and load %s %s\n", msg, (x == y) ? "ok" : "err");
	}
}

void loadSave(const SecretKey& sec, const PublicKey& pub, bool compress)
{
	printf("loadSave compress=%d\n", compress);
	int m = 123;
	CipherTextG1 c;
	pub.enc(c, m);
	loadSaveTest("sec", sec, compress);
	loadSaveTest("pub", pub, compress);
	loadSaveTest("ciphertext", c, compress);
}

void benchEnc(const PrecomputedPublicKey& ppub, int vecN)
{
	cybozu::CpuClock clk;
	CipherTextG1Vec cv;
	cv.resize(vecN);
	const int C = 10;
	for (int k = 0; k < C; k++) {
		clk.begin();
		#pragma omp parallel for
		for (int i = 0; i < vecN; i++) {
			ppub.enc(cv[i], i);
{'fraction_non_alphanumeric': 0.16752812404986317, 'fraction_numerical': 0.023715415019762844, 'mean_word_length': 3.9325337331334334, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '306219', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1344, 'n_words': 348}