Skip to content

Commit

Permalink
Add a better error message to the DhTest.
Browse files Browse the repository at this point in the history
A typical error message with the new JDK looks like this:

java.lang.AssertionError: X expected to have bit length 1504, but has value 92958950218418996462987643843877938499735925222249647906188789799246291415800, which has bit length 256

NOKEYCHECK=True
PiperOrigin-RevId: 548591594
  • Loading branch information
Wycheproof Team authored and copybara-github committed Jul 17, 2023
1 parent 6ff0cb2 commit 011fcc3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion java/com/google/security/wycheproof/testcases/DhTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,14 @@ private void testKeyPair(KeyPair keyPair, int expectedKeySize) {
// should be chosen to prevent attacks.
int minPrivateKeyBits = keySize / 2;
BigInteger x = priv.getX();
assertTrue(x.bitLength() >= minPrivateKeyBits - 32);
assertTrue(
"X expected to have bit length at least "
+ (minPrivateKeyBits - 32)
+ ", but has value "
+ x
+ ", which has bit length "
+ x.bitLength(),
x.bitLength() >= minPrivateKeyBits - 32);
// TODO(bleichen): add tests for weak random number generators.

// Verify the DH parameters.
Expand Down

0 comments on commit 011fcc3

Please sign in to comment.