-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Additive Homomorphism for ElGamal #15
Comments
@eNipu Sorry, the I mean, the input (plain text to be encrypted) should be two points M1 and M2, instead of two bytes (as you mentioned above). So, I made a fix on this commit 0526d93 (done in a hurry, the code will be improved in the future): @dataclass
class ElGamal:
curve: Curve
...
def encrypt_raw(self, plaintext: Point, public_key: Point,
randfunc: Callable = None) -> Tuple[Point, Point]:
randfunc = randfunc or urandom
# Base point
G = self.curve.G
M = plaintext
random.seed(randfunc(1024))
k = random.randint(1, self.curve.n)
C1 = k * G
C2 = M + k * public_key
return C1, C2
def decrypt_raw(self, private_key: int, C1: Point, C2: Point):
M = C2 + (self.curve.n - private_key) * C1
return M With these two interfaces, you could achieve it. And I gave you an example here: from ecc.curve import Curve25519, Point
from ecc.cipher import ElGamal
from ecc.key import gen_keypair
pri_key, pub_key = gen_keypair(Curve25519)
cipher_elg = ElGamal(Curve25519)
plain_text_1: Point = Curve25519.G * 999 # magic number 999, just an example
plain_text_2: Point = Curve25519.G * 777 # magic number 777, just an example
X=C1, C2 = cipher_elg.encrypt_raw(plain_text_1, pub_key)
Y=C3, C4 = cipher_elg.encrypt_raw(plain_text_2, pub_key)
C5 = Curve25519.add_point(C1,C3)
C6 = Curve25519.add_point(C2,C4)
result = cipher_elg.decrypt_raw(pri_key, C5, C6)
print(result == plain_text_1 + plain_text_2)
# >> True |
@lc6chang |
|
@lc6chang 👍🏾 I found some answers to it. Seems the |
This paper shows a good method https://eprint.iacr.org/2014/043.pdf |
@eNipu Thanks for letting me know. Yes, my |
I have tried to check if this implementation can be used for Additive homomorphism available in ElGamal.
For example, to achieve sometime like this this
ADD(X,Y) = Enc(plain_text_1+plain_text_2)
where
Then the output is expected to be 7.
Seems
cipher_elg.decrypt(pri_key, C5, C6)
will not work.Maybe it can be done as future improvements.
The text was updated successfully, but these errors were encountered: