Initial commit
[authen-passphrase-scrypt.git] / t / Authen-Passphrase-Scrypt.t
CommitLineData
0c1f3509
MG
1#!/usr/bin/perl
2use strict;
3use warnings;
4
5use Test::More tests => 9;
6BEGIN { use_ok('Authen::Passphrase::Scrypt') };
7
8# Vectors in the scrypt paper
9my @vectors = (
10 ['', '', 4, 1, 1, 64, '77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3fede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628cf35e20c38d18906'],
11 ['password', 'NaCl', 10, 8, 16, 64, 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640'],
12 ['pleaseletmein', 'SodiumChloride', 14, 8, 1, 64, '7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887'],
13 # Vector 4 omitted for performance reasons
14);
15
16for (1 .. @vectors) {
17 my ($pw, $salt, $logN, $r, $p, $len, $expected) = @{$vectors[$_ - 1]};
18 my $result = crypto_scrypt $pw, $salt, (1 << $logN), $r, $p, $len;
19 $result = unpack 'H*', $result;
20 is $result, $expected, "Test vector $_"
21}
22
23my $x = Authen::Passphrase::Scrypt->new({
24 passphrase => 'password1'
25});
26
27ok $x->match('password1'), 'new + match';
28ok !$x->match('password2'), 'new + match';
29
30my $test_rfc2307 = '{SCRYPT}c2NyeXB0AAwAAAAIAAAAAZ/+bp8gWcTZgEC7YQZeLLyxFeKRRdDkwbaGeFC0NkdUr/YFAWY/UwdOH4i/PxW48fXeXBDOTvGWtS3lLUgzNM0PlJbXhMOGd2bke0PvTSnW';
31
32$x = Authen::Passphrase::Scrypt->from_rfc2307($test_rfc2307);
33ok !$x->match('password1'), 'from_rfc2307 + match';
34ok $x->match('password2'), 'from_rfc2307 + match';
35
36my $y = Authen::Passphrase::Scrypt->new({
37 passphrase => 'password2',
38 salt => $x->salt,
39 logN => $x->logN,
40 r => 8,
41});
42
43is $y->as_rfc2307, $test_rfc2307, 'as_rfc2307';
This page took 0.012184 seconds and 4 git commands to generate.