2018-07-25 17:55:12 +00:00
|
|
|
"""
|
|
|
|
Copyright (C) 2018 NuCypher
|
|
|
|
|
|
|
|
This file is part of pyUmbral.
|
|
|
|
|
|
|
|
pyUmbral is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
pyUmbral is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with pyUmbral. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
|
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-21 21:12:59 +00:00
|
|
|
self.CURVE_KEY_SIZE_BYTES = self.curve.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-07-11 08:01:25 +00:00
|
|
|
parameters_seed = b'NuCypher/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
|
|
|
|
|
|
|
# TODO: This is not comparing the order, which currently is an OpenSSL pointer
|
2018-07-19 11:36:17 +00:00
|
|
|
self_attributes = self.curve, self.g, self.CURVE_KEY_SIZE_BYTES, self.u
|
|
|
|
others_attributes = other.curve, other.g, other.CURVE_KEY_SIZE_BYTES, other.u
|
2018-05-31 12:27:20 +00:00
|
|
|
|
2018-06-28 20:30:56 +00:00
|
|
|
return self_attributes == others_attributes
|