From 03265f4cf09b7bb59c09af722b8f44445a635d83 Mon Sep 17 00:00:00 2001
From: J08nY
Date: Wed, 29 Nov 2017 02:22:30 +0100
Subject: Add listing of supported curves to standalone libs.
---
build-standalone.xml | 4 +--
nbproject/reader/project.properties | 2 +-
nbproject/standalone/project.properties | 2 +-
.../ectester/standalone/ECTesterStandalone.java | 5 +++
.../ectester/standalone/libs/BouncyCastleLib.java | 14 ++++++++
.../crcs/ectester/standalone/libs/ECLibrary.java | 2 ++
src/cz/crcs/ectester/standalone/libs/SunECLib.java | 14 ++++++++
.../crcs/ectester/standalone/libs/TomcryptLib.java | 4 +++
.../standalone/libs/jni/NativeProvider.java | 8 ++---
src/cz/crcs/ectester/standalone/libs/jni/native.h | 8 +++++
.../crcs/ectester/standalone/libs/jni/tomcrypt.c | 41 +++++++++++++---------
11 files changed, 78 insertions(+), 26 deletions(-)
diff --git a/build-standalone.xml b/build-standalone.xml
index 300eec8..6e65c67 100644
--- a/build-standalone.xml
+++ b/build-standalone.xml
@@ -76,10 +76,10 @@
-
+
-
+
diff --git a/nbproject/reader/project.properties b/nbproject/reader/project.properties
index d372fd5..21441b3 100644
--- a/nbproject/reader/project.properties
+++ b/nbproject/reader/project.properties
@@ -6,7 +6,7 @@ annotation.processing.source.output=${build.generated.sources.dir}/ap-source-out
application.title=ECTesterReader
application.vendor=xsvenda
build.classes.dir=${build.dir}/classes
-build.classes.excludes=**/*.java,**/*.form,**/*.c,**/*.h,**/*.a
+build.classes.excludes=**/*.java,**/*.form,**/*.c,**/*.h,**/*.a,**/*.o,**/Makefile
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
diff --git a/nbproject/standalone/project.properties b/nbproject/standalone/project.properties
index 7714914..9fed4c2 100644
--- a/nbproject/standalone/project.properties
+++ b/nbproject/standalone/project.properties
@@ -6,7 +6,7 @@ annotation.processing.source.output=${build.generated.sources.dir}/ap-source-out
application.title=ECTesterStandalone
application.vendor=xsvenda
build.classes.dir=${build.dir}/classes
-build.classes.excludes=**/*.java,**/*.form,**/*.c,**/*.h,**/*.a
+build.classes.excludes=**/*.java,**/*.form,**/*.c,**/*.h,**/*.a,**/*.o,**/Makefile
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
diff --git a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
index de9953a..9fca2b6 100644
--- a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
+++ b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java
@@ -174,6 +174,11 @@ public class ECTesterStandalone {
if (!eckas.isEmpty()) {
System.out.println("\t\t- Signatures: " + String.join(",", sigs.stream().map(SignatureIdent::getName).collect(Collectors.toList())));
}
+ Set curves = lib.getCurves();
+ if (!curves.isEmpty()) {
+ System.out.println("\t\t- Curves: " + String.join(",", curves));
+ }
+ System.out.println();
}
}
}
diff --git a/src/cz/crcs/ectester/standalone/libs/BouncyCastleLib.java b/src/cz/crcs/ectester/standalone/libs/BouncyCastleLib.java
index aaf76be..c6600f9 100644
--- a/src/cz/crcs/ectester/standalone/libs/BouncyCastleLib.java
+++ b/src/cz/crcs/ectester/standalone/libs/BouncyCastleLib.java
@@ -1,7 +1,12 @@
package cz.crcs.ectester.standalone.libs;
+import org.bouncycastle.jce.ECNamedCurveTable;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import java.util.Enumeration;
+import java.util.Set;
+import java.util.TreeSet;
+
/**
* @author Jan Jancar johny@neuromancer.sk
*/
@@ -11,4 +16,13 @@ public class BouncyCastleLib extends ProviderECLibrary {
super(new BouncyCastleProvider());
}
+ @Override
+ public Set getCurves() {
+ Set result = new TreeSet<>();
+ Enumeration names = ECNamedCurveTable.getNames();
+ while (names.hasMoreElements()) {
+ result.add((String) names.nextElement());
+ }
+ return result;
+ }
}
diff --git a/src/cz/crcs/ectester/standalone/libs/ECLibrary.java b/src/cz/crcs/ectester/standalone/libs/ECLibrary.java
index 1e73e61..0f81978 100644
--- a/src/cz/crcs/ectester/standalone/libs/ECLibrary.java
+++ b/src/cz/crcs/ectester/standalone/libs/ECLibrary.java
@@ -14,6 +14,8 @@ public interface ECLibrary {
boolean isInitialized();
+ Set getCurves();
+
Set getKAs();
Set getSigs();
diff --git a/src/cz/crcs/ectester/standalone/libs/SunECLib.java b/src/cz/crcs/ectester/standalone/libs/SunECLib.java
index b64b740..3aec842 100644
--- a/src/cz/crcs/ectester/standalone/libs/SunECLib.java
+++ b/src/cz/crcs/ectester/standalone/libs/SunECLib.java
@@ -2,6 +2,9 @@ package cz.crcs.ectester.standalone.libs;
import sun.security.ec.SunEC;
+import java.util.Set;
+import java.util.TreeSet;
+
/**
* @author Jan Jancar johny@neuromancer.sk
*/
@@ -11,4 +14,15 @@ public class SunECLib extends ProviderECLibrary {
super(new SunEC());
}
+ @Override
+ public Set getCurves() {
+ String curves = provider.get("AlgorithmParameters.EC SupportedCurves").toString();
+ String[] split = curves.split("\\|");
+ Set result = new TreeSet<>();
+ for (String curve : split) {
+ String body = curve.split(",")[0].substring(1);
+ result.add(body);
+ }
+ return result;
+ }
}
diff --git a/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java b/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java
index 49e810c..78db00e 100644
--- a/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java
+++ b/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java
@@ -1,6 +1,7 @@
package cz.crcs.ectester.standalone.libs;
import java.security.Provider;
+import java.util.Set;
/**
* @author Jan Jancar johny@neuromancer.sk
@@ -13,4 +14,7 @@ public class TomcryptLib extends NativeECLibrary {
@Override
native Provider createProvider();
+
+ @Override
+ public native Set getCurves();
}
diff --git a/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java b/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java
index 53f8b3c..a2233e2 100644
--- a/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java
+++ b/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java
@@ -12,11 +12,9 @@ public abstract class NativeProvider extends Provider {
public NativeProvider(String name, double version, String info) {
super(name, version, info);
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- setup();
- return null;
- }
+ AccessController.doPrivileged((PrivilegedAction