Correction to Assignment 2 Specification

We have been forced to make changes to the assignment 2 specification because of limitations in the JCE API. As it says in the handout about the fair coin flipping algorithm, it uses the fact the RSA is commutative. However, RSA only commutes for equal moduli.

The JCE API unfortunately does not allow us to specify the modulus we want when we create keys, so the provider chooses one at random. To get around this problem, we are forced to make modifications to the Cryptix source code. These modifications allow us to specify the modulus we want when creating keys.

However, modifying the Cryptix provider causes further problems. For "security" reasons, Sun requires all cryptographic providers to be signed (by Sun) before they can be used. So when we modify the Cryptix provider, the signature validation fails, and JDK will not accept our modified Cryptix provider. See http://www.ibiblio.org/javafaq/reports/JCE_1.2.1.html for a description of the mechanism used by Sun to block third party providers, and a discussion of the issues.

It turns out to be possible to work around the problem by implementing RSA ourselves as a modification of the Cryptix source, in such a way that much of the rest of the Cryptix and JCE code is still usable. A template of the solution is provided with the updated assignment files below. Part of your task will be to make modifications to this template, to enable key generation for a given modulus. Specifically, you need to implement the following methods in MyRSAKeyPairGenerator.java. See the file itself for a more detailed description of the functionality of these methods.

public void generateModulus()
This method should generate the (prime) values p and q used in the RSA algorithm, such that the modulus n=p.q has the length with which the key generator was initialized. These values should be generated from a secure source of randomness.
public void setModulus(BigInteger modulusp, BigInteger modulusq)
This method should set the values p and q used in the RSA algorithm to the values given in the input.
public KeyPair generateKeyPairForModulus()
This method should generate an RSA key pair for modulus n = p.q where p and q are the values previously gemerated or set using either generateModulus() or setModulus().
public BigInteger getModulusp()
This method should return the value p used in the RSA algorithm.
public BigInteger getModulusq()
This method should return the value q used in the RSA algorithm.
For RSA operations, use the class MyRSAAlgorithm enclosed with the files below. Note that this class works directly on the BigInteger representation of a message rather than the byte string representation used in the JCE. For our purposes, this is a merit, since the byte string representation actually presents another problem for the double encryption required by the protocol. (If the modulus n is of length k bytes, then some strings of length k bytes are likely to correspond to numbers greater than n. To avoid this problem, the block size for encryption is typically taken to be k-1 bytes. However, the result of the encryption could be a number that corresponds to a string of k bytes. This is too large to be a block to be encrypted a second time!)

We have updated the interface descriptions for Alice (Alice.java) and Bob (Bob.java), and with our new implementation, we have been forced to modify Messages.java and CoinFlip.java. These updated files, along with the files you need to modify for RSA, are available here.