Skip to content

Commit

Permalink
Updates and improvements to JUnit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Rikard Höglund <rikard.hoglund@ri.se>
  • Loading branch information
rikard-sics committed Apr 16, 2023
1 parent 49a78a6 commit 80a1737
Show file tree
Hide file tree
Showing 35 changed files with 855 additions and 673 deletions.
609 changes: 609 additions & 0 deletions ace/src/test/java/se/sics/ace/as/TestTokenFailure.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -60,94 +60,6 @@ public class KeyRemapping {
private static BigIntegerFieldElement root = new BigIntegerFieldElement(ed25519Field,
new BigInteger("51042569399160536130206135233146329284152202253034631822681833788666877215207"));

/**
* Main method running a number of tests on the code.
*
* @param args command line arguments
* @throws Exception on failure in some of the tests
*/
public static void main(String args[]) throws Exception {
Provider EdDSA = new EdDSASecurityProvider();
Security.insertProviderAt(EdDSA, 1);

// Define test values x and y from RFC7748. Created as field elements to
// use for calculations in the field.
BigIntegerFieldElement x = new BigIntegerFieldElement(ed25519Field,
new BigInteger("15112221349535400772501151409588531511454012693041857206046113283949847762202"));
BigIntegerFieldElement y = new BigIntegerFieldElement(ed25519Field,
new BigInteger("46316835694926478169428394003475163141307993866256225615783033603165251855960"));

// Define correctly calculated values of u and v from RFC7748
BigIntegerFieldElement u_correct = new BigIntegerFieldElement(ed25519Field, new BigInteger("9"));
BigIntegerFieldElement v_correct = new BigIntegerFieldElement(ed25519Field,
new BigInteger("14781619447589544791020593568409986887264606134616475288964881837755586237401"));

// Calculate u and v values
FieldElement u = calcCurve25519_u(y);
FieldElement v = calcCurve25519_v(x, u);

// Print calculated values
System.out.println("x: " + x);
System.out.println("y: " + y);

System.out.println("v: " + v);
System.out.println("u: " + u);

// Check that calculated u and v values are correct
if (Arrays.equals(u.toByteArray(), u_correct.toByteArray())) {
System.out.println("u value is correct!");
} else {
System.out.println("u value is INCORRECT!");
}
if (Arrays.equals(v.toByteArray(), v_correct.toByteArray())) {
System.out.println("v value is correct!");
} else {
System.out.println("v value is INCORRECT!");
}

/**/
System.out.println();
System.out.println();
/**/

// Testing starting with a COSE Key

OneKey myKey = OneKey.generateKey(AlgorithmID.EDDSA);
FieldElement y_fromKeyAlt = extractCOSE_y_alt(myKey);
FieldElement y_fromKey = extractCOSE_y(myKey);

System.out.println("y from COSE key (alt): " + y_fromKeyAlt);
System.out.println("y from COSE key: " + y_fromKey);
System.out.println("COSE key X param_: " + myKey.get(KeyKeys.OKP_X));

System.out.println("y from COSE key (alt) (bytes): " + StringUtil.byteArray2HexString(y_fromKeyAlt.toByteArray()));
System.out.println("y from COSE key (bytes): " + StringUtil.byteArray2HexString(y_fromKey.toByteArray()));

// Check that calculating y in both ways give the same result
if (Arrays.equals(y_fromKeyAlt.toByteArray(), y_fromKey.toByteArray())) {
System.out.println("y from key value is correct!");
} else {
System.out.println("y from key value is INCORRECT!");
}

/**/
System.out.println();
System.out.println();
/**/

FieldElement x_fromKey = extractCOSE_x(myKey);
System.out.println("x from COSE key: " + x_fromKey);

FieldElement uuu1 = calcCurve25519_u(y_fromKeyAlt);
FieldElement uuu2 = calcCurve25519_u(y_fromKey);
// calcCurve25519_v(x_fromKey, uuu1);
// calcCurve25519_v(x_fromKey, uuu2);
//
System.out.println(uuu1);
System.out.println(uuu2);

}

/**
* Calculate Curve25519 u coordinate from Ed25519 y coordinate
*
Expand Down
Loading

0 comments on commit 80a1737

Please sign in to comment.