]> WPIA git - gigi.git/blob - tests/com/lambdaworks/crypto/test/SCryptTest.java
add: import scrypt 1.4.0
[gigi.git] / tests / com / lambdaworks / crypto / test / SCryptTest.java
1 // Copyright (C) 2011 - Will Glozer.  All rights reserved.
2
3 package com.lambdaworks.crypto.test;
4
5 import com.lambdaworks.crypto.SCrypt;
6 import org.junit.Test;
7
8 import static org.junit.Assert.*;
9 import static com.lambdaworks.crypto.test.CryptoTestUtil.*;
10 import static com.lambdaworks.crypto.SCrypt.*;
11
12 public class SCryptTest {
13     @Test
14     public void scrypt_paper_appendix_b() throws Exception {
15         byte[] P, S;
16         int N, r, p, dkLen;
17         String DK;
18
19         // empty key & salt test missing because unsupported by JCE
20
21         P = "password".getBytes("UTF-8");
22         S = "NaCl".getBytes("UTF-8");
23         N = 1024;
24         r = 8;
25         p = 16;
26         dkLen = 64;
27         DK = "fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640";
28
29         assertArrayEquals(decode(DK), SCrypt.scrypt(P, S, N, r, p, dkLen));
30
31         P = "pleaseletmein".getBytes("UTF-8");
32         S = "SodiumChloride".getBytes("UTF-8");
33         N = 16384;
34         r = 8;
35         p = 1;
36         dkLen = 64;
37         DK = "7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887";
38
39         assertArrayEquals(decode(DK), scrypt(P, S, N, r, p, dkLen));
40
41         P = "pleaseletmein".getBytes("UTF-8");
42         S = "SodiumChloride".getBytes("UTF-8");
43         N = 1048576;
44         r = 8;
45         p = 1;
46         dkLen = 64;
47         DK = "2101cb9b6a511aaeaddbbe09cf70f881ec568d574a2ffd4dabe5ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049e8a952fbcbf45c6fa77a41a4";
48
49         assertArrayEquals(decode(DK), SCrypt.scrypt(P, S, N, r, p, dkLen));
50     }
51
52     @Test(expected = IllegalArgumentException.class)
53     public void scrypt_invalid_N_zero() throws Exception {
54         byte[] P = "pleaseletmein".getBytes("UTF-8");
55         byte[] S = "SodiumChloride".getBytes("UTF-8");
56         scrypt(P, S, 0, 1, 1, 64);
57     }
58
59     @Test(expected = IllegalArgumentException.class)
60     public void scrypt_invalid_N_odd() throws Exception {
61         byte[] P = "pleaseletmein".getBytes("UTF-8");
62         byte[] S = "SodiumChloride".getBytes("UTF-8");
63         scrypt(P, S, 3, 1, 1, 64);
64     }
65
66     @Test(expected = IllegalArgumentException.class)
67     public void scrypt_invalid_N_large() throws Exception {
68         byte[] P = "pleaseletmein".getBytes("UTF-8");
69         byte[] S = "SodiumChloride".getBytes("UTF-8");
70         int    r = 8;
71         int    N = Integer.MAX_VALUE / 128;
72         scrypt(P, S, N, r, 1, 64);
73     }
74
75 //    @Test(expected = IllegalArgumentException.class)
76 //    public void scrypt_invalid_r_large() throws Exception {
77 //        byte[] P = "pleaseletmein".getBytes("UTF-8");
78 //        byte[] S = "SodiumChloride".getBytes("UTF-8");
79 //        int    N = 1024;
80 //        int    r = Integer.MAX_VALUE / 128 + 1;
81 //        int    p = 0;
82 //        scrypt(P, S, N, r, p, 64);
83 //    }
84 }