一、密钥生成
1. 方案密钥构造
2. Key Generation代码
/**
** User/Requester generate (pk,sk) pair
*/
public static void KeyGen() {
BigInteger tmp_lamda = Utils.LCM(q1.subtract(BigInteger.ONE),q2.subtract(BigInteger.ONE));
lamda = tmp_lamda.divide(BigInteger.valueOf(2));
ski_thetai = new BigInteger[NUM_USER+1]; //The last one stands for requester
hi = new BigInteger[NUM_USER+1];//Index NUM_USER stands for the requester
for(int i=0; i<NUM_USER+1; i++) {
BigInteger tmp_ski = Utils.getRangeRandom(n.divide(BigInteger.valueOf(4))).add(BigInteger.ONE);
ski_thetai[i] = tmp_ski;
hi[i] = g.modPow(tmp_ski, n_squre);
}
}
/**
** System initialization
** Generate q1, q2, n, g
*/
public static void setup() {
q1 = Utils.getPrimeRandom(secure_k);
q2 = Utils.getPrimeRandom(secure_k);
n = q1.multiply(q2);
n_squre = n.multiply(n);
//g = n.add(BigInteger.ONE);
//g = Utils.getRangeRandom(n_squre);
g = Utils.getRangeRandom(n_squre).add(BigInteger.ONE).modPow(BigInteger.valueOf(2).multiply(n), n_squre).negate();
//System.out.println("g="+g);
}
二、加密
1. 加密过程
2. Encryption代码
/**
* Run encryption operation
* @param:
* message
* pki
* @return:
* ci1,ci2
*/
public static Cipher encrypt(BigInteger message, BigInteger pki) {
Cipher cipher = new Cipher();
BigInteger tmp_ri = Utils.getRangeRandom(n.divide(BigInteger.valueOf(4))).add(BigInteger.ONE);
BigInteger ci1_left = pki.modPow(tmp_ri, n_squre);
BigInteger ci2_right = n.add(BigInteger.ONE).modPow(message, n_squre);
cipher.setCi1(ci1_left.multiply(ci2_right).mod(n_squre));
cipher.setCi2(g.modPow(tmp_ri, n_squre));
return cipher;
}
三、弱私钥解密
1. 使用弱私钥解密过程
2. Weak Decryption 代码
/**
*Weak decryption
* @param:
* ski
* ci1
* ci2
* @return:
* out_weak
*/
public static BigInteger weak_Decrypt(BigInteger ski, BigInteger ci1, BigInteger ci2) {
BigInteger tmpDown = ci2.modPow(ski, n_squre).modInverse(n_squre);
BigInteger out_weak = ci1.multiply(tmpDown).mod(n_squre).subtract(BigInteger.ONE).divide(n);
return out_weak;
}
四、强私钥解密
1. 强私钥解密过程
2. Strong Decryption代码
omit...
五、强私钥分割
1. 强私钥分割过程
2. Strong Key Split代码
/**
** Generate partial private key lamda1 and lamda2
*/
public static void SkeyS() {
BigInteger lamda_inverse = lamda.modInverse(n_squre);
lamda1 = Utils.getRangeRandom(lamda_inverse);
lamda2 = lamda_inverse.multiply(lamda).subtract(lamda1);
}
六、部分解密
1. 部分解密1
过程
Partial Decryption 1代码
/**
* @param cipher
* @return psd1_out
*/
public static BigInteger PSD1(Result cipher) {
BigInteger psd1_out = cipher.getCi1().modPow(lamda1, n_squre);
return psd1_out;
}
2. 部分解密2
过程
Partial Decryption 2代码
/**
*
* @param cipher
* @param psd1_out
* @return psd2_out
*/
public static BigInteger PSD2(Result cipher, BigInteger psd1_out) {
BigInteger tmp = cipher.getCi1().modPow(lamda2, n_squre);
BigInteger tmp_cipher = tmp.multiply(psd1_out).mod(n_squre);
BigInteger psd2_out = tmp_cipher.subtract(BigInteger.ONE).divide(n);
return psd2_out;
}
七、DT-PKC的同态特性
omit...
参考文献
[1] 2016-TIFS-An Efficient Privacy-Preserving Outsourced Calculation Toolkit With Multiple Keys