Search code examples
perlxs

How to pass C NULL to XS based function?


I am trying to use Crypt::OpenSSL::EC::EC_POINT::mul() function from Crypt::OpenSSL::EC module. It has such C prototype:

int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *n, const EC_POINT *q, const BIGNUM *m, BN_CTX *ctx)

And I need to pass NULL, NULL instead of EC_POINT *q, const BIGNUM *m as it made here: https://stackoverflow.com/a/12482384/3090865

But this module has such typemap:

INPUT
BIGNUM
    if( ! SvROK( $arg ) ) { croak( \"argument is not an object\" ); }
    $var = (${type}) SvIV( SvRV( $arg ) );

EC_METHOD
    if( ! SvROK( $arg ) ) { croak( \"argument is not an object\" ); }
    $var = (${type}) SvIV( SvRV( $arg ) );

EC_GROUP
    if( ! SvROK( $arg ) ) { croak( \"argument is not an object\" ); }
    $var = (${type}) SvIV( SvRV( $arg ) );

EC_POINT
    if( ! SvROK( $arg ) ) { croak( \"argument is not an object\" ); }
    $var = (${type}) SvIV( SvRV( $arg ) );

EC_KEY
    if( ! SvROK( $arg ) ) { croak( \"argument is not an object\" ); }
    $var = (${type}) SvIV( SvRV( $arg ) );

So, if i'll pass undef or 0, i'll get "argument is not an object" error. Is it possible to make what I want without changing this module? Maybe I can create NULL-based object somehow?


Solution

  • According to the typemap, passing a reference to zero \0 should work:

    Crypt::OpenSSL::EC::EC_POINT::mul($group, $r, $n, \0, \0, $ctx);