How to use the umbral.curvebn.CurveBN function in umbral

To help you get started, we’ve selected a few umbral examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nucypher / pyUmbral / tests / fixtures.py View on Github external
def random_ec_curvebn2():
    yield CurveBN.gen_rand()
github nucypher / pyUmbral / umbral / utils.py View on Github external
def lambda_coeff(id_i: CurveBN, selected_ids: List[CurveBN]) -> CurveBN:
    ids = [x for x in selected_ids if x != id_i]

    if not ids:
        return CurveBN.from_int(1, id_i.curve)

    result = ids[0] / (ids[0] - id_i)
    for id_j in ids[1:]:
        result = result * id_j / (id_j - id_i)

    return result
github nucypher / pyUmbral / umbral / point.py View on Github external
def gen_rand(cls, curve: Optional[Curve] = None) -> 'Point':
        """
        Returns a Point object with a cryptographically secure EC_POINT based
        on the provided curve.
        """
        curve = curve if curve is not None else default_curve()

        rand_point = openssl._get_new_EC_POINT(curve)
        rand_bn = CurveBN.gen_rand(curve).bignum

        with backend._tmp_bn_ctx() as bn_ctx:
            res = backend._lib.EC_POINT_mul(
                curve.ec_group, rand_point, backend._ffi.NULL, curve.generator,
                rand_bn, bn_ctx
            )
            backend.openssl_assert(res == 1)

        return cls(rand_point, curve)
github nucypher / pyUmbral / umbral / cfrags.py View on Github external
def expected_bytes_length(cls, curve: Optional[Curve] = None):
        """
        Returns the size (in bytes) of a CorrectnessProof without the metadata.
        If no curve is given, it will use the default curve.
        """
        curve = curve if curve is not None else default_curve()
        bn_size = CurveBN.expected_bytes_length(curve=curve)
        point_size = Point.expected_bytes_length(curve=curve)

        return (bn_size * 3) + (point_size * 4)
github nucypher / pyUmbral / umbral / cfrags.py View on Github external
def prove_correctness(self,
                          capsule,
                          kfrag,
                          metadata: Optional[bytes] = None):

        params = capsule.params

        # Check correctness of original ciphertext
        if not capsule.verify():
            raise capsule.NotValid("Capsule verification failed.")

        rk = kfrag.bn_key
        t = CurveBN.gen_rand(params.curve)
        ####
        # Here are the formulaic constituents shared with `verify_correctness`.
        ####
        e = capsule.point_e
        v = capsule.point_v

        e1 = self.point_e1
        v1 = self.point_v1

        u = params.u
        u1 = kfrag.point_commitment

        e2 = t * e  # type: Any
        v2 = t * v  # type: Any
        u2 = t * u  # type: Any
github nucypher / pyUmbral / umbral / curvebn.py View on Github external
"""
        # TODO: Should this stay in or not?
        if type(other) == int:
            other = openssl._int_to_bn(other)
            other = CurveBN(other, self.curve)

        other = cast('CurveBN', other)  # This is just for mypy

        power = openssl._get_new_BN()
        with backend._tmp_bn_ctx() as bn_ctx, openssl._tmp_bn_mont_ctx(self.curve.order) as bn_mont_ctx:
            res = backend._lib.BN_mod_exp_mont(
                power, self.bignum, other.bignum, self.curve.order, bn_ctx, bn_mont_ctx
            )
            backend.openssl_assert(res == 1)

        return CurveBN(power, self.curve)
github nucypher / pyUmbral / umbral / kfrags.py View on Github external
def expected_bytes_length(cls, curve: Optional[Curve] = None) -> int:
        """
        Returns the size (in bytes) of a KFrag given the curve.
        If no curve is provided, it will use the default curve.
        """
        curve = curve if curve is not None else default_curve()
        bn_size = CurveBN.expected_bytes_length(curve)
        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.signature_for_proxy --> 2 bn_size
        # self.signature_for_bob --> 2 bn_size
        # self.keys_in_signature --> 1

        return bn_size * 6 + point_size * 2 + 1
github nucypher / pyUmbral / umbral / pre.py View on Github external
def __init__(self,
                 params: UmbralParameters,
                 point_e: Point,
                 point_v: Point,
                 bn_sig: CurveBN,
                 ) -> None:

        self.params = params

        if not all((isinstance(point_e, Point),
                    isinstance(point_v, Point),
                    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._attached_cfrags = set()    # type: set
        self._cfrag_correctness_keys = {
            'delegating': None, 'receiving': None, 'verifying': None
        }   # type: dict