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.internal.kdf; |
21 |
|
|
22 |
|
import java.math.BigInteger; |
23 |
|
import java.util.Enumeration; |
24 |
|
|
25 |
|
import org.bouncycastle.asn1.ASN1Encodable; |
26 |
|
import org.bouncycastle.asn1.ASN1EncodableVector; |
27 |
|
import org.bouncycastle.asn1.ASN1Integer; |
28 |
|
import org.bouncycastle.asn1.ASN1Object; |
29 |
|
import org.bouncycastle.asn1.ASN1OctetString; |
30 |
|
import org.bouncycastle.asn1.ASN1Primitive; |
31 |
|
import org.bouncycastle.asn1.ASN1Sequence; |
32 |
|
import org.bouncycastle.asn1.DEROctetString; |
33 |
|
import org.bouncycastle.asn1.DERSequence; |
34 |
|
import org.bouncycastle.asn1.x509.AlgorithmIdentifier; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
|
|
| 80.8% |
Uncovered Elements: 15 (78) |
Complexity: 22 |
Complexity Density: 0.48 |
|
42 |
|
public class PBKDF2Params extends ASN1Object |
43 |
|
{ |
44 |
|
private final ASN1OctetString octStr; |
45 |
|
|
46 |
|
private final ASN1Integer iterationCount; |
47 |
|
|
48 |
|
private final ASN1Integer keyLength; |
49 |
|
|
50 |
|
private final AlgorithmIdentifier prf; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@param |
56 |
|
@param |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
0 |
public PBKDF2Params(byte[] salt, int iterationCount)... |
59 |
|
{ |
60 |
0 |
this(new DEROctetString(salt), new ASN1Integer(iterationCount), null, null); |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
@param |
67 |
|
@param |
68 |
|
@param |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
18 |
public PBKDF2Params(byte[] salt, int iterationCount, AlgorithmIdentifier prf)... |
71 |
|
{ |
72 |
18 |
this(new DEROctetString(salt), new ASN1Integer(iterationCount), null, prf); |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
@param |
79 |
|
@param |
80 |
|
@param |
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
public PBKDF2Params(byte[] salt, int iterationCount, int keyLength)... |
83 |
|
{ |
84 |
0 |
this(new DEROctetString(salt), new ASN1Integer(iterationCount), new ASN1Integer(keyLength), null); |
85 |
|
} |
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
@param |
91 |
|
@param |
92 |
|
@param |
93 |
|
@param |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
6 |
public PBKDF2Params(byte[] salt, int iterationCount, int keyLength, AlgorithmIdentifier prf)... |
96 |
|
{ |
97 |
6 |
this(new DEROctetString(salt), new ASN1Integer(iterationCount), new ASN1Integer(keyLength), prf); |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
100 |
24 |
private PBKDF2Params(ASN1OctetString salt, ASN1Integer iterationCount, ASN1Integer keyLength,... |
101 |
|
AlgorithmIdentifier prf) |
102 |
|
{ |
103 |
24 |
this.octStr = salt; |
104 |
24 |
this.iterationCount = iterationCount; |
105 |
24 |
this.keyLength = keyLength; |
106 |
24 |
this.prf = prf; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
@param |
113 |
|
|
|
|
| 90% |
Uncovered Elements: 2 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
114 |
26 |
private PBKDF2Params(ASN1Sequence seq)... |
115 |
|
{ |
116 |
26 |
@SuppressWarnings("unchecked") |
117 |
|
Enumeration<ASN1Encodable> e = seq.getObjects(); |
118 |
|
|
119 |
26 |
this.octStr = (ASN1OctetString) e.nextElement(); |
120 |
26 |
this.iterationCount = (ASN1Integer) e.nextElement(); |
121 |
|
|
122 |
26 |
if (e.hasMoreElements()) { |
123 |
14 |
Object obj = e.nextElement(); |
124 |
14 |
if (obj instanceof ASN1Integer) { |
125 |
6 |
this.keyLength = (ASN1Integer) obj; |
126 |
6 |
if (e.hasMoreElements()) { |
127 |
0 |
this.prf = AlgorithmIdentifier.getInstance(obj); |
128 |
|
} else { |
129 |
6 |
this.prf = null; |
130 |
|
} |
131 |
|
} else { |
132 |
8 |
this.keyLength = null; |
133 |
8 |
this.prf = AlgorithmIdentifier.getInstance(obj); |
134 |
|
} |
135 |
|
} else { |
136 |
12 |
this.keyLength = null; |
137 |
12 |
this.prf = null; |
138 |
|
} |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
@param |
145 |
|
@return |
146 |
|
|
|
|
| 50% |
Uncovered Elements: 9 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
147 |
38 |
public static PBKDF2Params getInstance(Object obj)... |
148 |
|
{ |
149 |
38 |
if (obj instanceof PBKDF2Params) { |
150 |
12 |
return (PBKDF2Params) obj; |
151 |
|
} |
152 |
|
|
153 |
26 |
if (obj instanceof org.bouncycastle.asn1.pkcs.PBKDF2Params) { |
154 |
0 |
org.bouncycastle.asn1.pkcs.PBKDF2Params params = (org.bouncycastle.asn1.pkcs.PBKDF2Params) obj; |
155 |
0 |
if (params.getKeyLength() != null) { |
156 |
0 |
return new PBKDF2Params(params.getSalt(), |
157 |
|
params.getIterationCount().intValue(), params.getKeyLength().intValue()); |
158 |
|
} else { |
159 |
0 |
return new PBKDF2Params(params.getSalt(), params.getIterationCount().intValue()); |
160 |
|
} |
161 |
|
} |
162 |
|
|
163 |
26 |
if (obj != null) { |
164 |
26 |
return new PBKDF2Params(ASN1Sequence.getInstance(obj)); |
165 |
|
} |
166 |
|
|
167 |
0 |
return null; |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
|
@return |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
173 |
14 |
public byte[] getSalt()... |
174 |
|
{ |
175 |
14 |
return this.octStr.getOctets(); |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
@return |
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
181 |
14 |
public BigInteger getIterationCount()... |
182 |
|
{ |
183 |
14 |
return this.iterationCount.getValue(); |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
@return |
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
189 |
18 |
public BigInteger getKeyLength()... |
190 |
|
{ |
191 |
18 |
if (this.keyLength != null) { |
192 |
8 |
return this.keyLength.getValue(); |
193 |
|
} |
194 |
|
|
195 |
10 |
return null; |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
|
@return |
200 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
201 |
14 |
public AlgorithmIdentifier getPseudoRandomFunctionIdentifier()... |
202 |
|
{ |
203 |
14 |
return this.prf; |
204 |
|
} |
205 |
|
|
206 |
|
|
207 |
|
@return |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
209 |
99 |
@Override... |
210 |
|
public ASN1Primitive toASN1Primitive() |
211 |
|
{ |
212 |
99 |
ASN1EncodableVector v = new ASN1EncodableVector(); |
213 |
|
|
214 |
99 |
v.add(this.octStr); |
215 |
99 |
v.add(this.iterationCount); |
216 |
|
|
217 |
99 |
if (this.keyLength != null) { |
218 |
21 |
v.add(this.keyLength); |
219 |
|
} |
220 |
|
|
221 |
99 |
if (this.prf != null) { |
222 |
48 |
v.add(this.prf); |
223 |
|
} |
224 |
|
|
225 |
99 |
return new DERSequence(v); |
226 |
|
} |
227 |
|
} |