Skip to content

Commit

Permalink
purge spu and add properties to indicate what some kind cipher can do…
Browse files Browse the repository at this point in the history
… or not

Signed-off-by: sagewe <wbwmat@gmail.com>
  • Loading branch information
sagewe committed Sep 8, 2023
1 parent 346c1aa commit 6fad46e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 316 deletions.
44 changes: 31 additions & 13 deletions python/fate/arch/context/_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,62 @@ def setup(self, options):

sk, pk, coder = keygen(key_size)
tensor_cipher = PHETensorCipher.from_raw_cipher(pk, coder, sk, evaluator)
return PHECipher(key_size, pk, sk, evaluator, coder, tensor_cipher)
return PHECipher(key_size, pk, sk, evaluator, coder, tensor_cipher, True, True, True)

if kind == "ou":
from fate.arch.protocol.phe.ou import evaluator, keygen
from fate.arch.tensor.phe import PHETensorCipher

sk, pk, coder = keygen(key_size)
tensor_cipher = PHETensorCipher.from_raw_cipher(pk, coder, sk, evaluator)
return PHECipher(key_size, pk, sk, evaluator, coder, tensor_cipher)

# if kind == "heu":
# from fate.arch.protocol.phe.heu import evaluator, keygen
# from fate.arch.tensor.phe import PHETensorCipher
#
# sk, pk, coder = keygen(key_size)
# tensor_cipher = PHETensorCipher.from_raw_cipher(pk, coder, sk, evaluator)
# return PHECipher(key_size, pk, sk, evaluator, coder, tensor_cipher)
# #
return PHECipher(key_size, pk, sk, evaluator, coder, tensor_cipher, False, False, True)

elif kind == "mock":
from fate.arch.protocol.phe.mock import evaluator, keygen
from fate.arch.tensor.phe import PHETensorCipher

sk, pk, coder = keygen(key_size)
tensor_cipher = PHETensorCipher.from_raw_cipher(pk, coder, sk, evaluator)
return PHECipher(key_size, pk, sk, evaluator, coder, tensor_cipher)
return PHECipher(key_size, pk, sk, evaluator, coder, tensor_cipher, True, False, False)

else:
raise ValueError(f"Unknown PHE keygen kind: {self.kind}")


class PHECipher:
def __init__(self, key_size, pk, sk, evaluator, coder, tensor_cipher) -> None:
def __init__(
self,
key_size,
pk,
sk,
evaluator,
coder,
tensor_cipher,
can_support_negative_number,
can_support_squeeze,
can_support_pack,
) -> None:
self._key_size = key_size
self._pk = pk
self._sk = sk
self._coder = coder
self._evaluator = evaluator
self._tensor_cipher = tensor_cipher
self._can_support_negative_number = can_support_negative_number
self._can_support_squeeze = can_support_squeeze
self._can_support_pack = can_support_pack

@property
def can_support_negative_number(self):
return self._tensor_cipher.can_support_negative_number

@property
def can_support_squeeze(self):
return self._tensor_cipher.can_support_squeeze

@property
def can_support_pack(self):
return self._tensor_cipher.can_support_pack

@property
def key_size(self):
Expand Down
303 changes: 0 additions & 303 deletions python/fate/arch/protocol/phe/heu.py

This file was deleted.

0 comments on commit 6fad46e

Please sign in to comment.