Code cleanups in the unit tests

This commit is contained in:
Rhys Weatherley 2016-06-27 19:17:00 +10:00
parent b5c1689d07
commit cb9ea54fd7
3 changed files with 11 additions and 12 deletions

View File

@ -36,27 +36,27 @@ public class Curve25519Tests {
public void curve25519() {
// Test vectors from section 6.1 of RFC 7748.
byte[] alicePrivate = TestUtils.stringToData("0x77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a");
byte[] alicePublic = TestUtils.stringToData("0x8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a");
byte[] bobPrivate = TestUtils.stringToData("0x5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb");
byte[] bobPublic = TestUtils.stringToData("0xde9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f");
byte[] alicePublic = TestUtils.stringToData("0x8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a");
byte[] bobPrivate = TestUtils.stringToData("0x5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb");
byte[] bobPublic = TestUtils.stringToData("0xde9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f");
byte[] sharedSecret = TestUtils.stringToData("0x4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742");
byte[] output = new byte [32];
// Test derivation of public keys from private keys.
Arrays.fill(output, (byte)0xAA);
Curve25519.eval(output, 0, alicePrivate, null);
assertTrue(Arrays.equals(output, alicePublic));
assertArrayEquals(alicePublic, output);
Arrays.fill(output, (byte)0xAA);
Curve25519.eval(output, 0, bobPrivate, null);
assertTrue(Arrays.equals(output, bobPublic));
assertArrayEquals(bobPublic, output);
// Test creation of the shared secret in both directions.
Arrays.fill(output, (byte)0xAA);
Curve25519.eval(output, 0, alicePrivate, bobPublic);
assertTrue(Arrays.equals(output, sharedSecret));
assertArrayEquals(sharedSecret, output);
Arrays.fill(output, (byte)0xAA);
Curve25519.eval(output, 0, bobPrivate, alicePublic);
assertTrue(Arrays.equals(output, sharedSecret));
assertArrayEquals(sharedSecret, output);
}
}

View File

@ -27,7 +27,6 @@ import static org.junit.Assert.*;
import java.security.DigestException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import org.junit.Test;
@ -52,7 +51,7 @@ public class HashTests {
} catch (DigestException e) {
fail("digest failed");
}
assertTrue(Arrays.equals(result, hashBytes));
assertArrayEquals(hashBytes, result);
// Hash the input in pieces to test split requests.
digest.reset();
@ -63,7 +62,7 @@ public class HashTests {
} catch (DigestException e) {
fail("digest failed");
}
assertTrue(Arrays.equals(result, hashBytes));
assertArrayEquals(hashBytes, result);
}
@Test

View File

@ -47,7 +47,7 @@ public class Poly1305Tests {
poly.reset(keyBytes, 0);
poly.update(dataBytes, 0, dataBytes.length);
poly.finish(token, 0);
assertTrue(Arrays.equals(token, hashBytes));
assertArrayEquals(hashBytes, token);
// Break the data up into chunks to test multiple calls to update().
Arrays.fill(token, (byte)0xDD);
@ -55,7 +55,7 @@ public class Poly1305Tests {
poly.update(dataBytes, 0, dataBytes.length / 2);
poly.update(dataBytes, dataBytes.length / 2, dataBytes.length - (dataBytes.length / 2));
poly.finish(token, 0);
assertTrue(Arrays.equals(token, hashBytes));
assertArrayEquals(hashBytes, token);
}
@Test