On Mon, 24 Apr 2023 20:50:23 GMT, Anthony Scarpino <ascarp...@openjdk.org> 
wrote:

>> Is the size always `Npk`? It could be less (if small) or bigger (if MSB is 
>> 1).
>
> If I understand what your saying, if `Npk` is larger than `uArray`, then 
> `copyOf()` will pad with zeros at the end.  I think that would change the 
> value.  And I don't see why `Npk` would be smaller than `uArray` otherwise 
> this would be returning an invalid key

In fact, since the byte array is reversed, it's actually OK to pad zeros at the 
end without changing the value.

On the other hand, if the big integer's size is exact `Npk` but the 
most-significant-bit is 1, `toByteArray` will add an extra 00 at the beginning 
to keep it positive. In this case, the byte array length is `Npk + 1`. After 
reversed we can truncate the extra 00 byte now at the end.

Fascinating, isn't it?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13256#discussion_r1175847108

Reply via email to