On Tue, 1 Dec 2026 07:49:02 GMT, xiaotaonan <[email protected]> wrote:

> `ECPoint.hashCode()` and `ECFieldF2m.hashCode()` compute the hash as:
> 
>     x.hashCode() << 5 + y.hashCode()
>     m << 5 + Objects.hashCode(rp)
> 
> Since `+` binds tighter than `<<`, these actually compute `x.hashCode() << (5 
> + y.hashCode())` instead of the intended `(x.hashCode() << 5) + y.hashCode()`.
> 
> This does not violate the `equals`/`hashCode` contract, but it produces poor 
> hash distribution (points with the same x and y.hashCode() values that agree 
> in their low 5 bits collide).
> 
> This fix adds explicit parentheses to both methods to restore the intended 
> computation.
> 
> Testing:
> - Ran the existing `java/security/spec` tests.
> - Verified that `equals`/`hashCode` contract still holds for `ECPoint` and 
> `ECFieldF2m`.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

@mdinacci @hns @landonf @joebowbeer Please take some time to review this pull 
request,thanks.

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

PR Comment: https://git.openjdk.org/jdk/pull/34150#issuecomment-7365689589

Reply via email to