Skip to content
Snippets Groups Projects
Commit bee1ff6b authored by Manfred Michaelis's avatar Manfred Michaelis :boom:
Browse files

Updated

parent dc4ca7cd
No related branches found
No related tags found
No related merge requests found
......@@ -10,22 +10,43 @@ import java.util.Arrays;
* of user credential comparisons.
*/
public class SafeEqualTest {
public static void main(String[] args) throws NoSuchAlgorithmException {
/**
* Test data initialization.
final static private CompareMethods compare = new CompareMethods();
public static void main(String[] args) {
try {
// Collect data from test
// calls of methods
runTests();
// Print the results in STD OUT.
System.out.println(compare.toCSV());
} catch (NoSuchAlgorithmException e) {
System.err.println("Fehler: " + e.getLocalizedMessage());
System.exit(1);
}
}
/**
* Benchmark 3 test cases
* String.equals() - two strings
* Arrays.equals() - two byte arrays that are derived of SHA3-256 hash values
* TimingSafe.equals() - also two byte arrays that are derived of SHA3-256 hash values
*/
static void runTests() throws NoSuchAlgorithmException {
/*
Test data initialization.
*/
final int ITERATIONS = 5;
final String PASSWD = "password123";
MessageDigest msgDigest = MessageDigest.getInstance("SHA3-256");
CompareMethods compare = new CompareMethods();
Object[] params = new Object[] {"user", PASSWD, new UserData("user", PASSWD)};
/**
* Case 1: Simple string comparison.
*
* @param arguments an array of Object with parameters.
* @return true if username and password equals test data, false otherwise.
*
/*
Case 1:
Simple string comparison.
@param arguments an array of Object with parameters.
@return true if username and password equals test data, false otherwise.
*/
Check normalUserCredCheck = arguments -> {
String username = (String) arguments[0];
......@@ -35,12 +56,11 @@ public class SafeEqualTest {
return data.USERNAME.equals(username) && data.PASSWORD.equals(password);
};
/**
* Case 2: Comparison of two byte arrays
* from SHA256 hashed strings.
*
* @param arguments an array of Object with parameters.
* @return true if username and hashed password equals test data, false otherwise.
/*
Case 2:
Comparison of two byte arrays from SHA256 hashed strings.
@param arguments an array of Object with parameters.
@return true if username and hashed password equals test data, false otherwise.
*/
Check hashedUserCredCheck = arguments -> {
String username = (String) arguments[0];
......@@ -50,14 +70,12 @@ public class SafeEqualTest {
return data.USERNAME.equals(username) && Arrays.equals(data.HASHED_PASSWORD, password);
};
/**
* Case 3: Comparison of two byte arrays
* from SHA256 hashed strings. Tries to
* execute the lambda expression in a
* fixed amount of time every call.
*
* @param arguments an array of Object with parameters.
* @return true if username and hashed password equals test data, false otherwise.
/*
Case 3:
Comparison of two byte arrays from SHA256 hashed strings. Tries to execute the
lambda expression in a fixed amount of time every call.
@param arguments an array of Object with parameters.
@return true if username and hashed password equals test data, false otherwise.
*/
Check timingSafeUserCredCheck = arguments -> {
String username = (String) arguments[0];
......@@ -116,9 +134,6 @@ public class SafeEqualTest {
}
x++;
}
// Print the results in STD OUT.
System.out.println(compare.toCSV());
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment