PBKDF2-Tiny-0.005/000755 000765 000024 00000000000 12433343647 013612 5ustar00davidstaff000000 000000 PBKDF2-Tiny-0.005/Changes000644 000765 000024 00000001477 12433343647 015116 0ustar00davidstaff000000 000000 Revision history for PBKDF2-Tiny 0.005 2014-11-20 05:51:16-05:00 America/New_York [FIXED] - fixed verification bug if derived key length was not passed to verify/verify_hex 0.004 2014-10-06 11:18:07-04:00 America/New_York [CHANGED] - password and salt must be encoded as octets; if the internal UTF8 flag is on, an exception is thrown. [DOCUMENTED] - Fixed minor doc typo for 'hmac' function 0.003 2014-09-29 10:21:45-04:00 America/New_York [FIXED] - Added 'hmac' and 'digest_fcn' to @EXPORT_OK. Also documented that nothing is exported by default. 0.002 2014-09-26 16:27:40-04:00 America/New_York [FIXED] - Fixed dependencies in Makefile.PL for Perl 5.8 and earlier 0.001 2014-09-26 16:21:44-04:00 America/New_York - First release PBKDF2-Tiny-0.005/CONTRIBUTING.mkdn000644 000765 000024 00000005751 12433343647 016404 0ustar00davidstaff000000 000000 ## HOW TO CONTRIBUTE Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with Dist::Zilla. This means than many of the usual files you might expect are not in the repository, but are generated at release time, as is much of the documentation. Some generated files are kept in the repository as a convenience (e.g. Makefile.PL or cpanfile). Generally, **you do not need Dist::Zilla to contribute patches**. You do need Dist::Zilla to create a tarball. See below for guidance. ### Getting dependencies If you have App::cpanminus 1.6 or later installed, you can use `cpanm` to satisfy dependencies like this: $ cpanm --installdeps . Otherwise, look for either a `Makefile.PL` or `cpanfile` file for a list of dependencies to satisfy. ### Running tests You can run tests directly using the `prove` tool: $ prove -l $ prove -lv t/some_test_file.t For most of my distributions, `prove` is entirely sufficient for you to test any patches you have. I use `prove` for 99% of my testing during development. ### Code style and tidying Please try to match any existing coding style. If there is a `.perltidyrc` file, please install Perl::Tidy and use perltidy before submitting patches. If there is a `tidyall.ini` file, you can also install Code::TidyAll and run `tidyall` on a file or `tidyall -a` to tidy all files. ### Patching documentation Much of the documentation Pod is generated at release time. Some is generated boilerplate; other documentation is built from pseudo-POD directives in the source like C<=method> or C<=func>. If you would like to submit a documentation edit, please limit yourself to the documentation you see. If you see typos or documentation issues in the generated docs, please email or open a bug ticket instead of patching. ### Installing and using Dist::Zilla Dist::Zilla is a very powerful authoring tool, optimized for maintaining a large number of distributions with a high degree of automation, but it has a large dependency chain, a bit of a learning curve and requires a number of author-specific plugins. To install it from CPAN, I recommend one of the following approaches for the quickest installation: # using CPAN.pm, but bypassing non-functional pod tests $ cpan TAP::Harness::Restricted $ PERL_MM_USE_DEFAULT=1 HARNESS_CLASS=TAP::Harness::Restricted cpan Dist::Zilla # using cpanm, bypassing *all* tests $ cpanm -n Dist::Zilla In either case, it's probably going to take about 10 minutes. Go for a walk, go get a cup of your favorite beverage, take a bathroom break, or whatever. When you get back, Dist::Zilla should be ready for you. Then you need to install any plugins specific to this distribution: $ cpan `dzil authordeps` $ dzil authordeps | cpanm Once installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil xtest You can learn more about Dist::Zilla at http://dzil.org/ PBKDF2-Tiny-0.005/cpanfile000644 000765 000024 00000002200 12433343647 015310 0ustar00davidstaff000000 000000 requires "Carp" => "0"; requires "Exporter" => "5.57"; requires "perl" => "5.008"; requires "strict" => "0"; requires "warnings" => "0"; on 'test' => sub { requires "Encode" => "0"; requires "ExtUtils::MakeMaker" => "0"; requires "File::Spec" => "0"; requires "Test::More" => "0.88"; requires "perl" => "5.008"; requires "utf8" => "0"; }; on 'test' => sub { recommends "CPAN::Meta" => "2.120900"; }; on 'configure' => sub { requires "Config" => "0"; requires "ExtUtils::MakeMaker" => "6.17"; requires "File::Spec" => "0"; requires "Text::ParseWords" => "0"; requires "perl" => "5.004"; }; on 'develop' => sub { requires "Dist::Zilla" => "5"; requires "Dist::Zilla::Plugin::RemovePrereqs" => "0"; requires "Dist::Zilla::PluginBundle::DAGOLDEN" => "0.070"; requires "File::Spec" => "0"; requires "File::Temp" => "0"; requires "IO::Handle" => "0"; requires "IPC::Open3" => "0"; requires "Pod::Coverage::TrustPod" => "0"; requires "Test::CPAN::Meta" => "0"; requires "Test::More" => "0"; requires "Test::Pod" => "1.41"; requires "Test::Pod::Coverage" => "1.08"; requires "Test::Spelling" => "0.12"; }; PBKDF2-Tiny-0.005/dist.ini000644 000765 000024 00000000547 12433343647 015264 0ustar00davidstaff000000 000000 name = PBKDF2-Tiny author = David Golden license = Apache_2_0 copyright_holder = David Golden copyright_year = 2014 [=inc::MakeMaker] eumm_version = 6.17 default_jobs = 9 [@DAGOLDEN] :version = 0.070 -remove = MakeMaker stopwords = hmac [RemovePrereqs] remove = Digest::SHA remove = Digest::SHA::PurePerl remove = inc::MakeMaker PBKDF2-Tiny-0.005/inc/000755 000765 000024 00000000000 12433343647 014363 5ustar00davidstaff000000 000000 PBKDF2-Tiny-0.005/lib/000755 000765 000024 00000000000 12433343647 014360 5ustar00davidstaff000000 000000 PBKDF2-Tiny-0.005/LICENSE000644 000765 000024 00000026354 12433343647 014631 0ustar00davidstaff000000 000000 This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. PBKDF2-Tiny-0.005/Makefile.PL000644 000765 000024 00000005556 12433343647 015577 0ustar00davidstaff000000 000000 # This Makefile.PL for PBKDF2-Tiny was generated by # inc::MakeMaker # and Dist::Zilla::Plugin::MakeMaker::Awesome 0.27. # Don't edit it but the dist.ini and plugins used to construct it. use strict; use warnings; use 5.008; use ExtUtils::MakeMaker 6.17; my %WriteMakefileArgs = ( "ABSTRACT" => "Minimalist PBKDF2 (RFC 2898) with HMAC-SHA1 or HMAC-SHA2", "AUTHOR" => "David Golden ", "CONFIGURE_REQUIRES" => { "Config" => 0, "ExtUtils::MakeMaker" => "6.17", "File::Spec" => 0, "Text::ParseWords" => 0 }, "DISTNAME" => "PBKDF2-Tiny", "EXE_FILES" => [], "LICENSE" => "apache", "NAME" => "PBKDF2::Tiny", "PREREQ_PM" => { "Carp" => 0, "Exporter" => "5.57", "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "Encode" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Test::More" => "0.88", "utf8" => 0 }, "VERSION" => "0.005", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Config" => 0, "Encode" => 0, "Exporter" => "5.57", "ExtUtils::MakeMaker" => "6.17", "File::Spec" => 0, "Test::More" => "0.88", "Text::ParseWords" => 0, "strict" => 0, "utf8" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; if ( $] < 5.010 ) { if ( !parse_args()->{PUREPERL_ONLY} && can_cc() ) { $WriteMakefileArgs{PREREQ_PM}{'Digest::SHA'} = 0; } else { $WriteMakefileArgs{PREREQ_PM}{'Digest::SHA::PurePerl'} = 0; } } WriteMakefile(%WriteMakefileArgs); use Config (); use File::Spec (); use Text::ParseWords (); # check if we can run some command sub can_run { my ($cmd) = @_; my $_cmd = $cmd; return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { next if $dir eq ''; my $abs = File::Spec->catfile($dir, $_[0]); return $abs if (-x $abs or $abs = MM->maybe_command($abs)); } return; } # can we locate a (the) C compiler sub can_cc { my @chunks = split(/ /, $Config::Config{cc}) or return; # $Config{cc} may contain args; try to find out the program part while (@chunks) { return can_run("@chunks") || (pop(@chunks), next); } return; } # XXX this is gross, but apparently it's the least gross option? sub parse_args { my $tmp = {}; # copied from EUMM ExtUtils::MakeMaker::parse_args( $tmp, Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''), @ARGV, ); return $tmp->{ARGS} || {}; } PBKDF2-Tiny-0.005/MANIFEST000644 000765 000024 00000001002 12433343647 014734 0ustar00davidstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.025. CONTRIBUTING.mkdn Changes LICENSE MANIFEST META.json META.yml Makefile.PL README cpanfile dist.ini inc/MakeMaker.pm lib/PBKDF2/Tiny.pm perlcritic.rc t/00-report-prereqs.dd t/00-report-prereqs.t t/pbkdf2.t tidyall.ini xt/author/00-compile.t xt/author/critic.t xt/author/pod-spell.t xt/release/distmeta.t xt/release/minimum-version.t xt/release/pod-coverage.t xt/release/pod-syntax.t xt/release/portability.t xt/release/test-version.t PBKDF2-Tiny-0.005/META.json000644 000765 000024 00000004773 12433343647 015246 0ustar00davidstaff000000 000000 { "abstract" : "Minimalist PBKDF2 (RFC 2898) with HMAC-SHA1 or HMAC-SHA2", "author" : [ "David Golden " ], "dynamic_config" : 1, "generated_by" : "Dist::Zilla version 5.025, CPAN::Meta::Converter version 2.142690", "license" : [ "apache_2_0" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "PBKDF2-Tiny", "no_index" : { "directory" : [ "t", "xt", "examples", "corpus" ], "package" : [ "DB" ] }, "prereqs" : { "configure" : { "requires" : { "Config" : "0", "ExtUtils::MakeMaker" : "6.17", "File::Spec" : "0", "Text::ParseWords" : "0", "perl" : "5.004" } }, "develop" : { "requires" : { "Dist::Zilla" : "5", "Dist::Zilla::Plugin::RemovePrereqs" : "0", "Dist::Zilla::PluginBundle::DAGOLDEN" : "0.070", "File::Spec" : "0", "File::Temp" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Pod::Coverage::TrustPod" : "0", "Test::CPAN::Meta" : "0", "Test::More" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08", "Test::Spelling" : "0.12" } }, "runtime" : { "requires" : { "Carp" : "0", "Exporter" : "5.57", "perl" : "5.008", "strict" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "Encode" : "0", "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "Test::More" : "0.88", "perl" : "5.008", "utf8" : "0" } } }, "provides" : { "PBKDF2::Tiny" : { "file" : "lib/PBKDF2/Tiny.pm", "version" : "0.005" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/dagolden/PBKDF2-Tiny/issues" }, "homepage" : "https://github.com/dagolden/PBKDF2-Tiny", "repository" : { "type" : "git", "url" : "https://github.com/dagolden/PBKDF2-Tiny.git", "web" : "https://github.com/dagolden/PBKDF2-Tiny" } }, "version" : "0.005", "x_authority" : "cpan:DAGOLDEN" } PBKDF2-Tiny-0.005/META.yml000644 000765 000024 00000002054 12433343647 015064 0ustar00davidstaff000000 000000 --- abstract: 'Minimalist PBKDF2 (RFC 2898) with HMAC-SHA1 or HMAC-SHA2' author: - 'David Golden ' build_requires: Encode: '0' ExtUtils::MakeMaker: '0' File::Spec: '0' Test::More: '0.88' perl: '5.008' utf8: '0' configure_requires: Config: '0' ExtUtils::MakeMaker: '6.17' File::Spec: '0' Text::ParseWords: '0' perl: '5.004' dynamic_config: 1 generated_by: 'Dist::Zilla version 5.025, CPAN::Meta::Converter version 2.142690' license: apache meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: PBKDF2-Tiny no_index: directory: - t - xt - examples - corpus package: - DB provides: PBKDF2::Tiny: file: lib/PBKDF2/Tiny.pm version: '0.005' requires: Carp: '0' Exporter: '5.57' perl: '5.008' strict: '0' warnings: '0' resources: bugtracker: https://github.com/dagolden/PBKDF2-Tiny/issues homepage: https://github.com/dagolden/PBKDF2-Tiny repository: https://github.com/dagolden/PBKDF2-Tiny.git version: '0.005' x_authority: cpan:DAGOLDEN PBKDF2-Tiny-0.005/perlcritic.rc000644 000765 000024 00000001166 12433343647 016304 0ustar00davidstaff000000 000000 severity = 5 verbose = 8 [Variables::ProhibitPunctuationVars] allow = $@ $! [TestingAndDebugging::ProhibitNoStrict] allow = refs [Variables::ProhibitEvilVariables] variables = $DB::single # Turn these off [-BuiltinFunctions::ProhibitStringyEval] [-ControlStructures::ProhibitPostfixControls] [-ControlStructures::ProhibitUnlessBlocks] [-Documentation::RequirePodSections] [-InputOutput::ProhibitInteractiveTest] [-References::ProhibitDoubleSigils] [-RegularExpressions::RequireExtendedFormatting] [-InputOutput::ProhibitTwoArgOpen] [-Modules::ProhibitEvilModules] # Turn this on [Lax::ProhibitStringyEval::ExceptForRequire] PBKDF2-Tiny-0.005/README000644 000765 000024 00000010063 12433343647 014472 0ustar00davidstaff000000 000000 NAME PBKDF2::Tiny - Minimalist PBKDF2 (RFC 2898) with HMAC-SHA1 or HMAC-SHA2 VERSION version 0.005 SYNOPSIS use PBKDF2::Tiny qw/derive verify/; my $dk = derive( 'SHA-1', $pass, $salt, $iters ); if ( verify( $dk, 'SHA-1', $pass, $salt, $iters ) ) { # password is correct } DESCRIPTION This module provides an RFC 2898 compliant PBKDF2 implementation using HMAC-SHA1 or HMAC-SHA2 in under 100 lines of code. If you are using Perl 5.10 or later, it uses only core Perl modules. If you are on an earlier version of Perl, you need Digest::SHA or Digest::SHA::PurePerl. All documented functions are optionally exported. No functions are exported by default. FUNCTIONS derive $dk = derive( $type, $password, $salt, $iterations, $dk_length ) The "derive" function outputs a binary string with the derived key. The first argument indicates the digest function to use. It must be one of: SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512. If a password or salt are not provided, they default to the empty string, so don't do that! RFC 2898 recommends a random salt of at least 8 octets. If you need a cryptographically strong salt, consider Crypt::URandom. The password and salt should encoded as octet strings. If not (i.e. if Perl's internal 'UTF8' flag is on), then an exception will be thrown. The number of iterations defaults to 1000 if not provided. If the derived key length is not provided, it defaults to the output size of the digest function. derive_hex Works just like "derive" but outputs a hex string. verify $bool = verify( $dk, $type, $password, $salt, $iterations, $dk_length ); The "verify" function checks that a given derived key (in binary form) matches the password and other parameters provided using a constant-time comparison function. The first parameter is the derived key to check. The remaining parameters are the same as for "derive". verify_hex Works just like "verify" but the derived key must be a hex string (without a leading "0x"). digest_fcn ($fcn, $block_size, $digest_length) = digest_fcn('SHA-1'); $digest = $fcn->($data); This function is used internally by PBKDF2::Tiny, but made available in case it's useful to someone. Given one of the valid digest types, it returns a function reference that digests a string of data. It also returns block size and digest length for that digest type. hmac $key = $digest_fcn->($key) if length($key) > $block_size; $hmac = hmac( $data, $key, $digest_fcn, $block_size ); This function is used internally by PBKDF2::Tiny, but made available in case it's useful to someone. The first two arguments are the data and key inputs to the HMAC function. Both should be encoded as octet strings, as underlying HMAC/digest functions may croak or may give unexpected results if Perl's internal UTF-8 flag is on. Note: if the key is longer than the digest block size, it must be preprocessed using the digesting function. The third and fourth arguments must be a digesting code reference (from "digest_fcn") and block size. SEE ALSO * Crypt::PBKDF2 * Digest::PBDKF2 SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. git clone https://github.com/dagolden/PBKDF2-Tiny.git AUTHOR David Golden COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 PBKDF2-Tiny-0.005/t/000755 000765 000024 00000000000 12433343647 014055 5ustar00davidstaff000000 000000 PBKDF2-Tiny-0.005/tidyall.ini000644 000765 000024 00000000240 12433343647 015751 0ustar00davidstaff000000 000000 ; Install Code::TidyAll ; run "tidyall -a" to tidy all files ; run "tidyall -g" to tidy only files modified from git [PerlTidy] select = {lib,t}/**/*.{pl,pm,t} PBKDF2-Tiny-0.005/xt/000755 000765 000024 00000000000 12433343647 014245 5ustar00davidstaff000000 000000 PBKDF2-Tiny-0.005/xt/author/000755 000765 000024 00000000000 12433343647 015547 5ustar00davidstaff000000 000000 PBKDF2-Tiny-0.005/xt/release/000755 000765 000024 00000000000 12433343647 015665 5ustar00davidstaff000000 000000 PBKDF2-Tiny-0.005/xt/release/distmeta.t000644 000765 000024 00000000172 12433343647 017664 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::MetaTests. use Test::CPAN::Meta; meta_yaml_ok(); PBKDF2-Tiny-0.005/xt/release/minimum-version.t000644 000765 000024 00000000266 12433343647 021214 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::MinimumVersion"; plan skip_all => "Test::MinimumVersion required for testing minimum versions" if $@; all_minimum_version_ok( qq{5.010} ); PBKDF2-Tiny-0.005/xt/release/pod-coverage.t000644 000765 000024 00000000334 12433343647 020425 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); PBKDF2-Tiny-0.005/xt/release/pod-syntax.t000644 000765 000024 00000000220 12433343647 020152 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); PBKDF2-Tiny-0.005/xt/release/portability.t000644 000765 000024 00000000332 12433343647 020412 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; eval 'use Test::Portability::Files'; plan skip_all => 'Test::Portability::Files required for testing portability' if $@; options(test_one_dot => 0); run_tests(); PBKDF2-Tiny-0.005/xt/release/test-version.t000644 000765 000024 00000000643 12433343647 020517 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 0.002004 BEGIN { eval "use Test::Version; 1;" or die $@; } my @imports = ( 'version_all_ok' ); my $params = { is_strict => 0, has_version => 1, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; PBKDF2-Tiny-0.005/xt/author/00-compile.t000644 000765 000024 00000002234 12433343647 017602 0ustar00davidstaff000000 000000 use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.051 use Test::More; plan tests => 1 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'PBKDF2/Tiny.pm' ); # fake home for cpan-testers use File::Temp; local $ENV{HOME} = File::Temp::tempdir( CLEANUP => 1 ); my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING}; PBKDF2-Tiny-0.005/xt/author/critic.t000644 000765 000024 00000000435 12433343647 017213 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; use English qw(-no_match_vars); eval "use Test::Perl::Critic"; plan skip_all => 'Test::Perl::Critic required to criticise code' if $@; Test::Perl::Critic->import( -profile => "perlcritic.rc" ) if -e "perlcritic.rc"; all_critic_ok(); PBKDF2-Tiny-0.005/xt/author/pod-spell.t000644 000765 000024 00000000420 12433343647 017627 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.006008 use Test::Spelling 0.12; use Pod::Wordlist; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ hmac David Golden dagolden lib PBKDF2 Tiny PBKDF2-Tiny-0.005/t/00-report-prereqs.dd000644 000765 000024 00000004611 12433343647 017577 0ustar00davidstaff000000 000000 do { my $x = { 'configure' => { 'requires' => { 'Config' => '0', 'ExtUtils::MakeMaker' => '6.17', 'File::Spec' => '0', 'Text::ParseWords' => '0', 'perl' => '5.004' } }, 'develop' => { 'requires' => { 'Dist::Zilla' => '5', 'Dist::Zilla::Plugin::RemovePrereqs' => '0', 'Dist::Zilla::PluginBundle::DAGOLDEN' => '0.070', 'File::Spec' => '0', 'File::Temp' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Pod::Coverage::TrustPod' => '0', 'Test::CPAN::Meta' => '0', 'Test::More' => '0', 'Test::Pod' => '1.41', 'Test::Pod::Coverage' => '1.08', 'Test::Spelling' => '0.12' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'Exporter' => '5.57', 'perl' => '5.008', 'strict' => '0', 'warnings' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'Encode' => '0', 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'Test::More' => '0.88', 'perl' => '5.008', 'utf8' => '0' } } }; $x; }PBKDF2-Tiny-0.005/t/00-report-prereqs.t000644 000765 000024 00000012314 12433343647 017452 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.019 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do 't/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; if ( $source && $HAS_CPAN_META ) { if ( my $meta = eval { CPAN::Meta->load_file($source) } ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } } else { $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( @dep_errors ) { diag join("\n", "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n", "The following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: PBKDF2-Tiny-0.005/t/pbkdf2.t000644 000765 000024 00000017562 12433343647 015425 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More 0.88; use utf8; use PBKDF2::Tiny qw/derive derive_hex verify verify_hex/; use Encode qw/encode_utf8/; #--------------------------------------------------------------------------# # custom test function #--------------------------------------------------------------------------# sub is_hex { my ( $got, $exp, $label ) = @_; local $Test::Builder::Level = $Test::Builder::Level + 1; is( unpack( "H*", $got ), unpack( "H*", $exp ), $label ); } sub exception(&) { my $code = shift; eval { $code->() }; return $@; } #--------------------------------------------------------------------------# # Test cases: #--------------------------------------------------------------------------# my @cases = ( # PBKDF2 HMAC-SHA1 test cases from RFC 6070 { n => 'SHA-1 1 iter', a => 'SHA-1', p => 'password', s => 'salt', c => 1, l => 20, o => "0c 60 c8 0f 96 1f 0e 71 f3 a9 b5 24 af 60 12 06 2f e0 37 a6", }, { n => 'SHA-1 2 iters', a => 'SHA-1', p => 'password', s => 'salt', c => 2, l => 20, o => "ea 6c 01 4d c7 2d 6f 8c cd 1e d9 2a ce 1d 41 f0 d8 de 89 57" }, { n => 'SHA-1 3 iters', a => 'SHA-1', p => 'password', s => 'salt', c => 3, l => 20, o => "6b4e26125c25cf21ae35ead955f479ea2e71f6ff", }, { n => 'SHA-1 4096 iters', a => 'SHA-1', p => 'password', s => 'salt', c => 4096, l => 20, o => "4b 00 79 01 b7 65 48 9a be ad 49 d9 26 f7 21 d0 65 a4 29 c1" }, { n => 'SHA-1 4096 iters, longer pw/salt/dk_length', a => 'SHA-1', p => 'passwordPASSWORDpassword', s => 'saltSALTsaltSALTsaltSALTsaltSALTsalt', c => 4096, l => 25, o => "3d 2e ec 4f e4 1c 84 9b 80 c8 d8 36 62 c0 e4 4a 8b 29 1a 96 4c f2 f0 70 38" }, { n => 'SHA-1 4096 iters, embedded nulls, short dk', a => 'SHA-1', p => "pass\x00word", s => "sa\x00lt", c => 4096, l => 16, o => "56 fa 6a a7 55 48 09 9d cc 37 d7 f0 34 25 e0 c3" }, # PBKDF2 HMAC-SHA2 test cases from Crypt::PBKDF2 { n => 'SHA-224 1 iter', a => 'SHA-224', p => 'password', s => 'salt', c => 1, l => 28, o => "3c198cbdb9464b7857966bd05b7bc92bc1cc4e6e63155d4e490557fd" }, { n => 'SHA-224 1000 iter', a => 'SHA-224', p => 'password', s => 'salt', c => 1000, l => 28, o => "d3bcf320fd918908eafcaa460faf40e201f6508d4e6f3d9c1c0abd30" }, { n => 'SHA-256 1 iter', a => 'SHA-256', p => 'password', s => 'salt', c => 1, l => 32, o => "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b" }, { n => 'SHA-256 1000 iter', a => 'SHA-256', p => 'password', s => 'salt', c => 1000, l => 32, o => "632c2812e46d4604102ba7618e9d6d7d2f8128f6266b4a03264d2a0460b7dcb3" }, { n => 'SHA-384 1 iter', a => 'SHA-384', p => 'password', s => 'salt', c => 1, l => 48, o => "c0e14f06e49e32d73f9f52ddf1d0c5c7191609233631dadd76a567db42b7867" . "6b38fc800cc53ddb642f5c74442e62be4" }, { n => 'SHA-384 1000 iter', a => 'SHA-384', p => 'password', s => 'salt', c => 1000, l => 48, o => "3bd37e2236941d4a77b1b5b714c6f913fabb6b0841a6d7d8656b99d611e900" . "fe06edb93b5b809efaa9678b635ce513e0" }, { n => 'SHA-512 1 iter', a => 'SHA-512', p => 'password', s => 'salt', c => 1, l => 64, o => "867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf" . "252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce" }, { n => 'SHA-512 1000 iter', a => 'SHA-512', p => 'password', s => 'salt', c => 1000, l => 64, o => "afe6c5530785b6cc6b1c6453384731bd5ee432ee549fd42fb6695779ad8a1" . "c5bf59de69c48f774efc4007d5298f9033c0241d5ab69305e7b64eceeb8d834cfec" }, ); #--------------------------------------------------------------------------# # test runner #--------------------------------------------------------------------------# subtest "Test cases" => sub { for my $c (@cases) { ( my $exp_hex = $c->{o} ) =~ s{ }{}g; # strip spaces my $exp = pack( "H*", $exp_hex ); my $got = derive( @{$c}{qw/a p s c l/} ); is_hex( $got, $exp, "$c->{n} (derive)" ); my $got_hex = derive_hex( @{$c}{qw/a p s c l/} ); is( $got_hex, $exp_hex, "$c->{n} (derive hex)" ); ok( verify( $exp, @{$c}{qw/a p s c l/} ), "$c->{n} (verify)" ); ok( verify_hex( $exp_hex, @{$c}{qw/a p s c l/} ), "$c->{n} (verify hex)" ); ok( !verify( $exp, $c->{a}, 'qwerty', @{$c}{qw/s c l/} ), "$c->{n} (verify bad pass)" ); ok( !verify_hex( $exp_hex, $c->{a}, 'qwerty', @{$c}{qw/s c l/} ), "$c->{n} (verify hex bad pas)" ); } }; subtest "Unicode" => sub { my $latin1 = "büller"; utf8::upgrade($latin1); my $wide = "☺♥☺•♥♥☺"; # password like( exception { derive( 'SHA-1', $latin1, 'salt', 1000 ) }, qr/password must be an octet string/, "password: UTF8-on latin-1 is fatal" ); is( exception { derive( 'SHA-1', encode_utf8($latin1), 'salt', 1000 ) }, '', "password: UTF-8 encoded latin-1 is OK" ); utf8::downgrade($latin1); is( exception { derive( 'SHA-1', $latin1, 'salt', 1000 ) }, '', "password: UTF8-off latin-1 is OK" ); like( exception { derive( 'SHA-1', $wide, 'salt', 1000 ) }, qr/password must be an octet string/, "password: UTF8-on wide is fatal" ); is( exception { derive( 'SHA-1', encode_utf8($wide), 'salt', 1000 ) }, '', "password: UTF-8 encoded wide is OK" ); # salt utf8::upgrade($latin1); like( exception { derive( 'SHA-1', 'pass', $latin1, 1000 ) }, qr/salt must be an octet string/, "salt: UTF8-on latin-1 is fatal" ); is( exception { derive( 'SHA-1', 'pass', encode_utf8($latin1), 1000 ) }, '', "salt: UTF-8 encoded latin-1 is OK" ); utf8::downgrade($latin1); is( exception { derive( 'SHA-1', 'pass', $latin1, 1000 ) }, '', "salt: UTF8-off latin-1 is OK" ); $wide = "☺♥☺•♥♥☺"; like( exception { derive( 'SHA-1', 'pass', $wide, 1000 ) }, qr/salt must be an octet string/, "salt: UTF8-on wide is fatal" ); is( exception { derive( 'SHA-1', 'pass', encode_utf8($wide), 1000 ) }, '', "salt: UTF-8 encoded wide is OK" ); }; subtest "missing dk length" => sub { my @gdargs = ( 'SHA-1', 'pass', 'salt', 1000 ); my @bdargs = ( 'SHA-1', 'notthepass', 'salt', 1000 ); my $key1 = derive_hex(@gdargs); my $key2 = derive_hex( @gdargs, 0 ); is( $key1, $key2, "0 as dk length ignored" ); ok( !verify_hex( $key1, @gdargs, length($key1) ), "verify w/length true (good pass)" ); ok( !verify_hex( $key1, @bdargs, length($key1) ), "verify w/length false (bad pass)" ); ok( verify_hex( $key1, @gdargs ), "verify w/o length true (good pass)" ); ok( !verify_hex( $key1, @bdargs ), "verify w/o length false (bad pass)" ); ok( verify_hex( $key1, @gdargs, 0 ), "verify with 0 length true (good pass)" ); ok( !verify_hex( $key1, @bdargs, 0 ), "verify with 0 length false (bad pass)" ); }; done_testing; # # This file is part of PBKDF2-Tiny # # This software is Copyright (c) 2014 by David Golden. # # This is free software, licensed under: # # The Apache License, Version 2.0, January 2004 # # vim: ts=4 sts=4 sw=4 et: PBKDF2-Tiny-0.005/lib/PBKDF2/000755 000765 000024 00000000000 12433343647 015270 5ustar00davidstaff000000 000000 PBKDF2-Tiny-0.005/lib/PBKDF2/Tiny.pm000644 000765 000024 00000025347 12433343647 016564 0ustar00davidstaff000000 000000 use strict; use warnings; package PBKDF2::Tiny; # ABSTRACT: Minimalist PBKDF2 (RFC 2898) with HMAC-SHA1 or HMAC-SHA2 our $VERSION = '0.005'; use Carp (); use Exporter 5.57 qw/import/; our @EXPORT_OK = qw/derive derive_hex verify verify_hex hmac digest_fcn/; my ( $BACKEND, $LOAD_ERR ); for my $mod (qw/Digest::SHA Digest::SHA::PurePerl/) { $BACKEND = $mod, last if eval "require $mod; 1"; $LOAD_ERR ||= $@; } die $LOAD_ERR if !$BACKEND; #--------------------------------------------------------------------------# # constants and lookup tables #--------------------------------------------------------------------------# # function coderef placeholder, block size in bytes, digest size in bytes my %DIGEST_TYPES = ( 'SHA-1' => [ undef, 64, 20 ], 'SHA-224' => [ undef, 64, 28 ], 'SHA-256' => [ undef, 64, 32 ], 'SHA-384' => [ undef, 128, 48 ], 'SHA-512' => [ undef, 128, 64 ], ); for my $type ( keys %DIGEST_TYPES ) { no strict 'refs'; ( my $name = lc $type ) =~ s{-}{}; $DIGEST_TYPES{$type}[0] = \&{"$BACKEND\::$name"}; } my %INT = map { $_ => pack( "N", $_ ) } 1 .. 16; #--------------------------------------------------------------------------# # public functions #--------------------------------------------------------------------------# #pod =func derive #pod #pod $dk = derive( $type, $password, $salt, $iterations, $dk_length ) #pod #pod The C function outputs a binary string with the derived key. #pod The first argument indicates the digest function to use. It must be one #pod of: SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512. #pod #pod If a password or salt are not provided, they default to the empty string, so #pod don't do that! L a random salt of at #pod least 8 octets. If you need a cryptographically strong salt, consider #pod L. #pod #pod The password and salt should encoded as octet strings. If not (i.e. if #pod Perl's internal 'UTF8' flag is on), then an exception will be thrown. #pod #pod The number of iterations defaults to 1000 if not provided. If the derived #pod key length is not provided, it defaults to the output size of the digest #pod function. #pod #pod =cut sub derive { my ( $type, $passwd, $salt, $iterations, $dk_length ) = @_; my ( $digester, $block_size, $digest_length ) = digest_fcn($type); $passwd = '' unless defined $passwd; $salt = '' unless defined $salt; $iterations ||= 1000; $dk_length ||= $digest_length; # we insist on octet strings for password and salt Carp::croak("password must be an octet string, not a character string") if utf8::is_utf8($passwd); Carp::croak("salt must be an octet string, not a character string") if utf8::is_utf8($salt); my $key = ( length($passwd) > $block_size ) ? $digester->($passwd) : $passwd; my $passes = int( $dk_length / $digest_length ); $passes++ if $dk_length % $digest_length; # need part of an extra pass my $dk = ""; for my $i ( 1 .. $passes ) { $INT{$i} ||= pack( "N", $i ); my $digest = my $result = "" . hmac( $salt . $INT{$i}, $key, $digester, $block_size ); for my $iter ( 2 .. $iterations ) { $digest = hmac( $digest, $key, $digester, $block_size ); $result ^= $digest; } $dk .= $result; } return substr( $dk, 0, $dk_length ); } #pod =func derive_hex #pod #pod Works just like L but outputs a hex string. #pod #pod =cut sub derive_hex { unpack( "H*", &derive ) } #pod =func verify #pod #pod $bool = verify( $dk, $type, $password, $salt, $iterations, $dk_length ); #pod #pod The C function checks that a given derived key (in binary form) matches #pod the password and other parameters provided using a constant-time comparison #pod function. #pod #pod The first parameter is the derived key to check. The remaining parameters #pod are the same as for L. #pod #pod =cut sub verify { my ( $dk1, @derive_args ) = @_; my $dk2 = derive(@derive_args); # shortcut if input dk is the wrong length entirely; this is not # constant time, but this doesn't really give much away as # the keys are of different types anyway return unless length($dk1) == length($dk2); # if lengths match, do constant time comparison to avoid timing attacks my $match = 1; for my $i ( 0 .. length($dk1) - 1 ) { $match &= ( substr( $dk1, $i, 1 ) eq substr( $dk2, $i, 1 ) ) ? 1 : 0; } return $match; } #pod =func verify_hex #pod #pod Works just like L but the derived key must be a hex string (without a #pod leading "0x"). #pod #pod =cut sub verify_hex { my $dk = pack( "H*", shift ); return verify( $dk, @_ ); } #pod =func digest_fcn #pod #pod ($fcn, $block_size, $digest_length) = digest_fcn('SHA-1'); #pod $digest = $fcn->($data); #pod #pod This function is used internally by PBKDF2::Tiny, but made available in case #pod it's useful to someone. #pod #pod Given one of the valid digest types, it returns a function reference that #pod digests a string of data. It also returns block size and digest length for that #pod digest type. #pod #pod =cut sub digest_fcn { my ($type) = @_; Carp::croak("Digest function '$type' not supported") unless exists $DIGEST_TYPES{$type}; return @{ $DIGEST_TYPES{$type} }; } #pod =func hmac #pod #pod $key = $digest_fcn->($key) if length($key) > $block_size; #pod $hmac = hmac( $data, $key, $digest_fcn, $block_size ); #pod #pod This function is used internally by PBKDF2::Tiny, but made available in case #pod it's useful to someone. #pod #pod The first two arguments are the data and key inputs to the HMAC function. Both #pod should be encoded as octet strings, as underlying HMAC/digest functions may #pod croak or may give unexpected results if Perl's internal UTF-8 flag is on. #pod #pod B: if the key is longer than the digest block size, it must be #pod preprocessed using the digesting function. #pod #pod The third and fourth arguments must be a digesting code reference (from #pod L) and block size. #pod #pod =cut # hmac function adapted from Digest::HMAC by Graham Barr and Gisle Aas. # Compared to that implementation, this *requires* a preprocessed # key and block size, which makes iterative hmac slightly more efficient. sub hmac { my ( $data, $key, $digest_func, $block_size ) = @_; my $k_ipad = $key ^ ( chr(0x36) x $block_size ); my $k_opad = $key ^ ( chr(0x5c) x $block_size ); &$digest_func( $k_opad, &$digest_func( $k_ipad, $data ) ); } 1; # vim: ts=4 sts=4 sw=4 et: __END__ =pod =encoding UTF-8 =head1 NAME PBKDF2::Tiny - Minimalist PBKDF2 (RFC 2898) with HMAC-SHA1 or HMAC-SHA2 =head1 VERSION version 0.005 =head1 SYNOPSIS use PBKDF2::Tiny qw/derive verify/; my $dk = derive( 'SHA-1', $pass, $salt, $iters ); if ( verify( $dk, 'SHA-1', $pass, $salt, $iters ) ) { # password is correct } =head1 DESCRIPTION This module provides an L compliant PBKDF2 implementation using HMAC-SHA1 or HMAC-SHA2 in under 100 lines of code. If you are using Perl 5.10 or later, it uses only core Perl modules. If you are on an earlier version of Perl, you need L or L. All documented functions are optionally exported. No functions are exported by default. =head1 FUNCTIONS =head2 derive $dk = derive( $type, $password, $salt, $iterations, $dk_length ) The C function outputs a binary string with the derived key. The first argument indicates the digest function to use. It must be one of: SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512. If a password or salt are not provided, they default to the empty string, so don't do that! L a random salt of at least 8 octets. If you need a cryptographically strong salt, consider L. The password and salt should encoded as octet strings. If not (i.e. if Perl's internal 'UTF8' flag is on), then an exception will be thrown. The number of iterations defaults to 1000 if not provided. If the derived key length is not provided, it defaults to the output size of the digest function. =head2 derive_hex Works just like L but outputs a hex string. =head2 verify $bool = verify( $dk, $type, $password, $salt, $iterations, $dk_length ); The C function checks that a given derived key (in binary form) matches the password and other parameters provided using a constant-time comparison function. The first parameter is the derived key to check. The remaining parameters are the same as for L. =head2 verify_hex Works just like L but the derived key must be a hex string (without a leading "0x"). =head2 digest_fcn ($fcn, $block_size, $digest_length) = digest_fcn('SHA-1'); $digest = $fcn->($data); This function is used internally by PBKDF2::Tiny, but made available in case it's useful to someone. Given one of the valid digest types, it returns a function reference that digests a string of data. It also returns block size and digest length for that digest type. =head2 hmac $key = $digest_fcn->($key) if length($key) > $block_size; $hmac = hmac( $data, $key, $digest_fcn, $block_size ); This function is used internally by PBKDF2::Tiny, but made available in case it's useful to someone. The first two arguments are the data and key inputs to the HMAC function. Both should be encoded as octet strings, as underlying HMAC/digest functions may croak or may give unexpected results if Perl's internal UTF-8 flag is on. B: if the key is longer than the digest block size, it must be preprocessed using the digesting function. The third and fourth arguments must be a digesting code reference (from L) and block size. =begin Pod::Coverage =end Pod::Coverage =head1 SEE ALSO =over 4 =item * L =item * L =back =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone https://github.com/dagolden/PBKDF2-Tiny.git =head1 AUTHOR David Golden =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut PBKDF2-Tiny-0.005/inc/MakeMaker.pm000644 000765 000024 00000004347 12433343647 016566 0ustar00davidstaff000000 000000 # copied/adapted from Package::Stash package inc::MakeMaker; use Moose; extends 'Dist::Zilla::Plugin::MakeMaker::Awesome'; with 'Dist::Zilla::Role::MetaProvider'; # XXX: this is pretty gross, it should be possible to clean this up later around _build_MakeFile_PL_template => sub { my $orig = shift; my $self = shift; # can_run and can_cc copied from M::I my $helpers = <<'HELPERS'; use Config (); use File::Spec (); use Text::ParseWords (); # check if we can run some command sub can_run { my ($cmd) = @_; my $_cmd = $cmd; return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { next if $dir eq ''; my $abs = File::Spec->catfile($dir, $_[0]); return $abs if (-x $abs or $abs = MM->maybe_command($abs)); } return; } # can we locate a (the) C compiler sub can_cc { my @chunks = split(/ /, $Config::Config{cc}) or return; # $Config{cc} may contain args; try to find out the program part while (@chunks) { return can_run("@chunks") || (pop(@chunks), next); } return; } # XXX this is gross, but apparently it's the least gross option? sub parse_args { my $tmp = {}; # copied from EUMM ExtUtils::MakeMaker::parse_args( $tmp, Text::ParseWords::shellwords($ENV{PERL_MM_OPT} || ''), @ARGV, ); return $tmp->{ARGS} || {}; } HELPERS my $fixup_prereqs = <{PUREPERL_ONLY} && can_cc() ) { \$WriteMakefileArgs{PREREQ_PM}{'Digest::SHA'} = 0; } else { \$WriteMakefileArgs{PREREQ_PM}{'Digest::SHA::PurePerl'} = 0; } } PREREQS my $template = $self->$orig(@_); $template =~ s/(WriteMakefile\()/$fixup_prereqs\n$1/; $template .= $helpers; return $template; }; after register_prereqs => sub { my $self = shift; $self->zilla->register_prereqs( { phase => 'configure' }, 'Config' => 0, 'File::Spec' => 0, 'Text::ParseWords' => 0, ); }; sub metadata { return +{ dynamic_config => 1 } } __PACKAGE__->meta->make_immutable; no Moose; 1;