Imported GNU Classpath 0.92

2006-08-14  Mark Wielaard  <mark@klomp.org>

       Imported GNU Classpath 0.92
       * HACKING: Add more importing hints. Update automake version
       requirement.

       * configure.ac (gconf-peer): New enable AC argument.
       Add --disable-gconf-peer and --enable-default-preferences-peer
       to classpath configure when gconf is disabled.
       * scripts/makemake.tcl: Set gnu/java/util/prefs/gconf and
       gnu/java/awt/dnd/peer/gtk to bc. Classify
       gnu/java/security/Configuration.java as generated source file.

       * gnu/java/lang/management/VMGarbageCollectorMXBeanImpl.java,
       gnu/java/lang/management/VMMemoryPoolMXBeanImpl.java,
       gnu/java/lang/management/VMClassLoadingMXBeanImpl.java,
       gnu/java/lang/management/VMRuntimeMXBeanImpl.java,
       gnu/java/lang/management/VMMemoryManagerMXBeanImpl.java,
       gnu/java/lang/management/VMThreadMXBeanImpl.java,
       gnu/java/lang/management/VMMemoryMXBeanImpl.java,
       gnu/java/lang/management/VMCompilationMXBeanImpl.java: New VM stub
       classes.
       * java/lang/management/VMManagementFactory.java: Likewise.
       * java/net/VMURLConnection.java: Likewise.
       * gnu/java/nio/VMChannel.java: Likewise.

       * java/lang/Thread.java (getState): Add stub implementation.
       * java/lang/Class.java (isEnum): Likewise.
       * java/lang/Class.h (isEnum): Likewise.

       * gnu/awt/xlib/XToolkit.java (getClasspathTextLayoutPeer): Removed.

       * javax/naming/spi/NamingManager.java: New override for StackWalker
       functionality.

       * configure, sources.am, Makefile.in, gcj/Makefile.in,
       include/Makefile.in, testsuite/Makefile.in: Regenerated.

From-SVN: r116139
This commit is contained in:
Mark Wielaard 2006-08-14 23:12:35 +00:00
parent abab460491
commit ac1ed908de
1294 changed files with 99479 additions and 35933 deletions

View file

@ -49,31 +49,26 @@ import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
/**
* <p>Utility methods related to the RSA algorithm.</p>
*
* <p>References:</p>
* Utility methods related to the RSA algorithm.
* <p>
* References:
* <ol>
* <li><a href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
* RSA-PSS Signature Scheme with Appendix, part B.</a><br>
* Primitive specification and supporting documentation.<br>
* Jakob Jonsson and Burt Kaliski.</li>
*
* <li><a href="http://www.ietf.org/rfc/rfc3447.txt">Public-Key Cryptography
* Standards (PKCS) #1:</a><br>
* RSA Cryptography Specifications Version 2.1.<br>
* Jakob Jonsson and Burt Kaliski.</li>
*
* <li><a href="http://crypto.stanford.edu/~dabo/abstracts/ssl-timing.html">
* Remote timing attacks are practical</a><br>
* D. Boneh and D. Brumley.</li>
* <li><a
* href="http://www.cosic.esat.kuleuven.ac.be/nessie/workshop/submissions/rsa-pss.zip">
* RSA-PSS Signature Scheme with Appendix, part B.</a><br>
* Primitive specification and supporting documentation.<br>
* Jakob Jonsson and Burt Kaliski.</li>
* <li><a href="http://www.ietf.org/rfc/rfc3447.txt">Public-Key Cryptography
* Standards (PKCS) #1:</a><br>
* RSA Cryptography Specifications Version 2.1.<br>
* Jakob Jonsson and Burt Kaliski.</li>
* <li><a href="http://crypto.stanford.edu/~dabo/abstracts/ssl-timing.html">
* Remote timing attacks are practical</a><br>
* D. Boneh and D. Brumley.</li>
* </ol>
*/
public class RSA
{
// Constants and variables
// -------------------------------------------------------------------------
private static final BigInteger ZERO = BigInteger.ZERO;
private static final BigInteger ONE = BigInteger.ONE;
@ -81,37 +76,28 @@ public class RSA
/** Our default source of randomness. */
private static final PRNG prng = PRNG.getInstance();
// Constructor(s)
// -------------------------------------------------------------------------
/** Trivial private constructor to enforce Singleton pattern. */
private RSA()
{
super();
}
// Class methods
// -------------------------------------------------------------------------
// Signature and verification methods --------------------------------------
/**
* <p>An implementation of the <b>RSASP</b> method: Assuming that the
* designated RSA private key is a valid one, this method computes a
* <i>signature representative</i> for a designated <i>message
* representative</i> signed by the holder of the designated RSA private
* key.<p>
*
* An implementation of the <b>RSASP</b> method: Assuming that the designated
* RSA private key is a valid one, this method computes a <i>signature
* representative</i> for a designated <i>message representative</i> signed
* by the holder of the designated RSA private key.
*
* @param K the RSA private key.
* @param m the <i>message representative</i>: an integer between
* <code>0</code> and <code>n - 1</code>, where <code>n</code> is the RSA
* <i>modulus</i>.
* <code>0</code> and <code>n - 1</code>, where <code>n</code>
* is the RSA <i>modulus</i>.
* @return the <i>signature representative</i>, an integer between
* <code>0</code> and <code>n - 1</code>, where <code>n</code> is the RSA
* <i>modulus</i>.
* <code>0</code> and <code>n - 1</code>, where <code>n</code>
* is the RSA <i>modulus</i>.
* @throws ClassCastException if <code>K</code> is not an RSA one.
* @throws IllegalArgumentException if <code>m</code> (the <i>message
* representative</i>) is out of range.
* representative</i>) is out of range.
*/
public static final BigInteger sign(final PrivateKey K, final BigInteger m)
{
@ -121,27 +107,27 @@ public class RSA
}
catch (IllegalArgumentException x)
{
throw new IllegalArgumentException(
"message representative out of range");
throw new IllegalArgumentException("message representative out of range");
}
}
/**
* <p>An implementation of the <b>RSAVP</b> method: Assuming that the
* designated RSA public key is a valid one, this method computes a
* <i>message representative</i> for the designated <i>signature
* representative</i> generated by an RSA private key, for a message
* intended for the holder of the designated RSA public key.</p>
*
* An implementation of the <b>RSAVP</b> method: Assuming that the designated
* RSA public key is a valid one, this method computes a <i>message
* representative</i> for the designated <i>signature representative</i>
* generated by an RSA private key, for a message intended for the holder of
* the designated RSA public key.
*
* @param K the RSA public key.
* @param s the <i>signature representative</i>, an integer between
* <code>0</code> and <code>n - 1</code>, where <code>n</code> is the RSA
* <i>modulus</i>.
* <code>0</code> and <code>n - 1</code>, where <code>n</code>
* is the RSA <i>modulus</i>.
* @return a <i>message representative</i>: an integer between <code>0</code>
* and <code>n - 1</code>, where <code>n</code> is the RSA <i>modulus</i>.
* and <code>n - 1</code>, where <code>n</code> is the RSA
* <i>modulus</i>.
* @throws ClassCastException if <code>K</code> is not an RSA one.
* @throws IllegalArgumentException if <code>s</code> (the <i>signature
* representative</i>) is out of range.
* representative</i>) is out of range.
*/
public static final BigInteger verify(final PublicKey K, final BigInteger s)
{
@ -151,25 +137,24 @@ public class RSA
}
catch (IllegalArgumentException x)
{
throw new IllegalArgumentException(
"signature representative out of range");
throw new IllegalArgumentException("signature representative out of range");
}
}
// Encryption and decryption methods ---------------------------------------
/**
* <p>An implementation of the <code>RSAEP</code> algorithm.</p>
*
* An implementation of the <code>RSAEP</code> algorithm.
*
* @param K the recipient's RSA public key.
* @param m the message representative as an MPI.
* @return the resulting MPI --an MPI between <code>0</code> and
* <code>n - 1</code> (<code>n</code> being the public shared modulus)-- that
* will eventually be padded with an appropriate framing/padding scheme.
* <code>n - 1</code> (<code>n</code> being the public shared
* modulus)-- that will eventually be padded with an appropriate
* framing/padding scheme.
* @throws ClassCastException if <code>K</code> is not an RSA one.
* @throws IllegalArgumentException if <code>m</code>, the message
* representative is not between <code>0</code> and <code>n - 1</code>
* (<code>n</code> being the public shared modulus).
* representative is not between <code>0</code> and
* <code>n - 1</code> (<code>n</code> being the public shared
* modulus).
*/
public static final BigInteger encrypt(final PublicKey K, final BigInteger m)
{
@ -179,22 +164,23 @@ public class RSA
}
catch (IllegalArgumentException x)
{
throw new IllegalArgumentException(
"message representative out of range");
throw new IllegalArgumentException("message representative out of range");
}
}
/**
* <p>An implementation of the <code>RSADP</code> algorithm.</p>
*
* An implementation of the <code>RSADP</code> algorithm.
*
* @param K the recipient's RSA private key.
* @param c the ciphertext representative as an MPI.
* @return the message representative, an MPI between <code>0</code> and
* <code>n - 1</code> (<code>n</code> being the shared public modulus).
* <code>n - 1</code> (<code>n</code> being the shared public
* modulus).
* @throws ClassCastException if <code>K</code> is not an RSA one.
* @throws IllegalArgumentException if <code>c</code>, the ciphertext
* representative is not between <code>0</code> and <code>n - 1</code>
* (<code>n</code> being the shared public modulus).
* representative is not between <code>0</code> and
* <code>n - 1</code> (<code>n</code> being the shared public
* modulus).
*/
public static final BigInteger decrypt(final PrivateKey K, final BigInteger c)
{
@ -204,22 +190,19 @@ public class RSA
}
catch (IllegalArgumentException x)
{
throw new IllegalArgumentException(
"ciphertext representative out of range");
throw new IllegalArgumentException("ciphertext representative out of range");
}
}
// Conversion methods ------------------------------------------------------
/**
* <p>Converts a <i>multi-precision integer</i> (MPI) <code>s</code> into an
* octet sequence of length <code>k</code>.</p>
*
* Converts a <i>multi-precision integer</i> (MPI) <code>s</code> into an
* octet sequence of length <code>k</code>.
*
* @param s the multi-precision integer to convert.
* @param k the length of the output.
* @return the result of the transform.
* @exception IllegalArgumentException if the length in octets of meaningful
* bytes of <code>s</code> is greater than <code>k</code>.
* bytes of <code>s</code> is greater than <code>k</code>.
*/
public static final byte[] I2OSP(final BigInteger s, final int k)
{
@ -236,9 +219,7 @@ public class RSA
for (int i = 0; i < limit; i++)
{
if (result[i] != 0x00)
{
throw new IllegalArgumentException("integer too large");
}
throw new IllegalArgumentException("integer too large");
}
final byte[] newResult = new byte[k];
System.arraycopy(result, limit, newResult, 0, k);
@ -247,17 +228,13 @@ public class RSA
return result;
}
// helper methods ----------------------------------------------------------
private static final BigInteger RSAEP(final RSAPublicKey K, final BigInteger m)
{
// 1. If the representative m is not between 0 and n - 1, output
// "representative out of range" and stop.
// "representative out of range" and stop.
final BigInteger n = K.getModulus();
if (m.compareTo(ZERO) < 0 || m.compareTo(n.subtract(ONE)) > 0)
{
throw new IllegalArgumentException();
}
throw new IllegalArgumentException();
// 2. Let c = m^e mod n.
final BigInteger e = K.getPublicExponent();
final BigInteger result = m.modPow(e, n);
@ -268,16 +245,13 @@ public class RSA
private static final BigInteger RSADP(final RSAPrivateKey K, BigInteger c)
{
// 1. If the representative c is not between 0 and n - 1, output
// "representative out of range" and stop.
// "representative out of range" and stop.
final BigInteger n = K.getModulus();
if (c.compareTo(ZERO) < 0 || c.compareTo(n.subtract(ONE)) > 0)
{
throw new IllegalArgumentException();
}
throw new IllegalArgumentException();
// 2. The representative m is computed as follows.
BigInteger result;
if (!(K instanceof RSAPrivateCrtKey))
if (! (K instanceof RSAPrivateCrtKey))
{
// a. If the first form (n, d) of K is used, let m = c^d mod n.
final BigInteger d = K.getPrivateExponent();
@ -303,38 +277,32 @@ public class RSA
final BigInteger x = r.modPow(e, n).multiply(c).mod(n);
c = x;
}
// b. If the second form (p, q, dP, dQ, qInv) and (r_i, d_i, t_i)
// of K is used, proceed as follows:
// of K is used, proceed as follows:
final BigInteger p = ((RSAPrivateCrtKey) K).getPrimeP();
final BigInteger q = ((RSAPrivateCrtKey) K).getPrimeQ();
final BigInteger dP = ((RSAPrivateCrtKey) K).getPrimeExponentP();
final BigInteger dQ = ((RSAPrivateCrtKey) K).getPrimeExponentQ();
final BigInteger qInv = ((RSAPrivateCrtKey) K).getCrtCoefficient();
// i. Let m_1 = c^dP mod p and m_2 = c^dQ mod q.
// i. Let m_1 = c^dP mod p and m_2 = c^dQ mod q.
final BigInteger m_1 = c.modPow(dP, p);
final BigInteger m_2 = c.modPow(dQ, q);
// ii. If u > 2, let m_i = c^(d_i) mod r_i, i = 3, ..., u.
// iii. Let h = (m_1 - m_2) * qInv mod p.
// ii. If u > 2, let m_i = c^(d_i) mod r_i, i = 3, ..., u.
// iii. Let h = (m_1 - m_2) * qInv mod p.
final BigInteger h = m_1.subtract(m_2).multiply(qInv).mod(p);
// iv. Let m = m_2 + q * h.
// iv. Let m = m_2 + q * h.
result = m_2.add(q.multiply(h));
if (rsaBlinding)
{ // post-decryption
result = result.multiply(r.modInverse(n)).mod(n);
}
if (rsaBlinding) // post-decryption
result = result.multiply(r.modInverse(n)).mod(n);
}
// 3. Output m
return result;
}
/**
* <p>Returns a random MPI with a random bit-length of the form <code>8b</code>,
* where <code>b</code> is in the range <code>[32..64]</code>.</p>
*
* Returns a random MPI with a random bit-length of the form <code>8b</code>,
* where <code>b</code> is in the range <code>[32..64]</code>.
*
* @return a random MPI whose length in bytes is between 32 and 64 inclusive.
*/
private static final BigInteger newR(final BigInteger N)