1 /*
2 * Copyright (c) 2001, 2012, 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
74 *
75 *
76 * @since 1.4
77 */
78
79 public class PSSParameterSpec implements AlgorithmParameterSpec {
80
81 private String mdName = "SHA-1";
82 private String mgfName = "MGF1";
83 private AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
84 private int saltLen = 20;
85 private int trailerField = 1;
86
87 /**
88 * The PSS parameter set with all default values.
89 * @since 1.5
90 */
91 public static final PSSParameterSpec DEFAULT = new PSSParameterSpec();
92
93 /**
94 * Constructs a new <code>PSSParameterSpec</code> as defined in
95 * the PKCS #1 standard using the default values.
96 */
97 private PSSParameterSpec() {
98 }
99
100 /**
101 * Creates a new <code>PSSParameterSpec</code> as defined in
102 * the PKCS #1 standard using the specified message digest,
103 * mask generation function, parameters for mask generation
104 * function, salt length, and trailer field values.
105 *
106 * @param mdName the algorithm name of the hash function.
107 * @param mgfName the algorithm name of the mask generation
108 * function.
109 * @param mgfSpec the parameters for the mask generation
110 * function. If null is specified, null will be returned by
111 * getMGFParameters().
112 * @param saltLen the length of salt.
113 * @param trailerField the value of the trailer field.
114 * @exception NullPointerException if <code>mdName</code>,
115 * or <code>mgfName</code> is null.
116 * @exception IllegalArgumentException if <code>saltLen</code>
117 * or <code>trailerField</code> is less than 0.
118 * @since 1.5
119 */
120 public PSSParameterSpec(String mdName, String mgfName,
121 AlgorithmParameterSpec mgfSpec,
122 int saltLen, int trailerField) {
123 if (mdName == null) {
124 throw new NullPointerException("digest algorithm is null");
125 }
126 if (mgfName == null) {
127 throw new NullPointerException("mask generation function " +
128 "algorithm is null");
129 }
130 if (saltLen < 0) {
131 throw new IllegalArgumentException("negative saltLen value: " +
132 saltLen);
133 }
134 if (trailerField < 0) {
135 throw new IllegalArgumentException("negative trailerField: " +
136 trailerField);
137 }
138 this.mdName = mdName;
139 this.mgfName = mgfName;
140 this.mgfSpec = mgfSpec;
141 this.saltLen = saltLen;
142 this.trailerField = trailerField;
143 }
144
145 /**
146 * Creates a new <code>PSSParameterSpec</code>
147 * using the specified salt length and other default values as
148 * defined in PKCS#1.
149 *
150 * @param saltLen the length of salt in bits to be used in PKCS#1
151 * PSS encoding.
152 * @exception IllegalArgumentException if <code>saltLen</code> is
153 * less than 0.
154 */
155 public PSSParameterSpec(int saltLen) {
156 if (saltLen < 0) {
157 throw new IllegalArgumentException("negative saltLen value: " +
158 saltLen);
159 }
160 this.saltLen = saltLen;
161 }
162
163 /**
164 * Returns the message digest algorithm name.
165 *
166 * @return the message digest algorithm name.
167 * @since 1.5
168 */
169 public String getDigestAlgorithm() {
170 return mdName;
171 }
172
|
1 /*
2 * Copyright (c) 2001, 2013, 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
74 *
75 *
76 * @since 1.4
77 */
78
79 public class PSSParameterSpec implements AlgorithmParameterSpec {
80
81 private String mdName = "SHA-1";
82 private String mgfName = "MGF1";
83 private AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
84 private int saltLen = 20;
85 private int trailerField = 1;
86
87 /**
88 * The PSS parameter set with all default values.
89 * @since 1.5
90 */
91 public static final PSSParameterSpec DEFAULT = new PSSParameterSpec();
92
93 /**
94 * Constructs a new {@code PSSParameterSpec} as defined in
95 * the PKCS #1 standard using the default values.
96 */
97 private PSSParameterSpec() {
98 }
99
100 /**
101 * Creates a new {@code PSSParameterSpec} as defined in
102 * the PKCS #1 standard using the specified message digest,
103 * mask generation function, parameters for mask generation
104 * function, salt length, and trailer field values.
105 *
106 * @param mdName the algorithm name of the hash function.
107 * @param mgfName the algorithm name of the mask generation
108 * function.
109 * @param mgfSpec the parameters for the mask generation
110 * function. If null is specified, null will be returned by
111 * getMGFParameters().
112 * @param saltLen the length of salt.
113 * @param trailerField the value of the trailer field.
114 * @exception NullPointerException if {@code mdName},
115 * or {@code mgfName} is null.
116 * @exception IllegalArgumentException if {@code saltLen}
117 * or {@code trailerField} is less than 0.
118 * @since 1.5
119 */
120 public PSSParameterSpec(String mdName, String mgfName,
121 AlgorithmParameterSpec mgfSpec,
122 int saltLen, int trailerField) {
123 if (mdName == null) {
124 throw new NullPointerException("digest algorithm is null");
125 }
126 if (mgfName == null) {
127 throw new NullPointerException("mask generation function " +
128 "algorithm is null");
129 }
130 if (saltLen < 0) {
131 throw new IllegalArgumentException("negative saltLen value: " +
132 saltLen);
133 }
134 if (trailerField < 0) {
135 throw new IllegalArgumentException("negative trailerField: " +
136 trailerField);
137 }
138 this.mdName = mdName;
139 this.mgfName = mgfName;
140 this.mgfSpec = mgfSpec;
141 this.saltLen = saltLen;
142 this.trailerField = trailerField;
143 }
144
145 /**
146 * Creates a new {@code PSSParameterSpec}
147 * using the specified salt length and other default values as
148 * defined in PKCS#1.
149 *
150 * @param saltLen the length of salt in bits to be used in PKCS#1
151 * PSS encoding.
152 * @exception IllegalArgumentException if {@code saltLen} is
153 * less than 0.
154 */
155 public PSSParameterSpec(int saltLen) {
156 if (saltLen < 0) {
157 throw new IllegalArgumentException("negative saltLen value: " +
158 saltLen);
159 }
160 this.saltLen = saltLen;
161 }
162
163 /**
164 * Returns the message digest algorithm name.
165 *
166 * @return the message digest algorithm name.
167 * @since 1.5
168 */
169 public String getDigestAlgorithm() {
170 return mdName;
171 }
172
|