summaryrefslogtreecommitdiffstats
path: root/luni/src/main/java/javax/crypto/spec/OAEPParameterSpec.java
blob: 340e57fff029dfc15785a4483270c8e6cf433cd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package javax.crypto.spec;

import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.MGF1ParameterSpec;

/**
 * The algorithm parameter specification for the <i>OAEP Padding</i> algorithm.
 * <p>
 * This padding algorithm is defined in the <a
 * href="http://www.ietf.org/rfc/rfc3447.txt">PKCS #1</a> standard.
 */
public class OAEPParameterSpec implements AlgorithmParameterSpec {

    private final String mdName;
    private final String mgfName;
    private final AlgorithmParameterSpec mgfSpec;
    private final PSource pSrc;

    /**
     * The algorithm parameter instance with default values.
     * <p>
     * It uses the following parameters:
     * <ul><li>message digest : <code>"SHA-1"</code></li>
     * <li>mask generation function (<i>mgf</i>) : <code>"MGF1"</code></li>
     * <li>parameters for the <i>mgf</i> : "SHA-1" {@link MGF1ParameterSpec#SHA1}</li>
     * <li>the source of the label <code>L</code>: {@link PSource.PSpecified#DEFAULT}</li>
     * </ul>
     */
    public static final OAEPParameterSpec DEFAULT = new OAEPParameterSpec();

    private OAEPParameterSpec() {
        this.mdName = "SHA-1";
        this.mgfName = "MGF1";
        this.mgfSpec = MGF1ParameterSpec.SHA1;
        this.pSrc = PSource.PSpecified.DEFAULT;
    }

    /**
     * Creates a new <code>OAEPParameterSpec</code> instance with the specified
     * <i>message digest</i> algorithm name, <i>mask generation function</i>
     * (<i>mgf</i>) algorithm name, <i>parameters</i> for the <i>mgf</i>
     * algorithm and the <i>source of the label <code>L</code></i>.
     *
     * @param mdName
     *            the message digest algorithm name.
     * @param mgfName
     *            the mask generation function algorithm name.
     * @param mgfSpec
     *            the algorithm parameter specification for the mask generation
     *            function algorithm.
     * @param pSrc
     *            the source of the label <code>L</code>.
     * @throws NullPointerException
     *             if one of <code>mdName</code>, <code>mgfName</code> or
     *             <code>pSrc</code> is null.
     */
    public OAEPParameterSpec(String mdName, String mgfName,
                                AlgorithmParameterSpec mgfSpec, PSource pSrc) {
        if (mdName == null) {
            throw new NullPointerException("mdName == null");
        } else if (mgfName == null) {
            throw new NullPointerException("mgfName == null");
        } else if (pSrc == null) {
            throw new NullPointerException("pSrc == null");
        }
        this.mdName = mdName;
        this.mgfName = mgfName;
        this.mgfSpec = mgfSpec;
        this.pSrc = pSrc;
    }

    /**
     * Returns the algorithm name of the <i>message digest</i>.
     *
     * @return the algorithm name of the message digest.
     */
    public String getDigestAlgorithm() {
        return mdName;
    }

    /**
     * Returns the algorithm name of the <i>mask generation function</i>.
     *
     * @return the algorithm name of the mask generation function.
     */
    public String getMGFAlgorithm() {
        return mgfName;
    }

    /**
     * Returns the algorithm parameter specification for the mask generation
     * function algorithm.
     *
     * @return the algorithm parameter specification for the mask generation
     *         function algorithm.
     */
    public AlgorithmParameterSpec getMGFParameters() {
        return mgfSpec;
    }

    /**
     * Returns the source of the label <code>L</code>.
     *
     * @return the source of the label <code>L</code>.
     */
    public PSource getPSource() {
        return pSrc;
    }
}