Skip to content

Commit

Permalink
add kind to cipher
Browse files Browse the repository at this point in the history
Signed-off-by: sagewe <wbwmat@gmail.com>
  • Loading branch information
sagewe committed Sep 8, 2023
1 parent 45324ba commit 170fffa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
18 changes: 12 additions & 6 deletions python/fate/arch/context/_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ def setup(self, options: typing.Optional[dict] = None):

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, True, True, True)
return PHECipher(kind, 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, False, False, True)
return PHECipher(kind, 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, True, False, False)
return PHECipher(kind, key_size, pk, sk, evaluator, coder, tensor_cipher, True, False, False)

else:
raise ValueError(f"Unknown PHE keygen kind: {self.kind}")
Expand All @@ -97,6 +97,7 @@ def setup(self, options: typing.Optional[dict] = None):
class PHECipher:
def __init__(
self,
kind,
key_size,
pk,
sk,
Expand All @@ -107,6 +108,7 @@ def __init__(
can_support_squeeze,
can_support_pack,
) -> None:
self._kind = kind
self._key_size = key_size
self._pk = pk
self._sk = sk
Expand All @@ -117,17 +119,21 @@ def __init__(
self._can_support_squeeze = can_support_squeeze
self._can_support_pack = can_support_pack

@property
def kind(self):
return self._kind

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

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

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

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

This file was deleted.

0 comments on commit 170fffa

Please sign in to comment.