Skip to content

Commit

Permalink
fix crypto with cryptodome
Browse files Browse the repository at this point in the history
  • Loading branch information
danigm committed Oct 1, 2018
1 parent 2a49b0b commit 0a89eb4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
31 changes: 16 additions & 15 deletions decide/local_settings.example.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ALLOWED_HOSTS = ["*"]

# Modules in use, commented modules that you won't use
MODULES = [
'authentication',
Expand All @@ -12,29 +14,28 @@
]

APIS = {
'authentication': 'http://localhost:8000',
'base': 'http://localhost:8000',
'booth': 'http://localhost:8000',
'census': 'http://localhost:8000',
'mixnet': 'http://localhost:8000',
'postproc': 'http://localhost:8000',
'store': 'http://localhost:8000',
'visualizer': 'http://localhost:8000',
'voting': 'http://localhost:8000',
'authentication': 'http://10.5.0.1:8000',
'base': 'http://10.5.0.1:8000',
'booth': 'http://10.5.0.1:8000',
'census': 'http://10.5.0.1:8000',
'mixnet': 'http://10.5.0.1:8000',
'postproc': 'http://10.5.0.1:8000',
'store': 'http://10.5.0.1:8000',
'visualizer': 'http://10.5.0.1:8000',
'voting': 'http://10.5.0.1:8000',
}

BASEURL = 'http://localhost:8000'
BASEURL = 'http://10.5.0.1:8000'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'decide',
'USER': 'decide',
'PASSWORD': 'decide',
'HOST': 'localhost',
'NAME': 'postgres',
'USER': 'postgres',
'HOST': 'db',
'PORT': '5432',
}
}

# number of bits for the key, all auths should use the same number of bits
KEYBITS = 64
KEYBITS = 256
13 changes: 7 additions & 6 deletions decide/mixnet/mixcrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

def rand(p):
while True:
k = random.StrongRandom().randint(1, p - 1)
k = random.StrongRandom().randint(1, int(p) - 1)
if GCD(k, p - 1) == 1: break
return k

Expand Down Expand Up @@ -129,11 +129,11 @@ def encrypt(self, m, k=None):
r = rand(self.k.p)
if not k:
k = self.k
a, b = k.encrypt(m, r)
a, b = k._encrypt(m, r)
return a, b

def decrypt(self, c):
m = self.k.decrypt(c)
m = self.k._decrypt(c)
return m

def multiple_decrypt(self, msgs, last=True):
Expand Down Expand Up @@ -183,10 +183,11 @@ def reencrypt(self, cipher, pubkey=None):
else:
k = self.k

a, b = cipher
a1, b1 = self.encrypt(1, k=k)
a, b = map(int, cipher)
a1, b1 = map(int, self.encrypt(1, k=k))
p = int(k.p)

return ((a * a1) % k.p, (b * b1) % k.p)
return ((a * a1) % p, (b * b1) % p)

def gen_perm(self, l):
x = list(range(l))
Expand Down
4 changes: 2 additions & 2 deletions decide/mixnet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ def gen_key(self, p=0, g=0):
k = crypt.setk(self.key.p, self.key.g, self.key.y, self.key.x)
elif (not g or not p):
k = crypt.genk()
key = Key(p=k.p, g=k.g, y=k.y, x=k.x)
key = Key(p=int(k.p), g=int(k.g), y=int(k.y), x=int(k.x))
key.save()

self.key = key
self.save()
else:
k = crypt.getk(p, g)
key = Key(p=k.p, g=k.g, y=k.y, x=k.x)
key = Key(p=int(k.p), g=int(k.g), y=int(k.y), x=int(k.x))
key.save()

self.key = key
Expand Down

0 comments on commit 0a89eb4

Please sign in to comment.