forked from microsoft/SEAL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keygen.cpp
76 lines (66 loc) · 1.84 KB
/
keygen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#include "seal/seal.h"
#include "seal/util/rlwe.h"
#include "bench.h"
using namespace benchmark;
using namespace sealbench;
using namespace seal;
using namespace std;
/**
This file defines benchmarks for KeyGen-related HE primitives.
*/
namespace seal
{
struct KeyGenerator::KeyGeneratorPrivateHelper
{
static void generate_sk(KeyGenerator *keygen)
{
return keygen->generate_sk();
}
};
} // namespace seal
namespace sealbench
{
void bm_keygen_secret(State &state, shared_ptr<BMEnv> bm_env)
{
KeyGenerator keygen(bm_env->context());
for (auto _ : state)
{
KeyGenerator::KeyGeneratorPrivateHelper::generate_sk(&keygen);
}
}
void bm_keygen_public(State &state, shared_ptr<BMEnv> bm_env)
{
shared_ptr<KeyGenerator> keygen = bm_env->keygen();
PublicKey pk;
for (auto _ : state)
{
keygen->create_public_key(pk);
}
}
void bm_keygen_relin(State &state, shared_ptr<BMEnv> bm_env)
{
shared_ptr<KeyGenerator> keygen = bm_env->keygen();
RelinKeys rlk;
for (auto _ : state)
{
keygen->create_relin_keys(rlk);
}
}
void bm_keygen_galois(State &state, shared_ptr<BMEnv> bm_env)
{
shared_ptr<KeyGenerator> keygen = bm_env->keygen();
GaloisKeys glk;
size_t slot_count = bm_env->parms().poly_modulus_degree() >> 1;
auto random_one_step = [&]() {
vector<int> res;
res.emplace_back(rand() & static_cast<int>(slot_count - 1));
return res;
};
for (auto _ : state)
{
keygen->create_galois_keys({ random_one_step() }, glk);
}
}
} // namespace sealbench