in reply to Usage problem with Crypt::DH::GMP::priv_key( )

$DH->priv_key($DH_private);

When you call priv_key() like that, I believe you provide the function with two args - the string "Crypt::DH::GMP" and $DH_private.

However, the priv_key() function takes only one argument, and returns a string.
I presume you therefore need to be calling priv_key() as something like:
my $string = priv_key($DH_private);
Afterthought: Or perhaps you'll need to call it by its fully qualified name:
my $string = Crypt::DH::GMP::priv_key($DH_private);
However, I know nothing of this module's functionality, and I couldn't find any example of priv_key() usage in either the documentation or the test suite.
AIUI, the priv_key function is provided in xs/dh_gmp.c as:
char * PerlCryptDHGMP_priv_key( PerlCryptDHGMP *dh ) { return PerlCryptDHGMP_mpz2sv_str(PerlCryptDHGMP_PRIVKEY_PTR(dh), 1 +0, NULL); }
Update: And all that essentially does is express the value contained in PerlCryptDHGMP *dh as a base 10 string, and then return that string (packed with extra 0's as needed).

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Usage problem with Crypt::DH::GMP::priv_key( )
by Llew_Llaw_Gyffes (Scribe) on Mar 08, 2016 at 05:05 UTC
    Actually, the author just replied to me. The problem is an API error in Crypt::DH::GMP, which he is going to fix.

      Immediate fix:

      While priv_key() in Crypt::DH::GMP does not work as a setter (but is supposed to; that's the bug), priv_key can be set in the constructor. So changing:

      $DH = Crypt::DH::GMP->new; $DH->g($g); $DH->p($p); $DH->priv_key($DH_private); $DH->generate_keys;

      to:

      $DH = Crypt::DH::GMP->new(p => $p, g => $g, priv_key => $DH_private); $DH->generate_keys;

      ...solves the problem, and is tidier code anyway.