2362N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This class generates parameters for the DSA algorithm. It uses a default 0N/A * prime modulus size of 1024 bits, which can be overwritten during 0N/A * @see java.security.AlgorithmParameters 0N/A * @see java.security.spec.AlgorithmParameterSpec 0N/A * @see DSAParameters 0N/A // the modulus length 0N/A // the source of randomness 0N/A // Make a SHA-1 hash function 0N/A * Initializes this parameter generator for a certain strength 0N/A * and source of randomness. 0N/A * @param strength the strength (size of prime) in bits 0N/A * @param random the source of randomness 0N/A * Bruce Schneier, "Applied Cryptography", 2nd Edition, 0N/A * Description of DSA: 0N/A * [...] The algorithm uses the following parameter: 0N/A * p=a prime number L bits long, when L ranges from 512 to 1024 and is 0N/A * a multiple of 64. [...] 0N/A (
"Prime size must range from 512 to 1024 " 0N/A +
"and be a multiple of 64");
0N/A * Initializes this parameter generator with a set of 0N/A * algorithm-specific parameter generation values. 0N/A * @param params the set of algorithm-specific parameter generation values 0N/A * @param random the source of randomness 0N/A * @exception InvalidAlgorithmParameterException if the given parameter 0N/A * generation values are inappropriate for this parameter generator 0N/A * Generates the parameters. 0N/A * @return the new AlgorithmParameters object 0N/A // this should never happen 0N/A // this should never happen, because we provide it 0N/A // this should never happen, because we provide it 0N/A * Generates the prime and subprime parameters for DSA, 0N/A * using the provided source of randomness. 0N/A * This method will generate new seeds until a suitable 0N/A * seed has been found. 0N/A * @param random the source of randomness to generate the 0N/A * @param L the size of <code>p</code>, in bits. 0N/A * @return an array of BigInteger, with <code>p</code> at index 0 and 0N/A * <code>q</code> at index 1. 0N/A for (
int i =
0; i <
20; i++) {
0N/A * Generates the prime and subprime parameters for DSA. 0N/A * <p>The seed parameter corresponds to the <code>SEED</code> parameter 0N/A * referenced in the FIPS specification of the DSA algorithm, 0N/A * and L is the size of <code>p</code>, in bits. 0N/A * @param seed the seed to generate the parameters 0N/A * @param L the size of <code>p</code>, in bits. 0N/A * @return an array of BigInteger, with <code>p</code> at index 0, 0N/A * <code>q</code> at index 1, the seed at index 2, and the counter value 0N/A * at index 3, or null if the seed does not yield suitable numbers. 0N/A /* Useful variables */ 0N/A int n = (L -
1) /
160;
0N/A int b = (L -
1) %
160;
0N/A /* Step 2 (Step 1 is getting seed). */ 0N/A /* Step 3: For q by setting the msb and lsb to 1 */ 0N/A for (
int k =
0; k <= n; k++) {
0N/A for (
int i =
1; i < n; i++) {
0N/A * Generates the <code>g</code> parameter for DSA. 0N/A * @param p the prime, <code>p</code>. 0N/A * @param q the subprime, <code>q</code>. 0N/A * @param the <code>g</code> 0N/A * Returns the SHA-1 digest of some data 0N/A * Converts the result of a BigInteger.toByteArray call to an exact 0N/A * signed magnitude representation for any positive number.