Java 实现分布式双门陷公钥密码系统(DT-PKC)

1 密钥生成

1.1 方案密钥构造

DT-PKC-Keygen

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);
}

2 加密

2.1 加密过程

DT-PKC-Encrypt

2.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;
}

3 弱私钥解密

3.1 使用弱私钥解密过程

DT-PKC-WeakDecrypt

3.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;
 }

4 强私钥解密

4.1 强私钥解密过程

DT-PKC-StrongDecrypt

4.2 Strong Decryption代码

omit...

5 强私钥分割

5.1 强私钥分割过程

DT-PKC-StrongKeySplit

5.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);
}

6 部分解密

6.1 部分解密1

6.1.1 过程

DT-PKC-PartialDecrypt1

6.1.2 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;
 }

6.2 部分解密2

6.2.1 过程

DT-PKC-ParitalDecrypt2

6.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;
 }

7 DT-PKC的同态特性

DT-PKC-Homo

omit...

参考文献

2016-TIFS-An Efficient Privacy-Preserving Outsourced Calculation
Toolkit With Multiple Keys

你可能感兴趣的:(网络空间安全,信息安全-密码学,密码学,java)