1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.password.params; |
21 |
|
|
22 |
|
import java.security.SecureRandom; |
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
@version |
28 |
|
@since |
29 |
|
|
|
|
| 75% |
Uncovered Elements: 8 (32) |
Complexity: 13 |
Complexity Density: 0.68 |
|
30 |
|
public class ScryptParameters extends KeyDerivationFunctionParameters |
31 |
|
{ |
32 |
|
private static final int SALT_DEFAULT_SIZE = 16; |
33 |
|
|
34 |
|
private static final int COST_DEFAULT = 1024; |
35 |
|
|
36 |
|
private static final int PARALLELIZATION_DEFAULT = 1; |
37 |
|
|
38 |
|
private static final int BLOCK_DEFAULT_SIZE = 8; |
39 |
|
|
40 |
|
private static final SecureRandom PRND = new SecureRandom(); |
41 |
|
|
42 |
|
private final byte[] salt; |
43 |
|
|
44 |
|
private final int costParameter; |
45 |
|
|
46 |
|
private final int blockSize; |
47 |
|
|
48 |
|
private final int parallelizationParameter; |
49 |
|
|
50 |
|
|
51 |
|
@value |
52 |
|
@value |
53 |
|
@value |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
0 |
public ScryptParameters()... |
56 |
|
{ |
57 |
0 |
this(-1, COST_DEFAULT, PARALLELIZATION_DEFAULT, BLOCK_DEFAULT_SIZE, getRandomSalt()); |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
@value |
62 |
|
@value |
63 |
|
@value |
64 |
|
|
65 |
|
@param |
66 |
|
|
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
1 |
public ScryptParameters(int keySize)... |
69 |
|
{ |
70 |
1 |
this(keySize, COST_DEFAULT, PARALLELIZATION_DEFAULT, BLOCK_DEFAULT_SIZE, getRandomSalt()); |
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
|
@value |
75 |
|
@value@value |
76 |
|
|
77 |
|
@param |
78 |
|
|
79 |
|
@param |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0 |
public ScryptParameters(int keySize, byte[] salt)... |
82 |
|
{ |
83 |
0 |
this(keySize, COST_DEFAULT, PARALLELIZATION_DEFAULT, BLOCK_DEFAULT_SIZE, salt); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
|
@value |
88 |
|
|
89 |
|
@param |
90 |
|
|
91 |
|
@param |
92 |
|
@param |
93 |
|
|
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
1 |
public ScryptParameters(int keySize, int costParameter, int parallelizationParameter)... |
96 |
|
{ |
97 |
1 |
this(keySize, costParameter, parallelizationParameter, BLOCK_DEFAULT_SIZE, getRandomSalt()); |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
@value |
102 |
|
|
103 |
|
@param |
104 |
|
|
105 |
|
@param |
106 |
|
@param |
107 |
|
|
108 |
|
@param |
109 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
110 |
0 |
public ScryptParameters(int keySize, int costParameter, int parallelizationParameter, byte[] salt)... |
111 |
|
{ |
112 |
0 |
this(keySize, costParameter, parallelizationParameter, BLOCK_DEFAULT_SIZE, salt); |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
@param |
119 |
|
|
120 |
|
@param |
121 |
|
|
122 |
|
@param |
123 |
|
|
124 |
|
@param |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
0 |
public ScryptParameters(int keySize, int costParameter, int parallelizationParameter, int blockSize)... |
127 |
|
{ |
128 |
0 |
this(keySize, costParameter, parallelizationParameter, blockSize, getRandomSalt()); |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
@param |
135 |
|
|
136 |
|
@param |
137 |
|
|
138 |
|
@param |
139 |
|
|
140 |
|
@param |
141 |
|
@param |
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
143 |
9 |
public ScryptParameters(int keySize, int costParameter, int parallelizationParameter, int blockSize, byte[] salt)... |
144 |
|
{ |
145 |
9 |
super(keySize); |
146 |
9 |
this.costParameter = costParameter; |
147 |
9 |
this.blockSize = blockSize; |
148 |
9 |
this.parallelizationParameter = parallelizationParameter; |
149 |
9 |
this.salt = salt; |
150 |
|
} |
151 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
152 |
2 |
private static byte[] getRandomSalt()... |
153 |
|
{ |
154 |
2 |
byte[] salt = new byte[SALT_DEFAULT_SIZE]; |
155 |
2 |
PRND.nextBytes(salt); |
156 |
2 |
return salt; |
157 |
|
} |
158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
159 |
2 |
@Override... |
160 |
|
public String getAlgorithmName() |
161 |
|
{ |
162 |
2 |
return "Scrypt"; |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
@return |
167 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
168 |
14 |
public int getCostParameter()... |
169 |
|
{ |
170 |
14 |
return this.costParameter; |
171 |
|
} |
172 |
|
|
173 |
|
|
174 |
|
@return |
175 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
176 |
14 |
public int getParallelizationParameter()... |
177 |
|
{ |
178 |
14 |
return this.parallelizationParameter; |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
@return |
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
14 |
public byte[] getSalt()... |
185 |
|
{ |
186 |
14 |
return this.salt; |
187 |
|
} |
188 |
|
|
189 |
|
|
190 |
|
@return |
191 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
192 |
14 |
public int getBlockSize()... |
193 |
|
{ |
194 |
14 |
return this.blockSize; |
195 |
|
} |
196 |
|
} |