mirror of https://github.com/nucypher/pyUmbral.git
Removes protected attribute scope in some umbral classes
parent
716428a8f9
commit
a6cb2a0450
|
@ -89,8 +89,8 @@ def test_cheating_ursula_sends_garbage(kfrags, prepared_capsule):
|
|||
cfrags.append(cfrag)
|
||||
|
||||
# Let's put random garbage in one of the cfrags
|
||||
cfrags[0]._point_e1 = Point.gen_rand()
|
||||
cfrags[0]._point_v1 = Point.gen_rand()
|
||||
cfrags[0].point_e1 = Point.gen_rand()
|
||||
cfrags[0].point_v1 = Point.gen_rand()
|
||||
|
||||
# Of course, this CFrag is not valid ...
|
||||
assert not cfrags[0].verify_correctness(capsule_alice)
|
||||
|
|
|
@ -182,9 +182,9 @@ def test_cfrags():
|
|||
'Invalid KFrag {}'.format(kfrag.to_bytes().hex())
|
||||
|
||||
new_cfrag = pre.reencrypt(kfrag, capsule, provide_proof=False)
|
||||
assert new_cfrag._point_e1 == cfrag._point_e1
|
||||
assert new_cfrag._point_v1 == cfrag._point_v1
|
||||
assert new_cfrag._kfrag_id == cfrag._kfrag_id
|
||||
assert new_cfrag._point_precursor == cfrag._point_precursor
|
||||
assert new_cfrag.point_e1 == cfrag.point_e1
|
||||
assert new_cfrag.point_v1 == cfrag.point_v1
|
||||
assert new_cfrag.kfrag_id == cfrag.kfrag_id
|
||||
assert new_cfrag.point_precursor == cfrag.point_precursor
|
||||
assert new_cfrag.proof is None
|
||||
assert cfrag.to_bytes() == new_cfrag.to_bytes()
|
||||
|
|
|
@ -19,21 +19,21 @@ along with pyUmbral. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
import pytest
|
||||
|
||||
from umbral import pre
|
||||
from umbral.pre import Capsule
|
||||
from umbral.curvebn import CurveBN
|
||||
from umbral.point import Point
|
||||
|
||||
|
||||
def test_capsule_serialization(capsule):
|
||||
def test_capsule_serialization(capsule: Capsule):
|
||||
params = capsule.params
|
||||
capsule_bytes = capsule.to_bytes()
|
||||
capsule_bytes_casted = bytes(capsule)
|
||||
assert capsule_bytes == capsule_bytes_casted
|
||||
|
||||
# A Capsule can be represented as the 98 total bytes of two Points (33 each) and a CurveBN (32).
|
||||
assert len(capsule_bytes) == pre.Capsule.expected_bytes_length()
|
||||
assert len(capsule_bytes) == Capsule.expected_bytes_length()
|
||||
|
||||
new_capsule = pre.Capsule.from_bytes(capsule_bytes, params)
|
||||
new_capsule = Capsule.from_bytes(capsule_bytes, params)
|
||||
|
||||
# Three ways to think about equality.
|
||||
# First, the public approach for the Capsule. Simply:
|
||||
|
@ -42,26 +42,24 @@ def test_capsule_serialization(capsule):
|
|||
# Second, we show that the original components (which is all we have here since we haven't activated) are the same:
|
||||
assert new_capsule.components() == capsule.components()
|
||||
|
||||
|
||||
# Third, we can directly compare the private original component attributes
|
||||
# (though this is not a supported approach):
|
||||
# TODO: revisit if/when these attributes are made public
|
||||
assert new_capsule._point_e == capsule._point_e
|
||||
assert new_capsule._point_v == capsule._point_v
|
||||
assert new_capsule._bn_sig == capsule._bn_sig
|
||||
assert new_capsule.point_e == capsule.point_e
|
||||
assert new_capsule.point_v == capsule.point_v
|
||||
assert new_capsule.bn_sig == capsule.bn_sig
|
||||
|
||||
|
||||
def test_cannot_create_capsule_from_bogus_material(alices_keys):
|
||||
params = alices_keys[0].params
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
capsule_of_questionable_parentage = pre.Capsule(params,
|
||||
point_e=Point.gen_rand(),
|
||||
point_v=42,
|
||||
bn_sig=CurveBN.gen_rand())
|
||||
_capsule_of_questionable_parentage = Capsule(params,
|
||||
point_e=Point.gen_rand(),
|
||||
point_v=42,
|
||||
bn_sig=CurveBN.gen_rand())
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
capsule_of_questionable_parentage = pre.Capsule(params,
|
||||
point_e=Point.gen_rand(),
|
||||
point_v=Point.gen_rand(),
|
||||
bn_sig=42)
|
||||
_capsule_of_questionable_parentage = Capsule(params,
|
||||
point_e=Point.gen_rand(),
|
||||
point_v=Point.gen_rand(),
|
||||
bn_sig=42)
|
||||
|
|
|
@ -34,17 +34,17 @@ def test_cfrag_serialization_with_proof_and_metadata(prepared_capsule, kfrags):
|
|||
assert proof.metadata is not None
|
||||
|
||||
new_cfrag = CapsuleFrag.from_bytes(cfrag_bytes)
|
||||
assert new_cfrag._point_e1 == cfrag._point_e1
|
||||
assert new_cfrag._point_v1 == cfrag._point_v1
|
||||
assert new_cfrag._kfrag_id == cfrag._kfrag_id
|
||||
assert new_cfrag._point_precursor == cfrag._point_precursor
|
||||
assert new_cfrag.point_e1 == cfrag.point_e1
|
||||
assert new_cfrag.point_v1 == cfrag.point_v1
|
||||
assert new_cfrag.kfrag_id == cfrag.kfrag_id
|
||||
assert new_cfrag.point_precursor == cfrag.point_precursor
|
||||
|
||||
new_proof = new_cfrag.proof
|
||||
assert new_proof is not None
|
||||
assert new_proof._point_e2 == proof._point_e2
|
||||
assert new_proof._point_v2 == proof._point_v2
|
||||
assert new_proof._point_kfrag_commitment == proof._point_kfrag_commitment
|
||||
assert new_proof._point_kfrag_pok == proof._point_kfrag_pok
|
||||
assert new_proof.point_e2 == proof.point_e2
|
||||
assert new_proof.point_v2 == proof.point_v2
|
||||
assert new_proof.point_kfrag_commitment == proof.point_kfrag_commitment
|
||||
assert new_proof.point_kfrag_pok == proof.point_kfrag_pok
|
||||
assert new_proof.bn_sig == proof.bn_sig
|
||||
assert new_proof.metadata == metadata
|
||||
assert new_proof.metadata == proof.metadata
|
||||
|
@ -65,17 +65,17 @@ def test_cfrag_serialization_with_proof_but_no_metadata(prepared_capsule, kfrags
|
|||
# assert len(cfrag_bytes) == 33 + 33 + 33 + 32 == 131
|
||||
|
||||
new_cfrag = CapsuleFrag.from_bytes(cfrag_bytes)
|
||||
assert new_cfrag._point_e1 == cfrag._point_e1
|
||||
assert new_cfrag._point_v1 == cfrag._point_v1
|
||||
assert new_cfrag._kfrag_id == cfrag._kfrag_id
|
||||
assert new_cfrag._point_precursor == cfrag._point_precursor
|
||||
assert new_cfrag.point_e1 == cfrag.point_e1
|
||||
assert new_cfrag.point_v1 == cfrag.point_v1
|
||||
assert new_cfrag.kfrag_id == cfrag.kfrag_id
|
||||
assert new_cfrag.point_precursor == cfrag.point_precursor
|
||||
|
||||
new_proof = new_cfrag.proof
|
||||
assert new_proof is not None
|
||||
assert new_proof._point_e2 == proof._point_e2
|
||||
assert new_proof._point_v2 == proof._point_v2
|
||||
assert new_proof._point_kfrag_commitment == proof._point_kfrag_commitment
|
||||
assert new_proof._point_kfrag_pok == proof._point_kfrag_pok
|
||||
assert new_proof.point_e2 == proof.point_e2
|
||||
assert new_proof.point_v2 == proof.point_v2
|
||||
assert new_proof.point_kfrag_commitment == proof.point_kfrag_commitment
|
||||
assert new_proof.point_kfrag_pok == proof.point_kfrag_pok
|
||||
assert new_proof.bn_sig == proof.bn_sig
|
||||
assert new_proof.metadata is None
|
||||
|
||||
|
@ -92,10 +92,10 @@ def test_cfrag_serialization_no_proof_no_metadata(prepared_capsule, kfrags):
|
|||
assert len(cfrag_bytes) == CapsuleFrag.expected_bytes_length()
|
||||
|
||||
new_cfrag = CapsuleFrag.from_bytes(cfrag_bytes)
|
||||
assert new_cfrag._point_e1 == cfrag._point_e1
|
||||
assert new_cfrag._point_v1 == cfrag._point_v1
|
||||
assert new_cfrag._kfrag_id == cfrag._kfrag_id
|
||||
assert new_cfrag._point_precursor == cfrag._point_precursor
|
||||
assert new_cfrag.point_e1 == cfrag.point_e1
|
||||
assert new_cfrag.point_v1 == cfrag.point_v1
|
||||
assert new_cfrag.kfrag_id == cfrag.kfrag_id
|
||||
assert new_cfrag.point_precursor == cfrag.point_precursor
|
||||
|
||||
new_proof = new_cfrag.proof
|
||||
assert new_proof is None
|
||||
|
@ -117,10 +117,10 @@ def test_correctness_proof_serialization(prepared_capsule, kfrags):
|
|||
# assert len(proof_bytes) == (33 * 4) + (32 * 3) == 228
|
||||
|
||||
new_proof = CorrectnessProof.from_bytes(proof_bytes)
|
||||
assert new_proof._point_e2 == proof._point_e2
|
||||
assert new_proof._point_v2 == proof._point_v2
|
||||
assert new_proof._point_kfrag_commitment == proof._point_kfrag_commitment
|
||||
assert new_proof._point_kfrag_pok == proof._point_kfrag_pok
|
||||
assert new_proof.point_e2 == proof.point_e2
|
||||
assert new_proof.point_v2 == proof.point_v2
|
||||
assert new_proof.point_kfrag_commitment == proof.point_kfrag_commitment
|
||||
assert new_proof.point_kfrag_pok == proof.point_kfrag_pok
|
||||
assert new_proof.bn_sig == proof.bn_sig
|
||||
assert new_proof.kfrag_signature == proof.kfrag_signature
|
||||
assert new_proof.metadata == proof.metadata
|
||||
|
|
|
@ -31,9 +31,9 @@ def test_kfrag_serialization(alices_keys, bobs_keys, kfrags):
|
|||
|
||||
new_kfrag = KFrag.from_bytes(kfrag_bytes)
|
||||
assert new_kfrag.id == kfrag.id
|
||||
assert new_kfrag._bn_key == kfrag._bn_key
|
||||
assert new_kfrag._point_precursor == kfrag._point_precursor
|
||||
assert new_kfrag._point_commitment == kfrag._point_commitment
|
||||
assert new_kfrag.bn_key == kfrag.bn_key
|
||||
assert new_kfrag.point_precursor == kfrag.point_precursor
|
||||
assert new_kfrag.point_commitment == kfrag.point_commitment
|
||||
assert new_kfrag.keys_in_signature == kfrag.keys_in_signature
|
||||
assert new_kfrag.signature_for_proxy == kfrag.signature_for_proxy
|
||||
assert new_kfrag.signature_for_bob == kfrag.signature_for_bob
|
||||
|
@ -55,7 +55,7 @@ def test_kfrag_verify_for_capsule(prepared_capsule, kfrags):
|
|||
|
||||
# Let's restore the KFrag, and alter the re-encryption key instead
|
||||
kfrag.id = previous_id
|
||||
kfrag._bn_key += kfrag._bn_key
|
||||
kfrag.bn_key += kfrag.bn_key
|
||||
assert not kfrag.verify_for_capsule(prepared_capsule)
|
||||
|
||||
|
||||
|
|
|
@ -51,22 +51,22 @@ signatures = tuples(integers(min_value=1, max_value=backend._bn_to_int(curve.ord
|
|||
|
||||
# # utility
|
||||
def assert_kfrag_eq(k0, k1):
|
||||
assert(all([ k0.id == k1.id
|
||||
, k0._bn_key == k1._bn_key
|
||||
, k0._point_precursor == k1._point_precursor
|
||||
, k0._point_commitment == k1._point_commitment
|
||||
, k0.signature_for_bob == k1.signature_for_bob
|
||||
assert(all([ k0.id == k1.id
|
||||
, k0.bn_key == k1.bn_key
|
||||
, k0.point_precursor == k1.point_precursor
|
||||
, k0.point_commitment == k1.point_commitment
|
||||
, k0.signature_for_bob == k1.signature_for_bob
|
||||
, k0.signature_for_proxy == k1.signature_for_proxy
|
||||
]))
|
||||
|
||||
def assert_cp_eq(c0, c1):
|
||||
assert(all([ c0._point_e2 == c1._point_e2
|
||||
, c0._point_v2 == c1._point_v2
|
||||
, c0._point_kfrag_commitment == c1._point_kfrag_commitment
|
||||
, c0._point_kfrag_pok == c1._point_kfrag_pok
|
||||
, c0.kfrag_signature == c1.kfrag_signature
|
||||
, c0.bn_sig == c1.bn_sig
|
||||
, c0.metadata == c1.metadata
|
||||
assert(all([ c0.point_e2 == c1.point_e2
|
||||
, c0.point_v2 == c1.point_v2
|
||||
, c0.point_kfrag_commitment == c1.point_kfrag_commitment
|
||||
, c0.point_kfrag_pok == c1.point_kfrag_pok
|
||||
, c0.kfrag_signature == c1.kfrag_signature
|
||||
, c0.bn_sig == c1.bn_sig
|
||||
, c0.metadata == c1.metadata
|
||||
]))
|
||||
|
||||
# tests
|
||||
|
|
|
@ -33,10 +33,10 @@ class CorrectnessProof(object):
|
|||
def __init__(self, point_e2: Point, point_v2: Point, point_kfrag_commitment: Point,
|
||||
point_kfrag_pok: Point, bn_sig: CurveBN, kfrag_signature: Signature,
|
||||
metadata: Optional[bytes] = None) -> None:
|
||||
self._point_e2 = point_e2
|
||||
self._point_v2 = point_v2
|
||||
self._point_kfrag_commitment = point_kfrag_commitment
|
||||
self._point_kfrag_pok = point_kfrag_pok
|
||||
self.point_e2 = point_e2
|
||||
self.point_v2 = point_v2
|
||||
self.point_kfrag_commitment = point_kfrag_commitment
|
||||
self.point_kfrag_pok = point_kfrag_pok
|
||||
self.bn_sig = bn_sig
|
||||
self.metadata = metadata
|
||||
self.kfrag_signature = kfrag_signature
|
||||
|
@ -79,10 +79,10 @@ class CorrectnessProof(object):
|
|||
"""
|
||||
Serialize the CorrectnessProof to a bytestring.
|
||||
"""
|
||||
e2 = self._point_e2.to_bytes()
|
||||
v2 = self._point_v2.to_bytes()
|
||||
kfrag_commitment = self._point_kfrag_commitment.to_bytes()
|
||||
kfrag_pok = self._point_kfrag_pok.to_bytes()
|
||||
e2 = self.point_e2.to_bytes()
|
||||
v2 = self.point_v2.to_bytes()
|
||||
kfrag_commitment = self.point_kfrag_commitment.to_bytes()
|
||||
kfrag_pok = self.point_kfrag_pok.to_bytes()
|
||||
|
||||
result = e2 \
|
||||
+ v2 \
|
||||
|
@ -106,10 +106,10 @@ class CapsuleFrag(object):
|
|||
kfrag_id: bytes,
|
||||
point_precursor: Point,
|
||||
proof: Optional[CorrectnessProof] = None) -> None:
|
||||
self._point_e1 = point_e1
|
||||
self._point_v1 = point_v1
|
||||
self._kfrag_id = kfrag_id
|
||||
self._point_precursor = point_precursor
|
||||
self.point_e1 = point_e1
|
||||
self.point_v1 = point_v1
|
||||
self.kfrag_id = kfrag_id
|
||||
self.point_precursor = point_precursor
|
||||
self.proof = proof
|
||||
|
||||
class NoProofProvided(TypeError):
|
||||
|
@ -158,11 +158,11 @@ class CapsuleFrag(object):
|
|||
"""
|
||||
Serialize the CapsuleFrag into a bytestring.
|
||||
"""
|
||||
e1 = self._point_e1.to_bytes()
|
||||
v1 = self._point_v1.to_bytes()
|
||||
precursor = self._point_precursor.to_bytes()
|
||||
e1 = self.point_e1.to_bytes()
|
||||
v1 = self.point_v1.to_bytes()
|
||||
precursor = self.point_precursor.to_bytes()
|
||||
|
||||
serialized_cfrag = e1 + v1 + self._kfrag_id + precursor
|
||||
serialized_cfrag = e1 + v1 + self.kfrag_id + precursor
|
||||
|
||||
if self.proof is not None:
|
||||
serialized_cfrag += self.proof.to_bytes()
|
||||
|
@ -184,18 +184,18 @@ class CapsuleFrag(object):
|
|||
####
|
||||
# Here are the formulaic constituents shared with `prove_cfrag_correctness`.
|
||||
####
|
||||
e = capsule._point_e
|
||||
v = capsule._point_v
|
||||
e = capsule.point_e
|
||||
v = capsule.point_v
|
||||
|
||||
e1 = self._point_e1
|
||||
v1 = self._point_v1
|
||||
e1 = self.point_e1
|
||||
v1 = self.point_v1
|
||||
|
||||
u = params.u
|
||||
u1 = self.proof._point_kfrag_commitment
|
||||
u1 = self.proof.point_kfrag_commitment
|
||||
|
||||
e2 = self.proof._point_e2
|
||||
v2 = self.proof._point_v2
|
||||
u2 = self.proof._point_kfrag_pok
|
||||
e2 = self.proof.point_e2
|
||||
v2 = self.proof.point_v2
|
||||
u2 = self.proof.point_kfrag_pok
|
||||
|
||||
hash_input = [e, e1, e2, v, v1, v2, u, u1, u2]
|
||||
if self.proof.metadata is not None:
|
||||
|
@ -204,8 +204,8 @@ class CapsuleFrag(object):
|
|||
h = hash_to_curvebn(*hash_input, params=params)
|
||||
########
|
||||
|
||||
precursor = self._point_precursor
|
||||
kfrag_id = self._kfrag_id
|
||||
precursor = self.point_precursor
|
||||
kfrag_id = self.kfrag_id
|
||||
|
||||
validity_input = (kfrag_id, delegating_pubkey, receiving_pubkey, u1, precursor)
|
||||
|
||||
|
@ -246,4 +246,4 @@ class CapsuleFrag(object):
|
|||
return self.to_bytes()
|
||||
|
||||
def __repr__(self):
|
||||
return "CFrag:{}".format(self._point_e1.to_bytes().hex()[2:17])
|
||||
return "CFrag:{}".format(self.point_e1.to_bytes().hex()[2:17])
|
||||
|
|
|
@ -50,9 +50,9 @@ class KFrag(object):
|
|||
keys_in_signature=DELEGATING_AND_RECEIVING,
|
||||
) -> None:
|
||||
self.id = identifier
|
||||
self._bn_key = bn_key
|
||||
self._point_commitment = point_commitment
|
||||
self._point_precursor = point_precursor
|
||||
self.bn_key = bn_key
|
||||
self.point_commitment = point_commitment
|
||||
self.point_precursor = point_precursor
|
||||
self.signature_for_proxy = signature_for_proxy
|
||||
self.signature_for_bob = signature_for_bob
|
||||
self.keys_in_signature = keys_in_signature
|
||||
|
@ -73,9 +73,9 @@ class KFrag(object):
|
|||
point_size = Point.expected_bytes_length(curve)
|
||||
|
||||
# self.id --> 1 bn_size
|
||||
# self._bn_key --> 1 bn_size
|
||||
# self._point_commitment --> 1 point_size
|
||||
# self._point_precursor --> 1 point_size
|
||||
# self.bn_key --> 1 bn_size
|
||||
# self.point_commitment --> 1 point_size
|
||||
# self.point_precursor --> 1 point_size
|
||||
# self.signature_for_proxy --> 2 bn_size
|
||||
# self.signature_for_bob --> 2 bn_size
|
||||
# self.keys_in_signature --> 1
|
||||
|
@ -117,9 +117,9 @@ class KFrag(object):
|
|||
"""
|
||||
Serialize the KFrag into a bytestring.
|
||||
"""
|
||||
key = self._bn_key.to_bytes()
|
||||
commitment = self._point_commitment.to_bytes()
|
||||
precursor = self._point_precursor.to_bytes()
|
||||
key = self.bn_key.to_bytes()
|
||||
commitment = self.point_commitment.to_bytes()
|
||||
precursor = self.point_precursor.to_bytes()
|
||||
signature_for_proxy = bytes(self.signature_for_proxy)
|
||||
signature_for_bob = bytes(self.signature_for_bob)
|
||||
mode = bytes(self.keys_in_signature)
|
||||
|
@ -144,9 +144,9 @@ class KFrag(object):
|
|||
u = params.u
|
||||
|
||||
kfrag_id = self.id
|
||||
key = self._bn_key
|
||||
commitment = self._point_commitment
|
||||
precursor = self._point_precursor
|
||||
key = self.bn_key
|
||||
commitment = self.point_commitment
|
||||
precursor = self.point_precursor
|
||||
|
||||
# We check that the commitment is well-formed
|
||||
correct_commitment = commitment == key * u
|
||||
|
|
|
@ -63,9 +63,9 @@ class Capsule(object):
|
|||
isinstance(bn_sig, CurveBN))):
|
||||
raise TypeError("Need valid point_e, point_v, and bn_sig to make a Capsule.")
|
||||
|
||||
self._point_e = point_e
|
||||
self._point_v = point_v
|
||||
self._bn_sig = bn_sig
|
||||
self.point_e = point_e
|
||||
self.point_v = point_v
|
||||
self.bn_sig = bn_sig
|
||||
|
||||
self._attached_cfrags = list() # type: list
|
||||
self._cfrag_correctness_keys = {
|
||||
|
@ -170,7 +170,7 @@ class Capsule(object):
|
|||
raise UmbralCorrectnessError(error_msg, [cfrag])
|
||||
|
||||
def components(self) -> Tuple[Point, Point, CurveBN]:
|
||||
return self._point_e, self._point_v, self._bn_sig
|
||||
return self.point_e, self.point_v, self.bn_sig
|
||||
|
||||
def __bytes__(self) -> bytes:
|
||||
return self.to_bytes()
|
||||
|
@ -191,7 +191,7 @@ class Capsule(object):
|
|||
return len(self._attached_cfrags)
|
||||
|
||||
def __repr__(self):
|
||||
return "{}:{}".format(self.__class__.__name__, hex(int(self._bn_sig))[2:17])
|
||||
return "{}:{}".format(self.__class__.__name__, hex(int(self.bn_sig))[2:17])
|
||||
|
||||
|
||||
def generate_kfrags(delegating_privkey: UmbralPrivateKey,
|
||||
|
@ -315,12 +315,12 @@ def reencrypt(kfrag: KFrag, capsule: Capsule, provide_proof: bool = True,
|
|||
elif not isinstance(kfrag, KFrag) or not kfrag.verify_for_capsule(capsule):
|
||||
raise KFrag.NotValid
|
||||
|
||||
rk = kfrag._bn_key
|
||||
e1 = rk * capsule._point_e # type: Any
|
||||
v1 = rk * capsule._point_v # type: Any
|
||||
rk = kfrag.bn_key
|
||||
e1 = rk * capsule.point_e # type: Any
|
||||
v1 = rk * capsule.point_v # type: Any
|
||||
|
||||
cfrag = CapsuleFrag(point_e1=e1, point_v1=v1, kfrag_id=kfrag.id,
|
||||
point_precursor=kfrag._point_precursor)
|
||||
point_precursor=kfrag.point_precursor)
|
||||
|
||||
if provide_proof:
|
||||
prove_cfrag_correctness(cfrag, kfrag, capsule, metadata)
|
||||
|
@ -340,19 +340,19 @@ def prove_cfrag_correctness(cfrag: CapsuleFrag,
|
|||
if not capsule.verify():
|
||||
raise capsule.NotValid("Capsule verification failed.")
|
||||
|
||||
rk = kfrag._bn_key
|
||||
rk = kfrag.bn_key
|
||||
t = CurveBN.gen_rand(params.curve)
|
||||
####
|
||||
# Here are the formulaic constituents shared with `assess_cfrag_correctness`.
|
||||
####
|
||||
e = capsule._point_e
|
||||
v = capsule._point_v
|
||||
e = capsule.point_e
|
||||
v = capsule.point_v
|
||||
|
||||
e1 = cfrag._point_e1
|
||||
v1 = cfrag._point_v1
|
||||
e1 = cfrag.point_e1
|
||||
v1 = cfrag.point_v1
|
||||
|
||||
u = params.u
|
||||
u1 = kfrag._point_commitment
|
||||
u1 = kfrag.point_commitment
|
||||
|
||||
e2 = t * e # type: Any
|
||||
v2 = t * v # type: Any
|
||||
|
@ -394,7 +394,7 @@ def _encapsulate(alice_pubkey: UmbralPublicKey,
|
|||
return key, Capsule(point_e=pub_r, point_v=pub_u, bn_sig=s, params=params)
|
||||
|
||||
|
||||
def _decapsulate_original(priv_key: UmbralPrivateKey,
|
||||
def _decapsulate_original(private_key: UmbralPrivateKey,
|
||||
capsule: Capsule,
|
||||
key_length: int = DEM_KEYSIZE) -> bytes:
|
||||
"""Derive the same symmetric key"""
|
||||
|
@ -403,7 +403,7 @@ def _decapsulate_original(priv_key: UmbralPrivateKey,
|
|||
# Check correctness of original ciphertext
|
||||
raise capsule.NotValid("Capsule verification failed.")
|
||||
|
||||
shared_key = priv_key.bn_key * (capsule._point_e + capsule._point_v) # type: Any
|
||||
shared_key = private_key.bn_key * (capsule.point_e + capsule.point_v) # type: Any
|
||||
key = kdf(shared_key, key_length)
|
||||
return key
|
||||
|
||||
|
@ -417,7 +417,7 @@ def _decapsulate_reencrypted(receiving_privkey: UmbralPrivateKey, capsule: Capsu
|
|||
pub_key = receiving_privkey.get_pubkey().point_key
|
||||
priv_key = receiving_privkey.bn_key
|
||||
|
||||
precursor = capsule._attached_cfrags[0]._point_precursor
|
||||
precursor = capsule._attached_cfrags[0].point_precursor
|
||||
dh_point = priv_key * precursor
|
||||
|
||||
# Combination of CFrags via Shamir's Secret Sharing reconstruction
|
||||
|
@ -425,17 +425,17 @@ def _decapsulate_reencrypted(receiving_privkey: UmbralPrivateKey, capsule: Capsu
|
|||
pub_key,
|
||||
dh_point,
|
||||
bytes(constants.X_COORDINATE),
|
||||
cfrag._kfrag_id,
|
||||
cfrag.kfrag_id,
|
||||
params=params)
|
||||
for cfrag in capsule._attached_cfrags]
|
||||
|
||||
e_summands, v_summands = list(), list()
|
||||
for cfrag, x in zip(capsule._attached_cfrags, xs):
|
||||
if precursor != cfrag._point_precursor:
|
||||
if precursor != cfrag.point_precursor:
|
||||
raise ValueError("Attached CFrags are not pairwise consistent")
|
||||
lambda_i = lambda_coeff(x, xs)
|
||||
e_summands.append(lambda_i * cfrag._point_e1)
|
||||
v_summands.append(lambda_i * cfrag._point_v1)
|
||||
e_summands.append(lambda_i * cfrag.point_e1)
|
||||
v_summands.append(lambda_i * cfrag.point_v1)
|
||||
|
||||
e_prime = sum(e_summands[1:], e_summands[0])
|
||||
v_prime = sum(v_summands[1:], v_summands[0])
|
||||
|
|
|
@ -71,15 +71,12 @@ capsule.set_correctness_keys(delegating=delegating_key,
|
|||
verifying=verifying_key)
|
||||
|
||||
cfrag = pre.reencrypt(kfrags[0], capsule)
|
||||
points = [capsule._point_e, cfrag._point_e1, cfrag.proof._point_e2,
|
||||
capsule._point_v, cfrag._point_v1, cfrag.proof._point_v2,
|
||||
capsule.params.u, cfrag.proof._point_kfrag_commitment, cfrag.proof._point_kfrag_pok]
|
||||
points = [capsule.point_e, cfrag.point_e1, cfrag.proof.point_e2,
|
||||
capsule.point_v, cfrag.point_v1, cfrag.proof.point_v2,
|
||||
capsule.params.u, cfrag.proof.point_kfrag_commitment, cfrag.proof.point_kfrag_pok]
|
||||
|
||||
z = cfrag.proof.bn_sig
|
||||
|
||||
# h = CurveBN.hash(*points, params=params)
|
||||
|
||||
|
||||
|
||||
#######################
|
||||
# CurveBN arithmetics #
|
||||
|
@ -117,16 +114,16 @@ create_test_vector_file(vector_suite, json_file, generate_again=generate_again)
|
|||
|
||||
|
||||
|
||||
##################
|
||||
# CurveBN.hash() #
|
||||
##################
|
||||
###################
|
||||
# hash_to_curvebn #
|
||||
###################
|
||||
|
||||
# Test vectors for different kinds of inputs (bytes, Points, CurveBNs, etc.)
|
||||
inputs = ([b''],
|
||||
[b'abc'],
|
||||
[capsule._point_e],
|
||||
[capsule.point_e],
|
||||
[z],
|
||||
[capsule._point_e, z],
|
||||
[capsule.point_e, z],
|
||||
points,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue