Skip to content

Commit

Permalink
Implement base libsecp256k1 context creation and destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrtj committed Sep 12, 2024
1 parent 67ce0e8 commit fe7d1f8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Secp256k1.xs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ MODULE = Bitcoin::Secp256k1 PACKAGE = Bitcoin::Secp256k1

PROTOTYPES: DISABLED

SV*
new(classname)
SV *classname
CODE:
secp256k1_context *secp_ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
/* TODO: fill_random is not a part of secp256k1, need to call Perl CSPRNG */
/* unsigned char randomize[32];
if (!fill_random(randomize, sizeof(randomize)) || !secp256k1_context_randomize(secp_ctx, randomize)) {
croak("Failed to randomize secp256k1 context");
} */

SV *secp_sv = newSViv(0);
RETVAL = sv_setref_iv(secp_sv, SvPVbyte_nolen(classname), (unsigned long) secp_ctx);
SvREADONLY_on(secp_sv);
OUTPUT:
RETVAL

void
DESTROY(self)
SV *self
CODE:
secp256k1_context *secp_ctx = (secp256k1_context*) SvIV(SvRV(self));
secp256k1_context_destroy(secp_ctx);

BOOT:
secp256k1_selftest();

3 changes: 2 additions & 1 deletion t/base.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use Bitcoin::Secp256k1;
# This tests whether blah blah blah
################################################################################

pass; # TODO
my $secp = Bitcoin::Secp256k1->new();
isa_ok $secp, 'Bitcoin::Secp256k1';

done_testing;

0 comments on commit fe7d1f8

Please sign in to comment.