1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #include "decryption.hpp"
- int decrypt(const Bipoint<curvepoint_fp_t>& ciphertext, const PublicKey& public_key, const PrivateKey& private_key)
- {
- static std::unordered_map<Bipoint<curvepoint_fp_t>, int> memoizer;
- static int max_checked = 0;
- static Bipoint<curvepoint_fp_t> pi_1_curvegen = private_key.pi_1(public_key.get_bipoint_curvegen());
- Bipoint<curvepoint_fp_t> pi_1_ciphertext = private_key.pi_1(ciphertext);
- auto lookup = memoizer.find(pi_1_ciphertext);
- if (lookup != memoizer.end())
- {
- return lookup->second;
- }
- Bipoint<curvepoint_fp_t> i = pi_1_curvegen * max_checked;
- do
- {
- memoizer[pi_1_ciphertext] = max_checked++;
- i = i + pi_1_curvegen;
- } while (i != pi_1_ciphertext);
- return max_checked - 1;
- }
- int decrypt(const Bipoint<twistpoint_fp2_t>& ciphertext, const PrivateKey& private_key) // pour les chiffrés de niveau 1
- {
- static std::unordered_map<Bipoint<twistpoint_fp2_t>, int> memoizer;
- static int max_checked = 0;
- static Bipoint<twistpoint_fp2_t> pi_2_twistgen = private_key.pi_2(public_key.get_bipoint_twistgen());
- Bipoint<twistpoint_fp2_t> pi_2_ciphertext = private_key.pi_2(ciphertext);
- auto lookup = memoizer.find(pi_2_ciphertext);
- if (lookup != memoizer.end())
- {
- return lookup->second;
- }
- Bipoint<twistpoint_fp2_t> i = pi_2_twistgen * max_checked;
- do
- {
- memoizer[pi_2_ciphertext] = max_checked++;
- i = i + pi_2_twistgen;
- } while (i != pi_2_ciphertext);
- return max_checked - 1;
- }
- void decrypt(const Quadripoint& ciphertext, const PrivateKey& private_key)
- {
- static std::unordered_map<Quadripoint, int> memoizer;
- static int max_checked = 0;
- static Quadripoint pi_T_pairgen = private_key.pi_T(pairing(public_key.get_bipoint_curvegen(), public_key.get_bipoint_twistgen()));
- Quadripoint pi_T_ciphertext = private_key.pi_T(ciphertext);
- auto lookup = memoizer.find(pi_T_ciphertext);
- if (lookup != memoizer.end())
- {
- return lookup->second;
- }
- Quadripoint i = pi_T_pairgen ^ max_checked;
- do
- {
- memoizer[pi_2_ciphertext] = max_checked++;
- i = i * pi_T_pairgen;
- } while (i != pi_T_ciphertext);
- return max_checked - 1;
- }
|