KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > security > spec > PSSParameterSpec


1 /*
2  * @(#)PSSParameterSpec.java 1.6 04/01/27
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.security.spec;
9
10 import java.math.BigInteger JavaDoc;
11 import java.security.spec.MGF1ParameterSpec JavaDoc;
12
13 /**
14  * This class specifies a parameter spec for RSA-PSS signature scheme,
15  * as defined in the
16  * <a HREF="http://www.rsa.com/rsalabs/pubs/PKCS/html/pkcs-1.html">
17  * PKCS#1 v2.1</a> standard.
18  *
19  * <p>Its ASN.1 definition in PKCS#1 standard is described below:
20  * <pre>
21  * RSASSA-PSS-params ::= SEQUENCE {
22  * hashAlgorithm [0] OAEP-PSSDigestAlgorithms DEFAULT sha1,
23  * maskGenAlgorithm [1] PKCS1MGFAlgorithms DEFAULT mgf1SHA1,
24  * saltLength [2] INTEGER DEFAULT 20,
25  * trailerField [3] INTEGER DEFAULT 1
26  * }
27  * </pre>
28  * where
29  * <pre>
30  * OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= {
31  * { OID id-sha1 PARAMETERS NULL }|
32  * { OID id-sha256 PARAMETERS NULL }|
33  * { OID id-sha384 PARAMETERS NULL }|
34  * { OID id-sha512 PARAMETERS NULL },
35  * ... -- Allows for future expansion --
36  * }
37  *
38  * PKCS1MGFAlgorithms ALGORITHM-IDENTIFIER ::= {
39  * { OID id-mgf1 PARAMETERS OAEP-PSSDigestAlgorithms },
40  * ... -- Allows for future expansion --
41  * }
42  * </pre>
43  * <p>Note: the PSSParameterSpec.DEFAULT uses the following:
44  * message digest -- "SHA-1"
45  * mask generation function (mgf) -- "MGF1"
46  * parameters for mgf -- MGF1ParameterSpec.SHA1
47  * SaltLength -- 20
48  * TrailerField -- 1
49  *
50  * @see MGF1ParameterSpec
51  * @see AlgorithmParameterSpec
52  * @see java.security.Signature
53  *
54  * @author Valerie Peng
55  *
56  * @version 1.6 04/01/27
57  *
58  * @since 1.4
59  */

60
61 public class PSSParameterSpec implements AlgorithmParameterSpec JavaDoc {
62
63     private String JavaDoc mdName = "SHA-1";
64     private String JavaDoc mgfName = "MGF1";
65     private AlgorithmParameterSpec JavaDoc mgfSpec = MGF1ParameterSpec.SHA1;
66     private int saltLen = 20;
67     private int trailerField = 1;
68
69     /**
70      * The PSS parameter set with all default values.
71      */

72     public static final PSSParameterSpec JavaDoc DEFAULT = new PSSParameterSpec JavaDoc();
73
74     /**
75      * Constructs a new <code>PSSParameterSpec</code> as defined in
76      * the PKCS #1 standard using the default values.
77      */

78     private PSSParameterSpec() {
79     }
80
81     /**
82      * Creates a new <code>PSSParameterSpec</code> as defined in
83      * the PKCS #1 standard using the specified message digest,
84      * mask generation function, parameters for mask generation
85      * function, salt length, and trailer field values.
86      *
87      * @param mdName the algorithm name of the hash function.
88      * @param mgfName the algorithm name of the mask generation
89      * function.
90      * @param mgfSpec the parameters for the mask generation
91      * function. If null is specified, null will be returned by
92      * getMGFParameters().
93      * @param saltLen the length of salt.
94      * @param trailerField the value of the trailer field.
95      * @exception NullPointerException if <code>mdName</code>,
96      * or <code>mgfName</code> is null.
97      * @exception IllegalArgumentException if <code>saltLen</code>
98      * or <code>trailerField</code> is less than 0.
99      * @since 1.5
100      */

101     public PSSParameterSpec(String JavaDoc mdName, String JavaDoc mgfName,
102                 AlgorithmParameterSpec JavaDoc mgfSpec,
103                 int saltLen, int trailerField) {
104     if (mdName == null) {
105         throw new NullPointerException JavaDoc("digest algorithm is null");
106     }
107     if (mgfName == null) {
108         throw new NullPointerException JavaDoc("mask generation function " +
109                        "algorithm is null");
110     }
111     if (saltLen < 0) {
112         throw new IllegalArgumentException JavaDoc("negative saltLen value: " +
113                            saltLen);
114     }
115     if (trailerField < 0) {
116         throw new IllegalArgumentException JavaDoc("negative trailerField: " +
117                            trailerField);
118     }
119         this.mdName = mdName;
120         this.mgfName = mgfName;
121         this.mgfSpec = mgfSpec;
122     this.saltLen = saltLen;
123     this.trailerField = trailerField;
124     }
125
126     /**
127      * Creates a new <code>PSSParameterSpec</code>
128      * using the specified salt length and other default values as
129      * defined in PKCS#1.
130      *
131      * @param saltLen the length of salt in bits to be used in PKCS#1
132      * PSS encoding.
133      * @exception IllegalArgumentException if <code>saltLen</code> is
134      * less than 0.
135      */

136     public PSSParameterSpec(int saltLen) {
137     if (saltLen < 0) {
138         throw new IllegalArgumentException JavaDoc("negative saltLen value: " +
139                            saltLen);
140     }
141     this.saltLen = saltLen;
142     }
143     
144     /**
145      * Returns the message digest algorithm name.
146      *
147      * @return the message digest algorithm name.
148      * @since 1.5
149      */

150     public String JavaDoc getDigestAlgorithm() {
151         return mdName;
152     }
153
154     /**
155      * Returns the mask generation function algorithm name.
156      *
157      * @return the mask generation function algorithm name.
158      *
159      * @since 1.5
160      */

161     public String JavaDoc getMGFAlgorithm() {
162         return mgfName;
163     }
164
165     /**
166      * Returns the parameters for the mask generation function.
167      *
168      * @return the parameters for the mask generation function.
169      * @since 1.5
170      */

171     public AlgorithmParameterSpec JavaDoc getMGFParameters() {
172         return mgfSpec;
173     }
174
175     /**
176      * Returns the salt length in bits.
177      *
178      * @return the salt length.
179      */

180     public int getSaltLength() {
181     return saltLen;
182     }
183
184     /**
185      * Returns the value for the trailer field, i.e. bc in PKCS#1 v2.1.
186      *
187      * @return the value for the trailer field, i.e. bc in PKCS#1 v2.1.
188      * @since 1.5
189      */

190     public int getTrailerField() {
191     return trailerField;
192     }
193 }
194
Popular Tags