Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NaccacheSternKeyGenerationParameters.java « params « crypto « spongycastle « org « java « main « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0b5998b69d10d83ad55751e5bafc7a7a28d1277 (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
package org.spongycastle.crypto.params;

import java.security.SecureRandom;

import org.spongycastle.crypto.KeyGenerationParameters;

/**
 * Parameters for NaccacheStern public private key generation. For details on
 * this cipher, please see
 * 
 * http://www.gemplus.com/smart/rd/publications/pdf/NS98pkcs.pdf
 */
public class NaccacheSternKeyGenerationParameters extends KeyGenerationParameters
{

    // private BigInteger publicExponent;
    private int certainty;

    private int cntSmallPrimes;

    private boolean debug = false;

    /**
     * Parameters for generating a NaccacheStern KeyPair.
     * 
     * @param random
     *            The source of randomness
     * @param strength
     *            The desired strength of the Key in Bits
     * @param certainty
     *            the probability that the generated primes are not really prime
     *            as integer: 2^(-certainty) is then the probability
     * @param cntSmallPrimes
     *            How many small key factors are desired
     */
    public NaccacheSternKeyGenerationParameters(SecureRandom random, int strength, int certainty, int cntSmallPrimes)
    {
        this(random, strength, certainty, cntSmallPrimes, false);
    }

    /**
     * Parameters for a NaccacheStern KeyPair.
     * 
     * @param random
     *            The source of randomness
     * @param strength
     *            The desired strength of the Key in Bits
     * @param certainty
     *            the probability that the generated primes are not really prime
     *            as integer: 2^(-certainty) is then the probability
     * @param cntSmallPrimes
     *            How many small key factors are desired
     * @param debug
     *            Turn debugging on or off (reveals secret information, use with
     *            caution)
     */
    public NaccacheSternKeyGenerationParameters(SecureRandom random,
            int strength, int certainty, int cntSmallPrimes, boolean debug)
    {
        super(random, strength);

        this.certainty = certainty;
        if (cntSmallPrimes % 2 == 1)
        {
            throw new IllegalArgumentException("cntSmallPrimes must be a multiple of 2");
        }
        if (cntSmallPrimes < 30)
        {
            throw new IllegalArgumentException("cntSmallPrimes must be >= 30 for security reasons");
        }
        this.cntSmallPrimes = cntSmallPrimes;

        this.debug = debug;
    }

    /**
     * @return Returns the certainty.
     */
    public int getCertainty()
    {
        return certainty;
    }

    /**
     * @return Returns the cntSmallPrimes.
     */
    public int getCntSmallPrimes()
    {
        return cntSmallPrimes;
    }

    public boolean isDebug()
    {
        return debug;
    }

}