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 parse_ec_params(items, curve_idx, pub_point_idx): from samson.public_key.ecdsa import ECDSA curve_oid = items[curve_idx].asTuple() oid_bytes = ber_encoder.encode(ObjectIdentifier(curve_oid))[2:] curve = WS_OID_LOOKUP[oid_bytes] x_y_bytes = Bytes(int(items[pub_point_idx])) x, y = ECDSA.decode_point(x_y_bytes) return x, y, curve
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) 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