src/sig/ec_key.c
int ec_structured_priv_key_import_from_buf(ec_priv_key *priv_key,
					   const ec_params *params,
					   const u8 *priv_key_buf,
					   u8 priv_key_buf_len,
					   ec_sig_alg_type ec_key_alg)
{
	u8 metadata_len = (3 * sizeof(u8));
	u8 crv_name_len;
	int ret;

	/* We first pull the metadata, consisting of:
	 *   - One byte = the key type (public or private)
	 *   - One byte = the algorithm type (ECDSA, ECKCDSA, ...)
	 *   - One byte = the curve type (FRP256V1, ...)
	 */
	MUST_HAVE(priv_key_buf != NULL);
	MUST_HAVE(priv_key_buf_len > metadata_len);
	MUST_HAVE(params != NULL);
	MUST_HAVE(params->curve_name != NULL);

	/* Pull and check the key type */
	if (EC_PRIVKEY != priv_key_buf[0]) {
		ret = -1;
		goto err;
	}

	/* Pull and check the algorithm type */
	if (ec_key_alg != priv_key_buf[1]) {
		ret = -1;
		goto err;
	}

	/* Pull and check the curve type */
	crv_name_len = (u8)local_strlen((const char *)params->curve_name) + 1;
	ret = ec_check_curve_type_and_name((ec_curve_type) (priv_key_buf[2]),
					   params->curve_name, crv_name_len);
	if (ret) {
		ret = -1;
		goto err;
	}

	ec_priv_key_import_from_buf(priv_key, params,
				    priv_key_buf + metadata_len,
				    priv_key_buf_len - metadata_len,
				    ec_key_alg);

 err:
	return ret;
}
/* Import a structured private key to buffer.
 * The structure allows some sanity checks.
 */
Import a structured private key to buffer.
The structure allows some sanity checks.
Import a structured private key to buffer . The structure allows some sanity checks .
int ec_structured_priv_key_import_from_buf(ec_priv_key *priv_key,
					   const ec_params *params,
					   const u8 *priv_key_buf,
					   u8 priv_key_buf_len,
					   ec_sig_alg_type ec_key_alg)
{
	u8 metadata_len = (3 * sizeof(u8));
	u8 crv_name_len;
	int ret;
	MUST_HAVE(priv_key_buf != NULL);
	MUST_HAVE(priv_key_buf_len > metadata_len);
	MUST_HAVE(params != NULL);
	MUST_HAVE(params->curve_name != NULL);
	if (EC_PRIVKEY != priv_key_buf[0]) {
		ret = -1;
		goto err;
	}
	if (ec_key_alg != priv_key_buf[1]) {
		ret = -1;
		goto err;
	}
	crv_name_len = (u8)local_strlen((const char *)params->curve_name) + 1;
	ret = ec_check_curve_type_and_name((ec_curve_type) (priv_key_buf[2]),
					   params->curve_name, crv_name_len);
	if (ret) {
		ret = -1;
		goto err;
	}
	ec_priv_key_import_from_buf(priv_key, params,
				    priv_key_buf + metadata_len,
				    priv_key_buf_len - metadata_len,
				    ec_key_alg);
 err:
	return ret;
}
int ec_structured_priv_key_import_from_buf ( ec_priv_key * priv_key , const ec_params * params , const u8 * priv_key_buf , u8 priv_key_buf_len , ec_sig_alg_type ec_key_alg ) { u8 metadata_len = ( 3 * sizeof ( u8 ) ) ; u8 crv_name_len ; int ret ; MUST_HAVE ( priv_key_buf != NULL ) ; MUST_HAVE ( priv_key_buf_len > metadata_len ) ; MUST_HAVE ( params != NULL ) ; MUST_HAVE ( params -> curve_name != NULL ) ; if ( EC_PRIVKEY != priv_key_buf [ 0 ] ) { ret = -1 ; goto err ; } if ( ec_key_alg != priv_key_buf [ 1 ] ) { ret = -1 ; goto err ; } crv_name_len = ( u8 ) local_strlen ( ( const char * ) params -> curve_name ) + 1 ; ret = ec_check_curve_type_and_name ( ( ec_curve_type ) ( priv_key_buf [ 2 ] ) , params -> curve_name , crv_name_len ) ; if ( ret ) { ret = -1 ; goto err ; } ec_priv_key_import_from_buf ( priv_key , params , priv_key_buf + metadata_len , priv_key_buf_len - metadata_len , ec_key_alg ) ; err : return ret ; }
Import a structured private key to buffer.
Import a structured private key to buffer .
/* We first pull the metadata, consisting of:
	 *   - One byte = the key type (public or private)
	 *   - One byte = the algorithm type (ECDSA, ECKCDSA, ...)
	 *   - One byte = the curve type (FRP256V1, ...)
	 */ /* Pull and check the key type */ /* Pull and check the algorithm type */ /* Pull and check the curve type */