2018-02-01 08:47:06 +00:00
|
|
|
from cryptography.hazmat.primitives.asymmetric import ec
|
2018-04-30 01:33:56 +00:00
|
|
|
from cryptography.hazmat.backends.openssl import backend
|
|
|
|
from umbral import openssl
|
2018-02-01 08:47:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UmbralParameters(object):
|
2018-02-08 04:41:05 +00:00
|
|
|
def __init__(self, curve: ec.EllipticCurve):
|
2018-02-08 21:38:43 +00:00
|
|
|
from umbral.point import Point, unsafe_hash_to_point
|
|
|
|
from umbral.utils import get_curve_keysize_bytes
|
2018-02-08 04:09:47 +00:00
|
|
|
|
|
|
|
self.curve = curve
|
2018-04-30 01:33:56 +00:00
|
|
|
curve_nid = backend._elliptic_curve_to_nid(curve)
|
2018-02-08 04:09:47 +00:00
|
|
|
|
2018-02-01 08:47:06 +00:00
|
|
|
self.g = Point.get_generator_from_curve(self.curve)
|
2018-04-30 01:33:56 +00:00
|
|
|
|
|
|
|
self.order = openssl._get_ec_order_by_curve_nid(curve_nid)
|
2018-02-01 08:47:06 +00:00
|
|
|
|
|
|
|
g_bytes = self.g.to_bytes(is_compressed=True)
|
|
|
|
|
2018-02-08 21:38:43 +00:00
|
|
|
self.CURVE_KEY_SIZE_BYTES = get_curve_keysize_bytes(self.curve)
|
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')
|