Test vectors version 0.4.12.
Tests using the new test vectors will be added in another CL. Changes: AES-GCM has test vectors for modified tags, which were previously missing. ECDSA has more test vectors for potential arithmetic errors. There are no more random test vectors. Webcrypto has a few test vectors with the bitcoin curve (since some libraries want to add this). DSA and ECDSA have more invalid test vectors with r,s = ((q-1)/2 or q-1). This is motivated by some weak ElGamal implementation in beecrypt. ECDH test vectors have some new files where the public key is just a point using SEC 1 / X9.62 format. All tests for ASN modifications are removed from ecdh_test.json, so that this file has a more resonable size. These test vectors are included in the files ecdh_curve_test.json. EDDSA has a few more invalid test vectors for malformed signatures. (I.e. the python implementation in the RFC has a small bug). Adding test vectors for AES-CCM. (tested against BouncyCastle, which sort of abuses the JCE interface) There are some test vectors for RSA-PSS (so far tested with BouncyCastle and boringSSL) More tests will be added when we have an idea what is actually being used. PiperOrigin-RevId: 205802874 GitOrigin-RevId: 250ab89370a0dcfc56e887fb185a494f45f9a3f5
This commit is contained in:
committed by
quannguyentm
parent
f1b3b3429b
commit
8f2cba4d3f
@@ -18,6 +18,8 @@ import static org.junit.Assert.fail;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.security.wycheproof.WycheproofRunner.NoPresubmitTest;
|
||||
import com.google.security.wycheproof.WycheproofRunner.ProviderType;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import javax.crypto.Cipher;
|
||||
@@ -63,7 +65,8 @@ public class JsonAeadTest {
|
||||
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
|
||||
GCMParameterSpec parameters = new GCMParameterSpec(tagSize, iv);
|
||||
cipher.init(opmode, keySpec, parameters);
|
||||
} else if (algorithm.equalsIgnoreCase("AES/EAX/NoPadding")) {
|
||||
} else if (algorithm.equalsIgnoreCase("AES/EAX/NoPadding")
|
||||
|| algorithm.equalsIgnoreCase("AES/CCM/NoPadding")) {
|
||||
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
|
||||
// TODO(bleichen): This works for BouncyCastle but looks non-standard.
|
||||
// org.bouncycastle.crypto.params.AEADParameters works too, but would add a dependency that
|
||||
@@ -103,13 +106,17 @@ public class JsonAeadTest {
|
||||
// This is a false positive, since errorprone cannot track values passed into a method.
|
||||
@SuppressWarnings("InsecureCryptoUsage")
|
||||
public void testAead(String filename, String algorithm) throws Exception {
|
||||
// Testing with old test vectors may a reason for a test failure.
|
||||
// Version number have the format major.minor[status].
|
||||
// Version number have the format major.minor[.subversion].
|
||||
// Versions before 1.0 are experimental and use formats that are expected to change.
|
||||
// Versions after 1.0 change the major number if the format changes and change
|
||||
// the minor number if only the test vectors (but not the format) changes.
|
||||
// Versions meant for distribution have no status.
|
||||
final String expectedVersion = "0.4";
|
||||
// Subversions are release candidate for the next version.
|
||||
//
|
||||
// Relevant version changes:
|
||||
// <ul>
|
||||
// <li> Version 0.5 adds test vectors for CCM.
|
||||
// </ul>
|
||||
final String expectedVersion = "0.5";
|
||||
JsonObject test = JsonUtil.getTestVectors(filename);
|
||||
String generatorVersion = test.get("generatorVersion").getAsString();
|
||||
if (!generatorVersion.equals(expectedVersion)) {
|
||||
@@ -228,4 +235,14 @@ public class JsonAeadTest {
|
||||
public void testAesEax() throws Exception {
|
||||
testAead("aes_eax_test.json", "AES/EAX/NoPadding");
|
||||
}
|
||||
|
||||
@NoPresubmitTest(
|
||||
providers = {ProviderType.BOUNCY_CASTLE},
|
||||
bugs = {"b/111153892"}
|
||||
)
|
||||
@Test
|
||||
public void testAesCcm() throws Exception {
|
||||
testAead("aes_ccm_test.json", "AES/CCM/NoPadding");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class JsonEcdhTest {
|
||||
* Example for test vector
|
||||
* {
|
||||
* "algorithm" : "ECDH",
|
||||
* "generatorVersion" : "0.1.3",
|
||||
* "generatorVersion" : "0.5",
|
||||
* "numberOfTests" : 335,
|
||||
* "header" : [],
|
||||
* "testGroups" : [
|
||||
@@ -74,12 +74,19 @@ public class JsonEcdhTest {
|
||||
**/
|
||||
public void testEcdhComp(String filename) throws Exception {
|
||||
// Testing with old test vectors may a reason for a test failure.
|
||||
// Version number have the format major.minor[status].
|
||||
// Version number have the format major.minor[.subversion].
|
||||
// Versions before 1.0 are experimental and use formats that are expected to change.
|
||||
// Versions after 1.0 change the major number if the format changes and change
|
||||
// the minor number if only the test vectors (but not the format) changes.
|
||||
// Versions meant for distribution have no status.
|
||||
final String expectedVersion = "0.4";
|
||||
// Subversions are release candidates for the next version.
|
||||
//
|
||||
// Changes:
|
||||
// Version 0.4 test vectors had a duplicate field for the curve (in the test group
|
||||
// and in the test itself). The duplicate has been removed for version 0.5, since all
|
||||
// tests in a test group use the same curve. The field curve describes the curve of
|
||||
// the private key. A test vector can contain a public key using a different curve,
|
||||
// in which case the ECDH implementation is expected to throw an exception.
|
||||
final String expectedVersion = "0.5";
|
||||
JsonObject test = JsonUtil.getTestVectors(filename);
|
||||
String generatorVersion = test.get("generatorVersion").getAsString();
|
||||
if (!generatorVersion.equals(expectedVersion)) {
|
||||
@@ -91,15 +98,15 @@ public class JsonEcdhTest {
|
||||
}
|
||||
int numTests = test.get("numberOfTests").getAsInt();
|
||||
int passedTests = 0;
|
||||
int rejectedTests = 0; // invalid test vectors leading to exceptions
|
||||
int skippedTests = 0; // valid test vectors leading to exceptions
|
||||
int rejectedTests = 0; // invalid test vectors leading to exceptions
|
||||
int skippedTests = 0; // valid test vectors leading to exceptions
|
||||
int errors = 0;
|
||||
for (JsonElement g : test.getAsJsonArray("testGroups")) {
|
||||
JsonObject group = g.getAsJsonObject();
|
||||
String curve = getString(group, "curve");
|
||||
for (JsonElement t : group.getAsJsonArray("tests")) {
|
||||
JsonObject testcase = t.getAsJsonObject();
|
||||
int tcid = testcase.get("tcId").getAsInt();
|
||||
String curve = getString(testcase, "curve");
|
||||
String comment = getString(testcase, "comment");
|
||||
BigInteger priv = getBigInteger(testcase, "private");
|
||||
byte[] publicEncoded = getBytes(testcase, "public");
|
||||
|
||||
Reference in New Issue
Block a user