Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/javax/crypto/spec/OAEPParameterSpec.java
41159 views
1
/*
2
* Copyright (c) 2003, 2018, 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 javax.crypto.spec;
27
28
import java.math.BigInteger;
29
import java.security.spec.AlgorithmParameterSpec;
30
import java.security.spec.MGF1ParameterSpec;
31
32
/**
33
* This class specifies the set of parameters used with OAEP Padding,
34
* as defined in the
35
* <a href="https://tools.ietf.org/rfc/rfc8017.txt">PKCS#1 v2.2</a> standard.
36
*
37
* Its ASN.1 definition in PKCS#1 standard is described below:
38
* <pre>
39
* RSAES-OAEP-params ::= SEQUENCE {
40
* hashAlgorithm [0] HashAlgorithm DEFAULT sha1,
41
* maskGenAlgorithm [1] MaskGenAlgorithm DEFAULT mgf1SHA1,
42
* pSourceAlgorithm [2] PSourceAlgorithm DEFAULT pSpecifiedEmpty
43
* }
44
* </pre>
45
* where
46
* <pre>
47
* HashAlgorithm ::= AlgorithmIdentifier {
48
* {OAEP-PSSDigestAlgorithms}
49
* }
50
* MaskGenAlgorithm ::= AlgorithmIdentifier { {PKCS1MGFAlgorithms} }
51
* PSourceAlgorithm ::= AlgorithmIdentifier {
52
* {PKCS1PSourceAlgorithms}
53
* }
54
*
55
* OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= {
56
* { OID id-sha1 PARAMETERS NULL }|
57
* { OID id-sha224 PARAMETERS NULL }|
58
* { OID id-sha256 PARAMETERS NULL }|
59
* { OID id-sha384 PARAMETERS NULL }|
60
* { OID id-sha512 PARAMETERS NULL }|
61
* { OID id-sha512-224 PARAMETERS NULL }|
62
* { OID id-sha512-256 PARAMETERS NULL },
63
* ... -- Allows for future expansion --
64
* }
65
* PKCS1MGFAlgorithms ALGORITHM-IDENTIFIER ::= {
66
* { OID id-mgf1 PARAMETERS HashAlgorithm },
67
* ... -- Allows for future expansion --
68
* }
69
* PKCS1PSourceAlgorithms ALGORITHM-IDENTIFIER ::= {
70
* { OID id-pSpecified PARAMETERS EncodingParameters },
71
* ... -- Allows for future expansion --
72
* }
73
* EncodingParameters ::= OCTET STRING(SIZE(0..MAX))
74
* </pre>
75
* <p>Note: the OAEPParameterSpec.DEFAULT uses the following:
76
* <pre>
77
* message digest -- "SHA-1"
78
* mask generation function (mgf) -- "MGF1"
79
* parameters for mgf -- MGF1ParameterSpec.SHA1
80
* source of encoding input -- PSource.PSpecified.DEFAULT
81
* </pre>
82
*
83
* @see java.security.spec.MGF1ParameterSpec
84
* @see PSource
85
*
86
* @author Valerie Peng
87
*
88
* @since 1.5
89
*/
90
public class OAEPParameterSpec implements AlgorithmParameterSpec {
91
92
private String mdName = "SHA-1";
93
private String mgfName = "MGF1";
94
private AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
95
private PSource pSrc = PSource.PSpecified.DEFAULT;
96
97
/**
98
* The OAEP parameter set with all default values.
99
*/
100
public static final OAEPParameterSpec DEFAULT = new OAEPParameterSpec();
101
102
/**
103
* Constructs a parameter set for OAEP padding as defined in
104
* the PKCS #1 standard using the default values.
105
*/
106
private OAEPParameterSpec() {
107
}
108
109
/**
110
* Constructs a parameter set for OAEP padding as defined in
111
* the PKCS #1 standard using the specified message digest
112
* algorithm <code>mdName</code>, mask generation function
113
* algorithm <code>mgfName</code>, parameters for the mask
114
* generation function <code>mgfSpec</code>, and source of
115
* the encoding input P <code>pSrc</code>.
116
*
117
* @param mdName the algorithm name for the message digest.
118
* @param mgfName the algorithm name for the mask generation
119
* function.
120
* @param mgfSpec the parameters for the mask generation function.
121
* If null is specified, null will be returned by getMGFParameters().
122
* @param pSrc the source of the encoding input P.
123
* @exception NullPointerException if <code>mdName</code>,
124
* <code>mgfName</code>, or <code>pSrc</code> is null.
125
*/
126
public OAEPParameterSpec(String mdName, String mgfName,
127
AlgorithmParameterSpec mgfSpec,
128
PSource pSrc) {
129
if (mdName == null) {
130
throw new NullPointerException("digest algorithm is null");
131
}
132
if (mgfName == null) {
133
throw new NullPointerException("mask generation function " +
134
"algorithm is null");
135
}
136
if (pSrc == null) {
137
throw new NullPointerException("source of the encoding input " +
138
"is null");
139
}
140
this.mdName = mdName;
141
this.mgfName = mgfName;
142
this.mgfSpec = mgfSpec;
143
this.pSrc = pSrc;
144
}
145
146
/**
147
* Returns the message digest algorithm name.
148
*
149
* @return the message digest algorithm name.
150
*/
151
public String getDigestAlgorithm() {
152
return mdName;
153
}
154
155
/**
156
* Returns the mask generation function algorithm name.
157
*
158
* @return the mask generation function algorithm name.
159
*/
160
public String getMGFAlgorithm() {
161
return mgfName;
162
}
163
164
/**
165
* Returns the parameters for the mask generation function.
166
*
167
* @return the parameters for the mask generation function.
168
*/
169
public AlgorithmParameterSpec getMGFParameters() {
170
return mgfSpec;
171
}
172
173
/**
174
* Returns the source of encoding input P.
175
*
176
* @return the source of encoding input P.
177
*/
178
public PSource getPSource() {
179
return pSrc;
180
}
181
}
182
183