Beispiel #1
0
 def __init__(self, poly_degree, ciph_modulus):
     big_modulus = ciph_modulus**2
     scaling_factor = 1 << 30
     
     params = CKKSParameters(poly_degree=poly_degree,
                             ciph_modulus=ciph_modulus,
                             big_modulus=big_modulus,
                             scaling_factor=scaling_factor)
     key_generator = CKKSKeyGenerator(params)
     public_key = key_generator.public_key
     secret_key = key_generator.secret_key
     encoder = CKKSEncoder(params)
     encryptor = CKKSEncryptor(params, public_key, secret_key)
     decryptor = CKKSDecryptor(params, secret_key)
     evaluator = CKKSEvaluator(params)
     
     self.poly_degree = poly_degree
     self.ciph_modulus = ciph_modulus
     self.scaling_factor = scaling_factor
     
     self.secret_key = secret_key
     
     self.encoder = encoder
     self.encryptor = encryptor
     self.decryptor = decryptor
     self.evaluator = evaluator
def main():

    poly_degree = 8
    ciph_modulus = 1 << 600
    big_modulus = 1 << 1200
    scaling_factor = 1 << 30
    params = CKKSParameters(poly_degree=poly_degree,
                            ciph_modulus=ciph_modulus,
                            big_modulus=big_modulus,
                            scaling_factor=scaling_factor)
    key_generator = CKKSKeyGenerator(params)
    public_key = key_generator.public_key
    secret_key = key_generator.secret_key
    relin_key = key_generator.relin_key
    encoder = CKKSEncoder(params)
    encryptor = CKKSEncryptor(params, public_key, secret_key)
    decryptor = CKKSDecryptor(params, secret_key)
    evaluator = CKKSEvaluator(params)

    message1 = [0.5, 0.3 + 0.2j, 0.78, 0.88j]
    message2 = [0.2, 0.11, 0.4 + 0.67j, 0.9 + 0.99j]
    plain1 = encoder.encode(message1, scaling_factor)
    plain2 = encoder.encode(message2, scaling_factor)
    ciph1 = encryptor.encrypt(plain1)
    ciph2 = encryptor.encrypt(plain2)
    ciph_prod = evaluator.multiply(ciph1, ciph2, relin_key)
    decrypted_prod = decryptor.decrypt(ciph_prod)
    decoded_prod = encoder.decode(decrypted_prod)

    print(decoded_prod)
Beispiel #3
0
 def setUp(self):
     self.degree = 64
     self.ciph_modulus = 1 << 1200
     self.big_modulus = 1 << 1200
     self.scaling_factor = 1 << 30
     self.params = CKKSParameters(poly_degree=self.degree,
                                  ciph_modulus=self.ciph_modulus,
                                  big_modulus=self.big_modulus,
                                  scaling_factor=self.scaling_factor)
     key_generator = CKKSKeyGenerator(self.params)
     public_key = key_generator.public_key
     secret_key = key_generator.secret_key
     self.encoder = CKKSEncoder(self.params)
     self.encryptor = CKKSEncryptor(self.params, public_key, secret_key)
     self.decryptor = CKKSDecryptor(self.params, secret_key)
Beispiel #4
0
    def setUp(self):
        self.degree = int(arg)
        self.ciph_modulus = 1 << 40
        self.big_modulus = 1 << 1200
        self.scaling_factor = 1 << 30

        self.params = CKKSParameters(poly_degree=self.degree,
                                     ciph_modulus=self.ciph_modulus,
                                     big_modulus=self.big_modulus,
                                     scaling_factor=self.scaling_factor,
                                     taylor_iterations=7,
                                     prime_size=None)
        self.key_generator = CKKSKeyGenerator(self.params)
        public_key = self.key_generator.public_key
        secret_key = self.key_generator.secret_key
        self.relin_key = self.key_generator.relin_key
        self.encoder = CKKSEncoder(self.params)
        self.encryptor = CKKSEncryptor(self.params, public_key, secret_key)
        self.decryptor = CKKSDecryptor(self.params, secret_key)
        self.evaluator = CKKSEvaluator(self.params)
    def run_test_simple_rotate(self, message, rot):
        poly = Polynomial(self.degree // 2, message)

        plain = self.encoder.encode(message, self.scaling_factor)

        rot_message = [0] * poly.ring_degree
        for i in range(poly.ring_degree):
            rot_message[i] = poly.coeffs[(i + rot) % poly.ring_degree]

        ciph = self.encryptor.encrypt(plain)
        ciph_rot0 = ciph.c0.rotate(rot).mod_small(self.ciph_modulus)
        ciph_rot1 = ciph.c1.rotate(rot).mod_small(self.ciph_modulus)
        ciph_rot = Ciphertext(ciph_rot0, ciph_rot1, ciph.scaling_factor,
                              self.ciph_modulus)
        decryptor = CKKSDecryptor(self.params,
                                  SecretKey(self.secret_key.s.rotate(rot)))
        decrypted_rot = decryptor.decrypt(ciph_rot)
        decoded_rot = self.encoder.decode(decrypted_rot)

        check_complex_vector_approx_eq(rot_message, decoded_rot, error=0.005)