// ********** SPECIAL ************// // p_first and p_second are already encrypted // return homomorphic sum of the 2 plaintext public override byte[] Addition(byte[] p_first, byte[] p_second) { //TODO: write addition var blocksize = o_key_struct.getCiphertextBlocksize(); if (p_first.Length != blocksize) { throw new System.ArgumentException("p_first", "Ciphertext to multiply should be exactly one block long."); } if (p_second.Length != blocksize) { throw new System.ArgumentException("p_second", "Ciphertext to multiply should be exactly one block long."); } // convert byte array to BigInteger BigInteger A = new BigInteger(p_first); BigInteger B = new BigInteger(p_second); BigInteger result = A * B % (o_key_struct.N * o_key_struct.N); byte[] result_byte = result.getBytes(); return(result_byte); //byte[] toBeDecrypted = new byte[blocksize]; //Array.Copy(result_byte, 0, toBeDecrypted, blocksize - result_byte.Length, result_byte.Length); //return toBeDecrypted; }
public PaillierAbstractCipher(PaillierKeyStruct p_key_struct) { // set the key details o_key_struct = p_key_struct; // calculate the blocksizes o_plaintext_blocksize = p_key_struct.getPlaintextBlocksize(); o_ciphertext_blocksize = p_key_struct.getCiphertextBlocksize(); // set the default block for plaintext, which is suitable for encryption o_block_size = o_plaintext_blocksize; }
// ********** SPECIAL ************// // p_first and p_second are already encrypted // return homomorphic sum of the 2 plaintext public override byte[] Addition(byte[] p_first, byte[] p_second) { var blocksize = o_key_struct.getCiphertextBlocksize(); if (p_first.Length != blocksize) { throw new ArgumentException("p_first", "Ciphertext to multiply should be exactly one block long."); } if (p_second.Length != blocksize) { throw new ArgumentException("p_second", "Ciphertext to multiply should be exactly one block long."); } return(Homomorphism.PaillierHomomorphism.Addition(p_first, p_second, o_key_struct.N.getBytes())); }