pyUmbral/umbral/params.py

30 lines
1.0 KiB
Python
Raw Normal View History

2018-04-30 01:33:56 +00:00
from cryptography.hazmat.backends.openssl import backend
2018-04-30 01:33:56 +00:00
from umbral import openssl
from umbral.curve import Curve
class UmbralParameters(object):
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.get_field_order_size_in_bytes()
self.g = Point.get_generator_from_curve(curve=curve)
g_bytes = self.g.to_bytes()
2018-02-08 19:16:57 +00:00
2018-02-08 23:28:47 +00:00
parameters_seed = b'NuCypherKMS/UmbralParameters/'
self.u = unsafe_hash_to_point(g_bytes, self, parameters_seed + b'u')
2018-05-31 12:27:20 +00:00
def __eq__(self, other: 'UmbralParameters') -> bool:
2018-05-31 12:27:20 +00:00
2018-07-01 17:50:06 +00:00
self_curve_nid = self.curve.curve_nid
other_curve_nid = other.curve.curve_nid
2018-05-31 12:27:20 +00:00
# TODO: This is not comparing the order, which currently is an OpenSSL pointer
self_attributes = self_curve_nid, self.g, self.CURVE_KEY_SIZE_BYTES, self.u
others_attributes = other_curve_nid, other.g, other.CURVE_KEY_SIZE_BYTES, other.u
return self_attributes == others_attributes