01: package org.bouncycastle.crypto.params;
02:
03: import java.security.SecureRandom;
04:
05: import org.bouncycastle.crypto.KeyGenerationParameters;
06:
07: /**
08: * Parameters for NaccacheStern public private key generation. For details on
09: * this cipher, please see
10: *
11: * http://www.gemplus.com/smart/rd/publications/pdf/NS98pkcs.pdf
12: */
13: public class NaccacheSternKeyGenerationParameters extends
14: KeyGenerationParameters {
15:
16: // private BigInteger publicExponent;
17: private int certainty;
18:
19: private int cntSmallPrimes;
20:
21: private boolean debug = false;
22:
23: /**
24: * Parameters for generating a NaccacheStern KeyPair.
25: *
26: * @param random
27: * The source of randomness
28: * @param strength
29: * The desired strength of the Key in Bits
30: * @param certainty
31: * the probability that the generated primes are not really prime
32: * as integer: 2^(-certainty) is then the probability
33: * @param cntSmallPrimes
34: * How many small key factors are desired
35: */
36: public NaccacheSternKeyGenerationParameters(SecureRandom random,
37: int strength, int certainty, int cntSmallPrimes) {
38: this (random, strength, certainty, cntSmallPrimes, false);
39: }
40:
41: /**
42: * Parameters for a NaccacheStern KeyPair.
43: *
44: * @param random
45: * The source of randomness
46: * @param strength
47: * The desired strength of the Key in Bits
48: * @param certainty
49: * the probability that the generated primes are not really prime
50: * as integer: 2^(-certainty) is then the probability
51: * @param cntSmallPrimes
52: * How many small key factors are desired
53: * @param debug
54: * Turn debugging on or off (reveals secret information, use with
55: * caution)
56: */
57: public NaccacheSternKeyGenerationParameters(SecureRandom random,
58: int strength, int certainty, int cntSmallPrimes,
59: boolean debug) {
60: super (random, strength);
61:
62: this .certainty = certainty;
63: if (cntSmallPrimes % 2 == 1) {
64: throw new IllegalArgumentException(
65: "cntSmallPrimes must be a multiple of 2");
66: }
67: if (cntSmallPrimes < 30) {
68: throw new IllegalArgumentException(
69: "cntSmallPrimes must be >= 30 for security reasons");
70: }
71: this .cntSmallPrimes = cntSmallPrimes;
72:
73: this .debug = debug;
74: }
75:
76: /**
77: * @return Returns the certainty.
78: */
79: public int getCertainty() {
80: return certainty;
81: }
82:
83: /**
84: * @return Returns the cntSmallPrimes.
85: */
86: public int getCntSmallPrimes() {
87: return cntSmallPrimes;
88: }
89:
90: public boolean isDebug() {
91: return debug;
92: }
93:
94: }
|