Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/sun/security/provider/MoreDrbgParameters.java
41159 views
1
/*
2
* Copyright (c) 2016, 2019, 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
28
import java.io.IOException;
29
import java.io.Serializable;
30
import java.security.DrbgParameters;
31
import java.security.SecureRandomParameters;
32
33
/**
34
* Exported and non-exported parameters that can be used by DRBGs.
35
*/
36
public class MoreDrbgParameters implements SecureRandomParameters, Serializable {
37
38
@java.io.Serial
39
private static final long serialVersionUID = 9L;
40
41
final transient EntropySource es;
42
43
final String mech;
44
final String algorithm;
45
final boolean usedf;
46
final int strength;
47
final DrbgParameters.Capability capability;
48
49
// The following 2 fields will be reassigned in readObject and
50
// thus cannot be final
51
byte[] nonce;
52
byte[] personalizationString;
53
54
/**
55
* Creates a new {@code MoreDrbgParameters} object.
56
*
57
* @param es the {@link EntropySource} to use. If set to {@code null},
58
* a default entropy source will be used.
59
* @param mech mech name. If set to {@code null}, the one in
60
* securerandom.drbg.config is used. This argument is ignored
61
* when passing to HashDrbg/HmacDrbg/CtrDrbg.
62
* @param algorithm the requested algorithm to use. If set to {@code null},
63
* the algorithm will be decided by strength.
64
* @param nonce the nonce to use. If set to {@code null},
65
* a nonce will be assigned.
66
* @param usedf whether a derivation function should be used
67
* @param config a {@link DrbgParameters.Instantiation} object
68
*/
69
public MoreDrbgParameters(EntropySource es, String mech,
70
String algorithm, byte[] nonce, boolean usedf,
71
DrbgParameters.Instantiation config) {
72
this.mech = mech;
73
this.algorithm = algorithm;
74
this.es = es;
75
this.nonce = (nonce == null) ? null : nonce.clone();
76
this.usedf = usedf;
77
78
this.strength = config.getStrength();
79
this.capability = config.getCapability();
80
this.personalizationString = config.getPersonalizationString();
81
}
82
83
@Override
84
public String toString() {
85
return mech + "," + algorithm + "," + usedf + "," + strength
86
+ "," + capability + "," + personalizationString;
87
}
88
89
@java.io.Serial
90
private void readObject(java.io.ObjectInputStream s)
91
throws IOException, ClassNotFoundException {
92
s.defaultReadObject();
93
if (nonce != null) {
94
nonce = nonce.clone();
95
}
96
if (personalizationString != null) {
97
personalizationString = personalizationString.clone();
98
}
99
if (capability == null) {
100
throw new IllegalArgumentException("Input data is corrupted");
101
}
102
}
103
}
104
105