clightning-dumpkeys

dump clightning output descriptors
git clone git://jb55.com/clightning-dumpkeys
Log | Files | Refs | README | LICENSE

ec.c (788B)


      1 /* from wally_core */
      2 
      3 #include "ec.h"
      4 #include <stdbool.h>
      5 #include "short_types.h"
      6 #include "compiler.h"
      7 
      8 int wally_ec_public_key_from_private_key(
      9 	const secp256k1_context *ctx,
     10 	const unsigned char *priv_key, size_t priv_key_len,
     11 	unsigned char *bytes_out, size_t len)
     12 {
     13 	secp256k1_pubkey pub;
     14 	size_t len_in_out = EC_PUBLIC_KEY_LEN;
     15 	bool ok;
     16 
     17 	if (!ctx)
     18 		return WALLY_ENOMEM;
     19 
     20 	ok = priv_key && priv_key_len == EC_PRIVATE_KEY_LEN &&
     21 		bytes_out && len == EC_PUBLIC_KEY_LEN &&
     22 		secp256k1_ec_pubkey_create(ctx, &pub, priv_key) &&
     23 		secp256k1_ec_pubkey_serialize(ctx, bytes_out, &len_in_out, &pub, SECP256K1_EC_COMPRESSED) &&
     24 		len_in_out == EC_PUBLIC_KEY_LEN;
     25 
     26 	if (!ok && bytes_out)
     27 		memclear(bytes_out, len);
     28 	memclear(&pub, sizeof(pub));
     29 	return ok ? WALLY_OK : WALLY_EINVAL;
     30 }