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.factory; |
21 |
|
|
22 |
|
import javax.inject.Singleton; |
23 |
|
|
24 |
|
import org.bouncycastle.asn1.ASN1Encodable; |
25 |
|
import org.bouncycastle.asn1.ASN1ObjectIdentifier; |
26 |
|
import org.bouncycastle.asn1.pkcs.KeyDerivationFunc; |
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.crypto.password.KeyDerivationFunction; |
29 |
|
import org.xwiki.crypto.password.internal.kdf.BcScryptKDF; |
30 |
|
import org.xwiki.crypto.password.internal.kdf.ScryptKDFParams; |
31 |
|
import org.xwiki.crypto.password.params.KeyDerivationFunctionParameters; |
32 |
|
import org.xwiki.crypto.password.params.ScryptParameters; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@Component(hints = { "Scrypt", "1.3.6.1.4.1.11591.4.11" }) |
44 |
|
@Singleton |
|
|
| 68.8% |
Uncovered Elements: 5 (16) |
Complexity: 5 |
Complexity Density: 0.62 |
|
45 |
|
public class BcScryptKeyDerivationFunctionFactory extends AbstractBcKDFFactory |
46 |
|
{ |
47 |
|
|
48 |
|
private static final ASN1ObjectIdentifier ALG_ID = new ASN1ObjectIdentifier("1.3.6.1.4.1.11591.4.11"); |
49 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
50 |
9 |
@Override... |
51 |
|
public KeyDerivationFunction getInstance(KeyDerivationFunctionParameters params) |
52 |
|
{ |
53 |
9 |
if (!(params instanceof ScryptParameters)) { |
54 |
0 |
throw new IllegalArgumentException("Invalid parameter used for Scrypt function: " |
55 |
|
+ params.getClass().getName()); |
56 |
|
} |
57 |
|
|
58 |
9 |
return new BcScryptKDF((ScryptParameters) params); |
59 |
|
} |
60 |
|
|
|
|
| 66.7% |
Uncovered Elements: 3 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
61 |
3 |
@Override... |
62 |
|
public KeyDerivationFunction getInstance(ASN1Encodable parameters) |
63 |
|
{ |
64 |
3 |
KeyDerivationFunc kdf = KeyDerivationFunc.getInstance(parameters); |
65 |
|
|
66 |
3 |
if (!kdf.getAlgorithm().equals(ALG_ID)) { |
67 |
0 |
throw new IllegalArgumentException("Illegal algorithm identifier for Scrypt: " |
68 |
|
+ kdf.getAlgorithm().getId()); |
69 |
|
} |
70 |
|
|
71 |
3 |
ScryptKDFParams params = ScryptKDFParams.getInstance(kdf.getParameters()); |
72 |
|
|
73 |
3 |
return getInstance( |
74 |
3 |
new ScryptParameters((params.getKeyLength() != null) ? params.getKeyLength().intValue() : -1, |
75 |
|
params.getCostParameter().intValue(), params.getParallelizationParameter().intValue(), |
76 |
|
params.getBlockSize().intValue(), params.getSalt())); |
77 |
|
} |
78 |
|
} |