summaryrefslogtreecommitdiff
path: root/repackaged_platform/bcprov/src/main/java/com/android/internal/org/bouncycastle/jcajce/spec/DHDomainParameterSpec.java
blob: e59e506c3801ad73059180e5d3ef703381f368a6 (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
128
129
130
131
/* GENERATED SOURCE. DO NOT MODIFY. */
package com.android.internal.org.bouncycastle.jcajce.spec;

import java.math.BigInteger;

import javax.crypto.spec.DHParameterSpec;

import com.android.internal.org.bouncycastle.crypto.params.DHParameters;
import com.android.internal.org.bouncycastle.crypto.params.DHValidationParameters;

/**
 * Extension class for DHParameterSpec that wraps a DHDomainParameters object and provides the q domain parameter.
 * @hide This class is not part of the Android public SDK API
 */
public class DHDomainParameterSpec
    extends DHParameterSpec
{
    private final BigInteger q;
    private final BigInteger j;
    private final int m;

    private DHValidationParameters validationParameters;

    /**
     * Base constructor - use the values in an existing set of domain parameters.
     *
     * @param domainParameters the Diffie-Hellman domain parameters to wrap.
     */
    public DHDomainParameterSpec(DHParameters domainParameters)
    {
        this(domainParameters.getP(), domainParameters.getQ(), domainParameters.getG(), domainParameters.getJ(), domainParameters.getM(), domainParameters.getL());
        this.validationParameters = domainParameters.getValidationParameters();
    }

    /**
     * Minimal constructor for parameters able to be used to verify a public key, or use with MQV.
     *
     * @param p the prime p defining the Galois field.
     * @param g the generator of the multiplicative subgroup of order g.
     * @param q specifies the prime factor of p - 1
     */
    public DHDomainParameterSpec(BigInteger p, BigInteger q, BigInteger g)
    {
        this(p, q, g, null, 0);
    }

    /**
     * Minimal constructor for parameters able to be used to verify a public key, or use with MQV, and a private value length.
     *
     * @param p the prime p defining the Galois field.
     * @param g the generator of the multiplicative subgroup of order g.
     * @param q specifies the prime factor of p - 1
     * @param l the maximum bit length for the private value.
     */
    public DHDomainParameterSpec(BigInteger p, BigInteger q, BigInteger g, int l)
    {
        this(p, q, g, null, l);
    }

    /**
     * X9.42 parameters with private value length.
     *
     * @param p the prime p defining the Galois field.
     * @param g the generator of the multiplicative subgroup of order g.
     * @param q specifies the prime factor of p - 1
     * @param j optionally specifies the value that satisfies the equation p = jq+1
     * @param l the maximum bit length for the private value.
     */
    public DHDomainParameterSpec(BigInteger p, BigInteger q, BigInteger g, BigInteger j, int l)
    {
        this(p, q, g, j, 0, l);
    }

    /**
     * Base constructor - the full domain parameter set.
     *
     * @param p the prime p defining the Galois field.
     * @param g the generator of the multiplicative subgroup of order g.
     * @param q specifies the prime factor of p - 1
     * @param j optionally specifies the value that satisfies the equation p = jq+1
     * @param m the minimum bit length for the private value.
     * @param l the maximum bit length for the private value.
     */
    public DHDomainParameterSpec(BigInteger p, BigInteger q, BigInteger g, BigInteger j, int m, int l)
    {
        super(p, g, l);
        this.q = q;
        this.j = j;
        this.m = m;
    }

    /**
     * Return the Q value for the domain parameter set.
     *
     * @return the value Q.
     */
    public BigInteger getQ()
    {
        return q;
    }

    /**
     * Return the J value for the domain parameter set if available.
     *
     * @return the value J, null otherwise.
     */
    public BigInteger getJ()
    {
        return j;
    }

    /**
     * Return the minimum bitlength for a private value to be generated from these parameters, 0 if not set.
     *
     * @return minimum bitlength for private value.
     */
    public int getM()
    {
        return m;
    }

    /**
     * Return the DHDomainParameters object we represent.
     *
     * @return the internal DHDomainParameters.
     */
    public DHParameters getDomainParameters()
    {
        return new DHParameters(getP(), getG(), q, m, getL(), j, validationParameters);
    }
}