src/sig/ec_key.c
int ec_structured_priv_key_export_to_buf(const ec_priv_key *priv_key,
					 u8 *priv_key_buf, u8 priv_key_buf_len)
{

	u8 metadata_len = (3 * sizeof(u8));
	const u8 *curve_name;
	u8 curve_name_len;
	ec_curve_type curve_type;

	priv_key_check_initialized(priv_key);

	/*
	 * We first put the metadata, consisting on:
	 *   - 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(priv_key->params->curve_name != NULL);

	/* Push the key type */
	priv_key_buf[0] = (u8)EC_PRIVKEY;

	/* Push the algorithm type */
	priv_key_buf[1] = (u8)priv_key->key_type;

	/* Push the curve type */
	curve_name = priv_key->params->curve_name;
	curve_name_len = (u8)local_strlen((const char *)curve_name) + 1;
	curve_type = ec_get_curve_type_by_name(curve_name, curve_name_len);
	priv_key_buf[2] = (u8)curve_type;

	/* Abort if this is an unknown curve ... */
	if ((ec_curve_type) priv_key_buf[2] == UNKNOWN_CURVE) {
		return -1;
	}

	/* Push the raw private key buffer */
	return ec_priv_key_export_to_buf(priv_key, priv_key_buf + metadata_len,
					 priv_key_buf_len - metadata_len);
}
/* Export a structured private key to buffer.
 * The structure allows some sanity checks.
 */
Export a structured private key to buffer.
The structure allows some sanity checks.
Export a structured private key to buffer . The structure allows some sanity checks .
int ec_structured_priv_key_export_to_buf(const ec_priv_key *priv_key,
					 u8 *priv_key_buf, u8 priv_key_buf_len)
{
	u8 metadata_len = (3 * sizeof(u8));
	const u8 *curve_name;
	u8 curve_name_len;
	ec_curve_type curve_type;
	priv_key_check_initialized(priv_key);
	MUST_HAVE(priv_key_buf != NULL);
	MUST_HAVE(priv_key_buf_len > metadata_len);
	MUST_HAVE(priv_key->params->curve_name != NULL);
	priv_key_buf[0] = (u8)EC_PRIVKEY;
	priv_key_buf[1] = (u8)priv_key->key_type;
	curve_name = priv_key->params->curve_name;
	curve_name_len = (u8)local_strlen((const char *)curve_name) + 1;
	curve_type = ec_get_curve_type_by_name(curve_name, curve_name_len);
	priv_key_buf[2] = (u8)curve_type;
	if ((ec_curve_type) priv_key_buf[2] == UNKNOWN_CURVE) {
		return -1;
	}
	return ec_priv_key_export_to_buf(priv_key, priv_key_buf + metadata_len,
					 priv_key_buf_len - metadata_len);
}
int ec_structured_priv_key_export_to_buf ( const ec_priv_key * priv_key , u8 * priv_key_buf , u8 priv_key_buf_len ) { u8 metadata_len = ( 3 * sizeof ( u8 ) ) ; const u8 * curve_name ; u8 curve_name_len ; ec_curve_type curve_type ; priv_key_check_initialized ( priv_key ) ; MUST_HAVE ( priv_key_buf != NULL ) ; MUST_HAVE ( priv_key_buf_len > metadata_len ) ; MUST_HAVE ( priv_key -> params -> curve_name != NULL ) ; priv_key_buf [ 0 ] = ( u8 ) EC_PRIVKEY ; priv_key_buf [ 1 ] = ( u8 ) priv_key -> key_type ; curve_name = priv_key -> params -> curve_name ; curve_name_len = ( u8 ) local_strlen ( ( const char * ) curve_name ) + 1 ; curve_type = ec_get_curve_type_by_name ( curve_name , curve_name_len ) ; priv_key_buf [ 2 ] = ( u8 ) curve_type ; if ( ( ec_curve_type ) priv_key_buf [ 2 ] == UNKNOWN_CURVE ) { return -1 ; } return ec_priv_key_export_to_buf ( priv_key , priv_key_buf + metadata_len , priv_key_buf_len - metadata_len ) ; }
Export a structured private key to buffer.
Export a structured private key to buffer .
/*
	 * We first put the metadata, consisting on:
	 *   - One byte = the key type (public or private)
	 *   - One byte = the algorithm type (ECDSA, ECKCDSA, ...)
	 *   - One byte = the curve type (FRP256V1, ...)
	 */ /* Push the key type */ /* Push the algorithm type */ /* Push the curve type */ /* Abort if this is an unknown curve ... */ /* Push the raw private key buffer */