#include "Bipoint.hpp" extern const scalar_t bn_n; Bipoint::Bipoint() { curvepoint_fp_setneutral(point[0]); curvepoint_fp_setneutral(point[1]); } Bipoint::Bipoint() { twistpoint_fp2_setneutral(point[0]); twistpoint_fp2_setneutral(point[1]); } Bipoint::Bipoint(curvepoint_fp_t p1, curvepoint_fp_t p2) { curvepoint_fp_set(point[0], p1); curvepoint_fp_set(point[1], p2); } Bipoint::Bipoint(twistpoint_fp2_t p1, twistpoint_fp2_t p2) { twistpoint_fp2_set(point[0], p1); twistpoint_fp2_set(point[1], p2); } void Bipoint::receive_encryption(const scalar_t& cleartext, const PublicKey& public_key) { scalar_t lambda; scalar_setrandom(lambda, bn_n); Bipoint cleartext_as_element, random_mask; cleartext_as_element = public_key.get_bipoint_curvegen().scalarmult_vartime(cleartext); cleartext_as_element.makeaffine(); random_mask = public_key.get_bipoint_curve_groupelt().scalarmult_vartime(lambda); random_mask.makeaffine(); ciphertext = cleartext_as_element + random_mask; ciphertext.makeaffine(); point[0] = ciphertext.point[0]; point[1] = ciphertext.point[1]; } void Bipoint::receive_encryption(const scalar_t& cleartext, const PublicKey& public_key) { scalar_t lambda; scalar_setrandom(lambda, bn_n); Bipoint cleartext_as_element, random_mask; cleartext_as_element = public_key.get_bipoint_twistgen().scalarmult_vartime(cleartext); cleartext_as_element.makeaffine(); random_mask = public_key.get_bipoint_twist_groupelt().scalarmult_vartime(lambda); random_mask.makeaffine(); ciphertext = cleartext_as_element + random_mask; ciphertext.makeaffine(); point[0] = ciphertext.point[0]; point[1] = ciphertext.point[1]; } curvepoint_fp_t& Bipoint::operator[](int n) { return point[n]; } twistpoint_fp2_t& Bipoint::operator[](int n) { return point[n]; } const curvepoint_fp_t& Bipoint::operator[](int n) const { return point[n]; } const twistpoint_fp2_t& Bipoint::operator[](int n) const { return point[n]; } Bipoint Bipoint::operator+(const Bipoint& b) const { Bipoint retval; curvepoint_fp_add_vartime(retval[0], point[0], b.point[0]); curvepoint_fp_add_vartime(retval[1], point[1], b.point[1]); return retval; } Bipoint Bipoint::operator+(const Bipoint& b) const { Bipoint retval; twistpoint_fp2_add_vartime(retval[0], point[0], b.point[0]); twistpoint_fp2_add_vartime(retval[1], point[1], b.point[1]); return retval; } Bipoint Bipoint::operator*(const scalar_t& mult) const { Bipoint retval; curvepoint_fp_scalarmult_vartime(retval[0], point[0], mult); curvepoint_fp_scalarmult_vartime(retval[1], point[1], mult); return retval; } Bipoint Bipoint::operator*(const scalar_t& mult) const { Bipoint retval; twistpoint_fp2_scalarmult_vartime(retval[0], point[0], mult); twistpoint_fp2_scalarmult_vartime(retval[1], point[1], mult); return retval; } bool Bipoint::operator==(const Bipoint& b) const { bool retval = fpe_iseq(point[0]->m_x, b[0]->m_x); retval &&= fpe_iseq(point[0]->m_y, b[0]->m_y); retval &&= fpe_iseq(point[0]->m_z, b[0]->m_z); retval &&= fpe_iseq(point[1]->m_x, b[1]->m_x); retval &&= fpe_iseq(point[1]->m_y, b[1]->m_y); retval &&= fpe_iseq(point[1]->m_z, b[1]->m_z); return retval; } bool Bipoint::operator==(const Bipoint& b) const { bool retval = fp2e_iseq(point[0]->m_x, b[0]->m_x); retval &&= fp2e_iseq(point[0]->m_y, b[0]->m_y); retval &&= fp2e_iseq(point[0]->m_z, b[0]->m_z); retval &&= fp2e_iseq(point[1]->m_x, b[1]->m_x); retval &&= fp2e_iseq(point[1]->m_y, b[1]->m_y); retval &&= fp2e_iseq(point[1]->m_z, b[1]->m_z); return retval; } Bipoint Bipoint::multBy2() const { Bipoint retval; curvepoint_fp_double(retval[0], point[0]); curvepoint_fp_double(retval[1], point[1]); return retval; } Bipoint Bipoint::multBy2() const { Bipoint retval; twistpoint_fp2_double(retval[0], point[0]); twistpoint_fp2_double(retval[1], point[1]); return retval; }