licel / jcardsim

https://jcardsim.org
224 stars 123 forks source link

ByteContainer should discard leading zero byte when set from BigInteger #15

Closed licel closed 10 years ago

licel commented 11 years ago

From erick...@bitflash.net on September 13, 2013 22:45:10

If the most significant bit of a BigInteger's magnitude is set, when encoded to a byte array, an extra leading byte will be added so that the resulting byte array can be passed back to the BigInteger constructor that takes only a byte array and no sign indicator.

This causes encoded parameters to sometimes be one byte longer than expected. All parameters (modulus, exponent, etc.) should be treated as unsigned numbers, and this leading byte can be discarded. In other words, since the sign of new BigInteger is fixed to be positive, we don't need to track the sign.

Original issue: http://code.google.com/p/jcardsim/issues/detail?id=15

licel commented 11 years ago

From jcard...@licel.ru on September 17, 2013 15:14:02

Status: Accepted