Skip to content

Commit

Permalink
Create smpc_protocol.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 7, 2024
1 parent 9a6d643 commit 02f38f9
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import random
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.backends import default_backend

class SMPCProtocol:
def __init__(self, parties: list, threshold: int):
self.parties = parties
self.threshold = threshold
self.public_keys = [serialization.load_pem_public_key(party.encode(), backend=default_backend()) for party in parties]

def share_secret(self, secret: int) -> list:
shares = []
for i in range(len(self.parties)):
share = secret + random.randint(0, 2**256 - 1)
shares.append(share)
return shares

def reconstruct_secret(self, shares: list) -> int:
secret = 0
for share in shares:
secret += share
return secret % 2**256

0 comments on commit 02f38f9

Please sign in to comment.