caller_do_bn_init.patch

Problem:

raw_decode_base_n leaks if we allocate the bignum with BN_new(),
because BN_init() is called on an initialized BIGNUM.

Fix:

raw_decode_base58 no longer calls BN_init() and the caller has to call
BN_init() if needed.

Signed-off-by: Nelson Castillo <nelsoneci@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Add function raw_decode_base_n

Generalize raw_decode_base58 and make raw_decode_base58 depend on
raw_decode_base_n.

This will make it decoding from other bases easier in the future.

Signed-off-by: Nelson Castillo <nelsoneci@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Add a test for raw_decode_base_n with n=16

This is the first time that we test raw_decode_base_* with a BIGNUM that
is allocated with BN_new. This function was leaking before and it doesn not
leak now that raw_decode_base_n does not call BN_init (Fixed in previous patch).

In other workds, this call sequence works well now:

  bn_priv = BN_new();
  assert(raw_decode_base_n(bn_priv, priv_b16, strlen(priv_b16), 16));

Signed-off-by: Nelson Castillo <nelsoneci@gmail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>