mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8311170: Simplify and modernize equals and hashCode in security area
Reviewed-by: djelinski, rriggs, valeriep
This commit is contained in:
parent
e9f751ab16
commit
19ae62ae2c
96 changed files with 567 additions and 951 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -26,6 +26,7 @@ package java.security.spec;
|
|||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This immutable class defines an elliptic curve (EC)
|
||||
|
@ -215,6 +216,7 @@ public class ECFieldF2m implements ECField {
|
|||
* of ECFieldF2m and both {@code m} and the reduction
|
||||
* polynomial match, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
|
||||
|
@ -226,15 +228,12 @@ public class ECFieldF2m implements ECField {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code value for this characteristic 2
|
||||
* finite field.
|
||||
* @return a hash code value.
|
||||
* {@return the hash code value for this characteristic 2 finite field}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int value = m << 5;
|
||||
value += (rp==null? 0:rp.hashCode());
|
||||
// no need to involve ks here since ks and rp
|
||||
// should be equivalent.
|
||||
return value;
|
||||
return m << 5 + Objects.hashCode(rp);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -79,6 +79,7 @@ public class ECFieldFp implements ECField {
|
|||
* @return true if {@code obj} is an instance
|
||||
* of ECFieldFp and the prime value match, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
|
||||
|
@ -87,9 +88,9 @@ public class ECFieldFp implements ECField {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code value for this prime finite field.
|
||||
* @return a hash code value.
|
||||
* {@return a hash code value for this prime finite field}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return p.hashCode();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -93,6 +93,7 @@ public class ECPoint {
|
|||
* @return true if {@code obj} is an instance of
|
||||
* ECPoint and the affine coordinates match, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (this == POINT_INFINITY) return false;
|
||||
|
@ -103,9 +104,9 @@ public class ECPoint {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code value for this elliptic curve point.
|
||||
* @return a hash code value.
|
||||
* {@return the hash code value for this elliptic curve point}
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (this == POINT_INFINITY) return 0;
|
||||
return x.hashCode() << 5 + y.hashCode();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue