Sorcerer's IsleCode cfPassphrase / files

 1<cfcomponent extends="TestBase">
 2<cfscript>
 3
 4	function init( IncludeSlowTests )
 5	{
 6		super.init( argumentcollection=arguments );
 7
 8		this.Name = 'scrypt';
 9
10		super.start();
11
12		this.test_info();
13
14		if ( IncludeSlowTests )
15			this.test_basic();
16		else
17			skip( 30 );
18
19		return super.end();
20	}
21
22
23	function test_info( TestData )
24	{
25		var info3 = PassphraseInfo('$s0$501ff$5JQALASFiKGKdfY9Z0GYMA==$8c4aMGktdRlLIeY+erIA62fNtgb2OxJrjyhw+XeWHk4=');
26		assertEqual(info3.Algorithm,'SCrypt');
27		assertEqual(info3.Status,'Supported');
28		assertEqual(info3.Version,'0');
29		assertEqual(info3.CpuCost,32);
30		assertEqual(info3.MemoryCost,1);
31		assertEqual(info3.Parallelization,255);
32		assertEqual(info3.Salt,'5JQALASFiKGKdfY9Z0GYMA==');
33		assertEqual(info3.Hash,'8c4aMGktdRlLIeY+erIA62fNtgb2OxJrjyhw+XeWHk4=');
34		assertEqual(StructCount(info3),8);
35	}
36
37
38	function test_basic()
39	{
40		var Passwd = "secret";
41		var N = 16384;
42		var r = 8;
43		var p = 1;
44
45		var hashed = PassphraseHash(Passwd,'scrypt',{CpuCost:N,MemoryCost:r,Parallelization:p});
46
47		var parts = hashed.split('\$');
48
49		assertEqual(len(parts),5);
50		assertEqual(parts[1],"");
51		assertEqual(parts[2],"s0");
52		assertEqual(len(BinaryDecode(parts[4],'base64')),16);
53		assertEqual(len(BinaryDecode(parts[5],'base64')),32);
54
55		var params = InputBaseN(parts[3],16);
56		assertEqual( N , 2^( BitAnd(BitShRn(params,16),65535)) );
57		assertEqual( r , BitAnd(BitShRn(params,8),255) );
58		assertEqual( p , BitAnd(BitShRn(params,0),255) );
59
60		assertTrue(PassphraseCheck(passwd,hashed));
61		assertFalse(PassphraseCheck("s3cr3t",hashed));
62	}
63
64
65</cfscript>
66</cfcomponent>