Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
Expand All @@ -22,5 +23,22 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
64 changes: 64 additions & 0 deletions src/net/i2p/crypto/eddsa/AlgorithmParameters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package net.i2p.crypto.eddsa;

import net.i2p.crypto.eddsa.spec.EdDSAGenParameterSpec;
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec;
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec;

import java.io.IOException;
import java.security.AlgorithmParametersSpi;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;

public class AlgorithmParameters extends AlgorithmParametersSpi{

private EdDSANamedCurveSpec edDSANamedCurveSpec = null;

@Override
protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {

if(paramSpec instanceof EdDSAGenParameterSpec){
edDSANamedCurveSpec = EdDSANamedCurveTable.getByName(((EdDSAGenParameterSpec) paramSpec).getName());
}
else if(paramSpec instanceof EdDSANamedCurveSpec){
this.edDSANamedCurveSpec= (EdDSANamedCurveSpec) paramSpec;
}
else throw new InvalidParameterSpecException("Invalid or not yet implemented "+ paramSpec.toString());
}

@Override
protected void engineInit(byte[] params) throws IOException {
throw new IOException("Not implemented yet...");
}

@Override
protected void engineInit(byte[] params, String format) throws IOException {
throw new IOException("Not implemented yet...");
}

@Override
protected <T extends AlgorithmParameterSpec> T engineGetParameterSpec(Class<T> paramSpec) throws InvalidParameterSpecException {
if(EdDSAParameterSpec.class.isAssignableFrom(paramSpec)){
return (T) this.edDSANamedCurveSpec;
}
else if(EdDSAGenParameterSpec.class.isAssignableFrom(paramSpec)){
return (T) new EdDSAGenParameterSpec(edDSANamedCurveSpec.getName());
}
else throw new InvalidParameterSpecException("Invalid or not yet implemented "+ paramSpec.toString());
}

@Override
protected byte[] engineGetEncoded() throws IOException {
throw new IOException("Not implemented yet...");
}

@Override
protected byte[] engineGetEncoded(String format) throws IOException {
throw new IOException("Not implemented yet...");
}

@Override
protected String engineToString() {
return this.getClass().getCanonicalName();
}
}
1 change: 1 addition & 0 deletions src/net/i2p/crypto/eddsa/EdDSASecurityProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ protected void setup() {
put("KeyFactory." + EdDSAKey.KEY_ALGORITHM, "net.i2p.crypto.eddsa.KeyFactory");
put("KeyPairGenerator." + EdDSAKey.KEY_ALGORITHM, "net.i2p.crypto.eddsa.KeyPairGenerator");
put("Signature." + EdDSAEngine.SIGNATURE_ALGORITHM, "net.i2p.crypto.eddsa.EdDSAEngine");
put("AlgorithmParameters." + EdDSAKey.KEY_ALGORITHM, "net.i2p.crypto.eddsa.AlgorithmParameters");

// OID Mappings
// See section "Mapping from OID to name".
Expand Down
73 changes: 73 additions & 0 deletions test/net/i2p/crypto/eddsa/AlgorithmParametersTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package net.i2p.crypto.eddsa;

import net.i2p.crypto.eddsa.spec.EdDSAGenParameterSpec;
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveSpec;
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.security.spec.ECGenParameterSpec;
import java.security.spec.InvalidParameterSpecException;

import static org.junit.Assert.assertTrue;

public class AlgorithmParametersTest {

@Test
public void testInitEngineWithEdGen() throws InvalidParameterSpecException {
AlgorithmParameters algorithmParameters = new AlgorithmParameters();
algorithmParameters.engineInit(new EdDSAGenParameterSpec(EdDSANamedCurveTable.ED_25519));
}

@Test
public void testInitEngineEdNameCurve() throws InvalidParameterSpecException {
AlgorithmParameters algorithmParameters = new AlgorithmParameters();
algorithmParameters.engineInit(EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519));
}

@Rule
public ExpectedException exception = ExpectedException.none();

@Test
public void testInitEngineWithNotImplementedParamSpec() throws InvalidParameterSpecException {
AlgorithmParameters algorithmParameters = new AlgorithmParameters();
EdDSANamedCurveSpec nameSpec = EdDSANamedCurveTable.ED_25519_CURVE_SPEC;
EdDSAParameterSpec paramSpec = new EdDSAParameterSpec(nameSpec.getCurve(),nameSpec.getHashAlgorithm(),nameSpec.getScalarOps(),nameSpec.getB());
exception.expect(InvalidParameterSpecException.class);
algorithmParameters.engineInit(paramSpec);
}

@Test
public void testengineGetParameterSpec_A() throws InvalidParameterSpecException {
AlgorithmParameters algorithmParameters = new AlgorithmParameters();
algorithmParameters.engineInit(EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519));
EdDSAGenParameterSpec edDSAGenParameterSpec = algorithmParameters.engineGetParameterSpec(EdDSAGenParameterSpec.class);
assertTrue(edDSAGenParameterSpec != null);
}

@Test
public void testengineGetParameterSpec_B() throws InvalidParameterSpecException {
AlgorithmParameters algorithmParameters = new AlgorithmParameters();
algorithmParameters.engineInit(new EdDSAGenParameterSpec(EdDSANamedCurveTable.ED_25519));
EdDSANamedCurveSpec edDSANamedCurveSpec = algorithmParameters.engineGetParameterSpec(EdDSANamedCurveSpec.class);
assertTrue(edDSANamedCurveSpec != null);
}

@Test
public void testengineGetParameterSpec_C() throws InvalidParameterSpecException {
AlgorithmParameters algorithmParameters = new AlgorithmParameters();
algorithmParameters.engineInit(new EdDSAGenParameterSpec(EdDSANamedCurveTable.ED_25519));
EdDSAParameterSpec edDSAParameterSpec = algorithmParameters.engineGetParameterSpec(EdDSAParameterSpec.class);
assertTrue(edDSAParameterSpec != null);
}

@Test
public void testengineGetParameterSpec_Exception() throws InvalidParameterSpecException {
AlgorithmParameters algorithmParameters = new AlgorithmParameters();
algorithmParameters.engineInit(new EdDSAGenParameterSpec(EdDSANamedCurveTable.ED_25519));
exception.expect(InvalidParameterSpecException.class);
ECGenParameterSpec edDSAParameterSpec = algorithmParameters.engineGetParameterSpec(ECGenParameterSpec.class);
}
}
2 changes: 2 additions & 0 deletions test/net/i2p/crypto/eddsa/EdDSASecurityProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
package net.i2p.crypto.eddsa;

import java.security.AlgorithmParameters;
import java.security.KeyFactory;
import java.security.KeyPairGenerator;
import java.security.NoSuchProviderException;
Expand Down Expand Up @@ -39,6 +40,7 @@ public void canGetInstancesWhenProviderIsPresent() throws Exception {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EdDSA", "EdDSA");
KeyFactory keyFac = KeyFactory.getInstance("EdDSA", "EdDSA");
Signature sgr = Signature.getInstance("NONEwithEdDSA", "EdDSA");
AlgorithmParameters algParam = AlgorithmParameters.getInstance("EdDSA","EdDSA");

Security.removeProvider("EdDSA");
}
Expand Down