Public key bbs98

pull/15/head
Michael Egorov 2017-08-19 14:50:34 -07:00
parent 8febc2798c
commit e8c06b8349
3 changed files with 22 additions and 2 deletions

View File

@ -26,6 +26,7 @@ def symmetric_from_algorithm(algorithm):
def pre_from_algorithm(algorithm):
kw = {k: v for k, v in algorithm['pre'].items()
if k != 'cipher' and v is not None}
module = importlib('nkms.crypto.block.' + algorithm['pre']['cipher'])
module = importlib.import_module(
'nkms.crypto.block.' + algorithm['pre']['cipher'])
# TODO need to cache this
return module.PRE(**kw)

View File

@ -36,4 +36,10 @@ class PRE(BasePRE):
return msgpack.dumps([2, epriv, remsg]) # type 2 emsg
def decrypt(self, priv, emsg, padding=True):
pass
# This is non-optimal b/c of double-deserialization
# but this cipher is for development/tests, not production
# so be it
emsg_l = msgpack.unpack(emsg)
if emsg_l[0] == 2:
_, priv, emsg = emsg_l
return super(PRE, self).decrypt(priv, emsg, padding=padding)

View File

@ -17,3 +17,16 @@ def test_symmetric():
def test_pre():
pre = pre_from_algorithm(default_algorithm)
sk_a = b'a' * 32
sk_b = b'b' * 32
pk_a = pre.priv2pub(sk_a)
pk_b = pre.priv2pub(sk_b)
msg = b'Hello world'
rk_ab = pre.rekey(sk_a, pk_b)
emsg_a = pre.encrypt(pk_a, msg)
emsg_b = pre.reencrypt(rk_ab, emsg_a)
assert pre.decrypt(sk_a, emsg_a) == msg
assert pre.decrypt(sk_b, emsg_a) != msg
assert pre.decrypt(sk_b, emsg_b) == msg