コード例 #1
0
ファイル: params.py プロジェクト: INVioU/python-cmd
    def __init__(self, curve: ec.EllipticCurve):
        from umbral.point import Point, unsafe_hash_to_point
        from umbral.utils import get_curve_keysize_bytes

        self.curve = curve

        self.g = Point.get_generator_from_curve(self.curve)
        self.order = Point.get_order_from_curve(self.curve)

        g_bytes = self.g.to_bytes(is_compressed=True)

        self.CURVE_MINVAL_SHA512 = (1 << 512) % int(self.order)
        self.CURVE_KEY_SIZE_BYTES = get_curve_keysize_bytes(self.curve)

        parameters_seed = b'NuCypherKMS/UmbralParameters/'
        self.h = unsafe_hash_to_point(g_bytes, self, parameters_seed + b'h')
        self.u = unsafe_hash_to_point(g_bytes, self, parameters_seed + b'u')
コード例 #2
0
    def __init__(self, curve: Curve) -> None:
        from umbral.point import Point, unsafe_hash_to_point

        self.curve = curve
        self.CURVE_KEY_SIZE_BYTES = self.curve.field_order_size_in_bytes

        self.g = Point.get_generator_from_curve(curve=curve)
        g_bytes = self.g.to_bytes()

        parameters_seed = b'NuCypher/UmbralParameters/'
        self.u = unsafe_hash_to_point(g_bytes, self, parameters_seed + b'u')
コード例 #3
0
    def __init__(self, curve: ec.EllipticCurve):
        from umbral.point import Point, unsafe_hash_to_point
        from umbral.utils import get_curve_keysize_bytes

        self.curve = curve
        curve_nid = backend._elliptic_curve_to_nid(curve)

        self.g = Point.get_generator_from_curve(self.curve)

        self.order = openssl._get_ec_order_by_curve_nid(curve_nid)

        g_bytes = self.g.to_bytes(is_compressed=True)

        self.CURVE_KEY_SIZE_BYTES = get_curve_keysize_bytes(self.curve)

        parameters_seed = b'NuCypherKMS/UmbralParameters/'
        self.u = unsafe_hash_to_point(g_bytes, self, parameters_seed + b'u')
コード例 #4
0
def test_unsafe_hash_to_point():

    vector_file = os.path.join('vectors', 'vectors_unsafe_hash_to_point.json')
    try:
        with open(vector_file) as f:
            vector_suite = json.load(f)
    except OSError:
        raise

    params = default_params()

    for item in vector_suite['vectors']:
        data = bytes.fromhex(item['data'])
        label = bytes.fromhex(item['label'])
        expected = Point.from_bytes(bytes.fromhex(item['point']))
        assert expected == unsafe_hash_to_point(label=label,
                                                data=data,
                                                params=params)
コード例 #5
0
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,
コード例 #6
0
########################
# unsafe_hash_to_point #
########################

inputs = (
    b'',
    b'abc',
    b'NuCypher',
    b'Nucypher',
)

vectors = list()
for data in inputs:
    for label in inputs:
        point = unsafe_hash_to_point(label=label, data=data, params=params)
        json_input = {
            'data': hexlify(data),
            'label': hexlify(label),
            'point': hexlify(point),
        }

        vectors.append(json_input)

vector_suite = {
    'name': 'Test vectors for umbral.point.Point.unsafe_hash_to_point',
    'params': 'default',
    'vectors': vectors
}

create_test_vector_file(vector_suite,