src/sig/ec_key.c
int ec_structured_pub_key_import_from_buf(ec_pub_key *pub_key,
					  const ec_params *params,
					  const u8 *pub_key_buf,
					  u8 pub_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(pub_key_buf != NULL);
	MUST_HAVE(pub_key_buf_len > metadata_len);
	MUST_HAVE(params != NULL);
	MUST_HAVE(params->curve_name != NULL);

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

	/* Pull and check the algorithm type */
	if (ec_key_alg != pub_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) (pub_key_buf[2]),
					   params->curve_name, crv_name_len);
	if (ret) {
		ret = -1;
		goto err;
	}

	ret = ec_pub_key_import_from_buf(pub_key, params,
					 pub_key_buf + metadata_len,
					 pub_key_buf_len - metadata_len,
					 ec_key_alg);
 err:
	return ret;
}
/*
 * Import a structured pub key from buffer.
 * The structure allows some sanity checks.
 */
Import a structured pub key from buffer.
The structure allows some sanity checks.
Import a structured pub key from buffer . The structure allows some sanity checks .
int ec_structured_pub_key_import_from_buf(ec_pub_key *pub_key,
					  const ec_params *params,
					  const u8 *pub_key_buf,
					  u8 pub_key_buf_len,
					  ec_sig_alg_type ec_key_alg)
{
	u8 metadata_len = (3 * sizeof(u8));
	u8 crv_name_len;
	int ret;
	MUST_HAVE(pub_key_buf != NULL);
	MUST_HAVE(pub_key_buf_len > metadata_len);
	MUST_HAVE(params != NULL);
	MUST_HAVE(params->curve_name != NULL);
	if (EC_PUBKEY != pub_key_buf[0]) {
		ret = -1;
		goto err;
	}
	if (ec_key_alg != pub_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) (pub_key_buf[2]),
					   params->curve_name, crv_name_len);
	if (ret) {
		ret = -1;
		goto err;
	}
	ret = ec_pub_key_import_from_buf(pub_key, params,
					 pub_key_buf + metadata_len,
					 pub_key_buf_len - metadata_len,
					 ec_key_alg);
 err:
	return ret;
}
int ec_structured_pub_key_import_from_buf ( ec_pub_key * pub_key , const ec_params * params , const u8 * pub_key_buf , u8 pub_key_buf_len , ec_sig_alg_type ec_key_alg ) { u8 metadata_len = ( 3 * sizeof ( u8 ) ) ; u8 crv_name_len ; int ret ; MUST_HAVE ( pub_key_buf != NULL ) ; MUST_HAVE ( pub_key_buf_len > metadata_len ) ; MUST_HAVE ( params != NULL ) ; MUST_HAVE ( params -> curve_name != NULL ) ; if ( EC_PUBKEY != pub_key_buf [ 0 ] ) { ret = -1 ; goto err ; } if ( ec_key_alg != pub_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 ) ( pub_key_buf [ 2 ] ) , params -> curve_name , crv_name_len ) ; if ( ret ) { ret = -1 ; goto err ; } ret = ec_pub_key_import_from_buf ( pub_key , params , pub_key_buf + metadata_len , pub_key_buf_len - metadata_len , ec_key_alg ) ; err : return ret ; }
Import a structured pub key from buffer.
Import a structured pub key from 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 */