Hmm...
It is possible to randomly generate a prime which is expressed in less than the
full number of provided bytes so it is possible (and legal) for sourceLength to
be less than or equal to destination length. What should probably be checked
here though is :
if (sourceLength > destinationLength) {
return -1;
}
(E.g. if you're trying to stuff N bytes in an N-1 length array it will be bad).
For the rest, it seems clumsy to do it that way (the loop and if statement) -
instead maybe do an
int off = sourceLength;
for (int i = 0; i < sourceLength; i++) {
destination[i] = sourceBytes[--off]; // note the pre decrement!
}
if (sourceLength < destinationLength) {
memset (destination + sourceLength, 0, destinationLength - sourceLength);
}
To copy and then clear.
And then
return destinationLength;
Mike
At 06:04 AM 6/19/2015, Weijun Wang wrote:
>I might have found a reason for SunMSCAPI crash
>
> http://cr.openjdk.java.net/~weijun/8023546/webrev.00
>
>Before this fix, the native function convertToLittleEndian() fails if you want
>to convert a 63 byte array to a 64 byte one. However, I observed that when a
>1024 bit RSA private key is generated, its prime exponent p can be only 63
>bytes long. Function is updated to accept this case.
>
>I'm not a cryptographer so if you believe the p must be of 64 bytes long
>please tell me.
>
>Thanks
>Max