def decode(buffer: bytes): from samson.public_key.ecdsa import ECDSA cert, _left_over = decoder.decode(buffer, asn1Spec=rfc2459.Certificate()) pub_info = cert['tbsCertificate']['subjectPublicKeyInfo'] curve_params, _ = decoder.decode( Bytes(pub_info['algorithm']['parameters'])) p = int(curve_params[1][1]) b = Bytes(curve_params[2][1]).int() q = int(curve_params[4]) gx, gy = ECDSA.decode_point(Bytes(curve_params[3])) curve = WeierstrassCurve(a=-3, b=b, ring=ZZ / ZZ(p), cardinality=q, base_tuple=(gx, gy)) x, y = ECDSA.decode_point(Bytes(int(pub_info['subjectPublicKey']))) ecdsa = ECDSA(curve.G, None, d=1) ecdsa.Q = curve(x, y) return ecdsa
def decode(buffer: bytes, **kwargs) -> object: """ Decodes a JWK JSON string into an ECDSA object. Parameters: buffer (bytes/str): JWK JSON string. Returns: ECDSA: ECDSA object. """ from samson.public_key.ecdsa import ECDSA if issubclass(type(buffer), (bytes, bytearray)): buffer = buffer.decode() jwk = json.loads(buffer) curve = JWK_INVERSE_CURVE_LOOKUP[jwk['crv']] x = Bytes(url_b64_decode(jwk['x'].encode('utf-8'))).int() y = Bytes(url_b64_decode(jwk['y'].encode('utf-8'))).int() if 'd' in jwk: d = Bytes(url_b64_decode(jwk['d'].encode('utf-8'))).int() else: d = 0 ecdsa = ECDSA(G=curve.G, hash_obj=None, d=d) ecdsa.Q = curve(x, y) return ecdsa
def decode(buffer: bytes, **kwargs): from samson.public_key.ecdsa import ECDSA items = bytes_to_der_sequence(buffer) d = Bytes(items[1]).int() x, y, curve = parse_ec_params(items, 2, 3) ecdsa = ECDSA(G=curve.G, hash_obj=None, d=d) ecdsa.Q = curve(x, y) return ecdsa
def decode(buffer: bytes, **kwargs): from samson.public_key.ecdsa import ECDSA _, pub = parse_openssh_key(buffer, SSH_PUBLIC_HEADER, ECDSAPublicKey, ECDSAPrivateKey, None) curve, x_y_bytes, d = pub.curve, pub.x_y_bytes, 1 curve = SSH_INVERSE_CURVE_LOOKUP[curve.decode()] ecdsa = ECDSA(G=curve.G, hash_obj=None, d=d) ecdsa.Q = curve(*ECDSA.decode_point(x_y_bytes)) return ecdsa
def decode(buffer: bytes, **kwargs): from samson.public_key.ecdsa import ECDSA items = bytes_to_der_sequence(buffer) # Move up OID for convenience items[0] = items[0][1] d = 1 x, y, curve = parse_ec_params(items, 0, 1) ecdsa = ECDSA(G=curve.G, hash_obj=None, d=d) ecdsa.Q = curve(x, y) return ecdsa
def decode(buffer: bytes, **kwargs): from samson.public_key.ecdsa import ECDSA items = bytes_to_der_sequence(buffer) curve_oid = items[1][1].asTuple() params, _ = decoder.decode(bytes(items[2])) d = Bytes(params[1]).int() x, y = ECDSA.decode_point(Bytes(int(params[2]))) oid_bytes = ber_encoder.encode(ObjectIdentifier(curve_oid))[2:] curve = WS_OID_LOOKUP[oid_bytes] ecdsa = ECDSA(d=d, G=curve.G) ecdsa.Q = curve(x, y) return ecdsa