2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package java.security.spec;
21 * The parameter specification for the RSA-PSS Signature scheme.
24 * href="http://www.rsa.com/rsalabs/pubs/PKCS/html/pkcs-1.html">PKCS #1 v2.1</a>
27 public class PSSParameterSpec implements AlgorithmParameterSpec {
30 * The default parameter specification. It specifies the following parameters:
32 * <li>message digest: {@code "SHA-1"}</li>
33 * <li>mask generation function (<i>mgf</i>): {@code "MGF1"}</li>
34 * <li>parameters for the <i>mgf</i>: {@link MGF1ParameterSpec#SHA1}</li>
35 * <li>salt length: {@code 20}</li>
36 * <li>trailer field: {@code -1}</li>
39 public static final PSSParameterSpec DEFAULT = new PSSParameterSpec(20);
41 // Message digest algorithm name
42 private final String mdName;
43 // Mask generation function algorithm name
44 private final String mgfName;
45 // Mask generation function parameters
46 private final AlgorithmParameterSpec mgfSpec;
47 // Trailer field value
48 private final int trailerField;
49 // Salt length in bits
50 private final int saltLen;
53 * Creates a new {@code PSSParameterSpec} with the specified salt length
54 * and the default values.
57 * the salt length (in bits).
58 * @throws IllegalArgumentException
59 * if {@code saltLen} is negative.
61 public PSSParameterSpec(int saltLen) {
63 throw new IllegalArgumentException("saltLen < 0");
65 this.saltLen = saltLen;
66 this.mdName = "SHA-1";
67 this.mgfName = "MGF1";
68 this.mgfSpec = MGF1ParameterSpec.SHA1;
69 this.trailerField = 1;
73 * Creates a new {@code PSSParameterSpec} with the specified message digest
74 * name, mask generation function name, mask generation function parameters,
75 * salt length, and trailer field value.
78 * the name of the message digest algorithm.
80 * the name of the mask generation function algorithm.
82 * the parameter for the mask generation function algorithm.
84 * the salt length (in bits).
86 * the trailer field value.
87 * @throws IllegalArgumentException
88 * if {@code saltLen} or {@code trailerField} is negative.
90 public PSSParameterSpec(String mdName, String mgfName,
91 AlgorithmParameterSpec mgfSpec, int saltLen, int trailerField) {
94 throw new NullPointerException("mdName == null");
96 if (mgfName == null) {
97 throw new NullPointerException("mgfName == null");
100 throw new IllegalArgumentException("saltLen < 0");
102 if (trailerField < 0) {
103 throw new IllegalArgumentException("trailerField < 0");
105 this.mdName = mdName;
106 this.mgfName = mgfName;
107 this.mgfSpec = mgfSpec;
108 this.saltLen = saltLen;
109 this.trailerField = trailerField;
113 * Returns the length of the salt (in bits).
115 * @return the length of the salt (in bits).
117 public int getSaltLength() {
122 * Returns the name of the message digest algorithm.
124 * @return the name of the message digest algorithm.
126 public String getDigestAlgorithm() {
131 * Returns the name of the mask generation function algorithm.
133 * @return the name of the mask generation function algorithm.
135 public String getMGFAlgorithm() {
140 * Returns the parameter for the mask generation function algorithm.
142 * @return the parameter for the mask generation function algorithm, or
143 * {@code null} if none specified.
145 public AlgorithmParameterSpec getMGFParameters() {
150 * Returns the trailer field value.
152 * @return the trailer field value.
154 public int getTrailerField() {