2018-04-30 01:33:56 +00:00
|
|
|
from cryptography.hazmat.backends.openssl import backend
|
2018-07-06 22:44:33 +00:00
|
|
|
|
2018-04-30 01:33:56 +00:00
|
|
|
from umbral import openssl
|
2018-06-28 20:30:56 +00:00
|
|
|
from umbral.curve import Curve
|
2018-02-01 08:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UmbralParameters(object):
|
2018-07-06 22:44:33 +00:00
|
|
|
def __init__(self, curve: Curve) -> None:
|
2018-02-08 21:38:43 +00:00
|
|
|
from umbral.point import Point, unsafe_hash_to_point
|
2018-02-08 04:09:47 +00:00
|
|
|
|
|
|
|
self.curve = curve
|
2018-07-11 07:51:01 +00:00
|
|
|
self.CURVE_KEY_SIZE_BYTES = self.curve.get_field_order_size_in_bytes()
|
2018-02-08 04:09:47 +00:00
|
|
|
|
2018-06-28 20:30:56 +00:00
|
|
|
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/'
|
2018-02-08 23:31:54 +00:00
|
|
|
self.u = unsafe_hash_to_point(g_bytes, self, parameters_seed + b'u')
|
2018-05-31 12:27:20 +00:00
|
|
|
|
2018-07-06 22:44:33 +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
|
|
|
|
|
2018-06-28 20:30:56 +00:00
|
|
|
return self_attributes == others_attributes
|