1 // Copyright (C) 2011 - Will Glozer. All rights reserved.
3 package com.lambdaworks.crypto.test;
5 import com.lambdaworks.crypto.SCrypt;
8 import static org.junit.Assert.*;
9 import static com.lambdaworks.crypto.test.CryptoTestUtil.*;
10 import static com.lambdaworks.crypto.SCrypt.*;
12 public class SCryptTest {
14 public void scrypt_paper_appendix_b() throws Exception {
19 // empty key & salt test missing because unsupported by JCE
21 P = "password".getBytes("UTF-8");
22 S = "NaCl".getBytes("UTF-8");
27 DK = "fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e77376634b3731622eaf30d92e22a3886ff109279d9830dac727afb94a83ee6d8360cbdfa2cc0640";
29 assertArrayEquals(decode(DK), SCrypt.scrypt(P, S, N, r, p, dkLen));
31 P = "pleaseletmein".getBytes("UTF-8");
32 S = "SodiumChloride".getBytes("UTF-8");
37 DK = "7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b543f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d651e40dfcf017b45575887";
39 assertArrayEquals(decode(DK), scrypt(P, S, N, r, p, dkLen));
41 P = "pleaseletmein".getBytes("UTF-8");
42 S = "SodiumChloride".getBytes("UTF-8");
47 DK = "2101cb9b6a511aaeaddbbe09cf70f881ec568d574a2ffd4dabe5ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049e8a952fbcbf45c6fa77a41a4";
49 assertArrayEquals(decode(DK), SCrypt.scrypt(P, S, N, r, p, dkLen));
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);
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);
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");
71 int N = Integer.MAX_VALUE / 128;
72 scrypt(P, S, N, r, 1, 64);
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");
80 // int r = Integer.MAX_VALUE / 128 + 1;
82 // scrypt(P, S, N, r, p, 64);