|
@@ -1,79 +0,0 @@
|
|
|
-#include "homomorphic_operations.hpp"
|
|
|
-
|
|
|
-extern const scalar_t bn_n;
|
|
|
-
|
|
|
-Bipoint<curvepoint_fp_t> bgn_homomorphic_addition(const Bipoint<curvepoint_fp_t>& a, const Bipoint<curvepoint_fp_t>& b, const PublicKey& public_key)
|
|
|
-{
|
|
|
- Bipoint<curvepoint_fp_t> retval, random_mask;
|
|
|
-
|
|
|
- scalar_t lambda;
|
|
|
- scalar_setrandom(lambda, bn_n);
|
|
|
-
|
|
|
- random_mask = public_key.get_bipoint_curve_groupelt().scalarmult_vartime(lambda);
|
|
|
- random_mask.makeaffine();
|
|
|
-
|
|
|
- retval = a + b + random_mask;
|
|
|
- retval.makeaffine();
|
|
|
-
|
|
|
- return retval;
|
|
|
-}
|
|
|
-
|
|
|
-Bipoint<twistpoint_fp2_t> bgn_homomorphic_addition(const Bipoint<twistpoint_fp2_t>& a, const Bipoint<twistpoint_fp2_t>& b, const PublicKey& public_key)
|
|
|
-{
|
|
|
- Bipoint<curvepoint_fp_t> retval, random_mask;
|
|
|
-
|
|
|
- scalar_t lambda;
|
|
|
- scalar_setrandom(lambda, bn_n);
|
|
|
-
|
|
|
- random_mask = public_key.get_bipoint_twist_groupelt().scalarmult_vartime(lambda);
|
|
|
- random_mask.makeaffine();
|
|
|
-
|
|
|
- retval = a + b + random_mask;
|
|
|
- retval.makeaffine();
|
|
|
-
|
|
|
- return retval;
|
|
|
-}
|
|
|
-
|
|
|
-Quadripoint bgn_homomorphic_addition(const Quadripoint& a, const Quadripoint& b, const PublicKey& public_key)
|
|
|
-{
|
|
|
- Quadripoint retval, random_mask;
|
|
|
- Bipoint<curvepoint_fp_t> random_mask_curve;
|
|
|
- Bipoint<twistpoint_fp2_t> random_mask_twist;
|
|
|
-
|
|
|
- scalar_t lambda1, lambda2;
|
|
|
- scalar_setrandom(lambda1, bn_n);
|
|
|
- scalar_setrandom(lambda2, bn_n);
|
|
|
-
|
|
|
- random_mask_curve = public_key.get_bipoint_curve_groupelt().scalarmult_vartime(lambda1);
|
|
|
- random_mask_curve.makeaffine();
|
|
|
-
|
|
|
- random_mask_twist = public_key.get_bipoint_twist_groupelt().scalarmult_vartime(lambda2);
|
|
|
- random_mask_twist.makeaffine();
|
|
|
-
|
|
|
- random_mask = pairing(public_key.get_bipoint_curvegen(), random_mask_twist) * pairing(random_mask_curve, public_key.get_bipoint_twistgen());
|
|
|
- retval = a * b * random_mask;
|
|
|
-
|
|
|
- return retval;
|
|
|
-}
|
|
|
-
|
|
|
-Quadripoint bgn_homomorphic_multiplication(const Bipoint<curvepoint_fp_t>& a, const Bipoint<twistpoint_fp2_t>& b, const PublicKey& public_key)
|
|
|
-{
|
|
|
- Quadripoint retval, random_mask;
|
|
|
- Bipoint<curvepoint_fp_t> random_mask_curve;
|
|
|
- Bipoint<twistpoint_fp2_t> random_mask_twist;
|
|
|
-
|
|
|
- scalar_t lambda1, lambda2;
|
|
|
- scalar_setrandom(lambda1, bn_n);
|
|
|
- scalar_setrandom(lambda2, bn_n);
|
|
|
-
|
|
|
- random_mask_curve = public_key.get_bipoint_curve_groupelt().scalarmult_vartime(lambda1);
|
|
|
- random_mask_curve.makeaffine();
|
|
|
-
|
|
|
- random_mask_twist = public_key.get_bipoint_twist_groupelt().scalarmult_vartime(lambda2);
|
|
|
- random_mask_twist.makeaffine();
|
|
|
-
|
|
|
- random_mask = pairing(public_key.get_bipoint_curvegen(), random_mask_twist) * pairing(random_mask_curve, public_key.get_bipoint_twistgen());
|
|
|
- retval = pairing(a, b) * random_mask;
|
|
|
-
|
|
|
- return retval;
|
|
|
-}
|