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: 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
def test_cast_curvebn_to_int(): x = CurveBN.gen_rand() x_as_int_from_dunder = x.__int__() x_as_int_type_caster = int(x) assert x_as_int_from_dunder == x_as_int_type_caster x = x_as_int_type_caster y = CurveBN.from_int(x) assert x == y
def from_bytes(cls, signature_as_bytes: bytes, der_encoded: bool = False, curve: Optional[Curve] = None) -> 'Signature': curve = curve if curve is not None else default_curve() if der_encoded: r, s = decode_dss_signature(signature_as_bytes) else: expected_len = cls.expected_bytes_length(curve) if not len(signature_as_bytes) == expected_len: raise ValueError( "Looking for exactly {} bytes if you call from_bytes \ with der_encoded=False and curve={}.".format( expected_len, curve)) else: r = int.from_bytes(signature_as_bytes[:(expected_len // 2)], "big") s = int.from_bytes(signature_as_bytes[(expected_len // 2):], "big") return cls(CurveBN.from_int(r, curve), CurveBN.from_int(s, curve))
def test_serialization_rotations_of_1(curve): size_in_bytes = CurveBN.expected_bytes_length(curve) for i in range(size_in_bytes): lonely_one = 1 << i bn = CurveBN.from_int(lonely_one, curve) lonely_one_in_bytes = lonely_one.to_bytes(size_in_bytes, 'big') # Check serialization assert bn.to_bytes() == lonely_one_in_bytes # Check deserialization assert CurveBN.from_bytes(lonely_one_in_bytes, curve) == bn
from umbral.params import UmbralParameters from umbral.point import Point from umbral.random_oracles import unsafe_hash_to_point from umbral.pre import Capsule # test parameters max_examples = 1000 # crypto constants curve = default_curve() params = UmbralParameters(curve) bn_size = curve.group_order_size_in_bytes # generators bns = integers(min_value=1, max_value=backend._bn_to_int(curve.order)).map( lambda x: CurveBN.from_int(x)) points = binary(min_size=1).map( lambda x: unsafe_hash_to_point(x, label=b'hypothesis', params=params)) signatures = tuples(integers(min_value=1, max_value=backend._bn_to_int(curve.order)), integers(min_value=1, max_value=backend._bn_to_int(curve.order))).map( lambda tup: tup[0].to_bytes(bn_size, 'big') + tup[1].to_bytes(bn_size, 'big')) # # 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
from umbral.params import UmbralParameters from umbral.point import Point from umbral.random_oracles import unsafe_hash_to_point from umbral.pre import Capsule # test parameters max_examples = 1000 # crypto constants curve = default_curve() params = UmbralParameters(curve) bn_size = curve.group_order_size_in_bytes # generators bns = integers(min_value=1, max_value=backend._bn_to_int( curve.order)).map(lambda x: CurveBN.from_int(x)) points = binary(min_size=1).map( lambda x: unsafe_hash_to_point(x, label=b'hypothesis', params=params)) signatures = tuples( integers(min_value=1, max_value=backend._bn_to_int(curve.order)), integers(min_value=1, max_value=backend._bn_to_int(curve.order))).map(lambda tup: tup[ 0].to_bytes(bn_size, 'big') + tup[1].to_bytes(bn_size, 'big')) # # utility def assert_kfrag_eq(k0, k1): assert (all([ k0.id == k1.id, k0.bn_key == k1.bn_key,