Creates EC keypair from the just secret key and curve name

    @param curve - name of elliptic curve
    @param num - byte array or long number representing key
167971
def create(curve, data):
    
    ec_key = libcrypto.EC_KEY_new_by_curve_name(curve.nid)
    if ec_key is None:
        raise PKeyError("EC_KEY_new_by_curvename")
    group = libcrypto.EC_KEY_get0_group(ec_key)
    if group is None:
        raise PKeyError("EC_KEY_get0_group")
    libcrypto.EC_GROUP_set_asn1_flag(group, 1)
    raw_key = libcrypto.BN_new()
    if isinstance(data, int):
        libcrypto.BN_hex2bn(byref(raw_key), hex(data))
    else:
        if raw_key is None:
            raise PKeyError("BN_new")
        if libcrypto.BN_bin2bn(data, len(data), raw_key) is None:
            raise PKeyError("BN_bin2bn")
    ctx = libcrypto.BN_CTX_new()
    if ctx is None:
        raise PKeyError("BN_CTX_new")
    order = libcrypto.BN_new()
    if order is None:
        raise PKeyError("BN_new")
    priv_key = libcrypto.BN_new()
    if priv_key is None:
        raise PKeyError("BN_new")
    if libcrypto.EC_GROUP_get_order(group, order, ctx) <= 0:
        raise PKeyError("EC_GROUP_get_order")
    if libcrypto.BN_nnmod(priv_key, raw_key, order, ctx) <= 0:
        raise PKeyError("BN_nnmod")
    if libcrypto.EC_KEY_set_private_key(ec_key, priv_key) <= 0:
        raise PKeyError("EC_KEY_set_private_key")
    pub_key = libcrypto.EC_POINT_new(group)
    if pub_key is None:
        raise PKeyError("EC_POINT_new")
    if libcrypto.EC_POINT_mul(group, pub_key, priv_key, None, None, ctx) <= 0:
        raise PKeyError("EC_POINT_mul")
    if libcrypto.EC_KEY_set_public_key(ec_key, pub_key) <= 0:
        raise PKeyError("EC_KEY_set_public_key")
    libcrypto.BN_free(raw_key)
    libcrypto.BN_free(order)
    libcrypto.BN_free(priv_key)
    libcrypto.BN_CTX_free(ctx)
    pkey = libcrypto.EVP_PKEY_new()
    if pkey is None:
        raise PKeyError("EVP_PKEY_new")
    if libcrypto.EVP_PKEY_set1_EC_KEY(pkey, ec_key) <= 0:
        raise PKeyError("EVP_PKEY_set1_EC_KEY")
    libcrypto.EC_KEY_free(ec_key)
    return PKey(ptr=pkey, cansign=True)
364793
def calculateSignature(privateSigningKey, message):
        
        if privateSigningKey.getType() == Curve.DJB_TYPE:
            rand = os.urandom(64)
            res = _curve.calculateSignature(rand, privateSigningKey.getPrivateKey(), message)
            return res
        else:
            raise InvalidKeyException("Unknown type: %s" % privateSigningKey.getType())
1324459
public static SecretKey generateKey(String cipherAlgorithm) throws NoSuchAlgorithmException {
        KeyGenerator keyGenerator = KeyGenerator.getInstance(cipherAlgorithm);
        keyGenerator.init(secureRandom);

        return keyGenerator.generateKey();
    }
697071
def ec_init(spec):
    

    kb = KeyBundle(keytype="EC")
    if 'use' in spec:
        for use in spec["use"]:
            eck = new_ec_key(crv=spec['crv'], use=use)
            kb.append(eck)
    else:
        eck = new_ec_key(crv=spec['crv'])
        kb.append(eck)

    return kb
1096760
function X9ECParameters(name) {
	var params = algs.curves[name];
	assert.object(params);

	var p = new jsbn(params.p);
	var a = new jsbn(params.a);
	var b = new jsbn(params.b);
	var n = new jsbn(params.n);
	var h = jsbn.ONE;
	var curve = new ec.ECCurveFp(p, a, b);
	var G = curve.decodePointHex(params.G.toString('hex'));

	this.curve = curve;
	this.g = G;
	this.n = n;
	this.h = h;
}
80056
function(ed25519Sk, callback){
		if (typeof callback != 'function') throw new TypeError('callback must be a function');

		try {
			isValidInput(ed25519Sk, 'ed25519Sk', MiniSodium.crypto_sign_SECRETKEYBYTES);
		} catch (e){
			callback(e);
			return;
		}

		ed25519Sk = to_hex(ed25519Sk);
		var params = [ed25519Sk];
		cordova.exec(resultHandlerFactory(callback), callback, 'MiniSodium', 'crypto_sign_ed25519_sk_to_curve25519', params);
	}
12183
def decompress_pubkey(pubkey, curve_name):
    
    vk = None
    if len(pubkey) == 33:
        decompress = {
            CURVE_NIST256: _decompress_nist256,
            CURVE_ED25519: _decompress_ed25519,
            ECDH_CURVE25519: _decompress_ed25519,
        }[curve_name]
        vk = decompress(pubkey)

    if not vk:
        msg = 'invalid {!s} public key: {!r}'.format(curve_name, pubkey)
        raise ValueError(msg)

    return vk
569299
def _compute_public_key(self):
        

        if self.algorithm == 'dsa':
            params = self['private_key_algorithm']['parameters']
            return Integer(pow(
                params['g'].native,
                self['private_key'].parsed.native,
                params['p'].native
            ))

        if self.algorithm == 'rsa':
            key = self['private_key'].parsed
            return RSAPublicKey({
                'modulus': key['modulus'],
                'public_exponent': key['public_exponent'],
            })

        if self.algorithm == 'ec':
            curve_type, details = self.curve

            if curve_type == 'implicit_ca':
                raise ValueError(unwrap(
                    '''
                    Unable to compute public key for EC key using Implicit CA
                    parameters
                    '''
                ))

            if curve_type == 'specified':
                if details['field_id']['field_type'] == 'characteristic_two_field':
                    raise ValueError(unwrap(
                        '''
                        Unable to compute public key for EC key over a
                        characteristic two field
                        '''
                    ))

                curve = PrimeCurve(
                    details['field_id']['parameters'],
                    int_from_bytes(details['curve']['a']),
                    int_from_bytes(details['curve']['b'])
                )
                base_x, base_y = self['private_key_algorithm']['parameters'].chosen['base'].to_coords()
                base_point = PrimePoint(curve, base_x, base_y)

            elif curve_type == 'named':
                if details not in ('secp192r1', 'secp224r1', 'secp256r1', 'secp384r1', 'secp521r1'):
                    raise ValueError(unwrap(
                        '''
                        Unable to compute public key for EC named curve %s,
                        parameters not currently included
                        ''',
                        details
                    ))

                base_point = {
                    'secp192r1': SECP192R1_BASE_POINT,
                    'secp224r1': SECP224R1_BASE_POINT,
                    'secp256r1': SECP256R1_BASE_POINT,
                    'secp384r1': SECP384R1_BASE_POINT,
                    'secp521r1': SECP521R1_BASE_POINT,
                }[details]

            public_point = base_point * self['private_key'].parsed['private_key'].native
            return ECPointBitString.from_coords(public_point.x, public_point.y)
607715
def random_secret_exponent(curve_order):
    
    # run a rejection sampling algorithm to ensure the random int is less
    # than the curve order
    while True:
        # generate a random 256 bit hex string
        random_hex = hexlify(dev_urandom_entropy(32))
        random_int = int(random_hex, 16)
        if random_int >= 1 and random_int < curve_order:
            break
    return random_int
502431
public static JsonWebKey fromEC(KeyPair keyPair, Provider provider) {

        ECPublicKey apub = (ECPublicKey) keyPair.getPublic();
        ECPoint point = apub.getW();
        ECPrivateKey apriv = (ECPrivateKey) keyPair.getPrivate();

        if (apriv != null) {
            return new JsonWebKey().withKty(JsonWebKeyType.EC).withCrv(getCurveFromKeyPair(keyPair, provider))
                    .withX(point.getAffineX().toByteArray()).withY(point.getAffineY().toByteArray())
                    .withD(apriv.getS().toByteArray()).withKty(JsonWebKeyType.EC);
        } else {
            return new JsonWebKey().withKty(JsonWebKeyType.EC).withCrv(getCurveFromKeyPair(keyPair, provider))
                    .withX(point.getAffineX().toByteArray()).withY(point.getAffineY().toByteArray())
                    .withKty(JsonWebKeyType.EC);
        }
    }
456687
private static KeyPair newKeyPair() throws Exception {
        KeyPairGenerator kpGen = KeyPairGenerator.getInstance(KEY_ALGORITHM, BC);
        kpGen.initialize(KEY_LENGTH, new SecureRandom());
        return kpGen.generateKeyPair();
    }
565518
public static PublicKey decodeECPoint(String encode, String curveName) {
		return decodeECPoint(SecureUtil.decode(encode), curveName);
	}
1026207
def from_hex_key(cls, key, network=BitcoinMainNet):
        
        if len(key) == 130 or len(key) == 66:
            # It might be a hexlified byte array
            try:
                key = unhexlify(key)
            except TypeError:
                pass
        key = ensure_bytes(key)

        compressed = False
        id_byte = key[0]
        if not isinstance(id_byte, six.integer_types):
            id_byte = ord(id_byte)
        if id_byte == 4:
            # Uncompressed public point
            # 1B ID + 32B x coord + 32B y coord = 65 B
            if len(key) != 65:
                raise KeyParseError("Invalid key length")
            public_pair = PublicPair(
                long_or_int(hexlify(key[1:33]), 16),
                long_or_int(hexlify(key[33:]), 16))
        elif id_byte in [2, 3]:
            # Compressed public point!
            compressed = True
            if len(key) != 33:
                raise KeyParseError("Invalid key length")
            y_odd = bool(id_byte & 0x01)  # 0 even, 1 odd
            x = long_or_int(hexlify(key[1:]), 16)
            # The following x-to-pair algorithm was lifted from pycoin
            # I still need to sit down an understand it. It is also described
            # in http://www.secg.org/collateral/sec1_final.pdf
            curve = SECP256k1.curve
            p = curve.p()
            # For SECP256k1, curve.a() is 0 and curve.b() is 7, so this is
            # effectively (x ** 3 + 7) % p, but the full equation is kept
            # for just-in-case-the-curve-is-broken future-proofing
            alpha = (pow(x, 3, p) + curve.a() * x + curve.b()) % p
            beta = square_root_mod_prime(alpha, p)
            y_even = not y_odd
            if y_even == bool(beta & 1):
                public_pair = PublicPair(x, p - beta)
            else:
                public_pair = PublicPair(x, beta)
        else:
            raise KeyParseError("The given key is not in a known format.")
        return cls.from_public_pair(public_pair, network=network,
                                    compressed=compressed)
331555
public static String hmacSha256(String input, String secretKey) {
        if (input == null) {
            throw new NullPointerException("input");
        } else if (secretKey == null) {
            throw new NullPointerException("secretKey");
        }
        return hmacSha256(input.getBytes(CHARSET_UTF8), secretKey.getBytes(CHARSET_UTF8));
    }
1327994
public static org.mariadb.jdbc.internal.com.send.authentication.ed25519.math.GroupElement p2(
      final Curve curve,
      final FieldElement X,
      final FieldElement Y,
      final FieldElement Z) {
    return new org.mariadb.jdbc.internal.com.send.authentication.ed25519.math.GroupElement(curve,
        Representation.P2, X, Y, Z, null);
  }
691718
def register_pubkey(self):
        
        # point_format = 0
        # if self.point[0] in [b'\x02', b'\x03']:
        #    point_format = 1

        curve_name = _tls_named_curves[self.named_curve]
        curve = ec._CURVE_TYPES[curve_name]()
        import_point = ec.EllipticCurvePublicNumbers.from_encoded_point
        pubnum = import_point(curve, self.point)
        s = self.tls_session
        s.server_kx_pubkey = pubnum.public_key(default_backend())

        if not s.client_kx_ecdh_params:
            s.client_kx_ecdh_params = curve
1132972
public static function fromCoordinates($x, $y, $named_curve = null, $bits = null): ECPublicKey
    {
        // if bitsize is not explicitly set, check from supported curves
        if (!isset($bits) && isset($named_curve)) {
            $bits = self::_curveSize($named_curve);
        }
        $mlen = null;
        if (isset($bits)) {
            $mlen = (int) ceil($bits / 8);
        }
        $x_os = ECConversion::integerToOctetString(new Integer($x), $mlen)->string();
        $y_os = ECConversion::integerToOctetString(new Integer($y), $mlen)->string();
        $ec_point = "\x4$x_os$y_os";
        return new self($ec_point, $named_curve);
    }