J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003-2006 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 | |
| 26 | package java.security.spec; |
| 27 | |
| 28 | import java.security.spec.AlgorithmParameterSpec; |
| 29 | |
| 30 | /** |
| 31 | * This class specifies the set of parameters used with mask generation |
| 32 | * function MGF1 in OAEP Padding and RSA-PSS signature scheme, as |
| 33 | * 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 | * MGF1Parameters ::= OAEP-PSSDigestAlgorthms |
| 40 | * </pre> |
| 41 | * where |
| 42 | * <pre> |
| 43 | * OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= { |
| 44 | * { OID id-sha1 PARAMETERS NULL }| |
| 45 | * { OID id-sha256 PARAMETERS NULL }| |
| 46 | * { OID id-sha384 PARAMETERS NULL }| |
| 47 | * { OID id-sha512 PARAMETERS NULL }, |
| 48 | * ... -- Allows for future expansion -- |
| 49 | * } |
| 50 | * </pre> |
| 51 | * @see PSSParameterSpec |
| 52 | * @see javax.crypto.spec.OAEPParameterSpec |
| 53 | * |
| 54 | * @author Valerie Peng |
| 55 | * |
| 56 | * @since 1.5 |
| 57 | */ |
| 58 | public class MGF1ParameterSpec implements AlgorithmParameterSpec { |
| 59 | |
| 60 | /** |
| 61 | * The MGF1ParameterSpec which uses "SHA-1" message digest. |
| 62 | */ |
| 63 | public static final MGF1ParameterSpec SHA1 = |
| 64 | new MGF1ParameterSpec("SHA-1"); |
| 65 | /** |
| 66 | * The MGF1ParameterSpec which uses "SHA-256" message digest. |
| 67 | */ |
| 68 | public static final MGF1ParameterSpec SHA256 = |
| 69 | new MGF1ParameterSpec("SHA-256"); |
| 70 | /** |
| 71 | * The MGF1ParameterSpec which uses "SHA-384" message digest. |
| 72 | */ |
| 73 | public static final MGF1ParameterSpec SHA384 = |
| 74 | new MGF1ParameterSpec("SHA-384"); |
| 75 | /** |
| 76 | * The MGF1ParameterSpec which uses SHA-512 message digest. |
| 77 | */ |
| 78 | public static final MGF1ParameterSpec SHA512 = |
| 79 | new MGF1ParameterSpec("SHA-512"); |
| 80 | |
| 81 | private String mdName; |
| 82 | |
| 83 | /** |
| 84 | * Constructs a parameter set for mask generation function MGF1 |
| 85 | * as defined in the PKCS #1 standard. |
| 86 | * |
| 87 | * @param mdName the algorithm name for the message digest |
| 88 | * used in this mask generation function MGF1. |
| 89 | * @exception NullPointerException if <code>mdName</code> is null. |
| 90 | */ |
| 91 | public MGF1ParameterSpec(String mdName) { |
| 92 | if (mdName == null) { |
| 93 | throw new NullPointerException("digest algorithm is null"); |
| 94 | } |
| 95 | this.mdName = mdName; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Returns the algorithm name of the message digest used by the mask |
| 100 | * generation function. |
| 101 | * |
| 102 | * @return the algorithm name of the message digest. |
| 103 | */ |
| 104 | public String getDigestAlgorithm() { |
| 105 | return mdName; |
| 106 | } |
| 107 | } |