blob: 06976b2de3e4893b2657885ecdda39f98c7a4e50 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2007 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package javax.crypto.spec;
27
28import java.math.BigInteger;
29import java.security.spec.AlgorithmParameterSpec;
30import 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="http://www.ietf.org/rfc/rfc3447.txt">PKCS #1</a>
36 * standard.
37 *
38 * Its ASN.1 definition in PKCS#1 standard is described below:
39 * <pre>
40 * RSAES-OAEP-params ::= SEQUENCE {
41 * hashAlgorithm [0] OAEP-PSSDigestAlgorithms DEFAULT sha1,
42 * maskGenAlgorithm [1] PKCS1MGFAlgorithms DEFAULT mgf1SHA1,
43 * pSourceAlgorithm [2] PKCS1PSourceAlgorithms DEFAULT pSpecifiedEmpty
44 * }
45 * </pre>
46 * where
47 * <pre>
48 * OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= {
49 * { OID id-sha1 PARAMETERS NULL }|
50 * { OID id-sha256 PARAMETERS NULL }|
51 * { OID id-sha384 PARAMETERS NULL }|
52 * { OID id-sha512 PARAMETERS NULL },
53 * ... -- Allows for future expansion --
54 * }
55 * PKCS1MGFAlgorithms ALGORITHM-IDENTIFIER ::= {
56 * { OID id-mgf1 PARAMETERS OAEP-PSSDigestAlgorithms },
57 * ... -- Allows for future expansion --
58 * }
59 * PKCS1PSourceAlgorithms ALGORITHM-IDENTIFIER ::= {
60 * { OID id-pSpecified PARAMETERS OCTET STRING },
61 * ... -- Allows for future expansion --
62 * }
63 * </pre>
64 * <p>Note: the OAEPParameterSpec.DEFAULT uses the following:
65 * message digest -- "SHA-1"
66 * mask generation function (mgf) -- "MGF1"
67 * parameters for mgf -- MGF1ParameterSpec.SHA1
68 * source of encoding input -- PSource.PSpecified.DEFAULT
69 *
70 * @see java.security.spec.MGF1ParameterSpec
71 * @see PSource
72 *
73 * @author Valerie Peng
74 *
75 * @since 1.5
76 */
77public class OAEPParameterSpec implements AlgorithmParameterSpec {
78
79 private String mdName = "SHA-1";
80 private String mgfName = "MGF1";
81 private AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
82 private PSource pSrc = PSource.PSpecified.DEFAULT;
83
84 /**
85 * The OAEP parameter set with all default values.
86 */
87 public static final OAEPParameterSpec DEFAULT = new OAEPParameterSpec();
88
89 /**
90 * Constructs a parameter set for OAEP padding as defined in
91 * the PKCS #1 standard using the default values.
92 */
93 private OAEPParameterSpec() {
94 }
95
96 /**
97 * Constructs a parameter set for OAEP padding as defined in
98 * the PKCS #1 standard using the specified message digest
99 * algorithm <code>mdName</code>, mask generation function
100 * algorithm <code>mgfName</code>, parameters for the mask
101 * generation function <code>mgfSpec</code>, and source of
102 * the encoding input P <code>pSrc</code>.
103 *
104 * @param mdName the algorithm name for the message digest.
105 * @param mgfName the algorithm name for the mask generation
106 * function.
107 * @param mgfSpec the parameters for the mask generation function.
108 * If null is specified, null will be returned by getMGFParameters().
109 * @param pSrc the source of the encoding input P.
110 * @exception NullPointerException if <code>mdName</code>,
111 * <code>mgfName</code>, or <code>pSrc</code> is null.
112 */
113 public OAEPParameterSpec(String mdName, String mgfName,
114 AlgorithmParameterSpec mgfSpec,
115 PSource pSrc) {
116 if (mdName == null) {
117 throw new NullPointerException("digest algorithm is null");
118 }
119 if (mgfName == null) {
120 throw new NullPointerException("mask generation function " +
121 "algorithm is null");
122 }
123 if (pSrc == null) {
124 throw new NullPointerException("source of the encoding input " +
125 "is null");
126 }
127 this.mdName = mdName;
128 this.mgfName = mgfName;
129 this.mgfSpec = mgfSpec;
130 this.pSrc = pSrc;
131 }
132
133 /**
134 * Returns the message digest algorithm name.
135 *
136 * @return the message digest algorithm name.
137 */
138 public String getDigestAlgorithm() {
139 return mdName;
140 }
141
142 /**
143 * Returns the mask generation function algorithm name.
144 *
145 * @return the mask generation function algorithm name.
146 */
147 public String getMGFAlgorithm() {
148 return mgfName;
149 }
150
151 /**
152 * Returns the parameters for the mask generation function.
153 *
154 * @return the parameters for the mask generation function.
155 */
156 public AlgorithmParameterSpec getMGFParameters() {
157 return mgfSpec;
158 }
159
160 /**
161 * Returns the source of encoding input P.
162 *
163 * @return the source of encoding input P.
164 */
165 public PSource getPSource() {
166 return pSrc;
167 }
168}