|
| 1 | +#include "exp.hpp" |
| 2 | +#include "kim_aggre.hpp" |
| 3 | + |
| 4 | +void ipe_equality_time(const int round){ |
| 5 | + // Open the output files. |
| 6 | + std::ofstream file("equality_time.txt", std::ios_base::app); |
| 7 | + file << "IPE Equality Timings" << std::endl; |
| 8 | + |
| 9 | + for (int num_col : {2, 10, 20}){ |
| 10 | + // Create holder for timings. |
| 11 | + std::chrono::duration<double, std::milli> time{}; |
| 12 | + |
| 13 | + // Create pp and msk. |
| 14 | + auto pp = IpeAggre::pp_gen(20); |
| 15 | + auto msk = IpeAggre::msk_gen(pp); |
| 16 | + |
| 17 | + // Perform round number of Enc. |
| 18 | + for (int i = 0; i < round; ++i){ |
| 19 | + // Create a random vector of desired length. |
| 20 | + auto x = Helper::rand_int_vec(20, 1, std::numeric_limits<int>::max()); |
| 21 | + auto y = Helper::rand_int_vec(20, 1, 5); |
| 22 | + // Set the unselected portion to zero. |
| 23 | + for (int j = num_col + 1; j < 20; ++j){ y[j] = 0; } |
| 24 | + |
| 25 | + // Compute ct and sk. |
| 26 | + auto ct = IpeAggre::enc(pp, msk, x); |
| 27 | + |
| 28 | + // Keygen timing. |
| 29 | + auto start = std::chrono::high_resolution_clock::now(); |
| 30 | + auto sk = IpeAggre::keygen(pp, msk, y, 100); |
| 31 | + auto end = std::chrono::high_resolution_clock::now(); |
| 32 | + time += end - start; |
| 33 | + |
| 34 | + // Decryption timings. |
| 35 | + start = std::chrono::high_resolution_clock::now(); |
| 36 | + std::ignore = IpeAggre::dec(ct, sk); |
| 37 | + end = std::chrono::high_resolution_clock::now(); |
| 38 | + time += end - start; |
| 39 | + } |
| 40 | + |
| 41 | + // Output the time. |
| 42 | + file << "(" << num_col << ", " << time.count() / round << ")" << std::endl; |
| 43 | + |
| 44 | + // Close the BP. |
| 45 | + BP::close(); |
| 46 | + } |
| 47 | + // Create some blank spaces. |
| 48 | + file << std::endl << std::endl; |
| 49 | +} |
| 50 | + |
| 51 | +void our_equality_time(const int round){ |
| 52 | + // Open the output files. |
| 53 | + std::ofstream file("equality_time.txt", std::ios_base::app); |
| 54 | + file << "Our Equality Timings" << std::endl; |
| 55 | + |
| 56 | + for (int num_col : {2, 10, 20}){ |
| 57 | + // Create holder for timings. |
| 58 | + std::chrono::duration<double, std::milli> time{}; |
| 59 | + |
| 60 | + // Create pp and msk. |
| 61 | + auto pp = Aggre::pp_gen(20); |
| 62 | + auto msk = Aggre::msk_gen(pp); |
| 63 | + |
| 64 | + // Perform round number of Enc. |
| 65 | + for (int i = 0; i < round; ++i){ |
| 66 | + // Create a random vector of desired length. |
| 67 | + auto x = Helper::rand_int_vec(20, 1, std::numeric_limits<int>::max()); |
| 68 | + // Create a random vector of desired length. |
| 69 | + auto y = Helper::rand_int_vec(num_col, 1, 5); |
| 70 | + |
| 71 | + // Set the unselected portion to zero. |
| 72 | + IntVec sel; |
| 73 | + for (int j = 0; j < num_col; ++j){ sel.push_back(j); } |
| 74 | + |
| 75 | + // Compute ct and sk. |
| 76 | + auto ct = Aggre::enc(pp, msk, x); |
| 77 | + |
| 78 | + // Keygen timing. |
| 79 | + auto start = std::chrono::high_resolution_clock::now(); |
| 80 | + auto sk = Aggre::keygen(pp, msk, y, 100, sel); |
| 81 | + auto end = std::chrono::high_resolution_clock::now(); |
| 82 | + time += end - start; |
| 83 | + |
| 84 | + // Decryption timings. |
| 85 | + start = std::chrono::high_resolution_clock::now(); |
| 86 | + std::ignore = Aggre::dec(ct, sk, sel); |
| 87 | + end = std::chrono::high_resolution_clock::now(); |
| 88 | + time += end - start; |
| 89 | + } |
| 90 | + |
| 91 | + // Output the time. |
| 92 | + file << "(" << num_col << ", " << time.count() / round << ")" << std::endl; |
| 93 | + |
| 94 | + // Close the BP. |
| 95 | + BP::close(); |
| 96 | + } |
| 97 | + // Create some blank spaces. |
| 98 | + file << std::endl << std::endl; |
| 99 | +} |
| 100 | + |
| 101 | +void kim_equality_time(const int round){ |
| 102 | + // Open the output files. |
| 103 | + std::ofstream file("equality_time.txt", std::ios_base::app); |
| 104 | + file << "Kim Equality Timings" << std::endl; |
| 105 | + |
| 106 | + for (int num_col : {2, 10, 20}){ |
| 107 | + // Create holder for timings. |
| 108 | + std::chrono::duration<double, std::milli> time{}; |
| 109 | + |
| 110 | + // Create pp and msk. |
| 111 | + auto pp = KimAggre::pp_gen(20); |
| 112 | + auto msk = KimAggre::msk_gen(pp); |
| 113 | + |
| 114 | + // Perform round number of Enc. |
| 115 | + for (int i = 0; i < round; ++i){ |
| 116 | + // Create a random vector of desired length. |
| 117 | + auto x = Helper::rand_int_vec(20, 1, std::numeric_limits<int>::max()); |
| 118 | + auto y = Helper::rand_int_vec(20, 1, 5); |
| 119 | + // Set the unselected portion to zero. |
| 120 | + for (int j = num_col + 1; j < 20; ++j){ y[j] = 0; } |
| 121 | + |
| 122 | + // Compute ct and sk. |
| 123 | + auto ct = KimAggre::enc(pp, msk, x); |
| 124 | + |
| 125 | + // Keygen timing. |
| 126 | + auto start = std::chrono::high_resolution_clock::now(); |
| 127 | + auto sk = KimAggre::keygen(pp, msk, y, 100); |
| 128 | + auto end = std::chrono::high_resolution_clock::now(); |
| 129 | + time += end - start; |
| 130 | + |
| 131 | + // Decryption timings. |
| 132 | + start = std::chrono::high_resolution_clock::now(); |
| 133 | + std::ignore = KimAggre::dec(ct, sk); |
| 134 | + end = std::chrono::high_resolution_clock::now(); |
| 135 | + time += end - start; |
| 136 | + } |
| 137 | + |
| 138 | + // Output the time. |
| 139 | + file << "(" << num_col << ", " << time.count() / round << ")" << std::endl; |
| 140 | + |
| 141 | + // Close the BP. |
| 142 | + BP::close(); |
| 143 | + } |
| 144 | + // Create some blank spaces. |
| 145 | + file << std::endl << std::endl; |
| 146 | +} |
| 147 | + |
| 148 | +void bench_equality_time(const int round){ |
| 149 | + ipe_equality_time(round); |
| 150 | + our_equality_time(round); |
| 151 | + kim_equality_time(round); |
| 152 | +} |
0 commit comments