Home | History | Annotate | Download | only in spec
      1 /*
      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
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     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.
     16  */
     17 
     18 package javax.crypto.spec;
     19 
     20 import java.security.spec.AlgorithmParameterSpec;
     21 import java.security.spec.MGF1ParameterSpec;
     22 
     23 /**
     24  * The algorithm parameter specification for the <i>OAEP Padding</i> algorithm.
     25  * <p>
     26  * This padding algorithm is defined in the <a
     27  * href="http://www.ietf.org/rfc/rfc3447.txt">PKCS #1</a> standard.
     28  */
     29 public class OAEPParameterSpec implements AlgorithmParameterSpec {
     30 
     31     private final String mdName;
     32     private final String mgfName;
     33     private final AlgorithmParameterSpec mgfSpec;
     34     private final PSource pSrc;
     35 
     36     /**
     37      * The algorithm parameter instance with default values.
     38      * <p>
     39      * It uses the following parameters:
     40      * <ul><li>message digest : <code>"SHA-1"</code></li>
     41      * <li>mask generation function (<i>mgf</i>) : <code>"MGF1"</code></li>
     42      * <li>parameters for the <i>mgf</i> : "SHA-1" {@link MGF1ParameterSpec#SHA1}</li>
     43      * <li>the source of the label <code>L</code>: {@link PSource.PSpecified#DEFAULT}</li>
     44      * </ul>
     45      */
     46     public static final OAEPParameterSpec DEFAULT = new OAEPParameterSpec();
     47 
     48     private OAEPParameterSpec() {
     49         this.mdName = "SHA-1";
     50         this.mgfName = "MGF1";
     51         this.mgfSpec = MGF1ParameterSpec.SHA1;
     52         this.pSrc = PSource.PSpecified.DEFAULT;
     53     }
     54 
     55     /**
     56      * Creates a new <code>OAEPParameterSpec</code> instance with the specified
     57      * <i>message digest</i> algorithm name, <i>mask generation function</i>
     58      * (<i>mgf</i>) algorithm name, <i>parameters</i> for the <i>mgf</i>
     59      * algorithm and the <i>source of the label <code>L</code></i>.
     60      *
     61      * @param mdName
     62      *            the message digest algorithm name.
     63      * @param mgfName
     64      *            the mask generation function algorithm name.
     65      * @param mgfSpec
     66      *            the algorithm parameter specification for the mask generation
     67      *            function algorithm.
     68      * @param pSrc
     69      *            the source of the label <code>L</code>.
     70      * @throws NullPointerException
     71      *             if one of <code>mdName</code>, <code>mgfName</code> or
     72      *             <code>pSrc</code> is null.
     73      */
     74     public OAEPParameterSpec(String mdName, String mgfName,
     75                                 AlgorithmParameterSpec mgfSpec, PSource pSrc) {
     76         if ((mdName == null) || (mgfName == null) || (pSrc == null)) {
     77             throw new NullPointerException();
     78         }
     79         this.mdName = mdName;
     80         this.mgfName = mgfName;
     81         this.mgfSpec = mgfSpec;
     82         this.pSrc = pSrc;
     83     }
     84 
     85     /**
     86      * Returns the algorithm name of the <i>message digest</i>.
     87      *
     88      * @return the algorithm name of the message digest.
     89      */
     90     public String getDigestAlgorithm() {
     91         return mdName;
     92     }
     93 
     94     /**
     95      * Returns the algorithm name of the <i>mask generation function</i>.
     96      *
     97      * @return the algorithm name of the mask generation function.
     98      */
     99     public String getMGFAlgorithm() {
    100         return mgfName;
    101     }
    102 
    103     /**
    104      * Returns the algorithm parameter specification for the mask generation
    105      * function algorithm.
    106      *
    107      * @return the algorithm parameter specification for the mask generation
    108      *         function algorithm.
    109      */
    110     public AlgorithmParameterSpec getMGFParameters() {
    111         return mgfSpec;
    112     }
    113 
    114     /**
    115      * Returns the source of the label <code>L</code>.
    116      *
    117      * @return the source of the label <code>L</code>.
    118      */
    119     public PSource getPSource() {
    120         return pSrc;
    121     }
    122 }
    123 
    124