37796
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.security.provider;
|
|
27 |
|
38853
|
28 |
import java.io.IOException;
|
|
29 |
import java.io.Serializable;
|
37796
|
30 |
import java.security.DrbgParameters;
|
|
31 |
import java.security.SecureRandomParameters;
|
|
32 |
|
|
33 |
/**
|
38853
|
34 |
* Exported and non-exported parameters that can be used by DRBGs.
|
37796
|
35 |
*/
|
38853
|
36 |
public class MoreDrbgParameters implements SecureRandomParameters, Serializable {
|
|
37 |
|
|
38 |
private static final long serialVersionUID = 9L;
|
|
39 |
|
|
40 |
final transient EntropySource es;
|
37796
|
41 |
|
|
42 |
final String mech;
|
|
43 |
final String algorithm;
|
|
44 |
final boolean usedf;
|
38853
|
45 |
final int strength;
|
|
46 |
final DrbgParameters.Capability capability;
|
|
47 |
|
|
48 |
// The following 2 fields will be reassigned in readObject and
|
|
49 |
// thus cannot be final
|
|
50 |
byte[] nonce;
|
|
51 |
byte[] personalizationString;
|
37796
|
52 |
|
|
53 |
/**
|
|
54 |
* Creates a new {@code MoreDrbgParameters} object.
|
|
55 |
*
|
|
56 |
* @param es the {@link EntropySource} to use. If set to {@code null},
|
|
57 |
* a default entropy source will be used.
|
|
58 |
* @param mech mech name. If set to {@code null}, the one in
|
|
59 |
* securerandom.drbg.config is used. This argument is ignored
|
|
60 |
* when passing to HashDrbg/HmacDrbg/CtrDrbg.
|
|
61 |
* @param algorithm the requested algorithm to use. If set to {@code null},
|
|
62 |
* the algorithm will be decided by strength.
|
|
63 |
* @param nonce the nonce to use. If set to {@code null},
|
|
64 |
* a nonce will be assigned.
|
|
65 |
* @param usedf whether a derivation function should be used
|
|
66 |
* @param config a {@link DrbgParameters.Instantiation} object
|
|
67 |
*/
|
|
68 |
public MoreDrbgParameters(EntropySource es, String mech,
|
|
69 |
String algorithm, byte[] nonce, boolean usedf,
|
|
70 |
DrbgParameters.Instantiation config) {
|
|
71 |
this.mech = mech;
|
|
72 |
this.algorithm = algorithm;
|
|
73 |
this.es = es;
|
38853
|
74 |
this.nonce = (nonce == null) ? null : nonce.clone();
|
37796
|
75 |
this.usedf = usedf;
|
38853
|
76 |
|
|
77 |
this.strength = config.getStrength();
|
|
78 |
this.capability = config.getCapability();
|
|
79 |
this.personalizationString = config.getPersonalizationString();
|
37796
|
80 |
}
|
|
81 |
|
|
82 |
@Override
|
|
83 |
public String toString() {
|
38853
|
84 |
return mech + "," + algorithm + "," + usedf + "," + strength
|
|
85 |
+ "," + capability + "," + personalizationString;
|
|
86 |
}
|
|
87 |
|
|
88 |
private void readObject(java.io.ObjectInputStream s)
|
|
89 |
throws IOException, ClassNotFoundException {
|
|
90 |
s.defaultReadObject();
|
|
91 |
if (nonce != null) {
|
|
92 |
nonce = nonce.clone();
|
|
93 |
}
|
|
94 |
if (personalizationString != null) {
|
|
95 |
personalizationString = personalizationString.clone();
|
|
96 |
}
|
|
97 |
if (capability == null) {
|
|
98 |
throw new IllegalArgumentException("Input data is corrupted");
|
|
99 |
}
|
37796
|
100 |
}
|
|
101 |
}
|