summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaif S. Naffah <raif@swiftdsl.com.au>2006-07-01 10:00:26 +0000
committerRaif S. Naffah <raif@swiftdsl.com.au>2006-07-01 10:00:26 +0000
commit1dcb1d0057fb785bab986cd7a20391349bf60969 (patch)
tree36b1a2a98c603f02468f18c87390da326b93bc2d
parentd4ee4396943a6512a9a22a29298cec1c92d0bfed (diff)
downloadclasspath-1dcb1d0057fb785bab986cd7a20391349bf60969.tar.gz
2006-07-01 Raif S. Naffah <raif@swiftdsl.com.au>
* gnu/javax/crypto/key/dh/DHKeyPairRawCodec.java: Source formatting. * gnu/javax/crypto/key/dh/DiffieHellmanKeyAgreement.java: Likewise. * gnu/javax/crypto/key/dh/DiffieHellmanReceiver.java: Likewise. * gnu/javax/crypto/key/dh/DiffieHellmanSender.java: Likewise. * gnu/javax/crypto/key/dh/ElGamalKeyAgreement.java: Likewise. * gnu/javax/crypto/key/dh/ElGamalReceiver.java: Likewise. * gnu/javax/crypto/key/dh/ElGamalSender.java: Likewise. * gnu/javax/crypto/key/dh/GnuDHKey.java: Likewise. * gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java: Likewise. * gnu/javax/crypto/key/dh/GnuDHPrivateKey.java: Likewise. * gnu/javax/crypto/key/dh/GnuDHPublicKey.java: Likewise. * gnu/javax/crypto/key/dh/RFC2631.java: Likewise. * gnu/javax/crypto/key/srp6/SRP6Host.java: Likewise. * gnu/javax/crypto/key/srp6/SRP6KeyAgreement.java: Likewise. * gnu/javax/crypto/key/srp6/SRP6SaslClient.java: Likewise. * gnu/javax/crypto/key/srp6/SRP6SaslServer.java: Likewise. * gnu/javax/crypto/key/srp6/SRP6TLSClient.java: Likewise. * gnu/javax/crypto/key/srp6/SRP6TLSServer.java: Likewise. * gnu/javax/crypto/key/srp6/SRP6User.java: Likewise. * gnu/javax/crypto/key/srp6/SRPAlgorithm.java: Likewise. * gnu/javax/crypto/key/srp6/SRPKey.java: Likewise. * gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java: Likewise. * gnu/javax/crypto/key/srp6/SRPKeyPairRawCodec.java: Likewise. * gnu/javax/crypto/key/srp6/SRPPrivateKey.java: Likewise. * gnu/javax/crypto/key/srp6/SRPPublicKey.java: Likewise. * gnu/javax/crypto/key/BaseKeyAgreementParty.java: Likewise. * gnu/javax/crypto/key/GnuSecretKey.java: Likewise. * gnu/javax/crypto/key/IKeyAgreementParty.java: Likewise. * gnu/javax/crypto/key/IncomingMessage.java: Likewise. * gnu/javax/crypto/key/KeyAgreementException.java: Likewise. * gnu/javax/crypto/key/KeyAgreementFactory.java: Likewise. * gnu/javax/crypto/key/OutgoingMessage.java: Likewise.
-rw-r--r--ChangeLog35
-rw-r--r--gnu/javax/crypto/key/BaseKeyAgreementParty.java88
-rw-r--r--gnu/javax/crypto/key/GnuSecretKey.java48
-rw-r--r--gnu/javax/crypto/key/IKeyAgreementParty.java43
-rw-r--r--gnu/javax/crypto/key/IncomingMessage.java114
-rw-r--r--gnu/javax/crypto/key/KeyAgreementException.java107
-rw-r--r--gnu/javax/crypto/key/KeyAgreementFactory.java88
-rw-r--r--gnu/javax/crypto/key/OutgoingMessage.java79
-rw-r--r--gnu/javax/crypto/key/dh/DHKeyPairRawCodec.java286
-rw-r--r--gnu/javax/crypto/key/dh/DiffieHellmanKeyAgreement.java91
-rw-r--r--gnu/javax/crypto/key/dh/DiffieHellmanReceiver.java50
-rw-r--r--gnu/javax/crypto/key/dh/DiffieHellmanSender.java51
-rw-r--r--gnu/javax/crypto/key/dh/ElGamalKeyAgreement.java91
-rw-r--r--gnu/javax/crypto/key/dh/ElGamalReceiver.java36
-rw-r--r--gnu/javax/crypto/key/dh/ElGamalSender.java34
-rw-r--r--gnu/javax/crypto/key/dh/GnuDHKey.java88
-rw-r--r--gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java82
-rw-r--r--gnu/javax/crypto/key/dh/GnuDHPrivateKey.java64
-rw-r--r--gnu/javax/crypto/key/dh/GnuDHPublicKey.java63
-rw-r--r--gnu/javax/crypto/key/dh/RFC2631.java93
-rw-r--r--gnu/javax/crypto/key/srp6/SRP6Host.java82
-rw-r--r--gnu/javax/crypto/key/srp6/SRP6KeyAgreement.java113
-rw-r--r--gnu/javax/crypto/key/srp6/SRP6SaslClient.java53
-rw-r--r--gnu/javax/crypto/key/srp6/SRP6SaslServer.java53
-rw-r--r--gnu/javax/crypto/key/srp6/SRP6TLSClient.java62
-rw-r--r--gnu/javax/crypto/key/srp6/SRP6TLSServer.java69
-rw-r--r--gnu/javax/crypto/key/srp6/SRP6User.java72
-rw-r--r--gnu/javax/crypto/key/srp6/SRPAlgorithm.java131
-rw-r--r--gnu/javax/crypto/key/srp6/SRPKey.java79
-rw-r--r--gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java90
-rw-r--r--gnu/javax/crypto/key/srp6/SRPKeyPairRawCodec.java292
-rw-r--r--gnu/javax/crypto/key/srp6/SRPPrivateKey.java129
-rw-r--r--gnu/javax/crypto/key/srp6/SRPPublicKey.java95
33 files changed, 1028 insertions, 1923 deletions
diff --git a/ChangeLog b/ChangeLog
index 3e756cdb1..a1b29f06e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,38 @@
+2006-07-01 Raif S. Naffah <raif@swiftdsl.com.au>
+
+ * gnu/javax/crypto/key/dh/DHKeyPairRawCodec.java: Source formatting.
+ * gnu/javax/crypto/key/dh/DiffieHellmanKeyAgreement.java: Likewise.
+ * gnu/javax/crypto/key/dh/DiffieHellmanReceiver.java: Likewise.
+ * gnu/javax/crypto/key/dh/DiffieHellmanSender.java: Likewise.
+ * gnu/javax/crypto/key/dh/ElGamalKeyAgreement.java: Likewise.
+ * gnu/javax/crypto/key/dh/ElGamalReceiver.java: Likewise.
+ * gnu/javax/crypto/key/dh/ElGamalSender.java: Likewise.
+ * gnu/javax/crypto/key/dh/GnuDHKey.java: Likewise.
+ * gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java: Likewise.
+ * gnu/javax/crypto/key/dh/GnuDHPrivateKey.java: Likewise.
+ * gnu/javax/crypto/key/dh/GnuDHPublicKey.java: Likewise.
+ * gnu/javax/crypto/key/dh/RFC2631.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRP6Host.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRP6KeyAgreement.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRP6SaslClient.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRP6SaslServer.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRP6TLSClient.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRP6TLSServer.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRP6User.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRPAlgorithm.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRPKey.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRPKeyPairRawCodec.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRPPrivateKey.java: Likewise.
+ * gnu/javax/crypto/key/srp6/SRPPublicKey.java: Likewise.
+ * gnu/javax/crypto/key/BaseKeyAgreementParty.java: Likewise.
+ * gnu/javax/crypto/key/GnuSecretKey.java: Likewise.
+ * gnu/javax/crypto/key/IKeyAgreementParty.java: Likewise.
+ * gnu/javax/crypto/key/IncomingMessage.java: Likewise.
+ * gnu/javax/crypto/key/KeyAgreementException.java: Likewise.
+ * gnu/javax/crypto/key/KeyAgreementFactory.java: Likewise.
+ * gnu/javax/crypto/key/OutgoingMessage.java: Likewise.
+
2006-07-01 Roman Kennke <kennke@aicas.com>
* gnu/java/awt/java2d/AbstractGraphics2D.java
diff --git a/gnu/javax/crypto/key/BaseKeyAgreementParty.java b/gnu/javax/crypto/key/BaseKeyAgreementParty.java
index bfd9378d2..fc5ddb714 100644
--- a/gnu/javax/crypto/key/BaseKeyAgreementParty.java
+++ b/gnu/javax/crypto/key/BaseKeyAgreementParty.java
@@ -47,41 +47,28 @@ import java.security.SecureRandom;
import java.util.Map;
/**
- * <p>A base abstract class to facilitate implementations of concrete key
- * agreement protocol handlers.</p>
+ * A base abstract class to facilitate implementations of concrete key agreement
+ * protocol handlers.
*/
-public abstract class BaseKeyAgreementParty implements IKeyAgreementParty
+public abstract class BaseKeyAgreementParty
+ implements IKeyAgreementParty
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
protected static final BigInteger TWO = BigInteger.valueOf(2L);
-
/** The canonical name of the protocol. */
protected String name;
-
/** Whether the instance is initialised or not. */
protected boolean initialised = false;
-
/** The current step index of the protocol exchange. */
protected int step = -1;
-
/** Whether the exchange has concluded or not. */
protected boolean complete = false;
-
/** The optional {@link SecureRandom} instance to use. */
protected SecureRandom rnd = null;
-
/** The optional {@link IRandom} instance to use. */
protected IRandom irnd = null;
-
/** Our default source of randomness. */
private PRNG prng = null;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
protected BaseKeyAgreementParty(String name)
{
super();
@@ -89,12 +76,6 @@ public abstract class BaseKeyAgreementParty implements IKeyAgreementParty
this.name = name;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
public String name()
{
return name;
@@ -103,12 +84,8 @@ public abstract class BaseKeyAgreementParty implements IKeyAgreementParty
public void init(Map attributes) throws KeyAgreementException
{
if (initialised)
- {
- throw new IllegalStateException("already initialised");
- }
-
+ throw new IllegalStateException("already initialised");
this.engineInit(attributes);
-
initialised = true;
this.step = -1;
this.complete = false;
@@ -117,15 +94,10 @@ public abstract class BaseKeyAgreementParty implements IKeyAgreementParty
public OutgoingMessage processMessage(IncomingMessage in)
throws KeyAgreementException
{
- if (!initialised)
- {
- throw new IllegalStateException("not initialised");
- }
+ if (! initialised)
+ throw new IllegalStateException("not initialised");
if (complete)
- {
- throw new IllegalStateException("exchange has already concluded");
- }
-
+ throw new IllegalStateException("exchange has already concluded");
step++;
return this.engineProcessMessage(in);
}
@@ -137,14 +109,10 @@ public abstract class BaseKeyAgreementParty implements IKeyAgreementParty
public byte[] getSharedSecret() throws KeyAgreementException
{
- if (!initialised)
- {
- throw new KeyAgreementException("not yet initialised");
- }
- if (!isComplete())
- {
- throw new KeyAgreementException("not yet computed");
- }
+ if (! initialised)
+ throw new KeyAgreementException("not yet initialised");
+ if (! isComplete())
+ throw new KeyAgreementException("not yet computed");
return engineSharedSecret();
}
@@ -157,8 +125,6 @@ public abstract class BaseKeyAgreementParty implements IKeyAgreementParty
}
}
- // abstract methods to be implemented by concrete subclasses ---------------
-
protected abstract void engineInit(Map attributes)
throws KeyAgreementException;
@@ -169,31 +135,25 @@ public abstract class BaseKeyAgreementParty implements IKeyAgreementParty
protected abstract void engineReset();
- // helper methods ----------------------------------------------------------
-
/**
* Fills the designated byte array with random data.
- *
+ *
* @param buffer the byte array to fill with random data.
*/
protected void nextRandomBytes(byte[] buffer)
{
if (rnd != null)
- {
- rnd.nextBytes(buffer);
- }
+ rnd.nextBytes(buffer);
else if (irnd != null)
- {
- try
- {
- irnd.nextBytes(buffer, 0, buffer.length);
- }
- catch (LimitReachedException lre)
- {
- irnd = null;
- getDefaultPRNG().nextBytes(buffer);
- }
- }
+ try
+ {
+ irnd.nextBytes(buffer, 0, buffer.length);
+ }
+ catch (LimitReachedException lre)
+ {
+ irnd = null;
+ getDefaultPRNG().nextBytes(buffer);
+ }
else
getDefaultPRNG().nextBytes(buffer);
}
@@ -205,4 +165,4 @@ public abstract class BaseKeyAgreementParty implements IKeyAgreementParty
return prng;
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/key/GnuSecretKey.java b/gnu/javax/crypto/key/GnuSecretKey.java
index 93b21a67c..3063fe406 100644
--- a/gnu/javax/crypto/key/GnuSecretKey.java
+++ b/gnu/javax/crypto/key/GnuSecretKey.java
@@ -42,27 +42,20 @@ import gnu.java.security.util.Util;
import java.security.Key;
/**
- * A secret key composed of a sequence of raw, unformatted octets. This class
- * is analogous to the {@link javax.crypto.spec.SecretKeySpec} class, but is
+ * A secret key composed of a sequence of raw, unformatted octets. This class is
+ * analogous to the {@link javax.crypto.spec.SecretKeySpec} class, but is
* provided for platforms that do not or cannot contain that class.
*/
-public class GnuSecretKey implements Key
+public class GnuSecretKey
+ implements Key
{
-
- // Field.
- // ------------------------------------------------------------------------
-
private final byte[] key;
-
private final String algorithm;
- // Constructors.
- // ------------------------------------------------------------------------
-
/**
* Creates a new secret key. The supplied byte array is copied by this
* constructor.
- *
+ *
* @param key The raw, secret key.
* @param algorithm The algorithm name, which can be null or empty.
*/
@@ -73,7 +66,7 @@ public class GnuSecretKey implements Key
/**
* Creates a new secret key from a portion of a byte array.
- *
+ *
* @param key The raw, secret key.
* @param offset The offset at which the key begins.
* @param length The number of bytes that comprise the key.
@@ -86,12 +79,9 @@ public class GnuSecretKey implements Key
this.algorithm = algorithm;
}
- // Instance methods.
- // ------------------------------------------------------------------------
-
/**
* Returns the algorithm name, if any.
- *
+ *
* @return The algorithm name.
*/
public String getAlgorithm()
@@ -103,7 +93,7 @@ public class GnuSecretKey implements Key
* Returns the encoded key, which is merely the byte array this class was
* created with. A reference to the internal byte array is returned, so the
* caller can delete this key from memory by modifying the returned array.
- *
+ *
* @return The raw key.
*/
public byte[] getEncoded()
@@ -113,7 +103,7 @@ public class GnuSecretKey implements Key
/**
* Returns the string "RAW".
- *
+ *
* @return The string "RAW".
*/
public String getFormat()
@@ -123,22 +113,14 @@ public class GnuSecretKey implements Key
public boolean equals(Object o)
{
- if (!(o instanceof GnuSecretKey))
- {
- return false;
- }
+ if (! (o instanceof GnuSecretKey))
+ return false;
if (key.length != ((GnuSecretKey) o).key.length)
- {
- return false;
- }
+ return false;
byte[] key2 = ((GnuSecretKey) o).key;
for (int i = 0; i < key.length; i++)
- {
- if (key[i] != key2[i])
- {
- return false;
- }
- }
+ if (key[i] != key2[i])
+ return false;
return true;
}
@@ -146,4 +128,4 @@ public class GnuSecretKey implements Key
{
return "GnuSecretKey [ " + algorithm + " " + Util.toString(key) + " ]";
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/key/IKeyAgreementParty.java b/gnu/javax/crypto/key/IKeyAgreementParty.java
index 05aef5e51..280f3f33d 100644
--- a/gnu/javax/crypto/key/IKeyAgreementParty.java
+++ b/gnu/javax/crypto/key/IKeyAgreementParty.java
@@ -41,65 +41,60 @@ package gnu.javax.crypto.key;
import java.util.Map;
/**
- * <p>The visible methods of an key agreement protocol participating party.</p>
+ * The visible methods of an key agreement protocol participating party.
*/
public interface IKeyAgreementParty
{
-
- // Constants
- // -------------------------------------------------------------------------
-
- // Methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the canonical name of the key agreement protocol.</p>
- *
+ * Returns the canonical name of the key agreement protocol.
+ *
* @return the canonical name of the key agreement protocol.
*/
String name();
/**
- * <p>Sets up the instance to operate with specific attributes.</p>
- *
+ * Sets up the instance to operate with specific attributes.
+ *
* @param attributes a map of name-values used by concrete implementations.
* @throws KeyAgreementException if an exception occurs during the setup.
*/
void init(Map attributes) throws KeyAgreementException;
/**
- * <p>Processes an incoming message at one end, generating a message that
- * will be processed by the other party(ies).</p>
- *
+ * Processes an incoming message at one end, generating a message that will be
+ * processed by the other party(ies).
+ *
* @param in the incoming message.
* @return an outgoing message, or <code>null</code> if this is an
- * intermediary step that does not cause any output.
+ * intermediary step that does not cause any output.
* @throws KeyAgreementException if an exception occurs during the processing
- * of the incoming message, or during the generation of the outgoing message.
+ * of the incoming message, or during the generation of the outgoing
+ * message.
*/
OutgoingMessage processMessage(IncomingMessage in)
throws KeyAgreementException;
/**
- * <p>Returns <code>true</code> if the party in the key agreement protocol
+ * Returns <code>true</code> if the party in the key agreement protocol
* exchange has completed its part of the exchange. If this is the case an
* {@link IllegalStateException} is thrown for any method invocation except
* <code>init()</code> or <code>reset()</code>.
+ *
* @return <code>true</code> if this party has completed its part of the key
- * agreement protocol exchange; <code>false</code> otherwise.
+ * agreement protocol exchange; <code>false</code> otherwise.
*/
boolean isComplete();
/**
- * <p>Returns the byte array containing the shared secret as generated by
- * this party.</p>
- *
+ * Returns the byte array containing the shared secret as generated by this
+ * party.
+ *
* @return the generated shared secret.
* @throws KeyAgreementException if the key agreement is not yet initialised,
- * or is initialised but the exchange is still in progress.
+ * or is initialised but the exchange is still in progress.
*/
byte[] getSharedSecret() throws KeyAgreementException;
/** Resets this instance for re-use with another set of attributes. */
void reset();
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/key/IncomingMessage.java b/gnu/javax/crypto/key/IncomingMessage.java
index e04c85399..9701d80a7 100644
--- a/gnu/javax/crypto/key/IncomingMessage.java
+++ b/gnu/javax/crypto/key/IncomingMessage.java
@@ -58,30 +58,22 @@ import java.security.PrivateKey;
import java.security.PublicKey;
/**
- * <p>An implementation of an incoming message for use with key agreement
- * protocols.</p>
+ * An implementation of an incoming message for use with key agreement
+ * protocols.
*/
public class IncomingMessage
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The internal buffer stream containing the message's contents. */
protected ByteArrayInputStream in;
-
/** The length of the message contents, according to its 4-byte header. */
protected int length;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Constructs an incoming message given the message's encoded form,
- * including its header bytes.</p>
- *
+ * Constructs an incoming message given the message's encoded form, including
+ * its header bytes.
+ *
* @param b the encoded form, including the header bytes, of an incoming
- * message.
+ * message.
* @throws KeyAgreementException if the buffer is malformed.
*/
public IncomingMessage(byte[] b) throws KeyAgreementException
@@ -89,15 +81,13 @@ public class IncomingMessage
this();
if (b.length < 4)
- {
- throw new KeyAgreementException("message header too short");
- }
- length = b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8
- | (b[3] & 0xFF);
+ throw new KeyAgreementException("message header too short");
+ length = b[0] << 24
+ | (b[1] & 0xFF) << 16
+ | (b[2] & 0xFF) << 8
+ | (b[3] & 0xFF);
if (length > Registry.SASL_BUFFER_MAX_LIMIT || length < 0)
- {
- throw new KeyAgreementException("message size limit exceeded");
- }
+ throw new KeyAgreementException("message size limit exceeded");
in = new ByteArrayInputStream(b, 4, length);
}
@@ -107,16 +97,13 @@ public class IncomingMessage
super();
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns an instance of a message given its encoded contents, excluding
- * the message's header bytes.</p>
- *
- * <p>Calls the method with the same name and three arguments as:
+ * Returns an instance of a message given its encoded contents, excluding the
+ * message's header bytes.
+ * <p>
+ * Calls the method with the same name and three arguments as:
* <code>getInstance(raw, 0, raw.length)</code>.
- *
+ *
* @param raw the encoded form, excluding the header bytes.
* @return a new instance of <code>IncomingMessage</code>.
*/
@@ -126,9 +113,9 @@ public class IncomingMessage
}
/**
- * <p>Returns an instance of a message given its encoded contents, excluding
- * the message's header bytes.</p>
- *
+ * Returns an instance of a message given its encoded contents, excluding the
+ * message's header bytes.
+ *
* @param raw the encoded form, excluding the header bytes.
* @param offset offset where to start using raw bytes from.
* @param len number of bytes to use.
@@ -142,8 +129,8 @@ public class IncomingMessage
}
/**
- * <p>Converts two octets into the number that they represent.</p>
- *
+ * Converts two octets into the number that they represent.
+ *
* @param b the two octets.
* @return the length.
*/
@@ -151,32 +138,27 @@ public class IncomingMessage
{
int result = (b[0] & 0xFF) << 8 | (b[1] & 0xFF);
if (result > Registry.SASL_TWO_BYTE_MAX_LIMIT)
- {
- throw new KeyAgreementException("encoded MPI size limit exceeded");
- }
+ throw new KeyAgreementException("encoded MPI size limit exceeded");
return result;
}
/**
- * <p>Converts four octets into the number that they represent.</p>
- *
+ * Converts four octets into the number that they represent.
+ *
* @param b the four octets.
* @return the length.
*/
public static int fourBytesToLength(byte[] b) throws KeyAgreementException
{
- int result = b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8
- | (b[3] & 0xFF);
+ int result = b[0] << 24
+ | (b[1] & 0xFF) << 16
+ | (b[2] & 0xFF) << 8
+ | (b[3] & 0xFF);
if (result > Registry.SASL_FOUR_BYTE_MAX_LIMIT || result < 0)
- {
- throw new KeyAgreementException("encoded entity size limit exceeded");
- }
+ throw new KeyAgreementException("encoded entity size limit exceeded");
return result;
}
- // Instance methods
- // -------------------------------------------------------------------------
-
public boolean hasMoreElements()
{
return (in.available() > 0);
@@ -195,18 +177,15 @@ public class IncomingMessage
{
if (in.available() < 5)
throw new KeyAgreementException("not enough bytes for a public key in message");
-
byte[] elementLengthBytes = new byte[4];
in.read(elementLengthBytes, 0, 4);
int elementLength = fourBytesToLength(elementLengthBytes);
if (in.available() < elementLength)
throw new KeyAgreementException("illegal public key encoding");
-
int keyTypeAndFormatID = in.read() & 0xFF;
elementLength--;
byte[] kb = new byte[elementLength];
in.read(kb, 0, elementLength);
-
// instantiate the right codec and decode
IKeyPairCodec kpc = getKeyPairCodec(keyTypeAndFormatID);
return kpc.decodePublicKey(kb);
@@ -225,66 +204,50 @@ public class IncomingMessage
{
if (in.available() < 5)
throw new KeyAgreementException("not enough bytes for a private key in message");
-
byte[] elementLengthBytes = new byte[4];
in.read(elementLengthBytes, 0, 4);
int elementLength = fourBytesToLength(elementLengthBytes);
if (in.available() < elementLength)
throw new KeyAgreementException("illegal private key encoding");
-
int keyTypeAndFormatID = in.read() & 0xFF;
elementLength--;
byte[] kb = new byte[elementLength];
in.read(kb, 0, elementLength);
-
// instantiate the right codec and decode
IKeyPairCodec kpc = getKeyPairCodec(keyTypeAndFormatID);
return kpc.decodePrivateKey(kb);
}
/**
- * <p>Decodes an MPI from the current message's contents.</p>
- *
+ * Decodes an MPI from the current message's contents.
+ *
* @return a native representation of an MPI.
* @throws KeyAgreementException if an encoding exception occurs during the
- * operation.
+ * operation.
*/
public BigInteger readMPI() throws KeyAgreementException
{
if (in.available() < 2)
- {
- throw new KeyAgreementException(
- "not enough bytes for an MPI in message");
- }
+ throw new KeyAgreementException("not enough bytes for an MPI in message");
byte[] elementLengthBytes = new byte[2];
in.read(elementLengthBytes, 0, 2);
int elementLength = twoBytesToLength(elementLengthBytes);
if (in.available() < elementLength)
- {
- throw new KeyAgreementException("illegal MPI encoding");
- }
-
+ throw new KeyAgreementException("illegal MPI encoding");
byte[] element = new byte[elementLength];
in.read(element, 0, element.length);
-
return new BigInteger(1, element);
}
public String readString() throws KeyAgreementException
{
if (in.available() < 2)
- {
- throw new KeyAgreementException(
- "not enough bytes for a text in message");
- }
+ throw new KeyAgreementException("not enough bytes for a text in message");
byte[] elementLengthBytes = new byte[2];
in.read(elementLengthBytes, 0, 2);
int elementLength = twoBytesToLength(elementLengthBytes);
if (in.available() < elementLength)
- {
- throw new KeyAgreementException("illegal text encoding");
- }
-
+ throw new KeyAgreementException("illegal text encoding");
byte[] element = new byte[elementLength];
in.read(element, 0, element.length);
String result = null;
@@ -296,7 +259,6 @@ public class IncomingMessage
{
throw new KeyAgreementException("unxupported UTF8 encoding", x);
}
-
return result;
}
@@ -353,4 +315,4 @@ public class IncomingMessage
+ formatID);
}
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/key/KeyAgreementException.java b/gnu/javax/crypto/key/KeyAgreementException.java
index c2fa434a2..f0fb1bb83 100644
--- a/gnu/javax/crypto/key/KeyAgreementException.java
+++ b/gnu/javax/crypto/key/KeyAgreementException.java
@@ -44,26 +44,19 @@ import java.io.Serializable;
import java.security.KeyManagementException;
/**
- * A generic exception indicating that an unexpected condition has
- * been detected during the setup and/or processing of a key agreement
- * protocol exchange.
+ * A generic exception indicating that an unexpected condition has been detected
+ * during the setup and/or processing of a key agreement protocol exchange.
*/
-public class KeyAgreementException extends KeyManagementException implements
- Serializable
+public class KeyAgreementException
+ extends KeyManagementException
+ implements Serializable
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** @serial The possibly <code>null</code> <i>root</i> cause exception. */
private Throwable cause = null;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Constructs a new instance of <code>KeyAgreementException</code>. The
- * root exception and the detailed message are <code>null</code>.</p>
+ * Constructs a new instance of <code>KeyAgreementException</code>. The
+ * root exception and the detailed message are <code>null</code>.
*/
public KeyAgreementException()
{
@@ -71,11 +64,11 @@ public class KeyAgreementException extends KeyManagementException implements
}
/**
- * <p>Constructs a new instance of <code>KeyAgreementException</code> with a
- * detailed message. The <i>root</i> exception is <code>null</code>.</p>
- *
+ * Constructs a new instance of <code>KeyAgreementException</code> with a
+ * detailed message. The <i>root</i> exception is <code>null</code>.
+ *
* @param detail a possibly <code>null</code> string containing details of
- * the exception.
+ * the exception.
* @see Throwable#getMessage()
*/
public KeyAgreementException(String detail)
@@ -84,13 +77,13 @@ public class KeyAgreementException extends KeyManagementException implements
}
/**
- * <p>Constructs a new instance of <code>KeyAgreementException</code> with a
- * detailed message and a <i>root</i> exception.</p>
- *
+ * Constructs a new instance of <code>KeyAgreementException</code> with a
+ * detailed message and a <i>root</i> exception.
+ *
* @param detail a possibly <code>null</code> string containing details of
- * the exception.
+ * the exception.
* @param cause a possibly <code>null</code> root exception that caused this
- * exception.
+ * exception.
* @see Throwable#getMessage()
* @see #getCause()
*/
@@ -100,17 +93,11 @@ public class KeyAgreementException extends KeyManagementException implements
this.cause = cause;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the cause of this throwable or <code>null</code> if the cause
- * is nonexistent or unknown. The <i>cause</i> is the throwable that caused
- * this exception to be thrown.</p>
- *
+ * Returns the cause of this throwable or <code>null</code> if the cause is
+ * nonexistent or unknown. The <i>cause</i> is the throwable that caused this
+ * exception to be thrown.
+ *
* @return the possibly <code>null</code> exception that caused this one.
*/
public Throwable getCause()
@@ -119,69 +106,61 @@ public class KeyAgreementException extends KeyManagementException implements
}
/**
- * <p>Prints this exception's stack trace to <code>System.err</code>. If this
+ * Prints this exception's stack trace to <code>System.err</code>. If this
* exception has a <i>root</i> exception; the stack trace of the <i>root</i>
- * exception is also printed to <code>System.err</code>.</p>
+ * exception is also printed to <code>System.err</code>.
*/
public void printStackTrace()
{
super.printStackTrace();
if (cause != null)
- {
- cause.printStackTrace();
- }
+ cause.printStackTrace();
}
/**
- * <p>Prints this exception's stack trace to a print stream. If this
- * exception has a <i>root</i> exception; the stack trace of the <i>root</i>
- * exception is also printed to the print stream.</p>
- *
+ * Prints this exception's stack trace to a print stream. If this exception
+ * has a <i>root</i> exception; the stack trace of the <i>root</i> exception
+ * is also printed to the print stream.
+ *
* @param ps the non-null print stream to which to print.
*/
public void printStackTrace(PrintStream ps)
{
super.printStackTrace(ps);
if (cause != null)
- {
- cause.printStackTrace(ps);
- }
+ cause.printStackTrace(ps);
}
/**
- * <p>Prints this exception's stack trace to a print writer. If this
- * exception has a <i>root</i> exception; the stack trace of the <i>root</i>
- * exception is also printed to the print writer.</p>
- *
+ * Prints this exception's stack trace to a print writer. If this exception
+ * has a <i>root</i> exception; the stack trace of the <i>root</i> exception
+ * is also printed to the print writer.
+ *
* @param pw the non-null print writer to use for output.
*/
public void printStackTrace(PrintWriter pw)
{
super.printStackTrace(pw);
if (cause != null)
- {
- cause.printStackTrace(pw);
- }
+ cause.printStackTrace(pw);
}
/**
- * <p>Returns the string representation of this exception. The string
- * representation contains this exception's class name, its detailed
- * messsage, and if it has a <i>root</i> exception, the string representation
- * of the root exception. This string representation is meant for debugging
- * and is not meant to be interpreted programmatically.</p>
- *
+ * Returns the string representation of this exception. The string
+ * representation contains this exception's class name, its detailed messsage,
+ * and if it has a <i>root</i> exception, the string representation of the
+ * root exception. This string representation is meant for debugging and is
+ * not meant to be interpreted programmatically.
+ *
* @return the non-null string representation of this exception.
* @see Throwable#getMessage()
*/
public String toString()
{
- StringBuffer sb = new StringBuffer(this.getClass().getName()).append(": ").append(
- super.toString());
+ StringBuffer sb = new StringBuffer(this.getClass().getName()).append(": ")
+ .append(super.toString());
if (cause != null)
- {
- sb.append("; caused by: ").append(cause.toString());
- }
+ sb.append("; caused by: ").append(cause.toString());
return sb.toString();
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/key/KeyAgreementFactory.java b/gnu/javax/crypto/key/KeyAgreementFactory.java
index e2a7faba1..ae9bf36ff 100644
--- a/gnu/javax/crypto/key/KeyAgreementFactory.java
+++ b/gnu/javax/crypto/key/KeyAgreementFactory.java
@@ -56,115 +56,77 @@ import java.util.HashSet;
import java.util.Set;
/**
- * <p>A <i>Factory</i> class to generate key agreement protocol handlers.</p>
+ * A <i>Factory</i> class to generate key agreement protocol handlers.
*/
public class KeyAgreementFactory
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial constructor to enforce <i>Singleton</i> pattern. */
private KeyAgreementFactory()
{
super();
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns an instance of a key agreeent protocol handler, for party
+ * Returns an instance of a key agreeent protocol handler, for party
* <code>A</code> in a two-party <code>A..B</code> exchange, given the
* canonical name of this protocol. Party <code>A</code> is usually the
- * initiator of the exchange.</p>
- *
+ * initiator of the exchange.
+ *
* @param name the case-insensitive key agreement protocol name.
* @return an instance of the key agreement protocol handler for party
- * <code>A</code>, or <code>null</code> if none found.
+ * <code>A</code>, or <code>null</code> if none found.
*/
public static IKeyAgreementParty getPartyAInstance(String name)
{
if (name == null)
- {
- return null;
- }
-
+ return null;
name = name.trim();
IKeyAgreementParty result = null;
if (name.equalsIgnoreCase(Registry.DH_KA))
- {
- result = new DiffieHellmanSender();
- }
+ result = new DiffieHellmanSender();
else if (name.equalsIgnoreCase(Registry.ELGAMAL_KA))
- {
- result = new ElGamalSender();
- }
+ result = new ElGamalSender();
else if (name.equalsIgnoreCase(Registry.SRP6_KA))
- {
- result = new SRP6User();
- }
+ result = new SRP6User();
else if (name.equalsIgnoreCase(Registry.SRP_SASL_KA))
- {
- result = new SRP6SaslClient();
- }
+ result = new SRP6SaslClient();
else if (name.equalsIgnoreCase(Registry.SRP_TLS_KA))
- {
- result = new SRP6TLSClient();
- }
-
+ result = new SRP6TLSClient();
return result;
}
/**
- * <p>Returns an instance of a key agreeent protocol handler, for party
+ * Returns an instance of a key agreeent protocol handler, for party
* <code>B</code> in a two-party <code>A..B</code> exchange, given the
- * canonical name of this protocol.</p>
- *
+ * canonical name of this protocol.
+ *
* @param name the case-insensitive key agreement protocol name.
* @return an instance of the key agreement protocol handler for party
- * <code>B</code>, or <code>null</code> if none found.
+ * <code>B</code>, or <code>null</code> if none found.
*/
public static IKeyAgreementParty getPartyBInstance(String name)
{
if (name == null)
- {
- return null;
- }
-
+ return null;
name = name.trim();
IKeyAgreementParty result = null;
if (name.equalsIgnoreCase(Registry.DH_KA))
- {
- result = new DiffieHellmanReceiver();
- }
+ result = new DiffieHellmanReceiver();
else if (name.equalsIgnoreCase(Registry.ELGAMAL_KA))
- {
- result = new ElGamalReceiver();
- }
+ result = new ElGamalReceiver();
else if (name.equalsIgnoreCase(Registry.SRP6_KA))
- {
- result = new SRP6Host();
- }
+ result = new SRP6Host();
else if (name.equalsIgnoreCase(Registry.SRP_SASL_KA))
- {
- result = new SRP6SaslServer();
- }
+ result = new SRP6SaslServer();
else if (name.equalsIgnoreCase(Registry.SRP_TLS_KA))
- {
- result = new SRP6TLSServer();
- }
-
+ result = new SRP6TLSServer();
return result;
}
/**
- * <p>Returns a {@link Set} of key agreement protocol names supported by this
- * <i>Factory</i>.</p>
- *
+ * Returns a {@link Set} of key agreement protocol names supported by this
+ * <i>Factory</i>.
+ *
* @return a {@link Set} of key agreement protocol names (Strings).
*/
public static final Set getNames()
@@ -178,4 +140,4 @@ public class KeyAgreementFactory
return Collections.unmodifiableSet(hs);
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/key/OutgoingMessage.java b/gnu/javax/crypto/key/OutgoingMessage.java
index 588012120..563b3ef5a 100644
--- a/gnu/javax/crypto/key/OutgoingMessage.java
+++ b/gnu/javax/crypto/key/OutgoingMessage.java
@@ -53,21 +53,13 @@ import java.security.PublicKey;
import java.math.BigInteger;
/**
- * <p>An implementation of outgoing messages for use with key agreement
- * protocols.</p>
+ * An implementation of outgoing messages for use with key agreement protocols.
*/
public class OutgoingMessage
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The internal output stream. */
private ByteArrayOutputStream out;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public OutgoingMessage()
{
super();
@@ -75,16 +67,10 @@ public class OutgoingMessage
out = new ByteArrayOutputStream();
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the encoded form of the current message including the 4-byte
- * length header.</p>
- *
+ * Returns the encoded form of the current message including the 4-byte length
+ * header.
+ *
* @throws KeyAgreementException if an encoding size constraint is violated.
*/
public byte[] toByteArray() throws KeyAgreementException
@@ -92,28 +78,25 @@ public class OutgoingMessage
byte[] buffer = wrap();
int length = buffer.length;
byte[] result = new byte[length + 4];
- result[0] = (byte) (length >>> 24);
- result[1] = (byte) (length >>> 16);
- result[2] = (byte) (length >>> 8);
+ result[0] = (byte)(length >>> 24);
+ result[1] = (byte)(length >>> 16);
+ result[2] = (byte)(length >>> 8);
result[3] = (byte) length;
System.arraycopy(buffer, 0, result, 4, length);
-
return result;
}
/**
- * <p>Returns the encoded form of the current message excluding the 4-byte
- * length header.</p>
- *
+ * Returns the encoded form of the current message excluding the 4-byte length
+ * header.
+ *
* @throws KeyAgreementException if an encoding size constraint is violated.
*/
public byte[] wrap() throws KeyAgreementException
{
int length = out.size();
if (length > Registry.SASL_BUFFER_MAX_LIMIT || length < 0)
- {
- throw new KeyAgreementException("message content is too long");
- }
+ throw new KeyAgreementException("message content is too long");
return out.toByteArray();
}
@@ -128,9 +111,8 @@ public class OutgoingMessage
* representing the total length, excluding these 4 bytes, of the bytes
* representing the encoded key and the one-byte representing the key-type and
* format; i.e.
- *
* <pre>
- * key --&gt; 4-byte-length || 1-byte-type-and-format || encoded-key-bytes
+ * key --&gt; 4-byte-length || 1-byte-type-and-format || encoded-key-bytes
* </pre>
*
* @param k the public key to encode.
@@ -152,9 +134,8 @@ public class OutgoingMessage
* representing the total length, excluding these 4 bytes, of the bytes
* representing the encoded key and the one-byte representing the key-type and
* format; i.e.
- *
* <pre>
- * key --&gt; 4-byte-length || 1-byte-type-and-format || encoded-key-bytes
+ * key --&gt; 4-byte-length || 1-byte-type-and-format || encoded-key-bytes
* </pre>
*
* @param k the private key to encode.
@@ -166,8 +147,8 @@ public class OutgoingMessage
}
/**
- * <p>Encodes an MPI into the message.</p>
- *
+ * Encodes an MPI into the message.
+ *
* @param val the MPI to encode.
* @throws KeyAgreementException if an encoding size constraint is violated.
*/
@@ -176,20 +157,18 @@ public class OutgoingMessage
byte[] b = val.toByteArray();
int length = b.length;
if (length > Registry.SASL_TWO_BYTE_MAX_LIMIT)
- {
- throw new KeyAgreementException("MPI is too long");
- }
- byte[] lengthBytes = { (byte) (length >>> 8), (byte) length };
+ throw new KeyAgreementException("MPI is too long");
+ byte[] lengthBytes = { (byte)(length >>> 8), (byte) length };
out.write(lengthBytes, 0, 2);
out.write(b, 0, b.length);
}
/**
- * <p>Encodes a string into the message.</p>
- *
+ * Encodes a string into the message.
+ *
* @param s the string to encode.
- * @throws KeyAgreementException if the UTF8 encoding is not supported on
- * this platform, or if an encoding size constraint is violated.
+ * @throws KeyAgreementException if the UTF8 encoding is not supported on this
+ * platform, or if an encoding size constraint is violated.
*/
public void writeString(String s) throws KeyAgreementException
{
@@ -204,10 +183,8 @@ public class OutgoingMessage
}
int length = b.length;
if (length > Registry.SASL_TWO_BYTE_MAX_LIMIT)
- {
- throw new KeyAgreementException("text too long");
- }
- byte[] lengthBytes = { (byte) (length >>> 8), (byte) length };
+ throw new KeyAgreementException("text too long");
+ byte[] lengthBytes = { (byte)(length >>> 8), (byte) length };
out.write(lengthBytes, 0, 2);
out.write(b, 0, b.length);
}
@@ -224,9 +201,11 @@ public class OutgoingMessage
int length = b.length + 1;
if (length > Registry.SASL_FOUR_BYTE_MAX_LIMIT)
throw new KeyAgreementException("Encoded key is too long");
-
- byte[] lengthBytes = { (byte) (length >>> 24), (byte) (length >>> 16),
- (byte) (length >>> 8), (byte) length };
+ byte[] lengthBytes = {
+ (byte)(length >>> 24),
+ (byte)(length >>> 16),
+ (byte)(length >>> 8),
+ (byte) length };
out.write(lengthBytes, 0, 4);
out.write(((keyType & 0x0F) << 4) | (formatID & 0x0F));
out.write(b, 0, b.length);
@@ -252,4 +231,4 @@ public class OutgoingMessage
throw new KeyAgreementException("Unknown or unsupported key type: "
+ k.getClass().getName());
}
-} \ No newline at end of file
+}
diff --git a/gnu/javax/crypto/key/dh/DHKeyPairRawCodec.java b/gnu/javax/crypto/key/dh/DHKeyPairRawCodec.java
index c0ff82bea..aefcd5ff4 100644
--- a/gnu/javax/crypto/key/dh/DHKeyPairRawCodec.java
+++ b/gnu/javax/crypto/key/dh/DHKeyPairRawCodec.java
@@ -47,62 +47,49 @@ import java.security.PrivateKey;
import java.security.PublicKey;
/**
- * <p>An object that implements the {@link IKeyPairCodec} operations for the
- * <i>Raw</i> format to use with Diffie-Hellman keypairs.</p>
+ * An object that implements the {@link IKeyPairCodec} operations for the
+ * <i>Raw</i> format to use with Diffie-Hellman keypairs.
*/
-public class DHKeyPairRawCodec implements IKeyPairCodec
+public class DHKeyPairRawCodec
+ implements IKeyPairCodec
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
- // implicit 0-arguments ctor
-
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // gnu.crypto.keys.IKeyPairCodec interface implementation -------------------
-
public int getFormatID()
{
return RAW_FORMAT;
}
/**
- * <p>Returns the encoded form of the designated Diffie-Hellman public key
- * according to the <i>Raw</i> format supported by this library.</p>
- *
- * <p>The <i>Raw</i> format for a DH public key, in this implementation, is
- * a byte sequence consisting of the following:</p>
- *
+ * Returns the encoded form of the designated Diffie-Hellman public key
+ * according to the <i>Raw</i> format supported by this library.
+ * <p>
+ * The <i>Raw</i> format for a DH public key, in this implementation, is a
+ * byte sequence consisting of the following:
* <ol>
- * <li>4-byte magic consisting of the value of the literal
- * {@link Registry#MAGIC_RAW_DH_PUBLIC_KEY},<li>
- * <li>1-byte version consisting of the constant: 0x01,</li>
- * <li>4-byte count of following bytes representing the DH parameter
- * <code>q</code> in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DH parameter <code>q</code>,</li>
- * <li>4-byte count of following bytes representing the DH parameter
- * <code>p</code> in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DH parameter <code>p</code>,</li>
- * <li>4-byte count of following bytes representing the DH parameter
- * <code>g</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DH parameter <code>g</code>,</li>
- * <li>4-byte count of following bytes representing the DH parameter
- * <code>y</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DH parameter <code>y</code>,</li>
+ * <li>4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_DH_PUBLIC_KEY},</li>
+ * <li>1-byte version consisting of the constant: 0x01,</li>
+ * <li>4-byte count of following bytes representing the DH parameter
+ * <code>q</code> in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DH parameter <code>q</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DH parameter
+ * <code>p</code> in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DH parameter <code>p</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DH parameter
+ * <code>g</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DH parameter <code>g</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DH parameter
+ * <code>y</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DH parameter <code>y</code>,
+ * </li>
* </ol>
- *
+ *
* @param key the key to encode.
* @return the <i>Raw</i> format encoding of the designated key.
* @throws IllegalArgumentException if the designated key is not a DH one.
@@ -110,59 +97,49 @@ public class DHKeyPairRawCodec implements IKeyPairCodec
*/
public byte[] encodePublicKey(PublicKey key)
{
- if (!(key instanceof GnuDHPublicKey))
- {
- throw new IllegalArgumentException("key");
- }
-
+ if (! (key instanceof GnuDHPublicKey))
+ throw new IllegalArgumentException("key");
GnuDHPublicKey dhKey = (GnuDHPublicKey) key;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
// magic
baos.write(Registry.MAGIC_RAW_DH_PUBLIC_KEY[0]);
baos.write(Registry.MAGIC_RAW_DH_PUBLIC_KEY[1]);
baos.write(Registry.MAGIC_RAW_DH_PUBLIC_KEY[2]);
baos.write(Registry.MAGIC_RAW_DH_PUBLIC_KEY[3]);
-
// version
baos.write(0x01);
-
// q
byte[] buffer = dhKey.getQ().toByteArray();
int length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
// p
buffer = dhKey.getParams().getP().toByteArray();
length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
// g
buffer = dhKey.getParams().getG().toByteArray();
length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
// y
buffer = dhKey.getY().toByteArray();
length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
return baos.toByteArray();
}
@@ -173,83 +150,84 @@ public class DHKeyPairRawCodec implements IKeyPairCodec
|| k[1] != Registry.MAGIC_RAW_DH_PUBLIC_KEY[1]
|| k[2] != Registry.MAGIC_RAW_DH_PUBLIC_KEY[2]
|| k[3] != Registry.MAGIC_RAW_DH_PUBLIC_KEY[3])
- {
- throw new IllegalArgumentException("magic");
- }
-
+ throw new IllegalArgumentException("magic");
// version
if (k[4] != 0x01)
- {
- throw new IllegalArgumentException("version");
- }
+ throw new IllegalArgumentException("version");
int i = 5;
int l;
byte[] buffer;
-
// q
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger q = new BigInteger(1, buffer);
-
// p
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger p = new BigInteger(1, buffer);
-
// g
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger g = new BigInteger(1, buffer);
-
// y
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger y = new BigInteger(1, buffer);
-
return new GnuDHPublicKey(q, p, g, y);
}
/**
- * <p>Returns the encoded form of the designated Diffie-Hellman private key
- * according to the <i>Raw</i> format supported by this library.</p>
- *
- * <p>The <i>Raw</i> format for a DH private key, in this implementation, is
- * a byte sequence consisting of the following:</p>
- *
+ * Returns the encoded form of the designated Diffie-Hellman private key
+ * according to the <i>Raw</i> format supported by this library.
+ * <p>
+ * The <i>Raw</i> format for a DH private key, in this implementation, is a
+ * byte sequence consisting of the following:
* <ol>
- * <li>4-byte magic consisting of the value of the literal
- * {@link Registry#MAGIC_RAW_DH_PRIVATE_KEY},<li>
- * <li>1-byte version consisting of the constant: 0x01,</li>
- * <li>4-byte count of following bytes representing the DH parameter
- * <code>q</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DH parameter <code>q</code>,</li>
- * <li>4-byte count of following bytes representing the DH parameter
- * <code>p</code> in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DH parameter <code>p</code>,</li>
- * <li>4-byte count of following bytes representing the DH parameter
- * <code>g</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DH parameter <code>g</code>,</li>
- * <li>4-byte count of following bytes representing the DH parameter
- * <code>x</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the DH parameter <code>x</code>,</li>
+ * <li>4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_DH_PRIVATE_KEY},</li>
+ * <li>1-byte version consisting of the constant: 0x01,</li>
+ * <li>4-byte count of following bytes representing the DH parameter
+ * <code>q</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DH parameter <code>q</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DH parameter
+ * <code>p</code> in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DH parameter <code>p</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DH parameter
+ * <code>g</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DH parameter <code>g</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the DH parameter
+ * <code>x</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the DH parameter <code>x</code>,
+ * </li>
* </ol>
- *
+ *
* @param key the key to encode.
* @return the <i>Raw</i> format encoding of the designated key.
* @throws IllegalArgumentException if the designated key is not a DH one.
@@ -257,59 +235,49 @@ public class DHKeyPairRawCodec implements IKeyPairCodec
*/
public byte[] encodePrivateKey(PrivateKey key)
{
- if (!(key instanceof GnuDHPrivateKey))
- {
- throw new IllegalArgumentException("key");
- }
-
+ if (! (key instanceof GnuDHPrivateKey))
+ throw new IllegalArgumentException("key");
GnuDHPrivateKey dhKey = (GnuDHPrivateKey) key;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
// magic
baos.write(Registry.MAGIC_RAW_DH_PRIVATE_KEY[0]);
baos.write(Registry.MAGIC_RAW_DH_PRIVATE_KEY[1]);
baos.write(Registry.MAGIC_RAW_DH_PRIVATE_KEY[2]);
baos.write(Registry.MAGIC_RAW_DH_PRIVATE_KEY[3]);
-
// version
baos.write(0x01);
-
// q
byte[] buffer = dhKey.getQ().toByteArray();
int length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
// p
buffer = dhKey.getParams().getP().toByteArray();
length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
// g
buffer = dhKey.getParams().getG().toByteArray();
length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
// x
buffer = dhKey.getX().toByteArray();
length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
return baos.toByteArray();
}
@@ -320,51 +288,49 @@ public class DHKeyPairRawCodec implements IKeyPairCodec
|| k[1] != Registry.MAGIC_RAW_DH_PRIVATE_KEY[1]
|| k[2] != Registry.MAGIC_RAW_DH_PRIVATE_KEY[2]
|| k[3] != Registry.MAGIC_RAW_DH_PRIVATE_KEY[3])
- {
- throw new IllegalArgumentException("magic");
- }
-
+ throw new IllegalArgumentException("magic");
// version
if (k[4] != 0x01)
- {
- throw new IllegalArgumentException("version");
- }
+ throw new IllegalArgumentException("version");
int i = 5;
int l;
byte[] buffer;
-
// q
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger q = new BigInteger(1, buffer);
-
// p
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger p = new BigInteger(1, buffer);
-
// g
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger g = new BigInteger(1, buffer);
-
// x
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger x = new BigInteger(1, buffer);
-
return new GnuDHPrivateKey(q, p, g, x);
}
}
diff --git a/gnu/javax/crypto/key/dh/DiffieHellmanKeyAgreement.java b/gnu/javax/crypto/key/dh/DiffieHellmanKeyAgreement.java
index 5b1caa7d1..244395054 100644
--- a/gnu/javax/crypto/key/dh/DiffieHellmanKeyAgreement.java
+++ b/gnu/javax/crypto/key/dh/DiffieHellmanKeyAgreement.java
@@ -49,78 +49,63 @@ import java.math.BigInteger;
import javax.crypto.interfaces.DHPrivateKey;
/**
- * <p>The basic version of the Diffie-Hellman key agreement is described in the
- * Handbook of Applied Cryptography [HAC] as follows:</p>
+ * The basic version of the Diffie-Hellman key agreement is described in the
+ * Handbook of Applied Cryptography [HAC] as follows:
* <ul>
- * <li>An appropriate prime p and generator g of Z<sub>p</sub><sup>*</sup>
- * (2 &lt;= g &lt;= p-2) are selected and published.</li>
- * <li>A and B each send the other one message over an open channel; as a
- * result, they both can then compute a shared secret key K which they can
- * use to protect their future communication.</li>
- * <li>A chooses a random secret x, 1 &lt;= x &lt;= p-2, and sends B message
- * (1) which is g^x mod p.</li>
- * <li>B chooses a random secret y, 1 &lt;= y &lt;= p-2, and sends A message
- * (2) which is g^y mod p.</li>
- * <li>B receives message (1) and computes the shared key as K = (g^x)^y mod
- * p.</li>
- * <li>A receives message (2) and computes the shared key as K = (g^y)^x mod
- * p.</li>
+ * <li>An appropriate prime p and generator g of Z<sub>p</sub><sup>*</sup>
+ * (2 &lt;= g &lt;= p-2) are selected and published.</li>
+ * <li>A and B each send the other one message over an open channel; as a
+ * result, they both can then compute a shared secret key K which they can use
+ * to protect their future communication.</li>
+ * <li>A chooses a random secret x, 1 &lt;= x &lt;= p-2, and sends B message
+ * (1) which is g^x mod p.</li>
+ * <li>B chooses a random secret y, 1 &lt;= y &lt;= p-2, and sends A message
+ * (2) which is g^y mod p.</li>
+ * <li>B receives message (1) and computes the shared key as K = (g^x)^y mod p.
+ * </li>
+ * <li>A receives message (2) and computes the shared key as K = (g^y)^x mod p.
+ * </li>
* </ul>
- *
- * <p>RFC-2631 describes a <i>Static-Static Mode</i> of operations with
- * Diffie-Hellman keypairs as follows:</p>
+ * <p>
+ * RFC-2631 describes a <i>Static-Static Mode</i> of operations with
+ * Diffie-Hellman keypairs as follows:
* <pre>
- * "In Static-Static mode, both the sender and the recipient have a
- static (and certified) key pair. Since the sender's and recipient's
- keys are therefore the same for each message, ZZ will be the same for
- each message. Thus, partyAInfo MUST be used (and different for each
- message) in order to ensure that different messages use different
- KEKs. Implementations MAY implement Static-Static mode."
+ * &quot;In Static-Static mode, both the sender and the recipient have a
+ * static (and certified) key pair. Since the sender's and recipient's
+ * keys are therefore the same for each message, ZZ will be the same for
+ * each message. Thus, partyAInfo MUST be used (and different for each
+ * message) in order to ensure that different messages use different
+ * KEKs. Implementations MAY implement Static-Static mode.&quot;
* </pre>
- *
- * <p>Reference:</p>
+ *
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
- * Agreement Method</a><br>
- * Eric Rescorla.</li>
- * <li><a href="http://www.cacr.math.uwaterloo.ca/hac">[HAC]</a>: Handbook of
- * Applied Cryptography.<br>
- * CRC Press, Inc. ISBN 0-8493-8523-7, 1997<br>
- * Menezes, A., van Oorschot, P. and S. Vanstone.</li>
+ * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
+ * Agreement Method</a><br>
+ * Eric Rescorla.</li>
+ * <li><a href="http://www.cacr.math.uwaterloo.ca/hac">[HAC]</a>: Handbook of
+ * Applied Cryptography.<br>
+ * CRC Press, Inc. ISBN 0-8493-8523-7, 1997<br>
+ * Menezes, A., van Oorschot, P. and S. Vanstone.</li>
* </ol>
*/
-public abstract class DiffieHellmanKeyAgreement extends BaseKeyAgreementParty
+public abstract class DiffieHellmanKeyAgreement
+ extends BaseKeyAgreementParty
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final String SOURCE_OF_RANDOMNESS = "gnu.crypto.dh.ka.prng";
-
- public static final String KA_DIFFIE_HELLMAN_OWNER_PRIVATE_KEY = "gnu.crypto.dh.ka.owner.private.key";
-
+ public static final String KA_DIFFIE_HELLMAN_OWNER_PRIVATE_KEY =
+ "gnu.crypto.dh.ka.owner.private.key";
/** The key agreement party's private key. */
protected DHPrivateKey ownerKey;
-
/** The shared secret key. */
protected BigInteger ZZ;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
protected DiffieHellmanKeyAgreement()
{
super(Registry.DH_KA);
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of common abstract methods in BaseKeyAGreementParty ------
-
protected byte[] engineSharedSecret() throws KeyAgreementException
{
return Util.trim(ZZ);
diff --git a/gnu/javax/crypto/key/dh/DiffieHellmanReceiver.java b/gnu/javax/crypto/key/dh/DiffieHellmanReceiver.java
index 4a3664d6a..ab1023ad3 100644
--- a/gnu/javax/crypto/key/dh/DiffieHellmanReceiver.java
+++ b/gnu/javax/crypto/key/dh/DiffieHellmanReceiver.java
@@ -51,50 +51,30 @@ import java.util.Map;
import javax.crypto.interfaces.DHPrivateKey;
/**
- * <p>This implementation is the receiver's part of the basic version of the
- * Diffie-Hellman key agreement exchange (B in [HAC]).</p>
- *
+ * This implementation is the receiver's part of the basic version of the
+ * Diffie-Hellman key agreement exchange (B in [HAC]).
+ *
* @see DiffieHellmanKeyAgreement
*/
-public class DiffieHellmanReceiver extends DiffieHellmanKeyAgreement
+public class DiffieHellmanReceiver
+ extends DiffieHellmanKeyAgreement
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private BigInteger y; // the receiver's random secret
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of abstract methods in base class ------------------------
-
protected void engineInit(Map attributes) throws KeyAgreementException
{
Object random = attributes.get(SOURCE_OF_RANDOMNESS);
rnd = null;
irnd = null;
if (random instanceof SecureRandom)
- {
- rnd = (SecureRandom) random;
- }
+ rnd = (SecureRandom) random;
else if (random instanceof IRandom)
- {
- irnd = (IRandom) random;
- }
+ irnd = (IRandom) random;
ownerKey = (DHPrivateKey) attributes.get(KA_DIFFIE_HELLMAN_OWNER_PRIVATE_KEY);
if (ownerKey == null)
- {
- throw new KeyAgreementException("missing owner's private key");
- }
+ throw new KeyAgreementException("missing owner's private key");
}
protected OutgoingMessage engineProcessMessage(IncomingMessage in)
@@ -109,20 +89,14 @@ public class DiffieHellmanReceiver extends DiffieHellmanKeyAgreement
}
}
- // own methods -------------------------------------------------------------
-
private OutgoingMessage computeSharedSecret(IncomingMessage in)
throws KeyAgreementException
{
BigInteger m1 = in.readMPI();
if (m1 == null)
- {
- throw new KeyAgreementException("missing message (1)");
- }
-
+ throw new KeyAgreementException("missing message (1)");
BigInteger p = ownerKey.getParams().getP();
BigInteger g = ownerKey.getParams().getG();
-
// B chooses a random integer y, 1 <= y <= p-2
// rfc-2631 restricts y to only be in [2, p-1]
BigInteger p_minus_2 = p.subtract(TWO);
@@ -132,16 +106,12 @@ public class DiffieHellmanReceiver extends DiffieHellmanKeyAgreement
nextRandomBytes(xBytes);
y = new BigInteger(1, xBytes);
}
- while (!(y.compareTo(TWO) >= 0 && y.compareTo(p_minus_2) <= 0));
-
+ while (! (y.compareTo(TWO) >= 0 && y.compareTo(p_minus_2) <= 0));
ZZ = m1.modPow(y, p); // ZZ = (yb ^ xa) mod p
-
complete = true;
-
// B sends A the message: g^y mod p
OutgoingMessage result = new OutgoingMessage();
result.writeMPI(g.modPow(y, p)); // message (2)
-
return result;
}
}
diff --git a/gnu/javax/crypto/key/dh/DiffieHellmanSender.java b/gnu/javax/crypto/key/dh/DiffieHellmanSender.java
index 0be82bfb4..52a030d67 100644
--- a/gnu/javax/crypto/key/dh/DiffieHellmanSender.java
+++ b/gnu/javax/crypto/key/dh/DiffieHellmanSender.java
@@ -51,50 +51,30 @@ import java.util.Map;
import javax.crypto.interfaces.DHPrivateKey;
/**
- * <p>This implementation is the sender's part of the basic version of the
- * Diffie-Hellman key agreement exchange (A in [HAC]).</p>
- *
+ * This implementation is the sender's part of the basic version of the
+ * Diffie-Hellman key agreement exchange (A in [HAC]).
+ *
* @see DiffieHellmanKeyAgreement
*/
-public class DiffieHellmanSender extends DiffieHellmanKeyAgreement
+public class DiffieHellmanSender
+ extends DiffieHellmanKeyAgreement
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private BigInteger x; // the sender's random secret
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of abstract methods in base class ------------------------
-
protected void engineInit(Map attributes) throws KeyAgreementException
{
Object random = attributes.get(SOURCE_OF_RANDOMNESS);
rnd = null;
irnd = null;
if (random instanceof SecureRandom)
- {
- rnd = (SecureRandom) random;
- }
+ rnd = (SecureRandom) random;
else if (random instanceof IRandom)
- {
- irnd = (IRandom) random;
- }
+ irnd = (IRandom) random;
ownerKey = (DHPrivateKey) attributes.get(KA_DIFFIE_HELLMAN_OWNER_PRIVATE_KEY);
if (ownerKey == null)
- {
- throw new KeyAgreementException("missing owner's private key");
- }
+ throw new KeyAgreementException("missing owner's private key");
}
protected OutgoingMessage engineProcessMessage(IncomingMessage in)
@@ -111,14 +91,11 @@ public class DiffieHellmanSender extends DiffieHellmanKeyAgreement
}
}
- // own methods -------------------------------------------------------------
-
private OutgoingMessage sendRandomSecret(IncomingMessage in)
throws KeyAgreementException
{
BigInteger p = ownerKey.getParams().getP();
BigInteger g = ownerKey.getParams().getG();
-
// A chooses a random integer x, 1 <= x <= p-2
// rfc-2631 restricts x to only be in [2, p-1]
BigInteger p_minus_2 = p.subtract(TWO);
@@ -128,12 +105,10 @@ public class DiffieHellmanSender extends DiffieHellmanKeyAgreement
nextRandomBytes(xBytes);
x = new BigInteger(1, xBytes);
}
- while (!(x.compareTo(TWO) >= 0 && x.compareTo(p_minus_2) <= 0));
-
+ while (! (x.compareTo(TWO) >= 0 && x.compareTo(p_minus_2) <= 0));
// A sends B the message: g^x mod p
OutgoingMessage result = new OutgoingMessage();
result.writeMPI(g.modPow(x, p));
-
return result;
}
@@ -142,13 +117,9 @@ public class DiffieHellmanSender extends DiffieHellmanKeyAgreement
{
BigInteger m1 = in.readMPI();
if (m1 == null)
- {
- throw new KeyAgreementException("missing message (2)");
- }
-
+ throw new KeyAgreementException("missing message (2)");
BigInteger p = ownerKey.getParams().getP();
- ZZ = m1.modPow(x, p); // ZZ = (yb ^ xa) mod p
-
+ ZZ = m1.modPow(x, p); // ZZ = (yb ^ xa) mod p
complete = true;
return null;
}
diff --git a/gnu/javax/crypto/key/dh/ElGamalKeyAgreement.java b/gnu/javax/crypto/key/dh/ElGamalKeyAgreement.java
index 1c4e11ce2..967eda3f5 100644
--- a/gnu/javax/crypto/key/dh/ElGamalKeyAgreement.java
+++ b/gnu/javax/crypto/key/dh/ElGamalKeyAgreement.java
@@ -47,77 +47,62 @@ import gnu.javax.crypto.key.KeyAgreementException;
import java.math.BigInteger;
/**
- * <p>The ElGamal key agreement, also known as the half-certified Diffie-Hellman
+ * The ElGamal key agreement, also known as the half-certified Diffie-Hellman
* key agreement, is described in the Handbook of Applied Cryptography [HAC] as
- * follows:</p>
+ * follows:
* <ul>
- * <li>A sends to B a single message allowing one-pass key agreement.</li>
- * <li>A obtains an authentic copy of B's public key (p, g, yb), where
- * yb = g**xb.</li>
- * <li>A chooses a random integer x, 1 &lt;= x &lt;= p-2, and sends B the
- * message g**x. A computes the shared secret key K as yb**x.</li>
- * <li>B computes the same key K on receipt of the previous message as
- * (g**x)**xb.</li>
+ * <li>A sends to B a single message allowing one-pass key agreement.</li>
+ * <li>A obtains an authentic copy of B's public key (p, g, yb), where yb =
+ * g**xb.</li>
+ * <li>A chooses a random integer x, 1 &lt;= x &lt;= p-2, and sends B the
+ * message g**x. A computes the shared secret key K as yb**x.</li>
+ * <li>B computes the same key K on receipt of the previous message as
+ * (g**x)**xb.</li>
* </ul>
- *
- * <p>RFC-2631 describes an <i>Ephemeral-Static Mode</i> of operations with
- * Diffie-Hellman keypairs as follows:</p>
+ * <p>
+ * RFC-2631 describes an <i>Ephemeral-Static Mode</i> of operations with
+ * Diffie-Hellman keypairs as follows:
* <pre>
- * "In Ephemeral-Static mode, the recipient has a static (and certified)
- * key pair, but the sender generates a new key pair for each message
- * and sends it using the originatorKey production. If the sender's key
- * is freshly generated for each message, the shared secret ZZ will be
- * similarly different for each message and partyAInfo MAY be omitted,
- * since it serves merely to decouple multiple KEKs generated by the
- * same set of pairwise keys. If, however, the same ephemeral sender key
- * is used for multiple messages (e.g. it is cached as a performance
- * optimization) then a separate partyAInfo MUST be used for each
- * message. All implementations of this standard MUST implement
- * Ephemeral-Static mode."
+ * &quot;In Ephemeral-Static mode, the recipient has a static (and certified)
+ * key pair, but the sender generates a new key pair for each message
+ * and sends it using the originatorKey production. If the sender's key
+ * is freshly generated for each message, the shared secret ZZ will be
+ * similarly different for each message and partyAInfo MAY be omitted,
+ * since it serves merely to decouple multiple KEKs generated by the
+ * same set of pairwise keys. If, however, the same ephemeral sender key
+ * is used for multiple messages (e.g. it is cached as a performance
+ * optimization) then a separate partyAInfo MUST be used for each
+ * message. All implementations of this standard MUST implement
+ * Ephemeral-Static mode.&quot;
* </pre>
- *
- * <p>Reference:</p>
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
- * Agreement Method</a><br>
- * Eric Rescorla.</li>
- * <li><a href="http://www.cacr.math.uwaterloo.ca/hac">[HAC]</a>: Handbook of
- * Applied Cryptography.<br>
- * CRC Press, Inc. ISBN 0-8493-8523-7, 1997<br>
- * Menezes, A., van Oorschot, P. and S. Vanstone.</li>
+ * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
+ * Agreement Method</a><br>
+ * Eric Rescorla.</li>
+ * <li><a href="http://www.cacr.math.uwaterloo.ca/hac">[HAC]</a>: Handbook of
+ * Applied Cryptography.<br>
+ * CRC Press, Inc. ISBN 0-8493-8523-7, 1997<br>
+ * Menezes, A., van Oorschot, P. and S. Vanstone.</li>
* </ol>
*/
-public abstract class ElGamalKeyAgreement extends BaseKeyAgreementParty
+public abstract class ElGamalKeyAgreement
+ extends BaseKeyAgreementParty
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final String SOURCE_OF_RANDOMNESS = "gnu.crypto.elgamal.ka.prng";
-
- public static final String KA_ELGAMAL_RECIPIENT_PRIVATE_KEY = "gnu.crypto.elgamal.ka.recipient.private.key";
-
- public static final String KA_ELGAMAL_RECIPIENT_PUBLIC_KEY = "gnu.crypto.elgamal.ka.recipient.public.key";
-
+ public static final String KA_ELGAMAL_RECIPIENT_PRIVATE_KEY =
+ "gnu.crypto.elgamal.ka.recipient.private.key";
+ public static final String KA_ELGAMAL_RECIPIENT_PUBLIC_KEY =
+ "gnu.crypto.elgamal.ka.recipient.public.key";
/** The shared secret key. */
protected BigInteger ZZ;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
protected ElGamalKeyAgreement()
{
super(Registry.ELGAMAL_KA);
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of common abstract methods in BaseKeyAGreementParty ------
-
protected byte[] engineSharedSecret() throws KeyAgreementException
{
return Util.trim(ZZ);
diff --git a/gnu/javax/crypto/key/dh/ElGamalReceiver.java b/gnu/javax/crypto/key/dh/ElGamalReceiver.java
index 24776cba1..bf9b4fb1f 100644
--- a/gnu/javax/crypto/key/dh/ElGamalReceiver.java
+++ b/gnu/javax/crypto/key/dh/ElGamalReceiver.java
@@ -49,33 +49,19 @@ import java.util.Map;
import javax.crypto.interfaces.DHPrivateKey;
/**
- * <p>This implementation is the receiver's part of the ElGamal key agreement
- * exchange (B in [HAC]).</p>
- *
+ * This implementation is the receiver's part of the ElGamal key agreement
+ * exchange (B in [HAC]).
+ *
* @see ElGamalKeyAgreement
*/
-public class ElGamalReceiver extends ElGamalKeyAgreement
+public class ElGamalReceiver
+ extends ElGamalKeyAgreement
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The recipient's private key. */
private DHPrivateKey B;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of abstract methods in base class ------------------------
-
protected void engineInit(Map attributes) throws KeyAgreementException
{
rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS);
@@ -83,9 +69,7 @@ public class ElGamalReceiver extends ElGamalKeyAgreement
// a keypair and publishes its public key
B = (DHPrivateKey) attributes.get(KA_ELGAMAL_RECIPIENT_PRIVATE_KEY);
if (B == null)
- {
- throw new KeyAgreementException("missing recipient private key");
- }
+ throw new KeyAgreementException("missing recipient private key");
}
protected OutgoingMessage engineProcessMessage(IncomingMessage in)
@@ -100,8 +84,6 @@ public class ElGamalReceiver extends ElGamalKeyAgreement
}
}
- // own methods -------------------------------------------------------------
-
private OutgoingMessage computeSharedSecret(IncomingMessage in)
throws KeyAgreementException
{
@@ -109,12 +91,8 @@ public class ElGamalReceiver extends ElGamalKeyAgreement
// K = (g^x)^xb mod p
BigInteger m1 = in.readMPI();
if (m1 == null)
- {
- throw new KeyAgreementException("missing message (1)");
- }
-
+ throw new KeyAgreementException("missing message (1)");
ZZ = m1.modPow(B.getX(), B.getParams().getP()); // ZZ = (ya ^ xb) mod p
-
complete = true;
return null;
}
diff --git a/gnu/javax/crypto/key/dh/ElGamalSender.java b/gnu/javax/crypto/key/dh/ElGamalSender.java
index a2de80a67..cdd1ef0da 100644
--- a/gnu/javax/crypto/key/dh/ElGamalSender.java
+++ b/gnu/javax/crypto/key/dh/ElGamalSender.java
@@ -49,33 +49,19 @@ import java.util.Map;
import javax.crypto.interfaces.DHPublicKey;
/**
- * <p>This implementation is the sender's part of the ElGamal key agreement
- * exchange (A in [HAC]).</p>
- *
+ * This implementation is the sender's part of the ElGamal key agreement
+ * exchange (A in [HAC]).
+ *
* @see ElGamalKeyAgreement
*/
-public class ElGamalSender extends ElGamalKeyAgreement
+public class ElGamalSender
+ extends ElGamalKeyAgreement
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The recipient's public key. */
private DHPublicKey B;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of abstract methods in base class ------------------------
-
protected void engineInit(Map attributes) throws KeyAgreementException
{
rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS);
@@ -83,9 +69,7 @@ public class ElGamalSender extends ElGamalKeyAgreement
// a keypair and publishes its public key
B = (DHPublicKey) attributes.get(KA_ELGAMAL_RECIPIENT_PUBLIC_KEY);
if (B == null)
- {
- throw new KeyAgreementException("missing recipient public key");
- }
+ throw new KeyAgreementException("missing recipient public key");
}
protected OutgoingMessage engineProcessMessage(IncomingMessage in)
@@ -100,15 +84,12 @@ public class ElGamalSender extends ElGamalKeyAgreement
}
}
- // own methods -------------------------------------------------------------
-
private OutgoingMessage computeSharedSecret(IncomingMessage in)
throws KeyAgreementException
{
BigInteger p = B.getParams().getP();
BigInteger g = B.getParams().getG();
BigInteger yb = B.getY();
-
// A chooses a random integer x, 1 <= x <= p-2
// rfc-2631 restricts x to only be in [2, p-1]
BigInteger p_minus_2 = p.subtract(TWO);
@@ -120,14 +101,11 @@ public class ElGamalSender extends ElGamalKeyAgreement
x = new BigInteger(1, xBytes);
}
while (x.compareTo(TWO) >= 0 && x.compareTo(p_minus_2) <= 0);
-
// A sends B the message: g^x mod p
OutgoingMessage result = new OutgoingMessage();
result.writeMPI(g.modPow(x, p));
-
// A computes the key as K = (yb)^x mod p
ZZ = yb.modPow(x, p); // ZZ = (yb ^ xa) mod p
-
complete = true;
return result;
}
diff --git a/gnu/javax/crypto/key/dh/GnuDHKey.java b/gnu/javax/crypto/key/dh/GnuDHKey.java
index aa16f4d7a..e37642f0a 100644
--- a/gnu/javax/crypto/key/dh/GnuDHKey.java
+++ b/gnu/javax/crypto/key/dh/GnuDHKey.java
@@ -49,49 +49,40 @@ import javax.crypto.interfaces.DHKey;
import javax.crypto.spec.DHParameterSpec;
/**
- * <p>A base asbtract class for both public and private Diffie-Hellman keys. It
- * encapsulates the two DH numbers: <code>p</code>, and <code>g</code>.</p>
- *
- * <p>According to the JDK, cryptographic <i>Keys</i> all have a <i>format</i>.
+ * A base asbtract class for both public and private Diffie-Hellman keys. It
+ * encapsulates the two DH numbers: <code>p</code>, and <code>g</code>.
+ * <p>
+ * According to the JDK, cryptographic <i>Keys</i> all have a <i>format</i>.
* The format used in this implementation is called <i>Raw</i>, and basically
* consists of the raw byte sequences of algorithm parameters. The exact order
- * of the byte sequences and the implementation details are given in each of
- * the relevant <code>getEncoded()</code> methods of each of the private and
- * public keys.</p>
- *
- * <p>Reference:</p>
+ * of the byte sequences and the implementation details are given in each of the
+ * relevant <code>getEncoded()</code> methods of each of the private and
+ * public keys.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
- * Agreement Method</a><br>
- * Eric Rescorla.</li>
+ * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
+ * Agreement Method</a><br>
+ * Eric Rescorla.</li>
* </ol>
*/
-public abstract class GnuDHKey implements Key, DHKey
+public abstract class GnuDHKey
+ implements Key, DHKey
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The public prime q. A prime divisor of p-1. */
protected BigInteger q;
-
/** The public prime p. */
protected BigInteger p;
-
/** The generator g. */
protected BigInteger g;
-
/**
- * Identifier of the default encoding format to use when externalizing the
- * key material.
+ * Identifier of the default encoding format to use when externalizing the key
+ * material.
*/
protected final int defaultFormat;
/** String representation of this key. Cached for speed. */
private transient String str;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Trivial protected constructor.
*
@@ -112,28 +103,13 @@ public abstract class GnuDHKey implements Key, DHKey
this.g = g;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // javax.crypto.interfaces.DHKey interface implementation ------------------
-
public DHParameterSpec getParams()
{
if (q == null)
- {
- return new DHParameterSpec(p, g);
- }
- else
- {
- return new DHParameterSpec(p, g, q.bitLength());
- }
+ return new DHParameterSpec(p, g);
+ return new DHParameterSpec(p, g, q.bitLength());
}
- // java.security.Key interface implementation ------------------------------
-
public String getAlgorithm()
{
return Registry.DH_KPG;
@@ -150,32 +126,25 @@ public abstract class GnuDHKey implements Key, DHKey
return FormatUtil.getEncodingShortName(defaultFormat);
}
- // Other instance methods --------------------------------------------------
-
public BigInteger getQ()
{
return q;
}
/**
- * <p>Returns <code>true</code> if the designated object is an instance of
- * {@link DHKey} and has the same Diffie-Hellman parameter values as this
- * one.</p>
- *
+ * Returns <code>true</code> if the designated object is an instance of
+ * {@link DHKey} and has the same Diffie-Hellman parameter values as this one.
+ *
* @param obj the other non-null DH key to compare to.
- * @return <code>true</code> if the designated object is of the same type and
- * value as this one.
+ * @return <code>true</code> if the designated object is of the same type
+ * and value as this one.
*/
public boolean equals(Object obj)
{
if (obj == null)
- {
- return false;
- }
- if (!(obj instanceof DHKey))
- {
- return false;
- }
+ return false;
+ if (! (obj instanceof DHKey))
+ return false;
DHKey that = (DHKey) obj;
return p.equals(that.getParams().getP())
&& g.equals(that.getParams().getG());
@@ -192,15 +161,12 @@ public abstract class GnuDHKey implements Key, DHKey
sb.append("q=null,");
else
sb.append("q=0x").append(q.toString(16)).append(",");
- sb.append(ls)
- .append("p=0x").append(p.toString(16)).append(",").append(ls)
+ sb.append(ls).append("p=0x").append(p.toString(16)).append(",").append(ls)
.append("g=0x").append(g.toString(16));
str = sb.toString();
}
return str;
}
- // abstract methods to be implemented by subclasses ------------------------
-
public abstract byte[] getEncoded(int format);
}
diff --git a/gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java b/gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java
index 989567f3d..13cfd9014 100644
--- a/gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java
+++ b/gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java
@@ -56,16 +56,17 @@ import javax.crypto.spec.DHGenParameterSpec;
import javax.crypto.spec.DHParameterSpec;
/**
- * <p>An implementation of a Diffie-Hellman keypair generator.</p>
- *
- * <p>Reference:</p>
+ * An implementation of a Diffie-Hellman keypair generator.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
- * Agreement Method</a><br>
- * Eric Rescorla.</li>
+ * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
+ * Agreement Method</a><br>
+ * Eric Rescorla.</li>
* </ol>
*/
-public class GnuDHKeyPairGenerator implements IKeyPairGenerator
+public class GnuDHKeyPairGenerator
+ implements IKeyPairGenerator
{
private static final Logger log = Logger.getLogger(GnuDHKeyPairGenerator.class.getName());
/**
@@ -73,79 +74,48 @@ public class GnuDHKeyPairGenerator implements IKeyPairGenerator
* default is to use a classloader singleton from {@link PRNG}.
*/
public static final String SOURCE_OF_RANDOMNESS = "gnu.crypto.dh.prng";
-
/**
* Property name of an optional {@link DHGenParameterSpec} or
* {@link DHParameterSpec} instance to use for this generator.
*/
public static final String DH_PARAMETERS = "gnu.crypto.dh.params";
-
/** Property name of the size in bits (Integer) of the public prime (p). */
public static final String PRIME_SIZE = "gnu.crypto.dh.L";
-
/** Property name of the size in bits (Integer) of the private exponent (x). */
public static final String EXPONENT_SIZE = "gnu.crypto.dh.m";
-
/**
* Property name of the preferred encoding format to use when externalizing
* generated instance of key-pairs from this generator. The property is taken
* to be an {@link Integer} that encapsulates an encoding format identifier.
*/
public static final String PREFERRED_ENCODING_FORMAT = "gnu.crypto.dh.encoding";
-
/** Default value for the size in bits of the public prime (p). */
- // private static final int DEFAULT_PRIME_SIZE = 1024;
public static final int DEFAULT_PRIME_SIZE = 512;
-
/** Default value for the size in bits of the private exponent (x). */
public static final int DEFAULT_EXPONENT_SIZE = 160;
-
/** Default encoding format to use when none was specified. */
private static final int DEFAULT_ENCODING_FORMAT = Registry.RAW_ENCODING_ID;
-
/** The SHA instance to use. */
private Sha160 sha = new Sha160();
-
/** The optional {@link SecureRandom} instance to use. */
private SecureRandom rnd = null;
-
/** The desired size in bits of the public prime (p). */
private int l;
-
/** The desired size in bits of the private exponent (x). */
private int m;
-
private BigInteger seed;
-
private BigInteger counter;
-
private BigInteger q;
-
private BigInteger p;
-
private BigInteger j;
-
private BigInteger g;
-
/** Our default source of randomness. */
private PRNG prng = null;
-
/** Preferred encoding format of generated keys. */
private int preferredFormat;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // gnu.crypto.keys.IKeyPairGenerator interface implementation ---------------
-
public String name()
{
return Registry.DH_KPG;
@@ -155,11 +125,9 @@ public class GnuDHKeyPairGenerator implements IKeyPairGenerator
{
// do we have a SecureRandom, or should we use our own?
rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS);
-
// are we given a set of Diffie-Hellman generation parameters or we shall
// use our own?
Object params = attributes.get(DH_PARAMETERS);
-
// find out the desired sizes
if (params instanceof DHGenParameterSpec)
{
@@ -177,7 +145,6 @@ public class GnuDHKeyPairGenerator implements IKeyPairGenerator
g = jceSpec.getG();
l = p.bitLength();
m = jceSpec.getL();
-
// If no exponent size was given, generate an exponent as
// large as the prime.
if (m == 0)
@@ -190,21 +157,12 @@ public class GnuDHKeyPairGenerator implements IKeyPairGenerator
bi = (Integer) attributes.get(EXPONENT_SIZE);
m = (bi == null ? DEFAULT_EXPONENT_SIZE : bi.intValue());
}
-
- // if ((L % 256) != 0 || L < 1024) {
if ((l % 256) != 0 || l < DEFAULT_PRIME_SIZE)
- {
- throw new IllegalArgumentException("invalid modulus size");
- }
+ throw new IllegalArgumentException("invalid modulus size");
if ((m % 8) != 0 || m < DEFAULT_EXPONENT_SIZE)
- {
- throw new IllegalArgumentException("invalid exponent size");
- }
+ throw new IllegalArgumentException("invalid exponent size");
if (m > l)
- {
- throw new IllegalArgumentException("exponent size > modulus size");
- }
-
+ throw new IllegalArgumentException("exponent size > modulus size");
// what is the preferred encoding format
Integer formatID = (Integer) attributes.get(PREFERRED_ENCODING_FORMAT);
preferredFormat = formatID == null ? DEFAULT_ENCODING_FORMAT
@@ -232,12 +190,10 @@ public class GnuDHKeyPairGenerator implements IKeyPairGenerator
log.fine("g: 0x" + g.toString(16));
}
}
-
// generate a private number x of length m such as: 1 < x < q - 1
BigInteger q_minus_1 = null;
if (q != null)
q_minus_1 = q.subtract(BigInteger.ONE);
-
// We already check if m is modulo 8 in `setup.' This could just
// be m >>> 3.
byte[] mag = new byte[(m + 7) / 8];
@@ -248,31 +204,23 @@ public class GnuDHKeyPairGenerator implements IKeyPairGenerator
x = new BigInteger(1, mag);
if (x.bitLength() == m && x.compareTo(BigInteger.ONE) > 0
&& (q_minus_1 == null || x.compareTo(q_minus_1) < 0))
- {
- break;
- }
+ break;
}
BigInteger y = g.modPow(x, p);
-
PrivateKey secK = new GnuDHPrivateKey(preferredFormat, q, p, g, x);
PublicKey pubK = new GnuDHPublicKey(preferredFormat, q, p, g, y);
-
return new KeyPair(pubK, secK);
}
- // other methods -----------------------------------------------------------
-
/**
- * <p>Fills the designated byte array with random data.</p>
- *
+ * Fills the designated byte array with random data.
+ *
* @param buffer the byte array to fill with random data.
*/
private void nextRandomBytes(byte[] buffer)
{
if (rnd != null)
- {
- rnd.nextBytes(buffer);
- }
+ rnd.nextBytes(buffer);
else
getDefaultPRNG().nextBytes(buffer);
}
diff --git a/gnu/javax/crypto/key/dh/GnuDHPrivateKey.java b/gnu/javax/crypto/key/dh/GnuDHPrivateKey.java
index f60343c54..7321102de 100644
--- a/gnu/javax/crypto/key/dh/GnuDHPrivateKey.java
+++ b/gnu/javax/crypto/key/dh/GnuDHPrivateKey.java
@@ -48,29 +48,24 @@ import java.math.BigInteger;
import javax.crypto.interfaces.DHPrivateKey;
/**
- * <p>An implementation of the Diffie-Hellman private key.</p>
- *
- * <p>Reference:</p>
+ * An implementation of the Diffie-Hellman private key.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
- * Agreement Method</a><br>
- * Eric Rescorla.</li>
+ * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
+ * Agreement Method</a><br>
+ * Eric Rescorla.</li>
* </ol>
*/
-public class GnuDHPrivateKey extends GnuDHKey implements DHPrivateKey
+public class GnuDHPrivateKey
+ extends GnuDHKey
+ implements DHPrivateKey
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The private exponent. */
private final BigInteger x;
/** String representation of this key. Cached for speed. */
private transient String str;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Convenience constructor. Calls the constructor with five arguments passing
* {@link Registry#RAW_ENCODING_ID} as the value of its first argument.
@@ -96,31 +91,27 @@ public class GnuDHPrivateKey extends GnuDHKey implements DHPrivateKey
* @param g the generator of the group.
* @param x the private value x.
*/
- public GnuDHPrivateKey(int preferredFormat,
- BigInteger q, BigInteger p, BigInteger g, BigInteger x)
+ public GnuDHPrivateKey(int preferredFormat, BigInteger q, BigInteger p,
+ BigInteger g, BigInteger x)
{
super(preferredFormat == Registry.ASN1_ENCODING_ID ? Registry.PKCS8_ENCODING_ID
: preferredFormat,
q, p, g);
-
this.x = x;
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>A class method that takes the output of the <code>encodePrivateKey()</code>
+ * A class method that takes the output of the <code>encodePrivateKey()</code>
* method of a DH keypair codec object (an instance implementing
* {@link IKeyPairCodec} for DH keys, and re-constructs an instance of this
- * object.</p>
- *
+ * object.
+ *
* @param k the contents of a previously encoded instance of this object.
- * @exception ArrayIndexOutOfBoundsException if there is not enough bytes,
- * in <code>k</code>, to represent a valid encoding of an instance of
- * this object.
- * @exception IllegalArgumentException if the byte sequence does not
- * represent a valid encoding of an instance of this object.
+ * @exception ArrayIndexOutOfBoundsException if there is not enough bytes, in
+ * <code>k</code>, to represent a valid encoding of an
+ * instance of this object.
+ * @exception IllegalArgumentException if the byte sequence does not represent
+ * a valid encoding of an instance of this object.
*/
public static GnuDHPrivateKey valueOf(byte[] k)
{
@@ -133,30 +124,22 @@ public class GnuDHPrivateKey extends GnuDHKey implements DHPrivateKey
catch (IllegalArgumentException ignored)
{
}
-
// try PKCS#8 codec
return (GnuDHPrivateKey) new DHKeyPairPKCS8Codec().decodePrivateKey(k);
}
- // Instance methods
- // -------------------------------------------------------------------------
-
- // javax.crypto.interfaces.DHPrivateKey interface implementation -----------
-
public BigInteger getX()
{
return x;
}
- // other methods -----------------------------------------------------------
-
/**
- * <p>Returns the encoded form of this private key according to the
- * designated format.</p>
- *
+ * Returns the encoded form of this private key according to the designated
+ * format.
+ *
* @param format the desired format identifier of the resulting encoding.
* @return the byte sequence encoding this key according to the designated
- * format.
+ * format.
* @exception IllegalArgumentException if the format is not supported.
* @see DHKeyPairRawCodec
*/
@@ -197,6 +180,7 @@ public class GnuDHPrivateKey extends GnuDHKey implements DHPrivateKey
DHPrivateKey that = (DHPrivateKey) obj;
return super.equals(that) && x.equals(that.getX());
}
+
public String toString()
{
if (str == null)
diff --git a/gnu/javax/crypto/key/dh/GnuDHPublicKey.java b/gnu/javax/crypto/key/dh/GnuDHPublicKey.java
index 3433379fd..5acc45299 100644
--- a/gnu/javax/crypto/key/dh/GnuDHPublicKey.java
+++ b/gnu/javax/crypto/key/dh/GnuDHPublicKey.java
@@ -47,28 +47,23 @@ import java.math.BigInteger;
import javax.crypto.interfaces.DHPublicKey;
/**
- * <p>An implementation of the Diffie-Hellman public key.</p>
- *
- * <p>Reference:</p>
+ * An implementation of the Diffie-Hellman public key.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
- * Agreement Method</a><br>
- * Eric Rescorla.</li>
+ * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
+ * Agreement Method</a><br>
+ * Eric Rescorla.</li>
* </ol>
*/
-public class GnuDHPublicKey extends GnuDHKey implements DHPublicKey
+public class GnuDHPublicKey
+ extends GnuDHKey
+ implements DHPublicKey
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
private BigInteger y;
/** String representation of this key. Cached for speed. */
private transient String str;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
* Convenience constructor. Calls the constructor with five arguments passing
* {@link Registry#RAW_ENCODING_ID} as the value of its first argument.
@@ -94,31 +89,27 @@ public class GnuDHPublicKey extends GnuDHKey implements DHPublicKey
* @param g the generator of the group.
* @param y the public value y.
*/
- public GnuDHPublicKey(int preferredFormat,
- BigInteger q, BigInteger p, BigInteger g, BigInteger y)
+ public GnuDHPublicKey(int preferredFormat, BigInteger q, BigInteger p,
+ BigInteger g, BigInteger y)
{
super(preferredFormat == Registry.ASN1_ENCODING_ID ? Registry.X509_ENCODING_ID
: preferredFormat,
q, p, g);
-
this.y = y;
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>A class method that takes the output of the <code>encodePublicKey()</code>
+ * A class method that takes the output of the <code>encodePublicKey()</code>
* method of a DH keypair codec object (an instance implementing
* {@link IKeyPairCodec} for DSS keys, and re-constructs an instance of this
- * object.</p>
- *
- * @param k the contents of a previously encoded instance of this object.
- * @exception ArrayIndexOutOfBoundsException if there is not enough bytes,
- * in <code>k</code>, to represent a valid encoding of an instance of this
* object.
- * @exception IllegalArgumentException if the byte sequence does not
- * represent a valid encoding of an instance of this object.
+ *
+ * @param k the contents of a previously encoded instance of this object.
+ * @exception ArrayIndexOutOfBoundsException if there is not enough bytes, in
+ * <code>k</code>, to represent a valid encoding of an
+ * instance of this object.
+ * @exception IllegalArgumentException if the byte sequence does not represent
+ * a valid encoding of an instance of this object.
*/
public static GnuDHPublicKey valueOf(byte[] k)
{
@@ -131,30 +122,22 @@ public class GnuDHPublicKey extends GnuDHKey implements DHPublicKey
catch (IllegalArgumentException ignored)
{
}
-
// try X.509 codec
return (GnuDHPublicKey) new DHKeyPairX509Codec().decodePublicKey(k);
}
- // Instance methods
- // -------------------------------------------------------------------------
-
- // javax.crypto.interfaces.DHPublicKey interface implementation ------------
-
public BigInteger getY()
{
return y;
}
- // other methods -----------------------------------------------------------
-
/**
- * <p>Returns the encoded form of this public key according to the designated
- * format.</p>
- *
+ * Returns the encoded form of this public key according to the designated
+ * format.
+ *
* @param format the desired format identifier of the resulting encoding.
* @return the byte sequence encoding this key according to the designated
- * format.
+ * format.
* @exception IllegalArgumentException if the format is not supported.
*/
public byte[] getEncoded(int format)
diff --git a/gnu/javax/crypto/key/dh/RFC2631.java b/gnu/javax/crypto/key/dh/RFC2631.java
index 7fcad8d86..673e44864 100644
--- a/gnu/javax/crypto/key/dh/RFC2631.java
+++ b/gnu/javax/crypto/key/dh/RFC2631.java
@@ -45,54 +45,36 @@ import java.math.BigInteger;
import java.security.SecureRandom;
/**
- * <p>An implementation of the Diffie-Hellman parameter generation as defined in
- * RFC-2631.</p>
- *
- * <p>Reference:</p>
+ * An implementation of the Diffie-Hellman parameter generation as defined in
+ * RFC-2631.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
- * Agreement Method</a><br>
- * Eric Rescorla.</li>
+ * <li><a href="http://www.ietf.org/rfc/rfc2631.txt">Diffie-Hellman Key
+ * Agreement Method</a><br>
+ * Eric Rescorla.</li>
* </ol>
*/
public class RFC2631
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final int DH_PARAMS_SEED = 0;
-
public static final int DH_PARAMS_COUNTER = 1;
-
public static final int DH_PARAMS_Q = 2;
-
public static final int DH_PARAMS_P = 3;
-
public static final int DH_PARAMS_J = 4;
-
public static final int DH_PARAMS_G = 5;
-
private static final BigInteger TWO = BigInteger.valueOf(2L);
-
/** The SHA instance to use. */
private Sha160 sha = new Sha160();
-
/** Length of private modulus and of q. */
private int m;
-
/** Length of public modulus p. */
private int L;
-
/** The optional {@link SecureRandom} instance to use. */
private SecureRandom rnd = null;
-
/** Our default source of randomness. */
private PRNG prng = null;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
public RFC2631(int m, int L, SecureRandom rnd)
{
super();
@@ -102,12 +84,6 @@ public class RFC2631
this.rnd = rnd;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
public BigInteger[] generateParameters()
{
int i, j, counter;
@@ -126,15 +102,16 @@ public class RFC2631
{
step4: while (true)
{
- // 4. Select an arbitrary bit string SEED such that length of SEED >= m
+ // 4. Select an arbitrary bit string SEED such that length of
+ // SEED >= m
nextRandomBytes(seedBytes);
SEED = new BigInteger(1, seedBytes).setBit(m - 1).setBit(0);
// 5. Set U = 0
U = BigInteger.ZERO;
// 6. For i = 0 to m' - 1
- // U = U + (SHA1[SEED + i] XOR SHA1[(SEED + m' + i)) * 2^(160 * i)
- // Note that for m=160, this reduces to the algorithm of [FIPS-186]
- // U = SHA1[SEED] XOR SHA1[(SEED+1) mod 2^160 ].
+ // U = U + (SHA1[SEED + i] XOR SHA1[(SEED + m' + i)) * 2^(160 * i)
+ // Note that for m=160, this reduces to the algorithm of FIPS-186
+ // U = SHA1[SEED] XOR SHA1[(SEED+1) mod 2^160 ].
for (i = 0; i < m_; i++)
{
u1 = SEED.add(BigInteger.valueOf(i)).toByteArray();
@@ -144,31 +121,27 @@ public class RFC2631
sha.update(u2, 0, u2.length);
u2 = sha.digest();
for (j = 0; j < u1.length; j++)
- {
- u1[j] ^= u2[j];
- }
+ u1[j] ^= u2[j];
U = U.add(new BigInteger(1, u1).multiply(TWO.pow(160 * i)));
}
// 5. Form q from U by computing U mod (2^m) and setting the most
- // significant bit (the 2^(m-1) bit) and the least significant bit to
- // 1. In terms of boolean operations, q = U OR 2^(m-1) OR 1. Note
- // that 2^(m-1) < q < 2^m
+ // significant bit (the 2^(m-1) bit) and the least significant
+ // bit to 1. In terms of boolean operations, q = U OR 2^(m-1) OR
+ // 1. Note that 2^(m-1) < q < 2^m
q = U.setBit(m - 1).setBit(0);
// 6. Use a robust primality algorithm to test whether q is prime.
// 7. If q is not prime then go to 4.
if (q.isProbablePrime(80))
- {
- break step4;
- }
+ break step4;
}
// 8. Let counter = 0
counter = 0;
step9: while (true)
{
// 9. Set R = seed + 2*m' + (L' * counter)
- R = SEED.add(BigInteger.valueOf(2 * m_)).add(
- BigInteger.valueOf(L_
- * counter));
+ R = SEED
+ .add(BigInteger.valueOf(2 * m_))
+ .add(BigInteger.valueOf(L_ * counter));
// 10. Set V = 0
V = BigInteger.ZERO;
// 12. For i = 0 to L'-1 do: V = V + SHA1(R + i) * 2^(160 * i)
@@ -186,9 +159,9 @@ public class RFC2631
X = W.setBit(L - 1);
// 15. Set p = X - (X mod (2*q)) + 1
p = X.add(BigInteger.ONE).subtract(X.mod(TWO.multiply(q)));
- // 16. If p > 2^(L-1) use a robust primality test to test whether p is
- // prime. Else go to 18.
- //17. If p is prime output p, q, seed, counter and stop.
+ // 16. If p > 2^(L-1) use a robust primality test to test whether p
+ // is prime. Else go to 18.
+ // 17. If p is prime output p, q, seed, counter and stop.
if (p.isProbablePrime(80))
{
break algorithm;
@@ -198,12 +171,9 @@ public class RFC2631
// 19. If counter < (4096 * N) then go to 8.
// 20. Output "failure"
if (counter >= 4096 * N_)
- {
- continue algorithm;
- }
+ continue algorithm;
}
}
-
// compute g. from FIPS-186, Appendix 4:
// 1. Generate p and q as specified in Appendix 2.
// 2. Let e = (p - 1) / q
@@ -218,28 +188,21 @@ public class RFC2631
// 4. Set g = h**e mod p
g = h.modPow(e, p);
// 5. If g = 1, go to step 3
- if (!g.equals(BigInteger.ONE))
- {
- break;
- }
+ if (! g.equals(BigInteger.ONE))
+ break;
}
-
return new BigInteger[] { SEED, BigInteger.valueOf(counter), q, p, e, g };
}
- // helper methods ----------------------------------------------------------
-
/**
- * <p>Fills the designated byte array with random data.</p>
+ * Fills the designated byte array with random data.
*
* @param buffer the byte array to fill with random data.
*/
private void nextRandomBytes(byte[] buffer)
{
if (rnd != null)
- {
- rnd.nextBytes(buffer);
- }
+ rnd.nextBytes(buffer);
else
getDefaultPRNG().nextBytes(buffer);
}
diff --git a/gnu/javax/crypto/key/srp6/SRP6Host.java b/gnu/javax/crypto/key/srp6/SRP6Host.java
index 192e877b7..44f994673 100644
--- a/gnu/javax/crypto/key/srp6/SRP6Host.java
+++ b/gnu/javax/crypto/key/srp6/SRP6Host.java
@@ -56,65 +56,41 @@ import java.util.HashMap;
import java.util.Map;
/**
- * <p>The implementation of the Host in the SRP-6 key agreement protocol.</p>
- *
- * <p>Reference:</p>
+ * The implementation of the Host in the SRP-6 key agreement protocol.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
- * Thomas J. Wu.</li>
+ * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
+ * Thomas J. Wu.</li>
* </ol>
*/
-public class SRP6Host extends SRP6KeyAgreement
+public class SRP6Host
+ extends SRP6KeyAgreement
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The user's ephemeral key pair. */
private KeyPair hostKeyPair;
/** The SRP password database. */
private SRPAuthInfoProvider passwordDB;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of abstract methods in base class ------------------------
-
protected void engineInit(final Map attributes) throws KeyAgreementException
{
rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS);
N = (BigInteger) attributes.get(SHARED_MODULUS);
if (N == null)
- {
- throw new KeyAgreementException("missing shared modulus");
- }
+ throw new KeyAgreementException("missing shared modulus");
g = (BigInteger) attributes.get(GENERATOR);
if (g == null)
- {
- throw new KeyAgreementException("missing generator");
- }
-
+ throw new KeyAgreementException("missing generator");
final String md = (String) attributes.get(HASH_FUNCTION);
- if (md == null || "".equals(md.trim()))
- {
- throw new KeyAgreementException("missing hash function");
- }
+ if (md == null || md.trim().length() == 0)
+ throw new KeyAgreementException("missing hash function");
srp = SRP.instance(md);
-
passwordDB = (SRPAuthInfoProvider) attributes.get(HOST_PASSWORD_DB);
if (passwordDB == null)
- {
- throw new KeyAgreementException("missing SRP password database");
- }
+ throw new KeyAgreementException("missing SRP password database");
}
protected OutgoingMessage engineProcessMessage(final IncomingMessage in)
@@ -135,14 +111,11 @@ public class SRP6Host extends SRP6KeyAgreement
super.engineReset();
}
- // own methods -------------------------------------------------------------
-
private OutgoingMessage computeSharedSecret(final IncomingMessage in)
throws KeyAgreementException
{
final String I = in.readString();
final BigInteger A = in.readMPI();
-
// get s and v for user identified by I
// ----------------------------------------------------------------------
final Map credentials;
@@ -157,56 +130,31 @@ public class SRP6Host extends SRP6KeyAgreement
{
throw new KeyAgreementException("computeSharedSecret()", x);
}
-
final BigInteger s = new BigInteger(
- 1,
- Util.fromBase64((String) credentials.get(SRPRegistry.SALT_FIELD)));
+ 1,Util.fromBase64((String) credentials.get(SRPRegistry.SALT_FIELD)));
final BigInteger v = new BigInteger(
- 1,
- Util.fromBase64((String) credentials.get(SRPRegistry.USER_VERIFIER_FIELD)));
-
- // Map configuration = null;
- // try {
- // String mode = (String) credentials.get(SRPRegistry.CONFIG_NDX_FIELD);
- // configuration = passwordDB.getConfiguration(mode);
- // } catch (IOException x) {
- // throw new KeyAgreementException("computeSharedSecret()", x);
- // }
- //
- // BigInteger N = new BigInteger(1, Util.fromBase64(
- // (String) configuration.get(SRPRegistry.SHARED_MODULUS)));
- // BigInteger g = new BigInteger(1, Util.fromBase64(
- // (String) configuration.get(SRPRegistry.FIELD_GENERATOR)));
- // ----------------------------------------------------------------------
-
+ 1, Util.fromBase64((String) credentials.get(SRPRegistry.USER_VERIFIER_FIELD)));
final SRPKeyPairGenerator kpg = new SRPKeyPairGenerator();
final Map attributes = new HashMap();
if (rnd != null)
- {
- attributes.put(SRPKeyPairGenerator.SOURCE_OF_RANDOMNESS, rnd);
- }
+ attributes.put(SRPKeyPairGenerator.SOURCE_OF_RANDOMNESS, rnd);
attributes.put(SRPKeyPairGenerator.SHARED_MODULUS, N);
attributes.put(SRPKeyPairGenerator.GENERATOR, g);
attributes.put(SRPKeyPairGenerator.USER_VERIFIER, v);
kpg.setup(attributes);
hostKeyPair = kpg.generate();
-
final BigInteger B = ((SRPPublicKey) hostKeyPair.getPublic()).getY();
final BigInteger u = uValue(A, B); // u = H(A | B)
-
// compute S = (Av^u) ^ b
final BigInteger b = ((SRPPrivateKey) hostKeyPair.getPrivate()).getX();
final BigInteger S = A.multiply(v.modPow(u, N)).modPow(b, N);
-
final byte[] sBytes = Util.trim(S);
final IMessageDigest hash = srp.newDigest();
hash.update(sBytes, 0, sBytes.length);
K = new BigInteger(1, hash.digest());
-
final OutgoingMessage result = new OutgoingMessage();
result.writeMPI(s);
result.writeMPI(B);
-
complete = true;
return result;
}
diff --git a/gnu/javax/crypto/key/srp6/SRP6KeyAgreement.java b/gnu/javax/crypto/key/srp6/SRP6KeyAgreement.java
index 63c981d80..b4264184e 100644
--- a/gnu/javax/crypto/key/srp6/SRP6KeyAgreement.java
+++ b/gnu/javax/crypto/key/srp6/SRP6KeyAgreement.java
@@ -49,98 +49,72 @@ import gnu.javax.crypto.sasl.srp.SRP;
import java.math.BigInteger;
/**
- * <p>The Secure Remote Password (SRP) key agreement protocol, also known as
- * SRP-6, is designed by Thomas J. Wu (see references). The protocol, and its
- * elements are described as follows:</p>
- *
+ * The Secure Remote Password (SRP) key agreement protocol, also known as SRP-6,
+ * is designed by Thomas J. Wu (see references). The protocol, and its elements
+ * are described as follows:
* <pre>
- * N A large safe prime (N = 2q+1, where q is prime)
- * All arithmetic is done modulo N.
- * g A generator modulo N
- * s User's salt
- * I Username
- * p Cleartext Password
- * H() One-way hash function
- * ^ (Modular) Exponentiation
- * u Random scrambling parameter
- * a,b Secret ephemeral values
- * A,B Public ephemeral values
- * x Private key (derived from p and s)
- * v Password verifier
- *
- * The host stores passwords using the following formula:
- * x = H(s | H(I ":" p)) (s is chosen randomly)
- * v = g^x (computes password verifier)
- *
- * The host then keeps {I, s, v} in its password database.
- *
- * The authentication protocol itself goes as follows:
- * User -> Host: I, A = g^a (identifies self, a = random number)
- * Host -> User: s, B = 3v + g^b (sends salt, b = random number)
- *
- * Both: u = H(A, B)
- *
- * User: x = H(s, p) (user enters password)
- * User: S = (B - 3g^x) ^ (a + ux) (computes session key)
- * User: K = H(S)
- *
- * Host: S = (Av^u) ^ b (computes session key)
- * Host: K = H(S)
+ * N A large safe prime (N = 2q+1, where q is prime)
+ * All arithmetic is done modulo N.
+ * g A generator modulo N
+ * s User's salt
+ * I Username
+ * p Cleartext Password
+ * H() One-way hash function
+ * &circ; (Modular) Exponentiation
+ * u Random scrambling parameter
+ * a,b Secret ephemeral values
+ * A,B Public ephemeral values
+ * x Private key (derived from p and s)
+ * v Password verifier
+ *
+ * The host stores passwords using the following formula:
+ * x = H(s | H(I &quot;:&quot; p)) (s is chosen randomly)
+ * v = g&circ;x (computes password verifier)
+ *
+ * The host then keeps {I, s, v} in its password database.
+ *
+ * The authentication protocol itself goes as follows:
+ * User -&gt; Host: I, A = g&circ;a (identifies self, a = random number)
+ * Host -&gt; User: s, B = 3v + g&circ;b (sends salt, b = random number)
+ *
+ * Both: u = H(A, B)
+ *
+ * User: x = H(s, p) (user enters password)
+ * User: S = (B - 3g&circ;x) &circ; (a + ux) (computes session key)
+ * User: K = H(S)
+ *
+ * Host: S = (Av&circ;u) &circ; b (computes session key)
+ * Host: K = H(S)
* </pre>
- *
- * <p>Reference:</p>
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
- * Thomas J. Wu.</li>
+ * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
+ * Thomas J. Wu.</li>
* </ol>
*/
-public abstract class SRP6KeyAgreement extends BaseKeyAgreementParty
+public abstract class SRP6KeyAgreement
+ extends BaseKeyAgreementParty
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
public static final String SOURCE_OF_RANDOMNESS = "gnu.crypto.srp6.ka.prng";
-
public static final String SHARED_MODULUS = "gnu.crypto.srp6.ka.N";
-
public static final String GENERATOR = "gnu.crypto.srp6.ka.g";
-
public static final String HASH_FUNCTION = "gnu.crypto.srp6.ka.H";
-
public static final String USER_IDENTITY = "gnu.crypto.srp6.ka.I";
-
public static final String USER_PASSWORD = "gnu.crypto.srp6.ka.p";
-
public static final String HOST_PASSWORD_DB = "gnu.crypto.srp6.ka.password.db";
-
protected static final BigInteger THREE = BigInteger.valueOf(3L);
-
protected SRP srp;
-
protected BigInteger N;
-
protected BigInteger g;
-
/** The shared secret key. */
protected BigInteger K;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
protected SRP6KeyAgreement()
{
super(Registry.SRP6_KA);
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of common abstract methods in BaseKeyAGreementParty ------
-
protected byte[] engineSharedSecret() throws KeyAgreementException
{
return Util.trim(K);
@@ -148,25 +122,20 @@ public abstract class SRP6KeyAgreement extends BaseKeyAgreementParty
protected void engineReset()
{
- // mda = null;
srp = null;
N = null;
g = null;
K = null;
}
- // helper methods ----------------------------------------------------------
-
protected BigInteger uValue(final BigInteger A, final BigInteger B)
{
- // IMessageDigest hash = (IMessageDigest) mda.clone();
final IMessageDigest hash = srp.newDigest();
byte[] b;
b = Util.trim(A);
hash.update(b, 0, b.length);
b = Util.trim(B);
hash.update(b, 0, b.length);
-
return new BigInteger(1, hash.digest());
}
}
diff --git a/gnu/javax/crypto/key/srp6/SRP6SaslClient.java b/gnu/javax/crypto/key/srp6/SRP6SaslClient.java
index ef460b13b..f5969f0c1 100644
--- a/gnu/javax/crypto/key/srp6/SRP6SaslClient.java
+++ b/gnu/javax/crypto/key/srp6/SRP6SaslClient.java
@@ -48,54 +48,43 @@ import gnu.javax.crypto.key.OutgoingMessage;
import java.math.BigInteger;
/**
- * <p>A variation of the SRP-6 protocol as used in the SASL-SRP mechanism, for
- * the User (client side).</p>
- *
- * <p>In this alternative, the exchange goes as follows:</p>
+ * A variation of the SRP-6 protocol as used in the SASL-SRP mechanism, for the
+ * User (client side).
+ * <p>
+ * In this alternative, the exchange goes as follows:
+ *
* <pre>
- * C -> S: I (identifies self)
- * S -> C: N, g, s, B = 3v + g^b (sends salt, b = random number)
- * C -> S: A = g^a (a = random number)
+ * C -&gt; S: I (identifies self)
+ * S -&gt; C: N, g, s, B = 3v + g&circ;b (sends salt, b = random number)
+ * C -&gt; S: A = g&circ;a (a = random number)
* </pre>
- *
- * <p>All elements are computed the same way as in the standard version.</p>
- *
- * <p>Reference:</p>
+ *
+ * <p>
+ * All elements are computed the same way as in the standard version.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://www.ietf.org/internet-drafts/draft-burdis-cat-srp-sasl-09.txt">
- * Secure Remote Password Authentication Mechanism</a><br>
- * K. Burdis, R. Naffah.</li>
- * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
- * Thomas J. Wu.</li>
+ * <li><a
+ * href="http://www.ietf.org/internet-drafts/draft-burdis-cat-srp-sasl-09.txt">
+ * Secure Remote Password Authentication Mechanism</a><br>
+ * K. Burdis, R. Naffah.</li>
+ * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
+ * Thomas J. Wu.</li>
* </ol>
*/
-public class SRP6SaslClient extends SRP6TLSClient
+public class SRP6SaslClient
+ extends SRP6TLSClient
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
protected OutgoingMessage computeSharedSecret(final IncomingMessage in)
throws KeyAgreementException
{
final OutgoingMessage result = super.computeSharedSecret(in);
-
final byte[] sBytes = Util.trim(K);
final IMessageDigest hash = srp.newDigest();
hash.update(sBytes, 0, sBytes.length);
K = new BigInteger(1, hash.digest());
-
return result;
}
}
diff --git a/gnu/javax/crypto/key/srp6/SRP6SaslServer.java b/gnu/javax/crypto/key/srp6/SRP6SaslServer.java
index 5e759964e..7e68c99c4 100644
--- a/gnu/javax/crypto/key/srp6/SRP6SaslServer.java
+++ b/gnu/javax/crypto/key/srp6/SRP6SaslServer.java
@@ -48,54 +48,43 @@ import gnu.javax.crypto.key.OutgoingMessage;
import java.math.BigInteger;
/**
- * <p>A variation of the SRP-6 protocol as used in the SASL-SRP mechanism, for
- * the Host (server side).</p>
- *
- * <p>In this alternative, the exchange goes as follows:</p>
+ * A variation of the SRP-6 protocol as used in the SASL-SRP mechanism, for the
+ * Host (server side).
+ * <p>
+ * In this alternative, the exchange goes as follows:
+ *
* <pre>
- * C -> S: I (identifies self)
- * S -> C: N, g, s, B = 3v + g^b (sends salt, b = random number)
- * C -> S: A = g^a (a = random number)
+ * C -&gt; S: I (identifies self)
+ * S -&gt; C: N, g, s, B = 3v + g&circ;b (sends salt, b = random number)
+ * C -&gt; S: A = g&circ;a (a = random number)
* </pre>
- *
- * <p>All elements are computed the same way as in the standard version.</p>
- *
- * <p>Reference:</p>
+ *
+ * <p>
+ * All elements are computed the same way as in the standard version.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://www.ietf.org/internet-drafts/draft-burdis-cat-srp-sasl-09.txt">
- * Secure Remote Password Authentication Mechanism</a><br>
- * K. Burdis, R. Naffah.</li>
- * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
- * Thomas J. Wu.</li>
+ * <li><a
+ * href="http://www.ietf.org/internet-drafts/draft-burdis-cat-srp-sasl-09.txt">
+ * Secure Remote Password Authentication Mechanism</a><br>
+ * K. Burdis, R. Naffah.</li>
+ * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
+ * Thomas J. Wu.</li>
* </ol>
*/
-public class SRP6SaslServer extends SRP6TLSServer
+public class SRP6SaslServer
+ extends SRP6TLSServer
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
protected OutgoingMessage computeSharedSecret(final IncomingMessage in)
throws KeyAgreementException
{
super.computeSharedSecret(in);
-
final byte[] sBytes = Util.trim(K);
final IMessageDigest hash = srp.newDigest();
hash.update(sBytes, 0, sBytes.length);
K = new BigInteger(1, hash.digest());
-
return null;
}
}
diff --git a/gnu/javax/crypto/key/srp6/SRP6TLSClient.java b/gnu/javax/crypto/key/srp6/SRP6TLSClient.java
index 5474a1e8e..af0be02df 100644
--- a/gnu/javax/crypto/key/srp6/SRP6TLSClient.java
+++ b/gnu/javax/crypto/key/srp6/SRP6TLSClient.java
@@ -51,62 +51,38 @@ import java.util.HashMap;
import java.util.Map;
/**
- * <p>A variation of the SRP6 key agreement protocol, for the client-side as
- * proposed in
- * <a href="http://www.ietf.org/internet-drafts/draft-ietf-tls-srp-05.txt">Using
+ * A variation of the SRP6 key agreement protocol, for the client-side as
+ * proposed in <a
+ * href="http://www.ietf.org/internet-drafts/draft-ietf-tls-srp-05.txt">Using
* SRP for TLS Authentication</a>. The only difference between it and the SASL
* variant is that the shared secret is the entity <code>S</code> and not
- * <code>H(S)</code>.</p>
+ * <code>H(S)</code>.
*/
-public class SRP6TLSClient extends SRP6KeyAgreement
+public class SRP6TLSClient
+ extends SRP6KeyAgreement
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The user's identity. */
private String I;
-
/** The user's cleartext password. */
private byte[] p;
-
/** The user's ephemeral key pair. */
private KeyPair userKeyPair;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of abstract methods in base class ------------------------
-
protected void engineInit(final Map attributes) throws KeyAgreementException
{
rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS);
-
final String md = (String) attributes.get(HASH_FUNCTION);
- if (md == null || "".equals(md.trim()))
- {
- throw new KeyAgreementException("missing hash function");
- }
+ if (md == null || md.trim().length() == 0)
+ throw new KeyAgreementException("missing hash function");
srp = SRP.instance(md);
-
I = (String) attributes.get(USER_IDENTITY);
if (I == null)
- {
- throw new KeyAgreementException("missing user identity");
- }
+ throw new KeyAgreementException("missing user identity");
p = (byte[]) attributes.get(USER_PASSWORD);
if (p == null)
- {
- throw new KeyAgreementException("missing user password");
- }
+ throw new KeyAgreementException("missing user password");
}
protected OutgoingMessage engineProcessMessage(final IncomingMessage in)
@@ -131,14 +107,11 @@ public class SRP6TLSClient extends SRP6KeyAgreement
super.engineReset();
}
- // own methods -------------------------------------------------------------
-
private OutgoingMessage sendIdentity(final IncomingMessage in)
throws KeyAgreementException
{
final OutgoingMessage result = new OutgoingMessage();
result.writeString(I);
-
return result;
}
@@ -149,19 +122,15 @@ public class SRP6TLSClient extends SRP6KeyAgreement
g = in.readMPI();
final BigInteger s = in.readMPI();
final BigInteger B = in.readMPI();
-
// generate an ephemeral keypair
final SRPKeyPairGenerator kpg = new SRPKeyPairGenerator();
final Map attributes = new HashMap();
if (rnd != null)
- {
- attributes.put(SRPKeyPairGenerator.SOURCE_OF_RANDOMNESS, rnd);
- }
+ attributes.put(SRPKeyPairGenerator.SOURCE_OF_RANDOMNESS, rnd);
attributes.put(SRPKeyPairGenerator.SHARED_MODULUS, N);
attributes.put(SRPKeyPairGenerator.GENERATOR, g);
kpg.setup(attributes);
userKeyPair = kpg.generate();
-
final BigInteger A = ((SRPPublicKey) userKeyPair.getPublic()).getY();
final BigInteger u = uValue(A, B); // u = H(A | B)
final BigInteger x;
@@ -173,18 +142,13 @@ public class SRP6TLSClient extends SRP6KeyAgreement
{
throw new KeyAgreementException("computeSharedSecret()", e);
}
-
// compute S = (B - 3g^x) ^ (a + ux)
final BigInteger a = ((SRPPrivateKey) userKeyPair.getPrivate()).getX();
- final BigInteger S = B.subtract(THREE.multiply(g.modPow(x, N))).modPow(
- a.add(u.multiply(x)),
- N);
-
+ final BigInteger S = B.subtract(THREE.multiply(g.modPow(x, N)))
+ .modPow(a.add(u.multiply(x)), N);
K = S;
-
final OutgoingMessage result = new OutgoingMessage();
result.writeMPI(A);
-
complete = true;
return result;
}
diff --git a/gnu/javax/crypto/key/srp6/SRP6TLSServer.java b/gnu/javax/crypto/key/srp6/SRP6TLSServer.java
index ecbe36f62..f91cffd00 100644
--- a/gnu/javax/crypto/key/srp6/SRP6TLSServer.java
+++ b/gnu/javax/crypto/key/srp6/SRP6TLSServer.java
@@ -55,54 +55,33 @@ import java.util.HashMap;
import java.util.Map;
/**
- * <p>A variation of the SRP6 key agreement protocol, for the server-side as
- * proposed in
- * <a href="http://www.ietf.org/internet-drafts/draft-ietf-tls-srp-05.txt">Using
+ * A variation of the SRP6 key agreement protocol, for the server-side as
+ * proposed in <a
+ * href="http://www.ietf.org/internet-drafts/draft-ietf-tls-srp-05.txt">Using
* SRP for TLS Authentication</a>. The only difference between it and the SASL
* variant is that the shared secret is the entity <code>S</code> and not
- * <code>H(S)</code>.</p>
+ * <code>H(S)</code>.
*/
-public class SRP6TLSServer extends SRP6KeyAgreement
+public class SRP6TLSServer
+ extends SRP6KeyAgreement
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The user's ephemeral key pair. */
private KeyPair hostKeyPair;
-
/** The SRP password database. */
private SRPAuthInfoProvider passwordDB;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of abstract methods in base class ------------------------
-
protected void engineInit(final Map attributes) throws KeyAgreementException
{
rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS);
-
final String md = (String) attributes.get(HASH_FUNCTION);
- if (md == null || "".equals(md.trim()))
- {
- throw new KeyAgreementException("missing hash function");
- }
+ if (md == null || md.trim().length() == 0)
+ throw new KeyAgreementException("missing hash function");
srp = SRP.instance(md);
-
passwordDB = (SRPAuthInfoProvider) attributes.get(HOST_PASSWORD_DB);
if (passwordDB == null)
- {
- throw new KeyAgreementException("missing SRP password database");
- }
+ throw new KeyAgreementException("missing SRP password database");
}
protected OutgoingMessage engineProcessMessage(final IncomingMessage in)
@@ -125,13 +104,10 @@ public class SRP6TLSServer extends SRP6KeyAgreement
super.engineReset();
}
- // own methods -------------------------------------------------------------
-
private OutgoingMessage sendParameters(final IncomingMessage in)
throws KeyAgreementException
{
final String I = in.readString();
-
// get s and v for user identified by I
// ----------------------------------------------------------------------
final Map credentials;
@@ -148,12 +124,9 @@ public class SRP6TLSServer extends SRP6KeyAgreement
}
final BigInteger s = new BigInteger(
- 1,
- Util.fromBase64((String) credentials.get(SRPRegistry.SALT_FIELD)));
+ 1, Util.fromBase64((String) credentials.get(SRPRegistry.SALT_FIELD)));
final BigInteger v = new BigInteger(
- 1,
- Util.fromBase64((String) credentials.get(SRPRegistry.USER_VERIFIER_FIELD)));
-
+ 1, Util.fromBase64((String) credentials.get(SRPRegistry.USER_VERIFIER_FIELD)));
final Map configuration;
try
{
@@ -164,36 +137,26 @@ public class SRP6TLSServer extends SRP6KeyAgreement
{
throw new KeyAgreementException("computeSharedSecret()", x);
}
-
N = new BigInteger(
- 1,
- Util.fromBase64((String) configuration.get(SRPRegistry.SHARED_MODULUS)));
+ 1, Util.fromBase64((String) configuration.get(SRPRegistry.SHARED_MODULUS)));
g = new BigInteger(
- 1,
- Util.fromBase64((String) configuration.get(SRPRegistry.FIELD_GENERATOR)));
- // ----------------------------------------------------------------------
-
+ 1, Util.fromBase64((String) configuration.get(SRPRegistry.FIELD_GENERATOR)));
// generate an ephemeral keypair
final SRPKeyPairGenerator kpg = new SRPKeyPairGenerator();
final Map attributes = new HashMap();
if (rnd != null)
- {
- attributes.put(SRPKeyPairGenerator.SOURCE_OF_RANDOMNESS, rnd);
- }
+ attributes.put(SRPKeyPairGenerator.SOURCE_OF_RANDOMNESS, rnd);
attributes.put(SRPKeyPairGenerator.SHARED_MODULUS, N);
attributes.put(SRPKeyPairGenerator.GENERATOR, g);
attributes.put(SRPKeyPairGenerator.USER_VERIFIER, v);
kpg.setup(attributes);
hostKeyPair = kpg.generate();
-
final BigInteger B = ((SRPPublicKey) hostKeyPair.getPublic()).getY();
-
final OutgoingMessage result = new OutgoingMessage();
result.writeMPI(N);
result.writeMPI(g);
result.writeMPI(s);
result.writeMPI(B);
-
return result;
}
@@ -201,17 +164,13 @@ public class SRP6TLSServer extends SRP6KeyAgreement
throws KeyAgreementException
{
final BigInteger A = in.readMPI();
-
final BigInteger B = ((SRPPublicKey) hostKeyPair.getPublic()).getY();
final BigInteger u = uValue(A, B); // u = H(A | B)
-
// compute S = (Av^u) ^ b
final BigInteger b = ((SRPPrivateKey) hostKeyPair.getPrivate()).getX();
final BigInteger v = ((SRPPrivateKey) hostKeyPair.getPrivate()).getV();
final BigInteger S = A.multiply(v.modPow(u, N)).modPow(b, N);
-
K = S;
-
complete = true;
return null;
}
diff --git a/gnu/javax/crypto/key/srp6/SRP6User.java b/gnu/javax/crypto/key/srp6/SRP6User.java
index d300d6f76..7c97e7697 100644
--- a/gnu/javax/crypto/key/srp6/SRP6User.java
+++ b/gnu/javax/crypto/key/srp6/SRP6User.java
@@ -52,73 +52,45 @@ import java.util.HashMap;
import java.util.Map;
/**
- * <p>The implementation of the User in the SRP-6 protocol.</p>
- *
- * <p>Reference:</p>
+ * The implementation of the User in the SRP-6 protocol.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
- * Thomas J. Wu.</li>
+ * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
+ * Thomas J. Wu.</li>
* </ol>
*/
-public class SRP6User extends SRP6KeyAgreement
+public class SRP6User
+ extends SRP6KeyAgreement
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The user's identity. */
private String I;
-
/** The user's cleartext password. */
private byte[] p;
-
/** The user's ephemeral key pair. */
private KeyPair userKeyPair;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// default 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // implementation of abstract methods in base class ------------------------
-
protected void engineInit(final Map attributes) throws KeyAgreementException
{
rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS);
N = (BigInteger) attributes.get(SHARED_MODULUS);
if (N == null)
- {
- throw new KeyAgreementException("missing shared modulus");
- }
+ throw new KeyAgreementException("missing shared modulus");
g = (BigInteger) attributes.get(GENERATOR);
if (g == null)
- {
- throw new KeyAgreementException("missing generator");
- }
-
+ throw new KeyAgreementException("missing generator");
final String md = (String) attributes.get(HASH_FUNCTION);
- if (md == null || "".equals(md.trim()))
- {
- throw new KeyAgreementException("missing hash function");
- }
+ if (md == null || md.trim().length() == 0)
+ throw new KeyAgreementException("missing hash function");
srp = SRP.instance(md);
-
I = (String) attributes.get(USER_IDENTITY);
if (I == null)
- {
- throw new KeyAgreementException("missing user identity");
- }
+ throw new KeyAgreementException("missing user identity");
p = (byte[]) attributes.get(USER_PASSWORD);
if (p == null)
- {
- throw new KeyAgreementException("missing user password");
- }
+ throw new KeyAgreementException("missing user password");
}
protected OutgoingMessage engineProcessMessage(final IncomingMessage in)
@@ -143,8 +115,6 @@ public class SRP6User extends SRP6KeyAgreement
super.engineReset();
}
- // own methods -------------------------------------------------------------
-
private OutgoingMessage sendIdentity(final IncomingMessage in)
throws KeyAgreementException
{
@@ -152,18 +122,14 @@ public class SRP6User extends SRP6KeyAgreement
final SRPKeyPairGenerator kpg = new SRPKeyPairGenerator();
final Map attributes = new HashMap();
if (rnd != null)
- {
- attributes.put(SRPKeyPairGenerator.SOURCE_OF_RANDOMNESS, rnd);
- }
+ attributes.put(SRPKeyPairGenerator.SOURCE_OF_RANDOMNESS, rnd);
attributes.put(SRPKeyPairGenerator.SHARED_MODULUS, N);
attributes.put(SRPKeyPairGenerator.GENERATOR, g);
kpg.setup(attributes);
userKeyPair = kpg.generate();
-
final OutgoingMessage result = new OutgoingMessage();
result.writeString(I);
result.writeMPI(((SRPPublicKey) userKeyPair.getPublic()).getY());
-
return result;
}
@@ -172,10 +138,8 @@ public class SRP6User extends SRP6KeyAgreement
{
final BigInteger s = in.readMPI();
final BigInteger B = in.readMPI();
-
final BigInteger A = ((SRPPublicKey) userKeyPair.getPublic()).getY();
final BigInteger u = uValue(A, B); // u = H(A | B)
-
final BigInteger x;
try
{
@@ -185,18 +149,14 @@ public class SRP6User extends SRP6KeyAgreement
{
throw new KeyAgreementException("computeSharedSecret()", e);
}
-
// compute S = (B - 3g^x) ^ (a + ux)
final BigInteger a = ((SRPPrivateKey) userKeyPair.getPrivate()).getX();
- final BigInteger S = B.subtract(THREE.multiply(g.modPow(x, N))).modPow(
- a.add(u.multiply(x)),
- N);
-
+ final BigInteger S = B.subtract(THREE.multiply(g.modPow(x, N)))
+ .modPow(a.add(u.multiply(x)), N);
final byte[] sBytes = Util.trim(S);
final IMessageDigest hash = srp.newDigest();
hash.update(sBytes, 0, sBytes.length);
K = new BigInteger(1, hash.digest());
-
complete = true;
return null;
}
diff --git a/gnu/javax/crypto/key/srp6/SRPAlgorithm.java b/gnu/javax/crypto/key/srp6/SRPAlgorithm.java
index e59ab373f..85b3b1139 100644
--- a/gnu/javax/crypto/key/srp6/SRPAlgorithm.java
+++ b/gnu/javax/crypto/key/srp6/SRPAlgorithm.java
@@ -43,9 +43,9 @@ import gnu.javax.crypto.sasl.srp.SRPRegistry;
import java.math.BigInteger;
/**
- * <p>Utilities for use with SRP-6 based methods and protocols.</p>
- *
- * <p>Reference:</p>
+ * Utilities for use with SRP-6 based methods and protocols.
+ * <p>
+ * Reference:
* <ol>
* <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
* Thomas J. Wu.</li>
@@ -53,122 +53,79 @@ import java.math.BigInteger;
*/
public class SRPAlgorithm
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
// lifted from draft-burdis-cat-srp-sasl-09
public static final BigInteger N_2048 = new BigInteger(
- "AC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC3192943DB56050"
- + "A37329CBB4A099ED8193E0757767A13DD52312AB4B03310DCD7F48A9DA04FD50"
- + "E8083969EDB767B0CF6095179A163AB3661A05FBD5FAAAE82918A9962F0B93B8"
- + "55F97993EC975EEAA80D740ADBF4FF747359D041D5C33EA71D281E446B14773B"
- + "CA97B43A23FB801676BD207A436C6481F1D2B9078717461A5B9D32E688F87748"
- + "544523B524B0D57D5EA77A2775D2ECFA032CFBDBF52FB3786160279004E57AE6"
- + "AF874E7303CE53299CCC041C7BC308D82A5698F3A8D0C38271AE35F8E9DBFBB6"
- + "94B5C803D89F7AE435DE236D525F54759B65E372FCD68EF20FA7111F9E4AFF73",
- 16);
-
+ "AC6BDB41324A9A9BF166DE5E1389582FAF72B6651987EE07FC3192943DB56050"
+ + "A37329CBB4A099ED8193E0757767A13DD52312AB4B03310DCD7F48A9DA04FD50"
+ + "E8083969EDB767B0CF6095179A163AB3661A05FBD5FAAAE82918A9962F0B93B8"
+ + "55F97993EC975EEAA80D740ADBF4FF747359D041D5C33EA71D281E446B14773B"
+ + "CA97B43A23FB801676BD207A436C6481F1D2B9078717461A5B9D32E688F87748"
+ + "544523B524B0D57D5EA77A2775D2ECFA032CFBDBF52FB3786160279004E57AE6"
+ + "AF874E7303CE53299CCC041C7BC308D82A5698F3A8D0C38271AE35F8E9DBFBB6"
+ + "94B5C803D89F7AE435DE236D525F54759B65E372FCD68EF20FA7111F9E4AFF73", 16);
public static final BigInteger N_1536 = new BigInteger(
- "9DEF3CAFB939277AB1F12A8617A47BBBDBA51DF499AC4C80BEEEA9614B19CC4D"
- + "5F4F5F556E27CBDE51C6A94BE4607A291558903BA0D0F84380B655BB9A22E8DC"
- + "DF028A7CEC67F0D08134B1C8B97989149B609E0BE3BAB63D47548381DBC5B1FC"
- + "764E3F4B53DD9DA1158BFD3E2B9C8CF56EDF019539349627DB2FD53D24B7C486"
- + "65772E437D6C7F8CE442734AF7CCB7AE837C264AE3A9BEB87F8A2FE9B8B5292E"
- + "5A021FFF5E91479E8CE7A28C2442C6F315180F93499A234DCF76E3FED135F9BB",
- 16);
-
+ "9DEF3CAFB939277AB1F12A8617A47BBBDBA51DF499AC4C80BEEEA9614B19CC4D"
+ + "5F4F5F556E27CBDE51C6A94BE4607A291558903BA0D0F84380B655BB9A22E8DC"
+ + "DF028A7CEC67F0D08134B1C8B97989149B609E0BE3BAB63D47548381DBC5B1FC"
+ + "764E3F4B53DD9DA1158BFD3E2B9C8CF56EDF019539349627DB2FD53D24B7C486"
+ + "65772E437D6C7F8CE442734AF7CCB7AE837C264AE3A9BEB87F8A2FE9B8B5292E"
+ + "5A021FFF5E91479E8CE7A28C2442C6F315180F93499A234DCF76E3FED135F9BB", 16);
public static final BigInteger N_1280 = new BigInteger(
- "D77946826E811914B39401D56A0A7843A8E7575D738C672A090AB1187D690DC4"
- + "3872FC06A7B6A43F3B95BEAEC7DF04B9D242EBDC481111283216CE816E004B78"
- + "6C5FCE856780D41837D95AD787A50BBE90BD3A9C98AC0F5FC0DE744B1CDE1891"
- + "690894BC1F65E00DE15B4B2AA6D87100C9ECC2527E45EB849DEB14BB2049B163"
- + "EA04187FD27C1BD9C7958CD40CE7067A9C024F9B7C5A0B4F5003686161F0605B",
- 16);
-
+ "D77946826E811914B39401D56A0A7843A8E7575D738C672A090AB1187D690DC4"
+ + "3872FC06A7B6A43F3B95BEAEC7DF04B9D242EBDC481111283216CE816E004B78"
+ + "6C5FCE856780D41837D95AD787A50BBE90BD3A9C98AC0F5FC0DE744B1CDE1891"
+ + "690894BC1F65E00DE15B4B2AA6D87100C9ECC2527E45EB849DEB14BB2049B163"
+ + "EA04187FD27C1BD9C7958CD40CE7067A9C024F9B7C5A0B4F5003686161F0605B", 16);
public static final BigInteger N_1024 = new BigInteger(
- "EEAF0AB9ADB38DD69C33F80AFA8FC5E86072618775FF3C0B9EA2314C9C256576"
- + "D674DF7496EA81D3383B4813D692C6E0E0D5D8E250B98BE48E495C1D6089DAD1"
- + "5DC7D7B46154D6B6CE8EF4AD69B15D4982559B297BCF1885C529F566660E57EC"
- + "68EDBC3C05726CC02FD4CBF4976EAA9AFD5138FE8376435B9FC61D2FC0EB06E3",
- 16);
-
+ "EEAF0AB9ADB38DD69C33F80AFA8FC5E86072618775FF3C0B9EA2314C9C256576"
+ + "D674DF7496EA81D3383B4813D692C6E0E0D5D8E250B98BE48E495C1D6089DAD1"
+ + "5DC7D7B46154D6B6CE8EF4AD69B15D4982559B297BCF1885C529F566660E57EC"
+ + "68EDBC3C05726CC02FD4CBF4976EAA9AFD5138FE8376435B9FC61D2FC0EB06E3", 16);
public static final BigInteger N_768 = new BigInteger(
- "B344C7C4F8C495031BB4E04FF8F84EE95008163940B9558276744D91F7CC9F40"
- + "2653BE7147F00F576B93754BCDDF71B636F2099E6FFF90E79575F3D0DE694AFF"
- + "737D9BE9713CEF8D837ADA6380B1093E94B6A529A8C6C2BE33E0867C60C3262B",
- 16);
-
+ "B344C7C4F8C495031BB4E04FF8F84EE95008163940B9558276744D91F7CC9F40"
+ + "2653BE7147F00F576B93754BCDDF71B636F2099E6FFF90E79575F3D0DE694AFF"
+ + "737D9BE9713CEF8D837ADA6380B1093E94B6A529A8C6C2BE33E0867C60C3262B", 16);
public static final BigInteger N_640 = new BigInteger(
- "C94D67EB5B1A2346E8AB422FC6A0EDAEDA8C7F894C9EEEC42F9ED250FD7F0046"
- + "E5AF2CF73D6B2FA26BB08033DA4DE322E144E7A8E9B12A0E4637F6371F34A207"
- + "1C4B3836CBEEAB15034460FAA7ADF483",
- 16);
-
+ "C94D67EB5B1A2346E8AB422FC6A0EDAEDA8C7F894C9EEEC42F9ED250FD7F0046"
+ + "E5AF2CF73D6B2FA26BB08033DA4DE322E144E7A8E9B12A0E4637F6371F34A207"
+ + "1C4B3836CBEEAB15034460FAA7ADF483", 16);
public static final BigInteger N_512 = new BigInteger(
- "D4C7F8A2B32C11B8FBA9581EC4BA4F1B04215642EF7355E37C0FC0443EF756EA"
- + "2C6B8EEB755A1C723027663CAA265EF785B8FF6A9B35227A52D86633DBDFCA43",
- 16);
-
+ "D4C7F8A2B32C11B8FBA9581EC4BA4F1B04215642EF7355E37C0FC0443EF756EA"
+ + "2C6B8EEB755A1C723027663CAA265EF785B8FF6A9B35227A52D86633DBDFCA43", 16);
public static final BigInteger N_384 = new BigInteger(
- "8025363296FB943FCE54BE717E0E2958A02A9672EF561953B2BAA3BAACC3ED57"
- + "54EB764C7AB7184578C57D5949CCB41B",
- 16);
-
+ "8025363296FB943FCE54BE717E0E2958A02A9672EF561953B2BAA3BAACC3ED57"
+ + "54EB764C7AB7184578C57D5949CCB41B", 16);
public static final BigInteger N_264 = new BigInteger(
- "115B8B692E0E045692CF280B436735C77A5A9E8A9E7ED56C965F87DB5B2A2ECE3",
- 16);
-
+ "115B8B692E0E045692CF280B436735C77A5A9E8A9E7ED56C965F87DB5B2A2ECE3", 16);
private static final BigInteger ZERO = BigInteger.ZERO;
-
private static final BigInteger ONE = BigInteger.ONE;
-
private static final BigInteger TWO = BigInteger.valueOf(2L);
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/** Trivial constructor to enforce usage through class methods. */
private SRPAlgorithm()
{
super();
}
- // Class methods
- // -------------------------------------------------------------------------
-
public static void checkParams(final BigInteger N, final BigInteger g)
{
// 1. N should be at least 512-bit long
final int blen = N.bitLength();
if (blen < SRPRegistry.MINIMUM_MODULUS_BITLENGTH)
- {
- throw new IllegalArgumentException(
- "Bit length of N ("
- + blen
- + ") is too low. Should be at least "
- + SRPRegistry.MINIMUM_MODULUS_BITLENGTH);
- }
+ throw new IllegalArgumentException("Bit length of N ("
+ + blen
+ + ") is too low. Should be at least "
+ + SRPRegistry.MINIMUM_MODULUS_BITLENGTH);
// 2. N should be a prime
if (! N.isProbablePrime(80))
- {
- throw new IllegalArgumentException("N should be prime but isn't");
- }
+ throw new IllegalArgumentException("N should be prime but isn't");
// 3. N should be of the form 2*q + 1, where q is prime
final BigInteger q = N.subtract(ONE).divide(TWO);
if (! q.isProbablePrime(80))
- {
- throw new IllegalArgumentException("(N-1)/2 should be prime but isn't");
- }
+ throw new IllegalArgumentException("(N-1)/2 should be prime but isn't");
// 4. g**q should be -1 mod N
final BigInteger gq = g.modPow(q, N).add(ONE).mod(N);
if (gq.compareTo(ZERO) != 0)
- {
- throw new IllegalArgumentException(
- "g**q should be -1 (mod N) but isn't");
- }
+ throw new IllegalArgumentException("g**q should be -1 (mod N) but isn't");
}
-
- // Instance methods
- // -------------------------------------------------------------------------
}
diff --git a/gnu/javax/crypto/key/srp6/SRPKey.java b/gnu/javax/crypto/key/srp6/SRPKey.java
index 202ef33b7..06ba47a9f 100644
--- a/gnu/javax/crypto/key/srp6/SRPKey.java
+++ b/gnu/javax/crypto/key/srp6/SRPKey.java
@@ -46,37 +46,30 @@ import java.math.BigInteger;
import java.security.Key;
/**
- * <p>An abstract representation of a base SRP ephemeral key.</p>
- *
- * <p>This object encapsulates the two numbers:</p>
+ * An abstract representation of a base SRP ephemeral key.
+ * <p>
+ * This object encapsulates the two numbers:
* <ul>
- * <li><b>N</b>: A large safe prime (N = 2q+1, where q is prime).</li>
- * <li><b>g</b>: A generator modulo N.</li>
+ * <li><b>N</b>: A large safe prime (N = 2q+1, where q is prime).</li>
+ * <li><b>g</b>: A generator modulo N.</li>
* </ul>
- *
- * <p>Note that in SRP, all arithmetic is done modulo N.</p>
- *
- * <p>Reference:</p>
+ * <p>
+ * Note that in SRP, all arithmetic is done modulo N.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
- * Thomas J. Wu.</li>
+ * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
+ * Thomas J. Wu.</li>
* </ol>
*/
-public abstract class SRPKey implements Key, Serializable
+public abstract class SRPKey
+ implements Key, Serializable
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/** The public, Germaine prime, shared modulus. */
protected final BigInteger N;
-
/** The generator. */
protected final BigInteger g;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
protected SRPKey(BigInteger N, BigInteger g)
{
super();
@@ -85,17 +78,9 @@ public abstract class SRPKey implements Key, Serializable
this.g = g;
}
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // java.security.Key interface implementation ------------------------------
-
/**
- * <p>Returns the standard algorithm name for this key.</p>
- *
+ * Returns the standard algorithm name for this key.
+ *
* @return the standard algorithm name for this key.
*/
public String getAlgorithm()
@@ -112,7 +97,7 @@ public abstract class SRPKey implements Key, Serializable
/**
* Returns {@link Registry#RAW_ENCODING_SHORT_NAME} which is the sole format
* supported for this type of keys.
- *
+ *
* @return {@link Registry#RAW_ENCODING_SHORT_NAME} ALWAYS.
*/
public String getFormat()
@@ -120,11 +105,9 @@ public abstract class SRPKey implements Key, Serializable
return Registry.RAW_ENCODING_SHORT_NAME;
}
- // other methods -----------------------------------------------------------
-
/**
- * <p>Returns the public shared modulus.</p>
- *
+ * Returns the public shared modulus.
+ *
* @return <code>N</code>.
*/
public BigInteger getN()
@@ -133,8 +116,8 @@ public abstract class SRPKey implements Key, Serializable
}
/**
- * <p>Returns the generator.</p>
- *
+ * Returns the generator.
+ *
* @return <code>g</code>.
*/
public BigInteger getG()
@@ -143,28 +126,22 @@ public abstract class SRPKey implements Key, Serializable
}
/**
- * <p>Returns <code>true</code> if the designated object is an instance of
- * <code>SRPKey</code> and has the same SRP parameter values as this one.</p>
- *
+ * Returns <code>true</code> if the designated object is an instance of
+ * <code>SRPKey</code> and has the same SRP parameter values as this one.
+ *
* @param obj the other non-null SRP key to compare to.
- * @return <code>true</code> if the designated object is of the same type and
- * value as this one.
+ * @return <code>true</code> if the designated object is of the same type
+ * and value as this one.
*/
public boolean equals(Object obj)
{
if (obj == null)
- {
- return false;
- }
- if (!(obj instanceof SRPKey))
- {
- return false;
- }
+ return false;
+ if (! (obj instanceof SRPKey))
+ return false;
SRPKey that = (SRPKey) obj;
return N.equals(that.getN()) && g.equals(that.getG());
}
- // abstract methods to be implemented by subclasses ------------------------
-
public abstract byte[] getEncoded(int format);
}
diff --git a/gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java b/gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java
index 562347c95..8d50c9b71 100644
--- a/gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java
+++ b/gnu/javax/crypto/key/srp6/SRPKeyPairGenerator.java
@@ -50,80 +50,52 @@ import java.util.Map;
import java.util.logging.Logger;
/**
- *
- *
- * <p>Reference:</p>
+ * Reference:
* <ol>
- * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
- * Thomas J. Wu.</li>
+ * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
+ * Thomas J. Wu.</li>
* </ol>
*/
-public class SRPKeyPairGenerator implements IKeyPairGenerator
+public class SRPKeyPairGenerator
+ implements IKeyPairGenerator
{
private static final Logger log = Logger.getLogger(SRPKeyPairGenerator.class.getName());
private static final BigInteger ZERO = BigInteger.ZERO;
-
private static final BigInteger ONE = BigInteger.ONE;
-
private static final BigInteger TWO = BigInteger.valueOf(2L);
-
private static final BigInteger THREE = BigInteger.valueOf(3L);
-
/** Property name of the length (Integer) of the modulus (N) of an SRP key. */
public static final String MODULUS_LENGTH = "gnu.crypto.srp.L";
-
/** Property name of the Boolean indicating wether or not to use defaults. */
public static final String USE_DEFAULTS = "gnu.crypto.srp.use.defaults";
-
/** Property name of the modulus (N) of an SRP key. */
public static final String SHARED_MODULUS = "gnu.crypto.srp.N";
-
/** Property name of the generator (g) of an SRP key. */
public static final String GENERATOR = "gnu.crypto.srp.g";
-
/** Property name of the user's verifier (v) for a Server SRP key. */
public static final String USER_VERIFIER = "gnu.crypto.srp.v";
-
/**
* Property name of an optional {@link SecureRandom} instance to use. The
* default is to use a classloader singleton from {@link PRNG}.
*/
public static final String SOURCE_OF_RANDOMNESS = "gnu.crypto.srp.prng";
-
/** Default value for the modulus length. */
private static final int DEFAULT_MODULUS_LENGTH = 1024;
-
/** The optional {@link SecureRandom} instance to use. */
private SecureRandom rnd = null;
-
/** Bit length of the shared modulus. */
private int l;
-
/** The shared public modulus. */
private BigInteger N;
-
/** The Field generator. */
private BigInteger g;
-
/** The user's verifier MPI. */
private BigInteger v;
-
/** Our default source of randomness. */
private PRNG prng = null;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// implicit 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // gnu.crypto.key.IKeyPairGenerator interface implementation ---------------
-
public String name()
{
return Registry.SRP_KPG;
@@ -133,25 +105,20 @@ public class SRPKeyPairGenerator implements IKeyPairGenerator
{
// do we have a SecureRandom, or should we use our own?
rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS);
-
N = (BigInteger) attributes.get(SHARED_MODULUS);
if (N != null)
{
l = N.bitLength();
g = (BigInteger) attributes.get(GENERATOR);
if (g == null)
- {
- g = TWO;
- }
+ g = TWO;
SRPAlgorithm.checkParams(N, g);
}
else
{ // generate or use default values for N and g
Boolean useDefaults = (Boolean) attributes.get(USE_DEFAULTS);
if (useDefaults == null)
- {
- useDefaults = Boolean.TRUE;
- }
+ useDefaults = Boolean.TRUE;
Integer L = (Integer) attributes.get(MODULUS_LENGTH);
l = DEFAULT_MODULUS_LENGTH;
if (useDefaults.equals(Boolean.TRUE))
@@ -184,26 +151,23 @@ public class SRPKeyPairGenerator implements IKeyPairGenerator
break;
default:
throw new IllegalArgumentException(
- "unknown default shared modulus bit length");
+ "unknown default shared modulus bit length");
}
g = TWO;
l = N.bitLength();
}
}
- else
- { // generate new N and g
+ else // generate new N and g
+ {
if (L != null)
{
l = L.intValue();
if ((l % 256) != 0 || l < 512 || l > 2048)
- {
- throw new IllegalArgumentException(
- "invalid shared modulus bit length");
- }
+ throw new IllegalArgumentException(
+ "invalid shared modulus bit length");
}
}
}
-
// are we using this generator on the server side, or the client side?
v = (BigInteger) attributes.get(USER_VERIFIER);
}
@@ -223,16 +187,13 @@ public class SRPKeyPairGenerator implements IKeyPairGenerator
log.fine("g: " + g.toString(16));
}
}
-
return (v != null ? hostKeyPair() : userKeyPair());
}
- // helper methods ----------------------------------------------------------
-
private synchronized BigInteger[] generateParameters()
{
- // N A large safe prime (N = 2q+1, where q is prime)
- // g A generator modulo N
+ // N A large safe prime (N = 2q+1, where q is prime)
+ // g A generator modulo N
BigInteger q, p, g;
byte[] qBytes = new byte[l / 8];
do
@@ -247,7 +208,6 @@ public class SRPKeyPairGenerator implements IKeyPairGenerator
p = q.multiply(TWO).add(ONE);
}
while (p.bitLength() != l || ! p.isProbablePrime(80));
-
// compute g. from FIPS-186, Appendix 4: e == 2
BigInteger p_minus_1 = p.subtract(ONE);
g = TWO;
@@ -258,12 +218,9 @@ public class SRPKeyPairGenerator implements IKeyPairGenerator
// Set g = h**2 mod p
g = h.modPow(TWO, p);
// If g = 1, go to step 3
- if (!g.equals(ONE))
- {
- break;
- }
+ if (! g.equals(ONE))
+ break;
}
-
return new BigInteger[] { q, p, g };
}
@@ -282,11 +239,8 @@ public class SRPKeyPairGenerator implements IKeyPairGenerator
B = THREE.multiply(v).add(g.modPow(b, N)).mod(N);
}
while (B.compareTo(ZERO) == 0 || B.compareTo(N) >= 0);
-
- KeyPair result = new KeyPair(
- new SRPPublicKey(new BigInteger[] { N, g, B }),
- new SRPPrivateKey(new BigInteger[] { N, g, b,
- v }));
+ KeyPair result = new KeyPair(new SRPPublicKey(new BigInteger[] { N, g, B }),
+ new SRPPrivateKey(new BigInteger[] { N, g, b, v }));
return result;
}
@@ -305,9 +259,7 @@ public class SRPKeyPairGenerator implements IKeyPairGenerator
A = g.modPow(a, N);
}
while (A.compareTo(ZERO) == 0 || A.compareTo(N) >= 0);
-
- KeyPair result = new KeyPair(
- new SRPPublicKey(new BigInteger[] { N, g, A }),
+ KeyPair result = new KeyPair(new SRPPublicKey(new BigInteger[] { N, g, A }),
new SRPPrivateKey(new BigInteger[] { N, g, a }));
return result;
}
@@ -315,9 +267,7 @@ public class SRPKeyPairGenerator implements IKeyPairGenerator
private void nextRandomBytes(byte[] buffer)
{
if (rnd != null)
- {
- rnd.nextBytes(buffer);
- }
+ rnd.nextBytes(buffer);
else
getDefaultPRNG().nextBytes(buffer);
}
diff --git a/gnu/javax/crypto/key/srp6/SRPKeyPairRawCodec.java b/gnu/javax/crypto/key/srp6/SRPKeyPairRawCodec.java
index 39234b627..555dc23cf 100644
--- a/gnu/javax/crypto/key/srp6/SRPKeyPairRawCodec.java
+++ b/gnu/javax/crypto/key/srp6/SRPKeyPairRawCodec.java
@@ -47,116 +47,93 @@ import java.security.PrivateKey;
import java.security.PublicKey;
/**
- * <p>An object that implements the {@link IKeyPairCodec} operations for the
- * <i>Raw</i> format to use with SRP keypairs.</p>
- *
- * <p>Reference:</p>
+ * An object that implements the {@link IKeyPairCodec} operations for the
+ * <i>Raw</i> format to use with SRP keypairs.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
- * Thomas J. Wu.</li>
+ * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
+ * Thomas J. Wu.</li>
* </ol>
*/
-public class SRPKeyPairRawCodec implements IKeyPairCodec
+public class SRPKeyPairRawCodec
+ implements IKeyPairCodec
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
- // Constructor(s)
- // -------------------------------------------------------------------------
-
// implicit 0-arguments constructor
- // Class methods
- // -------------------------------------------------------------------------
-
- // Instance methods
- // -------------------------------------------------------------------------
-
- // gnu.crypto.keys.IKeyPairCodec interface implementation ------------------
-
public int getFormatID()
{
return RAW_FORMAT;
}
/**
- * <p>Returns the encoded form of the designated SRP public key according to
- * the <i>Raw</i> format supported by this library.</p>
- *
- * <p>The <i>Raw</i> format for an SRP public key, in this implementation, is
- * a byte sequence consisting of the following:</p>
+ * Returns the encoded form of the designated SRP public key according to the
+ * <i>Raw</i> format supported by this library.
+ * <p>
+ * The <i>Raw</i> format for an SRP public key, in this implementation, is a
+ * byte sequence consisting of the following:
* <ol>
- * <li>4-byte magic consisting of the value of the literal
- * {@link Registry#MAGIC_RAW_SRP_PUBLIC_KEY},<li>
- * <li>1-byte version consisting of the constant: 0x01,</li>
- * <li>4-byte count of following bytes representing the SRP parameter
- * <code>N</code> in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the SRP parameter
- * <code>N</code>,</li>
- * <li>4-byte count of following bytes representing the SRP parameter
- * <code>g</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the SRP parameter
- * <code>g</code>,</li>
- * <li>4-byte count of following bytes representing the SRP parameter
- * <code>y</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the SRP parameter
- * <code>y</code>,</li>
+ * <li>4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_SRP_PUBLIC_KEY},</li>
+ * <li>1-byte version consisting of the constant: 0x01,</li>
+ * <li>4-byte count of following bytes representing the SRP parameter
+ * <code>N</code> in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the SRP parameter <code>N</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the SRP parameter
+ * <code>g</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the SRP parameter <code>g</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the SRP parameter
+ * <code>y</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the SRP parameter <code>y</code>,
+ * </li>
* </ol>
- *
+ *
* @param key the key to encode.
* @return the <i>Raw</i> format encoding of the designated key.
* @throws IllegalArgumentException if the designated key is not an SRP one.
*/
public byte[] encodePublicKey(PublicKey key)
{
- if (!(key instanceof SRPPublicKey))
- {
- throw new IllegalArgumentException("key");
- }
-
+ if (! (key instanceof SRPPublicKey))
+ throw new IllegalArgumentException("key");
SRPPublicKey srpKey = (SRPPublicKey) key;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
// magic
baos.write(Registry.MAGIC_RAW_SRP_PUBLIC_KEY[0]);
baos.write(Registry.MAGIC_RAW_SRP_PUBLIC_KEY[1]);
baos.write(Registry.MAGIC_RAW_SRP_PUBLIC_KEY[2]);
baos.write(Registry.MAGIC_RAW_SRP_PUBLIC_KEY[3]);
-
// version
baos.write(0x01);
-
// N
byte[] buffer = srpKey.getN().toByteArray();
int length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
// g
buffer = srpKey.getG().toByteArray();
length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
// y
buffer = srpKey.getY().toByteArray();
length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
return baos.toByteArray();
}
@@ -167,150 +144,133 @@ public class SRPKeyPairRawCodec implements IKeyPairCodec
|| k[1] != Registry.MAGIC_RAW_SRP_PUBLIC_KEY[1]
|| k[2] != Registry.MAGIC_RAW_SRP_PUBLIC_KEY[2]
|| k[3] != Registry.MAGIC_RAW_SRP_PUBLIC_KEY[3])
- {
- throw new IllegalArgumentException("magic");
- }
-
+ throw new IllegalArgumentException("magic");
// version
if (k[4] != 0x01)
- {
- throw new IllegalArgumentException("version");
- }
+ throw new IllegalArgumentException("version");
int i = 5;
-
int l;
byte[] buffer;
-
// N
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger N = new BigInteger(1, buffer);
-
// g
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger g = new BigInteger(1, buffer);
-
// y
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger y = new BigInteger(1, buffer);
-
return new SRPPublicKey(N, g, y);
}
/**
- * <p>Returns the encoded form of the designated SRP private key according to
- * the <i>Raw</i> format supported by this library.</p>
- *
- * <p>The <i>Raw</i> format for an SRP private key, in this implementation,
- * is a byte sequence consisting of the following:</p>
+ * Returns the encoded form of the designated SRP private key according to the
+ * <i>Raw</i> format supported by this library.
+ * <p>
+ * The <i>Raw</i> format for an SRP private key, in this implementation, is a
+ * byte sequence consisting of the following:
* <ol>
- * <li>4-byte magic consisting of the value of the literal
- * {@link Registry#MAGIC_RAW_SRP_PRIVATE_KEY},<li>
- * <li>1-byte version consisting of the constant: 0x01,</li>
- * <li>4-byte count of following bytes representing the SRP parameter
- * <code>N</code> in internet order,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the SRP parameter
- * <code>N</code>,</li>
- * <li>4-byte count of following bytes representing the SRP parameter
- * <code>g</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the SRP parameter
- * <code>g</code>,</li>
- * <li>4-byte count of following bytes representing the SRP parameter
- * <code>x</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the SRP parameter
- * <code>x</code>,</li>
- * <li>one byte which indicates whether the SRP parameter <code>v</code>
- * is included in this encoding (value <code>0x01</code>) or not
- * (value <code>0x00</code>).</li>
- * <li>4-byte count of following bytes representing the SRP parameter
- * <code>v</code>,</li>
- * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
- * the <code>toByteArray()</code> method on the SRP parameter
- * <code>v</code>,</li>
+ * <li>4-byte magic consisting of the value of the literal
+ * {@link Registry#MAGIC_RAW_SRP_PRIVATE_KEY},</li>
+ * <li>1-byte version consisting of the constant: 0x01,</li>
+ * <li>4-byte count of following bytes representing the SRP parameter
+ * <code>N</code> in internet order,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the SRP parameter <code>N</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the SRP parameter
+ * <code>g</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the SRP parameter <code>g</code>,
+ * </li>
+ * <li>4-byte count of following bytes representing the SRP parameter
+ * <code>x</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the SRP parameter <code>x</code>,
+ * </li>
+ * <li>one byte which indicates whether the SRP parameter <code>v</code> is
+ * included in this encoding (value <code>0x01</code>) or not (value
+ * <code>0x00</code>).</li>
+ * <li>4-byte count of following bytes representing the SRP parameter
+ * <code>v</code>,</li>
+ * <li>n-bytes representation of a {@link BigInteger} obtained by invoking
+ * the <code>toByteArray()</code> method on the SRP parameter <code>v</code>,
+ * </li>
* </ol>
- *
+ *
* @param key the key to encode.
* @return the <i>Raw</i> format encoding of the designated key.
* @throws IllegalArgumentException if the designated key is not an SRP one.
*/
public byte[] encodePrivateKey(PrivateKey key)
{
- if (!(key instanceof SRPPrivateKey))
- {
- throw new IllegalArgumentException("key");
- }
-
+ if (! (key instanceof SRPPrivateKey))
+ throw new IllegalArgumentException("key");
SRPPrivateKey srpKey = (SRPPrivateKey) key;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
// magic
baos.write(Registry.MAGIC_RAW_SRP_PRIVATE_KEY[0]);
baos.write(Registry.MAGIC_RAW_SRP_PRIVATE_KEY[1]);
baos.write(Registry.MAGIC_RAW_SRP_PRIVATE_KEY[2]);
baos.write(Registry.MAGIC_RAW_SRP_PRIVATE_KEY[3]);
-
// version
baos.write(0x01);
-
// N
byte[] buffer = srpKey.getN().toByteArray();
int length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
// g
buffer = srpKey.getG().toByteArray();
length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
// x
buffer = srpKey.getX().toByteArray();
length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
-
// v
if (srpKey.getV() != null)
{
baos.write(0x01);
-
buffer = srpKey.getV().toByteArray();
length = buffer.length;
- baos.write(length >>> 24);
+ baos.write( length >>> 24);
baos.write((length >>> 16) & 0xFF);
- baos.write((length >>> 8) & 0xFF);
- baos.write(length & 0xFF);
+ baos.write((length >>> 8) & 0xFF);
+ baos.write( length & 0xFF);
baos.write(buffer, 0, length);
}
else
- {
- baos.write(0x00);
- }
-
+ baos.write(0x00);
return baos.toByteArray();
}
@@ -321,60 +281,54 @@ public class SRPKeyPairRawCodec implements IKeyPairCodec
|| k[1] != Registry.MAGIC_RAW_SRP_PRIVATE_KEY[1]
|| k[2] != Registry.MAGIC_RAW_SRP_PRIVATE_KEY[2]
|| k[3] != Registry.MAGIC_RAW_SRP_PRIVATE_KEY[3])
- {
- throw new IllegalArgumentException("magic");
- }
-
+ throw new IllegalArgumentException("magic");
// version
if (k[4] != 0x01)
- {
- throw new IllegalArgumentException("version");
- }
+ throw new IllegalArgumentException("version");
int i = 5;
-
int l;
byte[] buffer;
-
// N
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger N = new BigInteger(1, buffer);
-
// g
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger g = new BigInteger(1, buffer);
-
// x
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger x = new BigInteger(1, buffer);
-
// v
l = k[i++];
if (l == 0x01)
{
- l = k[i++] << 24 | (k[i++] & 0xFF) << 16 | (k[i++] & 0xFF) << 8
- | (k[i++] & 0xFF);
+ l = k[i++] << 24
+ | (k[i++] & 0xFF) << 16
+ | (k[i++] & 0xFF) << 8
+ | (k[i++] & 0xFF);
buffer = new byte[l];
System.arraycopy(k, i, buffer, 0, l);
i += l;
BigInteger v = new BigInteger(1, buffer);
-
return new SRPPrivateKey(N, g, x, v);
}
- else
- {
- return new SRPPrivateKey(N, g, x);
- }
+ return new SRPPrivateKey(N, g, x);
}
}
diff --git a/gnu/javax/crypto/key/srp6/SRPPrivateKey.java b/gnu/javax/crypto/key/srp6/SRPPrivateKey.java
index d9f7a19a6..d5ade07d7 100644
--- a/gnu/javax/crypto/key/srp6/SRPPrivateKey.java
+++ b/gnu/javax/crypto/key/srp6/SRPPrivateKey.java
@@ -45,39 +45,33 @@ import java.math.BigInteger;
import java.security.PrivateKey;
/**
- * <p>A representation of an SRP ephemeral private key.</p>
- *
- * <p>Reference:</p>
+ * A representation of an SRP ephemeral private key.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
- * Thomas J. Wu.</li>
+ * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
+ * Thomas J. Wu.</li>
* </ol>
*/
-public class SRPPrivateKey extends SRPKey implements PrivateKey
+public class SRPPrivateKey
+ extends SRPKey
+ implements PrivateKey
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/**
- * The private exponent for either the server or the client engaged in the
- * SRP protocol exchange.
+ * The private exponent for either the server or the client engaged in the SRP
+ * protocol exchange.
*/
private final BigInteger X;
-
/**
- * The user's verifier (v) --for the server-- also computed at the client
- * side as g.modPow(x, N), where x is the hashed output of the user name and
+ * The user's verifier (v) --for the server-- also computed at the client side
+ * as g.modPow(x, N), where x is the hashed output of the user name and
* password .
*/
private final BigInteger v;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Public constructor for use from outside this package.</p>
- *
+ * Public constructor for use from outside this package.
+ *
* @param N the public shared modulus.
* @param g the generator.
* @param x the private exponent of the ephemeral key.
@@ -88,8 +82,8 @@ public class SRPPrivateKey extends SRPKey implements PrivateKey
}
/**
- * <p>Public constructor for use from outside this package.</p>
- *
+ * Public constructor for use from outside this package.
+ *
* @param N the public shared modulus.
* @param g the generator.
* @param x the private exponent of the ephemeral key.
@@ -105,15 +99,16 @@ public class SRPPrivateKey extends SRPKey implements PrivateKey
}
/**
- * <p>Default constructor. Assumes N and g are already validated.</p>
- *
+ * Default constructor. Assumes N and g are already validated.
+ *
* @param params an array of either 3 or 4 values representing N, g, and
- * either v and X for the server, or just X for the client. Those values
- * represent the following:
- * <ol>
- * <li>v (server side): the user's verifier.</li>
- * <li>X (both sides): the server's or client's ephemeral private exponent.</li>
- * </ol>
+ * either v and X for the server, or just X for the client. Those
+ * values represent the following:
+ * <ol>
+ * <li>v (server side): the user's verifier.</li>
+ * <li>X (both sides): the server's or client's ephemeral private
+ * exponent.</li>
+ * </ol>
*/
SRPPrivateKey(BigInteger[] params)
{
@@ -130,31 +125,27 @@ public class SRPPrivateKey extends SRPKey implements PrivateKey
v = params[3];
}
else
- {
- throw new IllegalArgumentException("invalid number of SRP parameters");
- }
+ throw new IllegalArgumentException("invalid number of SRP parameters");
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>A class method that takes the output of the <code>encodePrivateKey()</code>
+ * A class method that takes the output of the <code>encodePrivateKey()</code>
* method of an SRP keypair codec object (an instance implementing
* {@link IKeyPairCodec} for DSS keys, and re-constructs an instance of this
- * object.</p>
- *
+ * object.
+ *
* @param k the contents of a previously encoded instance of this object.
* @throws ArrayIndexOutOfBoundsException if there is not enough bytes, in
- * <code>k</code>, to represent a valid encoding of an instance of this object.
+ * <code>k</code>, to represent a valid encoding of an instance
+ * of this object.
* @throws IllegalArgumentException if the byte sequence does not represent a
- * valid encoding of an instance of this object.
+ * valid encoding of an instance of this object.
*/
public static SRPPrivateKey valueOf(byte[] k)
{
// check magic...
// we should parse here enough bytes to know which codec to use, and
- // direct the byte array to the appropriate codec. since we only have one
+ // direct the byte array to the appropriate codec. since we only have one
// codec, we could have immediately tried it; nevertheless since testing
// one byte is cheaper than instatiating a codec that will fail we test
// the first byte before we carry on.
@@ -164,18 +155,12 @@ public class SRPPrivateKey extends SRPKey implements PrivateKey
IKeyPairCodec codec = new SRPKeyPairRawCodec();
return (SRPPrivateKey) codec.decodePrivateKey(k);
}
- else
- {
- throw new IllegalArgumentException("magic");
- }
+ throw new IllegalArgumentException("magic");
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the private exponent of the key as a {@link BigInteger}.</p>
- *
+ * Returns the private exponent of the key as a {@link BigInteger}.
+ *
* @return the private exponent of the key as a {@link BigInteger}.
*/
public BigInteger getX()
@@ -184,26 +169,24 @@ public class SRPPrivateKey extends SRPKey implements PrivateKey
}
/**
- * <p>Returns the user's verifier as a {@link BigInteger}.</p>
- *
+ * Returns the user's verifier as a {@link BigInteger}.
+ *
* @return the user's verifier as a {@link BigInteger} if this is an SRP
- * private key of a Host, or <code>null</code> if this is a private SRP key
- * for a User.
+ * private key of a Host, or <code>null</code> if this is a private
+ * SRP key for a User.
*/
public BigInteger getV()
{
return v;
}
- // Other instance methods --------------------------------------------------
-
/**
- * <p>Returns the encoded form of this private key according to the
- * designated format.</p>
- *
+ * Returns the encoded form of this private key according to the designated
+ * format.
+ *
* @param format the desired format identifier of the resulting encoding.
* @return the byte sequence encoding this key according to the designated
- * format.
+ * format.
* @throws IllegalArgumentException if the format is not supported.
*/
public byte[] getEncoded(int format)
@@ -221,30 +204,24 @@ public class SRPPrivateKey extends SRPKey implements PrivateKey
}
/**
- * <p>Returns <code>true</code> if the designated object is an instance of
+ * Returns <code>true</code> if the designated object is an instance of
* <code>SRPPrivateKey</code> and has the same SRP parameter values as this
- * one.</p>
- *
+ * one.
+ *
* @param obj the other non-null SRP key to compare to.
- * @return <code>true</code> if the designated object is of the same type and
- * value as this one.
+ * @return <code>true</code> if the designated object is of the same type
+ * and value as this one.
*/
public boolean equals(Object obj)
{
if (obj == null)
- {
- return false;
- }
- if (!(obj instanceof SRPPrivateKey))
- {
- return false;
- }
+ return false;
+ if (! (obj instanceof SRPPrivateKey))
+ return false;
SRPPrivateKey that = (SRPPrivateKey) obj;
boolean result = super.equals(that) && X.equals(that.getX());
if (v != null)
- {
- result = result && v.equals(that.getV());
- }
+ result = result && v.equals(that.getV());
return result;
}
}
diff --git a/gnu/javax/crypto/key/srp6/SRPPublicKey.java b/gnu/javax/crypto/key/srp6/SRPPublicKey.java
index 7283fd3da..04a949211 100644
--- a/gnu/javax/crypto/key/srp6/SRPPublicKey.java
+++ b/gnu/javax/crypto/key/srp6/SRPPublicKey.java
@@ -45,32 +45,27 @@ import java.math.BigInteger;
import java.security.PublicKey;
/**
- * <p>A representation of an SRP ephemeral public key.</p>
- *
- * <p>Reference:</p>
+ * A representation of an SRP ephemeral public key.
+ * <p>
+ * Reference:
* <ol>
- * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
- * Thomas J. Wu.</li>
+ * <li><a href="http://srp.stanford.edu/design.html">SRP Protocol Design</a><br>
+ * Thomas J. Wu.</li>
* </ol>
*/
-public class SRPPublicKey extends SRPKey implements PublicKey
+public class SRPPublicKey
+ extends SRPKey
+ implements PublicKey
{
-
- // Constants and variables
- // -------------------------------------------------------------------------
-
/**
- * The public exponent for either the server or the client engaged in the
- * SRP protocol exchange.
+ * The public exponent for either the server or the client engaged in the SRP
+ * protocol exchange.
*/
private final BigInteger Y;
- // Constructor(s)
- // -------------------------------------------------------------------------
-
/**
- * <p>Public constructor for use from outside this package.</p>
- *
+ * Public constructor for use from outside this package.
+ *
* @param N the public shared modulus.
* @param g the generator.
* @param Y the public exponent of the ephemeral key.
@@ -84,10 +79,10 @@ public class SRPPublicKey extends SRPKey implements PublicKey
}
/**
- * <p>Default constructor. Assumes that N and g are already validated.</p>
- *
+ * Default constructor. Assumes that N and g are already validated.
+ *
* @param params an array of 3 values representing N, g and Y; the latter
- * being the client's or server's public exponent.
+ * being the client's or server's public exponent.
*/
SRPPublicKey(BigInteger[] params)
{
@@ -96,26 +91,24 @@ public class SRPPublicKey extends SRPKey implements PublicKey
this.Y = params[2];
}
- // Class methods
- // -------------------------------------------------------------------------
-
/**
- * <p>A class method that takes the output of the <code>encodePublicKey()</code>
+ * A class method that takes the output of the <code>encodePublicKey()</code>
* method of an SRP keypair codec object (an instance implementing
* {@link IKeyPairCodec} for SRP keys, and re-constructs an instance of this
- * object.</p>
- *
+ * object.
+ *
* @param k the contents of a previously encoded instance of this object.
* @throws ArrayIndexOutOfBoundsException if there is not enough bytes, in
- * <code>k</code>, to represent a valid encoding of an instance of this object.
+ * <code>k</code>, to represent a valid encoding of an instance
+ * of this object.
* @throws IllegalArgumentException if the byte sequence does not represent a
- * valid encoding of an instance of this object.
+ * valid encoding of an instance of this object.
*/
public static SRPPublicKey valueOf(byte[] k)
{
// check magic...
// we should parse here enough bytes to know which codec to use, and
- // direct the byte array to the appropriate codec. since we only have one
+ // direct the byte array to the appropriate codec. since we only have one
// codec, we could have immediately tried it; nevertheless since testing
// one byte is cheaper than instatiating a codec that will fail we test
// the first byte before we carry on.
@@ -125,18 +118,12 @@ public class SRPPublicKey extends SRPKey implements PublicKey
IKeyPairCodec codec = new SRPKeyPairRawCodec();
return (SRPPublicKey) codec.decodePublicKey(k);
}
- else
- {
- throw new IllegalArgumentException("magic");
- }
+ throw new IllegalArgumentException("magic");
}
- // Instance methods
- // -------------------------------------------------------------------------
-
/**
- * <p>Returns the public exponent of the key as a {@link BigInteger}.</p>
- *
+ * Returns the public exponent of the key as a {@link BigInteger}.
+ *
* @return the public exponent of the key as a {@link BigInteger}.
*/
public BigInteger getY()
@@ -144,15 +131,13 @@ public class SRPPublicKey extends SRPKey implements PublicKey
return Y;
}
- // Other instance methods --------------------------------------------------
-
/**
- * <p>Returns the encoded form of this public key according to the designated
- * format.</p>
- *
+ * Returns the encoded form of this public key according to the designated
+ * format.
+ *
* @param format the desired format identifier of the resulting encoding.
* @return the byte sequence encoding this key according to the designated
- * format.
+ * format.
* @throws IllegalArgumentException if the format is not supported.
*/
public byte[] getEncoded(int format)
@@ -170,24 +155,20 @@ public class SRPPublicKey extends SRPKey implements PublicKey
}
/**
- * <p>Returns <code>true</code> if the designated object is an instance of
- * <code>SRPPublicKey</code>and has the same SRP parameter values as this one.
- * </p>
- *
+ * Returns <code>true</code> if the designated object is an instance of
+ * <code>SRPPublicKey</code>and has the same SRP parameter values as this
+ * one.
+ *
* @param obj the other non-null SRP key to compare to.
- * @return <code>true</code> if the designated object is of the same type and
- * value as this one.
+ * @return <code>true</code> if the designated object is of the same type
+ * and value as this one.
*/
public boolean equals(Object obj)
{
if (obj == null)
- {
- return false;
- }
- if (!(obj instanceof SRPPublicKey))
- {
- return false;
- }
+ return false;
+ if (! (obj instanceof SRPPublicKey))
+ return false;
SRPPublicKey that = (SRPPublicKey) obj;
return super.equals(that) && Y.equals(that.getY());
}