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
|
#include <gmp.h>
#include <flint.h>
#include <fmpz.h>
#include "bv_she.hpp"
#include "bv_types.hpp"
#include "num_unencrypted.hpp"
//function that encrypts a code, given as array
void enc_code(fmpz_t u_code[], bv_enc_t (&e_code)[4], bv_pk_t &pk, BV_she &bv) {
//encrypt u_code per bit
for(int i=0; i<4; i++) {
bv.encrypt(e_code[i], u_code[i], pk);
}
}
int denominator(fmpz_t u_maskAB[]) {
//works
}
void compute_num(BV_she bv, bv_sk_t sk, bv_enc_t e_codeA[], bv_enc_t e_codeB[], bv_enc_t e_codeAinv[], bv_enc_t e_codeBinv[], fmpz_t u_maskAB[], fmpz_t &u_num) {
int addMaskAB = denominator(u_maskAB);
bv_enc_t e_addMultAB;
bv_enc_init(e_addMultAB);
bv_enc_t e_addMultABinv;
bv_enc_init(e_addMultABinv);
bv_enc_t temp;
bv_enc_init(temp);
for(int i=0; i<4; i++) {
if(fmpz_is_one(u_maskAB[i])) {
//Multiply codeA[i] and codeB[i] and put the result in temp
bv.mult(temp, e_codeA[i], e_codeB[i]);
//Add temp to addMultAB
bv.add(e_addMultAB, e_addMultAB, temp);
//Perform the same operations for the inversed codeA and codeB
bv.mult(temp, e_codeAinv[i], e_codeBinv[i]);
bv.add(e_addMultABinv, e_addMultABinv, temp);
}
}
//first decrypt addMultAB and addMultABinv, then compute numerator
fmpz_t u_addMultAB;
fmpz_init(u_addMultAB);
fmpz_t u_addMultABinv;
fmpz_init(u_addMultABinv);
bv.decrypt(u_addMultAB, e_addMultAB, sk);
bv.decrypt(u_addMultABinv, e_addMultABinv, sk);
//compute numerator (num)
fmpz_set_ui(u_num, addMaskAB);
fmpz_sub(u_num, u_num, u_addMultAB);
fmpz_sub(u_num, u_num, u_addMultABinv);
}
|