Cryptography Reference
In-Depth Information
There is a single public constructor, which reads in a string of digits, and parses it as a
BigInteger, say
. If this is the first IntCRT object created, we must set up the moduli. We
begin with the largest odd primitive int value, and test it for primality. If it succeeds, we add
it to the moduli, and if not, we subtract two from this number and continue in the same way
until we have a product of moduli whose bit length exceeds the maximum modulus bit
length specified in the constructor. We then produce the residues by taking the BigInteger
n
n
modulo each modulus. We convert each residue to a primitive long. Do not be concerned
that we use the BigInteger class here (it seems like cheating). We only use it for input/out-
put purposes. The addition/multiplication of IntCRT objects (the bulk of processing time for
crypto purposes) will be done entirely with the primitive type residues.
//This constructor produces the residues from the string of decimal digits
//Also produces the prime moduli
public IntCRT(String digitString, int maxModulusBitLength) {
//If modulus<=64 bits, we might as well be using ints
if (maxModulusBitLength<65) throw new IllegalArgumentException
(“The maximum modulus bit length must be at least 65 bits”);
this.maxModulusBitLength=maxModulusBitLength;
//If the prime moduli are not yet set up, set them up
if (moduli==null) setupModuli();
//The residues are long, but each will be no larger than an int
//This is because multiplication of residues may exceed the size of an int,
//requiring a long to store
residues=new long[moduli.length];
//Get the string and make it into a BigInteger; BigInteger only used for IO
//conversions,
//not for calculations
BigInteger n=new BigInteger(digitString);
if (n.compareTo(BigIntegerMath.ZERO)<0) throw new IllegalArgumentException
(“IntCRT objects must be nonnegative.”);
if (n.bitLength()>=maxModulusBitLength) throw new IllegalArgumentException
(“IntCRT objects must be less than maximum modulus bit length = ”
+maxModulusBitLength+”.”);
//Make each residue
for (int i=0;i<residues.length;i++)
residues[i]=n.mod(BigInteger.valueOf(moduli[i])).longValue();
}
//Private constructor to make IntCRT object by passing in residues
private IntCRT(long[] residues) {
this.residues=residues;
}
Search WWH ::




Custom Search