mirror of https://github.com/nucypher/nucypher.git
Public key bbs98
parent
8febc2798c
commit
e8c06b8349
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue