Beispiel #1
0
def reencrypt(kfrag: KFrag,
              capsule: Capsule,
              provide_proof: bool = True,
              metadata: Optional[bytes] = None,
              verify_kfrag: bool = True) -> CapsuleFrag:

    if not isinstance(capsule, Capsule) or not capsule.verify():
        raise Capsule.NotValid

    if verify_kfrag:
        if 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

    cfrag = CapsuleFrag(point_e1=e1,
                        point_v1=v1,
                        kfrag_id=kfrag.id,
                        point_precursor=kfrag.point_precursor)

    if provide_proof:
        cfrag.prove_correctness(capsule, kfrag, metadata)

    return cfrag
Beispiel #2
0
def hop_reencrypt(kfrag: KFrag,
                  cfrag: CapsuleFrag,
                  capsule: Capsule,
                  metadata: Optional[bytes] = None,
                  provide_proof: bool = True) -> CapsuleFrag:

    rk = kfrag.bn_key
    e1 = rk * cfrag.point_e1
    v1 = rk * cfrag.point_v1

    cfrag = CapsuleFrag(point_e1=e1,
                        point_v1=v1,
                        kfrag_id=kfrag.id,
                        point_precursor=kfrag.point_precursor)

    if provide_proof:
        cfrag.prove_correctness(capsule, kfrag, metadata)

    return cfrag