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 |
|
|
24 |
|
import org.bouncycastle.asn1.ASN1EncodableVector; |
25 |
|
import org.bouncycastle.asn1.ASN1Integer; |
26 |
|
import org.bouncycastle.asn1.ASN1Object; |
27 |
|
import org.bouncycastle.asn1.ASN1OctetString; |
28 |
|
import org.bouncycastle.asn1.ASN1Primitive; |
29 |
|
import org.bouncycastle.asn1.ASN1Sequence; |
30 |
|
import org.bouncycastle.asn1.DEROctetString; |
31 |
|
import org.bouncycastle.asn1.DERSequence; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 79.6% |
Uncovered Elements: 11 (54) |
Complexity: 16 |
Complexity Density: 0.5 |
|
39 |
|
public class ScryptKDFParams extends ASN1Object |
40 |
|
{ |
41 |
|
private ASN1OctetString salt; |
42 |
|
|
43 |
|
private ASN1Integer costParameter; |
44 |
|
|
45 |
|
private ASN1Integer blockSize; |
46 |
|
|
47 |
|
private ASN1Integer parallelizationParameter; |
48 |
|
|
49 |
|
private ASN1Integer keyLength; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@param |
55 |
|
@param |
56 |
|
@param |
57 |
|
@param |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
0 |
public ScryptKDFParams(byte[] salt, int costParameter, int blockSize, int parallelizationParameter)... |
60 |
|
{ |
61 |
0 |
this(salt, costParameter, blockSize, parallelizationParameter, -1); |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@param |
68 |
|
@param |
69 |
|
@param |
70 |
|
@param |
71 |
|
@param |
72 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
73 |
5 |
public ScryptKDFParams(byte[] salt, int costParameter, int blockSize, int parallelizationParameter, int keyLength)... |
74 |
|
{ |
75 |
5 |
this.salt = new DEROctetString(salt); |
76 |
5 |
this.costParameter = new ASN1Integer(costParameter); |
77 |
5 |
this.blockSize = new ASN1Integer(blockSize); |
78 |
5 |
this.parallelizationParameter = new ASN1Integer(parallelizationParameter); |
79 |
5 |
this.keyLength = (keyLength >= 0) ? new ASN1Integer(keyLength) : null; |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@param |
86 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
87 |
3 |
private ScryptKDFParams(ASN1Sequence seq)... |
88 |
|
{ |
89 |
3 |
this.salt = (ASN1OctetString) seq.getObjectAt(0); |
90 |
3 |
this.costParameter = (ASN1Integer) seq.getObjectAt(1); |
91 |
3 |
this.blockSize = (ASN1Integer) seq.getObjectAt(2); |
92 |
3 |
this.parallelizationParameter = (ASN1Integer) seq.getObjectAt(3); |
93 |
3 |
if (seq.size() > 4) { |
94 |
3 |
this.keyLength = (ASN1Integer) seq.getObjectAt(4); |
95 |
|
} |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
@param |
102 |
|
@return |
103 |
|
|
|
|
| 55.6% |
Uncovered Elements: 4 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
104 |
3 |
public static ScryptKDFParams getInstance(Object obj)... |
105 |
|
{ |
106 |
3 |
if (obj instanceof ScryptKDFParams) { |
107 |
0 |
return (ScryptKDFParams) obj; |
108 |
|
} |
109 |
3 |
if (obj != null) { |
110 |
3 |
return new ScryptKDFParams(ASN1Sequence.getInstance(obj)); |
111 |
|
} |
112 |
0 |
return null; |
113 |
|
} |
114 |
|
|
115 |
|
|
116 |
|
@return |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
3 |
public byte[] getSalt()... |
119 |
|
{ |
120 |
3 |
return this.salt.getOctets(); |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
@return |
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
126 |
3 |
public BigInteger getCostParameter()... |
127 |
|
{ |
128 |
3 |
return this.costParameter.getValue(); |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
@return |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
134 |
3 |
public BigInteger getBlockSize()... |
135 |
|
{ |
136 |
3 |
return this.blockSize.getValue(); |
137 |
|
} |
138 |
|
|
139 |
|
|
140 |
|
@return |
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
3 |
public BigInteger getParallelizationParameter()... |
143 |
|
{ |
144 |
3 |
return this.parallelizationParameter.getValue(); |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
@return |
149 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
150 |
6 |
public BigInteger getKeyLength()... |
151 |
|
{ |
152 |
6 |
if (this.keyLength == null) { |
153 |
0 |
return null; |
154 |
|
} |
155 |
6 |
return this.keyLength.getValue(); |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
@return |
160 |
|
|
|
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
161 |
16 |
@Override... |
162 |
|
public ASN1Primitive toASN1Primitive() |
163 |
|
{ |
164 |
16 |
ASN1EncodableVector v = new ASN1EncodableVector(); |
165 |
|
|
166 |
16 |
v.add(this.salt); |
167 |
16 |
v.add(this.costParameter); |
168 |
16 |
v.add(this.blockSize); |
169 |
16 |
v.add(this.parallelizationParameter); |
170 |
16 |
if (this.keyLength != null) { |
171 |
16 |
v.add(this.keyLength); |
172 |
|
} |
173 |
|
|
174 |
16 |
return new DERSequence(v); |
175 |
|
} |
176 |
|
} |