Code review request: 7197245: Eliminate sun.security.ssl.JsseJce dependency on sun.security.ec (original) (raw)
Michael StJohns mstjohns at comcast.net
Wed Sep 12 17:15:09 UTC 2012
- Previous message (by thread): Code review request: 7197245: Eliminate sun.security.ssl.JsseJce dependency on sun.security.ec
- Next message (by thread): Code review request: 7197245: Eliminate sun.security.ssl.JsseJce dependency on sun.security.ec
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 06:31 AM 9/12/2012, Vincent Ryan wrote:
Also, instead of the function trimZeroes, how about instead a "static byte getMagnitude (BigInteger val, int magSize)" method which is really what you're trying to do. Still throw the RuntimeError, but do it inside that method. This is a method I really wish were part of BigInteger. Returns a byte[] I guess. What value is passed in magSize?
Here's a version that covers all the possibilities for getting the magnitude from a BigInteger. It has the property that
orig.equals (new BigInteger (orig.signum(), getMagnitude(orig, magSize)))
for any value of magSize >= ((orig.bitLength() +7 ) >> 3)
Mike
static byte[] getMagnitude (BigInteger value, int magSize) {
if (BigInteger.ZERO.equals(value)) return new byte[1]; BigInteger val = value; if (value.signum() == -1) val = value.negate(); int repLength = (val.bitLength()+7) >> 3; if (magSize < repLength)_ _throw new RuntimeException ("Magnitude size invalid");_ _byte[] data = val.toByteArray();_ _if (magSize == data.length)_ _return data;_ _byte[] result = new byte[magSize];_ _if (data.length > result.length) { // leading zeros System.arraycopy (data, data.length-magSize, result, 0, magSize); } else { // needs padding System.arraycopy (data, 0, result, magSize-data.length, data.length); }
return result; }
- Previous message (by thread): Code review request: 7197245: Eliminate sun.security.ssl.JsseJce dependency on sun.security.ec
- Next message (by thread): Code review request: 7197245: Eliminate sun.security.ssl.JsseJce dependency on sun.security.ec
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]