NAME

Developer::Dashboard::Crypto::PBKDF2 - native PBKDF2 adapter

PURPOSE

This module calls OpenSSL's one-shot PBKDF2-HMAC-SHA256 implementation through the distribution's shared XS extension. It is a narrow adapter for dashboard helper authentication; it does not translate or accelerate arbitrary Perl subroutines.

WHY IT EXISTS

The prior derivation called the XS HMAC function once per PBKDF2 round from a Perl loop. A single native PBKDF2 call avoids that repeated Perl/native boundary while retaining the existing digest, output size, and iteration count. The portable Perl implementation remains the path when no compatible system libcrypto is available, the XS extension is not built, or input byte semantics cannot safely cross the native boundary. Failures in an available native PBKDF2 call remain visible.

WHEN TO USE

Use this module only for SHA-256 PBKDF2 derivation with scalar password/salt values representable as Perl byte strings and a positive integer work factor. Do not use it to reduce the iteration count or to parallelize one PBKDF2 chain; the chain is intentionally sequential.

HOW TO USE

Call native_available to inspect whether the XS adapter and a compatible OpenSSL library are available. Call derive_sha256 with named password, salt, and iterations arguments. An undefined result means the caller should execute its explicit Perl implementation. Library-binding and native-call failures die with a visible error rather than being hidden as fallback.

WHAT USES IT

Developer::Dashboard::Auth calls this adapter when creating and verifying PBKDF2 helper-user records. The Auth module retains the existing Digest::SHA implementation for unsupported input and systems without libcrypto.

EXAMPLES

Example 1:

my $digest = Developer::Dashboard::Crypto::PBKDF2->derive_sha256(
  password => $password,
  salt => $salt,
  iterations => 210_000,
);

Derive the same stored PBKDF2-SHA256 key through OpenSSL when the adapter can preserve the input byte semantics.

Example 2:

if (Developer::Dashboard::Crypto::PBKDF2->native_available) {
    print "OpenSSL PBKDF2 acceleration is available\n";
}

Check whether the current machine has a compatible native crypto library.

Example 3:

d2 docker compose exec dev prove -Iblib/arch -Iblib/lib -Ilib -lv t/651-crypto-pbkdf2-xs.t

Run digest-parity, unsupported-Unicode, invalid-input, and missing-library tests.