History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/java/security/spec/PSSParameterSpec.java (1 of 18352 files). Show all

Unified · Split

java/pkg/java/security/spec/PSSParameterSpec.java+211−0
@@ -0,0 +1,211 @@
1+/*
2+ * Copyright (c) 2001, 2006, 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 java.security.spec;
27+
28+import java.math.BigInteger;
29+import java.security.spec.MGF1ParameterSpec;
30+
31+/**
32+ * This class specifies a parameter spec for RSA-PSS signature scheme,
33+ * as defined in the
34+ * <a href="http://www.ietf.org/rfc/rfc3447.txt">PKCS#1 v2.1</a>
35+ * standard.
36+ *
37+ * <p>Its ASN.1 definition in PKCS#1 standard is described below:
38+ * <pre>
39+ * RSASSA-PSS-params ::= SEQUENCE {
40+ * hashAlgorithm [0] OAEP-PSSDigestAlgorithms DEFAULT sha1,
41+ * maskGenAlgorithm [1] PKCS1MGFAlgorithms DEFAULT mgf1SHA1,
42+ * saltLength [2] INTEGER DEFAULT 20,
43+ * trailerField [3] INTEGER DEFAULT 1
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+ *
56+ * PKCS1MGFAlgorithms ALGORITHM-IDENTIFIER ::= {
57+ * { OID id-mgf1 PARAMETERS OAEP-PSSDigestAlgorithms },
58+ * ... -- Allows for future expansion --
59+ * }
60+ * </pre>
61+ * <p>Note: the PSSParameterSpec.DEFAULT uses the following:
62+ * message digest -- "SHA-1"
63+ * mask generation function (mgf) -- "MGF1"
64+ * parameters for mgf -- MGF1ParameterSpec.SHA1
65+ * SaltLength -- 20
66+ * TrailerField -- 1
67+ *
68+ * @see MGF1ParameterSpec
69+ * @see AlgorithmParameterSpec
70+ * @see java.security.Signature
71+ *
72+ * @author Valerie Peng
73+ *
74+ *
75+ * @since 1.4
76+ */
77+
78+public class PSSParameterSpec implements AlgorithmParameterSpec {
79+
80+ private String mdName = "SHA-1";
81+ private String mgfName = "MGF1";
82+ private AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
83+ private int saltLen = 20;
84+ private int trailerField = 1;
85+
86+ /**
87+ * The PSS parameter set with all default values.
88+ * @since 1.5
89+ */
90+ public static final PSSParameterSpec DEFAULT = new PSSParameterSpec();
91+
92+ /**
93+ * Constructs a new <code>PSSParameterSpec</code> as defined in
94+ * the PKCS #1 standard using the default values.
95+ */
96+ private PSSParameterSpec() {
97+ }
98+
99+ /**
100+ * Creates a new <code>PSSParameterSpec</code> as defined in
101+ * the PKCS #1 standard using the specified message digest,
102+ * mask generation function, parameters for mask generation
103+ * function, salt length, and trailer field values.
104+ *
105+ * @param mdName the algorithm name of the hash function.
106+ * @param mgfName the algorithm name of the mask generation
107+ * function.
108+ * @param mgfSpec the parameters for the mask generation
109+ * function. If null is specified, null will be returned by
110+ * getMGFParameters().
111+ * @param saltLen the length of salt.
112+ * @param trailerField the value of the trailer field.
113+ * @exception NullPointerException if <code>mdName</code>,
114+ * or <code>mgfName</code> is null.
115+ * @exception IllegalArgumentException if <code>saltLen</code>
116+ * or <code>trailerField</code> is less than 0.
117+ * @since 1.5
118+ */
119+ public PSSParameterSpec(String mdName, String mgfName,
120+ AlgorithmParameterSpec mgfSpec,
121+ int saltLen, int trailerField) {
122+ if (mdName == null) {
123+ throw new NullPointerException("digest algorithm is null");
124+ }
125+ if (mgfName == null) {
126+ throw new NullPointerException("mask generation function " +
127+ "algorithm is null");
128+ }
129+ if (saltLen < 0) {
130+ throw new IllegalArgumentException("negative saltLen value: " +
131+ saltLen);
132+ }
133+ if (trailerField < 0) {
134+ throw new IllegalArgumentException("negative trailerField: " +
135+ trailerField);
136+ }
137+ this.mdName = mdName;
138+ this.mgfName = mgfName;
139+ this.mgfSpec = mgfSpec;
140+ this.saltLen = saltLen;
141+ this.trailerField = trailerField;
142+ }
143+
144+ /**
145+ * Creates a new <code>PSSParameterSpec</code>
146+ * using the specified salt length and other default values as
147+ * defined in PKCS#1.
148+ *
149+ * @param saltLen the length of salt in bits to be used in PKCS#1
150+ * PSS encoding.
151+ * @exception IllegalArgumentException if <code>saltLen</code> is
152+ * less than 0.
153+ */
154+ public PSSParameterSpec(int saltLen) {
155+ if (saltLen < 0) {
156+ throw new IllegalArgumentException("negative saltLen value: " +
157+ saltLen);
158+ }
159+ this.saltLen = saltLen;
160+ }
161+
162+ /**
163+ * Returns the message digest algorithm name.
164+ *
165+ * @return the message digest algorithm name.
166+ * @since 1.5
167+ */
168+ public String getDigestAlgorithm() {
169+ return mdName;
170+ }
171+
172+ /**
173+ * Returns the mask generation function algorithm name.
174+ *
175+ * @return the mask generation function algorithm name.
176+ *
177+ * @since 1.5
178+ */
179+ public String getMGFAlgorithm() {
180+ return mgfName;
181+ }
182+
183+ /**
184+ * Returns the parameters for the mask generation function.
185+ *
186+ * @return the parameters for the mask generation function.
187+ * @since 1.5
188+ */
189+ public AlgorithmParameterSpec getMGFParameters() {
190+ return mgfSpec;
191+ }
192+
193+ /**
194+ * Returns the salt length in bits.
195+ *
196+ * @return the salt length.
197+ */
198+ public int getSaltLength() {
199+ return saltLen;
200+ }
201+
202+ /**
203+ * Returns the value for the trailer field, i.e. bc in PKCS#1 v2.1.
204+ *
205+ * @return the value for the trailer field, i.e. bc in PKCS#1 v2.1.
206+ * @since 1.5
207+ */
208+ public int getTrailerField() {
209+ return trailerField;
210+ }
211+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t