summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build-standalone.xml4
-rw-r--r--nbproject/reader/project.properties2
-rw-r--r--nbproject/standalone/project.properties2
-rw-r--r--src/cz/crcs/ectester/standalone/ECTesterStandalone.java5
-rw-r--r--src/cz/crcs/ectester/standalone/libs/BouncyCastleLib.java14
-rw-r--r--src/cz/crcs/ectester/standalone/libs/ECLibrary.java2
-rw-r--r--src/cz/crcs/ectester/standalone/libs/SunECLib.java14
-rw-r--r--src/cz/crcs/ectester/standalone/libs/TomcryptLib.java4
-rw-r--r--src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java8
-rw-r--r--src/cz/crcs/ectester/standalone/libs/jni/native.h8
-rw-r--r--src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c41
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 @@
<antcall target="dist-build.package"/>
</target>
<target name="libs">
- <exec dir="src/cz/crcs/ectester/standalone/libs/jni" executable="make" osfamily="unix"/>
+ <exec dir="src/cz/crcs/ectester/standalone/libs/jni" failonerror="true" executable="make" osfamily="unix"/>
</target>
<target name="-post-clean">
- <exec dir="src/cz/crcs/ectester/standalone/libs/jni" executable="make clean" osfamily="unix"/>
+ <exec dir="src/cz/crcs/ectester/standalone/libs/jni" failonerror="true" executable="make clean" osfamily="unix"/>
</target>
<target name="headers" depends="compile">
<javah classpath="${build.classes.dir}" outputfile="src/cz/crcs/ectester/standalone/libs/jni/native.h">
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<String> 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<String> getCurves() {
+ Set<String> 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<String> getCurves();
+
Set<KeyAgreementIdent> getKAs();
Set<SignatureIdent> 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<String> getCurves() {
+ String curves = provider.get("AlgorithmParameters.EC SupportedCurves").toString();
+ String[] split = curves.split("\\|");
+ Set<String> 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<String> 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<Object>) () -> {
+ setup();
+ return null;
});
}
diff --git a/src/cz/crcs/ectester/standalone/libs/jni/native.h b/src/cz/crcs/ectester/standalone/libs/jni/native.h
index e4e5009..e607738 100644
--- a/src/cz/crcs/ectester/standalone/libs/jni/native.h
+++ b/src/cz/crcs/ectester/standalone/libs/jni/native.h
@@ -15,6 +15,14 @@ extern "C" {
JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_TomcryptLib_createProvider
(JNIEnv *, jobject);
+/*
+ * Class: cz_crcs_ectester_standalone_libs_TomcryptLib
+ * Method: getCurves
+ * Signature: ()Ljava/util/Set;
+ */
+JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_TomcryptLib_getCurves
+ (JNIEnv *, jobject);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c b/src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c
index db1de88..7f8f303 100644
--- a/src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c
+++ b/src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c
@@ -7,49 +7,56 @@ JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_TomcryptLib_crea
jclass provider_class = (*env)->FindClass(env, "cz/crcs/ectester/standalone/libs/jni/NativeProvider$TomCrypt");
jmethodID init = (*env)->GetMethodID(env, provider_class, "<init>", "(Ljava/lang/String;DLjava/lang/String;)V");
- if (init == NULL) {
- return NULL;
- }
+
jstring name = (*env)->NewStringUTF(env, "libtomcrypt " SCRYPT);
double version = strtod(SCRYPT, NULL);
+
return (*env)->NewObject(env, provider_class, init, name, version, name);
}
JNIEXPORT void JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeProvider_00024TomCrypt_setup(JNIEnv *env, jobject this) {
-
/* Initialize libtommath as the math lib. */
ltc_mp = ltm_desc;
jclass provider_class = (*env)->FindClass(env, "cz/crcs/ectester/standalone/libs/jni/NativeProvider$TomCrypt");
jmethodID put = (*env)->GetMethodID(env, provider_class, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
- if (put == NULL) {
- return;
- }
- const ltc_ecc_set_type * curve = ltc_ecc_sets;
- while (curve->name != NULL) {
- printf("%s\n", curve->name);
- curve++;
- }
- /* Just test ecc key generation at this time. */
+/* *//* Just test ecc key generation at this time. *//*
ecc_key mykey;
prng_state prng;
int err;
- /* register yarrow */
+ *//* register yarrow *//*
if (register_prng(&yarrow_desc) == -1) {
printf("Error registering Yarrow\n");
return;
}
- /* setup the PRNG */
+ *//* setup the PRNG *//*
if ((err = rng_make_prng(128, find_prng("yarrow"), &prng, NULL)) != CRYPT_OK) {
printf("Error setting up PRNG, %s\n", error_to_string(err));
return;
}
- /* make a 192-bit ECC key */
+ *//* make a 192-bit ECC key *//*
if ((err = ecc_make_key(&prng, find_prng("yarrow"), 24, &mykey)) != CRYPT_OK) {
printf("Error making key: %s\n", error_to_string(err));
return;
}
- return;
+ return;*/
+}
+
+JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_TomcryptLib_getCurves(JNIEnv *env, jobject this) {
+ jclass hash_set_class = (*env)->FindClass(env, "java/util/TreeSet");
+
+ jmethodID hash_set_ctr = (*env)->GetMethodID(env, hash_set_class, "<init>", "()V");
+ jmethodID hash_set_add = (*env)->GetMethodID(env, hash_set_class, "add", "(Ljava/lang/Object;)Z");
+
+ jobject result = (*env)->NewObject(env, hash_set_class, hash_set_ctr);
+ const ltc_ecc_set_type * curve = ltc_ecc_sets;
+ while (curve->size != 0) {
+ jstring curve_name = (*env)->NewStringUTF(env, curve->name);
+ (*env)->CallBooleanMethod(env, result, hash_set_add, curve_name);
+ curve++;
+ }
+
+ return result;
} \ No newline at end of file