From 9bce1e13ec136c06650868acf3438e789e366d5f Mon Sep 17 00:00:00 2001 From: J08nY Date: Mon, 27 Nov 2017 23:19:48 +0100 Subject: Add a basic NativeECLibrary interface. --- .../ectester/standalone/libs/NativeECLibrary.java | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java (limited to 'src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java') diff --git a/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java b/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java new file mode 100644 index 0000000..40691e6 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java @@ -0,0 +1,131 @@ +package cz.crcs.ectester.standalone.libs; + +import cz.crcs.ectester.standalone.consts.KeyAgreementIdent; +import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent; +import cz.crcs.ectester.standalone.consts.SignatureIdent; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.security.Provider; +import java.util.Collections; +import java.util.Set; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public abstract class NativeECLibrary implements ECLibrary { + private ProviderECLibrary loaded; + private String resource; + private String libname; + + public NativeECLibrary(String resource, String libname) { + this.resource = resource; + this.libname = libname; + } + + @Override + public boolean initialize() { + try { + String suffix; + Path appData; + if (System.getProperty("os.name").startsWith("Windows")) { + suffix = "dll"; + appData = Paths.get(System.getenv("AppData")); + } else { + suffix = "so"; + if (System.getProperty("os.name").startsWith("Linux")) { + appData = Paths.get(System.getenv("XDG_DATA_HOME")); + if (appData == null) { + appData = Paths.get(System.getProperty("user.home"), ".local", "share"); + } + } else { + appData = Paths.get(System.getProperty("user.home"), ".local", "share"); + } + } + Path libDir = appData.resolve("ECTesterStandalone"); + File libDirFile = libDir.toFile(); + Path libPath = libDir.resolve(libname + "." + suffix); + File libFile = libPath.toFile(); + + URL jarURL = NativeECLibrary.class.getResource("/cz/crcs/ectester/standalone/libs/" + resource + "." + suffix); + if (jarURL == null) { + return false; + } + URLConnection jarConnection = jarURL.openConnection(); + + boolean write = false; + if (libDirFile.isDirectory() && libFile.isFile()) { + long jarModified = jarConnection.getLastModified(); + + long libModified = Files.getLastModifiedTime(libPath).toMillis(); + if (jarModified > libModified) { + write = true; + } + } else { + libDir.toFile().mkdirs(); + libFile.createNewFile(); + write = true; + } + + if (write) { + Files.copy(jarConnection.getInputStream(), libPath, StandardCopyOption.REPLACE_EXISTING); + } + jarConnection.getInputStream().close(); + + System.load(libPath.toString()); + + loaded = new ProviderECLibrary(getProvider()); + return true; + } catch (IOException ignored) { + + } + return false; + } + + public abstract Provider getProvider(); + + @Override + public boolean isInitialized() { + return loaded != null && loaded.isInitialized(); + } + + @Override + public Set getECKAs() { + if (!isInitialized()) { + return Collections.emptySet(); + } + return loaded.getECKAs(); + } + + @Override + public Set getECSigs() { + if (!isInitialized()) { + return Collections.emptySet(); + } + return loaded.getECSigs(); + } + + @Override + public Set getKPGs() { + if (!isInitialized()) { + return Collections.emptySet(); + } + return loaded.getKPGs(); + } + + @Override + public String name() { + return loaded.name(); + } + + @Override + public String toString() { + return name(); + } +} -- cgit v1.2.3-70-g09d2 From e22139e18d28906f9533a1dc31e0622080b5f35c Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 28 Nov 2017 00:25:54 +0100 Subject: Add ECDH testing to standalone part. --- .../ectester/standalone/ECTesterStandalone.java | 112 +++++++++++++++------ .../crcs/ectester/standalone/libs/ECLibrary.java | 4 +- .../ectester/standalone/libs/NativeECLibrary.java | 54 +--------- .../standalone/libs/ProviderECLibrary.java | 15 +-- .../crcs/ectester/standalone/libs/TomcryptLib.java | 2 +- 5 files changed, 100 insertions(+), 87 deletions(-) (limited to 'src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java') diff --git a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java index e36ffcd..ec681c7 100644 --- a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java +++ b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java @@ -17,11 +17,9 @@ import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; +import javax.crypto.KeyAgreement; import java.io.IOException; -import java.security.InvalidAlgorithmParameterException; -import java.security.KeyPair; -import java.security.KeyPairGenerator; -import java.security.NoSuchAlgorithmException; +import java.security.*; import java.security.interfaces.ECPrivateKey; import java.security.interfaces.ECPublicKey; import java.security.spec.ECParameterSpec; @@ -87,9 +85,13 @@ public class ECTesterStandalone { export(); } - } catch (ParseException | NoSuchAlgorithmException | IOException ex) { + } catch (ParseException | IOException ex) { System.err.println(ex.getMessage()); } catch (InvalidAlgorithmParameterException e) { + System.err.println("Invalid algorithm parameter: " + e.getMessage()); + } catch (NoSuchAlgorithmException nsaex) { + System.err.println("Algorithm not supported by the selected library: " + nsaex.getMessage()); + } catch (InvalidKeyException e) { e.printStackTrace(); } } @@ -103,6 +105,9 @@ public class ECTesterStandalone { Options ecdhOpts = new Options(); ecdhOpts.addOption(Option.builder("t").longOpt("type").desc("Set KeyAgreement object [type].").hasArg().argName("type").optionalArg(false).build()); + ecdhOpts.addOption(Option.builder("n").longOpt("amount").hasArg().argName("amount").optionalArg(false).desc("Do ECDH [amount] times.").build()); + ecdhOpts.addOption(Option.builder("b").longOpt("bits").hasArg().argName("n").optionalArg(false).desc("What size of curve to use.").build()); + ecdhOpts.addOption(Option.builder("nc").longOpt("named-curve").desc("Use a named curve, from CurveDB: ").hasArg().argName("cat/id").build()); ParserOptions ecdh = new ParserOptions(new DefaultParser(), ecdhOpts); actions.put("ecdh", ecdh); @@ -156,11 +161,11 @@ public class ECTesterStandalone { if (!kpgs.isEmpty()) { System.out.println("\t\t- KeyPairGenerators: " + String.join(",", kpgs.stream().map(KeyPairGeneratorIdent::getName).collect(Collectors.toList()))); } - Set eckas = lib.getECKAs(); + Set eckas = lib.getKAs(); if (!eckas.isEmpty()) { System.out.println("\t\t- KeyAgreements: " + String.join(",", eckas.stream().map(KeyAgreementIdent::getName).collect(Collectors.toList()))); } - Set sigs = lib.getECSigs(); + Set sigs = lib.getSigs(); if (!eckas.isEmpty()) { System.out.println("\t\t- Signatures: " + String.join(",", sigs.stream().map(SignatureIdent::getName).collect(Collectors.toList()))); } @@ -171,8 +176,68 @@ public class ECTesterStandalone { /** * */ - private void ecdh() { + private void ecdh() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException { + if (cfg.selected instanceof ProviderECLibrary) { + ProviderECLibrary lib = (ProviderECLibrary) cfg.selected; + + String algo = cli.getOptionValue("ecdh.type", "ECDH"); + KeyAgreementIdent kaIdent = null; + for (KeyAgreementIdent ident : lib.getKAs()) { + if (ident.contains(algo)) { + kaIdent = ident; + break; + } + } + + KeyPairGeneratorIdent kpIdent = null; + for (KeyPairGeneratorIdent ident : lib.getKPGs()) { + if (ident.contains("EC")) { + kpIdent = ident; + break; + } + } + + if (kaIdent == null || kpIdent == null) { + throw new NoSuchAlgorithmException(algo); + } else { + KeyAgreement ka = kaIdent.getInstance(lib.getProvider()); + KeyPairGenerator kpg = kpIdent.getInstance(lib.getProvider()); + if (cli.hasOption("ecdh.bits")) { + int bits = Integer.parseInt(cli.getOptionValue("ecdh.bits")); + kpg.initialize(bits); + } else if (cli.hasOption("ecdh.named-curve")) { + String curveName = cli.getOptionValue("ecdh.named-curve"); + EC_Curve curve = dataStore.getObject(EC_Curve.class, curveName); + if (curve == null) { + System.err.println("Curve not found: " + curveName); + return; + } + kpg.initialize(curve.toSpec()); + } + System.out.println("index;nanotime;pubW;privS;secret"); + + int amount = Integer.parseInt(cli.getOptionValue("ecdh.amount", "1")); + for (int i = 0; i < amount; ++i) { + KeyPair one = kpg.genKeyPair(); + KeyPair other = kpg.genKeyPair(); + + ECPrivateKey privkey = (ECPrivateKey) one.getPrivate(); + ECPublicKey pubkey = (ECPublicKey) other.getPublic(); + + long elapsed = -System.nanoTime(); + ka.init(privkey); + ka.doPhase(pubkey, true); + elapsed += System.nanoTime(); + byte[] result = ka.generateSecret(); + + String pub = ByteUtil.bytesToHex(ECUtil.toX962Uncompressed(pubkey.getW()), false); + String priv = ByteUtil.bytesToHex(privkey.getS().toByteArray(), false); + String dh = ByteUtil.bytesToHex(result, false); + System.out.println(String.format("%d;%d;%s;%s;%s", i, elapsed, pub, priv, dh)); + } + } + } } /** @@ -187,10 +252,10 @@ public class ECTesterStandalone { */ private void generate() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { if (cfg.selected instanceof ProviderECLibrary) { - ProviderECLibrary jlib = (ProviderECLibrary) cfg.selected; + ProviderECLibrary lib = (ProviderECLibrary) cfg.selected; KeyPairGeneratorIdent ident = null; String algo = cli.getOptionValue("generate.type", "EC"); - for (KeyPairGeneratorIdent kpIdent : jlib.getKPGs()) { + for (KeyPairGeneratorIdent kpIdent : lib.getKPGs()) { if (kpIdent.contains(algo)) { ident = kpIdent; break; @@ -199,7 +264,7 @@ public class ECTesterStandalone { if (ident == null) { throw new NoSuchAlgorithmException(algo); } else { - KeyPairGenerator kpg = ident.getInstance(jlib.getProvider()); + KeyPairGenerator kpg = ident.getInstance(lib.getProvider()); if (cli.hasOption("generate.bits")) { int bits = Integer.parseInt(cli.getOptionValue("generate.bits")); kpg.initialize(bits); @@ -212,7 +277,7 @@ public class ECTesterStandalone { } kpg.initialize(curve.toSpec()); } - System.out.println("index;time;pubW;privS"); + System.out.println("index;nanotime;pubW;privS"); int amount = Integer.parseInt(cli.getOptionValue("generate.amount", "1")); for (int i = 0; i < amount; ++i) { @@ -224,7 +289,7 @@ public class ECTesterStandalone { String pub = ByteUtil.bytesToHex(ECUtil.toX962Uncompressed(publicKey.getW()), false); String priv = ByteUtil.bytesToHex(privateKey.getS().toByteArray(), false); - System.out.println(String.format("%d;%d;%s;%s", i, elapsed / 1000000, pub, priv)); + System.out.println(String.format("%d;%d;%s;%s", i, elapsed, pub, priv)); } } } @@ -242,10 +307,10 @@ public class ECTesterStandalone { */ private void export() throws NoSuchAlgorithmException, IOException { if (cfg.selected instanceof ProviderECLibrary) { - ProviderECLibrary jlib = (ProviderECLibrary) cfg.selected; + ProviderECLibrary lib = (ProviderECLibrary) cfg.selected; KeyPairGeneratorIdent ident = null; String algo = cli.getOptionValue("export.type", "EC"); - for (KeyPairGeneratorIdent kpIdent : jlib.getKPGs()) { + for (KeyPairGeneratorIdent kpIdent : lib.getKPGs()) { if (kpIdent.contains(algo)) { ident = kpIdent; break; @@ -254,7 +319,7 @@ public class ECTesterStandalone { if (ident == null) { throw new NoSuchAlgorithmException(algo); } else { - KeyPairGenerator kpg = ident.getInstance(jlib.getProvider()); + KeyPairGenerator kpg = ident.getInstance(lib.getProvider()); if (cli.hasOption("export.bits")) { int bits = Integer.parseInt(cli.getOptionValue("export.bits")); kpg.initialize(bits); @@ -287,23 +352,14 @@ public class ECTesterStandalone { } boolean readOptions(TreeCommandLine cli) { - if (cli.isNext("generate")) { - if (!cli.hasArg(-1)) { - System.err.println("Missing library name argument."); - return false; - } - - if (cli.hasOption("generate.bits") && cli.hasOption("generate.named-curve")) { - System.err.println("You can only specify bitsize or a named curve, nor both."); - return false; - } - } else if (cli.isNext("export")) { + if (cli.isNext("generate") || cli.isNext("export") || cli.isNext("ecdh")) { if (!cli.hasArg(-1)) { System.err.println("Missing library name argument."); return false; } - if (cli.hasOption("export.bits") && cli.hasOption("export.named-curve")) { + String next = cli.getNextName(); + if (cli.hasOption(next + ".bits") && cli.hasOption(next + ".named-curve")) { System.err.println("You can only specify bitsize or a named curve, nor both."); return false; } diff --git a/src/cz/crcs/ectester/standalone/libs/ECLibrary.java b/src/cz/crcs/ectester/standalone/libs/ECLibrary.java index 7e26dbe..1e73e61 100644 --- a/src/cz/crcs/ectester/standalone/libs/ECLibrary.java +++ b/src/cz/crcs/ectester/standalone/libs/ECLibrary.java @@ -14,9 +14,9 @@ public interface ECLibrary { boolean isInitialized(); - Set getECKAs(); + Set getKAs(); - Set getECSigs(); + Set getSigs(); Set getKPGs(); diff --git a/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java b/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java index 40691e6..44fb47b 100644 --- a/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java +++ b/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java @@ -1,9 +1,5 @@ package cz.crcs.ectester.standalone.libs; -import cz.crcs.ectester.standalone.consts.KeyAgreementIdent; -import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent; -import cz.crcs.ectester.standalone.consts.SignatureIdent; - import java.io.File; import java.io.IOException; import java.net.URL; @@ -13,14 +9,11 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.security.Provider; -import java.util.Collections; -import java.util.Set; /** * @author Jan Jancar johny@neuromancer.sk */ -public abstract class NativeECLibrary implements ECLibrary { - private ProviderECLibrary loaded; +public abstract class NativeECLibrary extends ProviderECLibrary { private String resource; private String libname; @@ -80,52 +73,13 @@ public abstract class NativeECLibrary implements ECLibrary { System.load(libPath.toString()); - loaded = new ProviderECLibrary(getProvider()); - return true; + provider = createProvider(); + return super.initialize(); } catch (IOException ignored) { } return false; } - public abstract Provider getProvider(); - - @Override - public boolean isInitialized() { - return loaded != null && loaded.isInitialized(); - } - - @Override - public Set getECKAs() { - if (!isInitialized()) { - return Collections.emptySet(); - } - return loaded.getECKAs(); - } - - @Override - public Set getECSigs() { - if (!isInitialized()) { - return Collections.emptySet(); - } - return loaded.getECSigs(); - } - - @Override - public Set getKPGs() { - if (!isInitialized()) { - return Collections.emptySet(); - } - return loaded.getKPGs(); - } - - @Override - public String name() { - return loaded.name(); - } - - @Override - public String toString() { - return name(); - } + abstract Provider createProvider(); } diff --git a/src/cz/crcs/ectester/standalone/libs/ProviderECLibrary.java b/src/cz/crcs/ectester/standalone/libs/ProviderECLibrary.java index 879cc16..9108eaf 100644 --- a/src/cz/crcs/ectester/standalone/libs/ProviderECLibrary.java +++ b/src/cz/crcs/ectester/standalone/libs/ProviderECLibrary.java @@ -14,13 +14,16 @@ import java.util.function.Function; /** * @author Jan Jancar johny@neuromancer.sk */ -public class ProviderECLibrary implements ECLibrary { - private Provider provider; - private boolean initialized; +public abstract class ProviderECLibrary implements ECLibrary { + Provider provider; + private boolean initialized = false; + + public ProviderECLibrary() { + + } public ProviderECLibrary(Provider provider) { this.provider = provider; - this.initialized = false; } @Override @@ -60,12 +63,12 @@ public class ProviderECLibrary implements ECLibrary { } @Override - public Set getECKAs() { + public Set getKAs() { return getIdents("KeyAgreement", KeyAgreementIdent::get); } @Override - public Set getECSigs() { + public Set getSigs() { return getIdents("Signature", SignatureIdent::get); } diff --git a/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java b/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java index 31d6812..fe4a79d 100644 --- a/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java +++ b/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java @@ -12,5 +12,5 @@ public class TomcryptLib extends NativeECLibrary { } @Override - public native Provider getProvider(); + native Provider createProvider(); } -- cgit v1.2.3-70-g09d2 From cd117b707bfae0271b86b5c647d2fbc72dd3676c Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 28 Nov 2017 22:23:31 +0100 Subject: Implement a basic NativeProvider using libtomcrypt. --- .gitignore | 6 ++- build-standalone.xml | 3 +- nbproject/reader/project.properties | 2 +- nbproject/standalone/project.properties | 2 +- .../ectester/standalone/ECTesterStandalone.java | 11 ++--- .../ectester/standalone/libs/NativeECLibrary.java | 22 ++++++--- .../crcs/ectester/standalone/libs/TomcryptLib.java | 2 +- src/cz/crcs/ectester/standalone/libs/jni/Makefile | 48 +++++++++++++++++++ .../standalone/libs/jni/NativeProvider.java | 25 ++++++++++ .../standalone/libs/jni/TomCryptProvider.java | 11 +++++ src/cz/crcs/ectester/standalone/libs/jni/native.h | 54 ++++++++++++++++++++++ .../crcs/ectester/standalone/libs/jni/tomcrypt.c | 40 ++++++++++++++++ src/cz/crcs/ectester/standalone/libs/native.h | 21 --------- 13 files changed, 206 insertions(+), 41 deletions(-) create mode 100644 src/cz/crcs/ectester/standalone/libs/jni/Makefile create mode 100644 src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java create mode 100644 src/cz/crcs/ectester/standalone/libs/jni/TomCryptProvider.java create mode 100644 src/cz/crcs/ectester/standalone/libs/jni/native.h create mode 100644 src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c delete mode 100644 src/cz/crcs/ectester/standalone/libs/native.h (limited to 'src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java') diff --git a/.gitignore b/.gitignore index 4724134..8390d09 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,8 @@ /dist/ectester-reader.sh /dist/ectester-reader.bat /dist/ECTesterStandalone.jar -/dist/ECTesterStandalone-dist.jar \ No newline at end of file +/dist/ECTesterStandalone-dist.jar + +/src/**/*.a +/src/**/*.o +/src/**/*.so diff --git a/build-standalone.xml b/build-standalone.xml index 05dc174..447b9b1 100644 --- a/build-standalone.xml +++ b/build-standalone.xml @@ -76,8 +76,9 @@ - + + diff --git a/nbproject/reader/project.properties b/nbproject/reader/project.properties index ac98170..d372fd5 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 +build.classes.excludes=**/*.java,**/*.form,**/*.c,**/*.h,**/*.a # 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 868bcfa..7714914 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 +build.classes.excludes=**/*.java,**/*.form,**/*.c,**/*.h,**/*.a # 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 3ec11ed..de9953a 100644 --- a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java +++ b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java @@ -8,10 +8,7 @@ import cz.crcs.ectester.data.EC_Store; import cz.crcs.ectester.standalone.consts.KeyAgreementIdent; import cz.crcs.ectester.standalone.consts.KeyPairGeneratorIdent; import cz.crcs.ectester.standalone.consts.SignatureIdent; -import cz.crcs.ectester.standalone.libs.BouncyCastleLib; -import cz.crcs.ectester.standalone.libs.ECLibrary; -import cz.crcs.ectester.standalone.libs.ProviderECLibrary; -import cz.crcs.ectester.standalone.libs.SunECLib; +import cz.crcs.ectester.standalone.libs.*; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; @@ -37,7 +34,7 @@ import java.util.stream.Collectors; * @version v0.1.0 */ public class ECTesterStandalone { - private ECLibrary[] libs = new ECLibrary[]{new SunECLib(), new BouncyCastleLib()}; + private ECLibrary[] libs = new ECLibrary[]{new SunECLib(), new BouncyCastleLib(), new TomcryptLib()}; private EC_Store dataStore; private Config cfg; @@ -297,7 +294,6 @@ public class ECTesterStandalone { } else { Signature sig = sigIdent.getInstance(lib.getProvider()); KeyPairGenerator kpg = kpIdent.getInstance(lib.getProvider()); - AlgorithmParameterSpec spec = null; if (cli.hasOption("ecdsa.bits")) { int bits = Integer.parseInt(cli.getOptionValue("ecdsa.bits")); kpg.initialize(bits); @@ -308,8 +304,7 @@ public class ECTesterStandalone { System.err.println("Curve not found: " + curveName); return; } - spec = curve.toSpec(); - kpg.initialize(spec); + kpg.initialize(curve.toSpec()); } System.out.println("index;data;signtime;verifytime;pubW;privS;signature;verified"); diff --git a/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java b/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java index 44fb47b..5d1b9d7 100644 --- a/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java +++ b/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java @@ -15,11 +15,13 @@ import java.security.Provider; */ public abstract class NativeECLibrary extends ProviderECLibrary { private String resource; - private String libname; + private String[] requriements; - public NativeECLibrary(String resource, String libname) { + public static String LIB_RESOURCE_DIR = "/cz/crcs/ectester/standalone/libs/jni/"; + + public NativeECLibrary(String resource, String... requirements) { this.resource = resource; - this.libname = libname; + this.requriements = requirements; } @Override @@ -33,8 +35,10 @@ public abstract class NativeECLibrary extends ProviderECLibrary { } else { suffix = "so"; if (System.getProperty("os.name").startsWith("Linux")) { - appData = Paths.get(System.getenv("XDG_DATA_HOME")); - if (appData == null) { + String dataHome = System.getenv("XDG_DATA_HOME"); + if (dataHome != null) { + appData = Paths.get(dataHome); + } else { appData = Paths.get(System.getProperty("user.home"), ".local", "share"); } } else { @@ -43,10 +47,10 @@ public abstract class NativeECLibrary extends ProviderECLibrary { } Path libDir = appData.resolve("ECTesterStandalone"); File libDirFile = libDir.toFile(); - Path libPath = libDir.resolve(libname + "." + suffix); + Path libPath = libDir.resolve(resource + "." + suffix); File libFile = libPath.toFile(); - URL jarURL = NativeECLibrary.class.getResource("/cz/crcs/ectester/standalone/libs/" + resource + "." + suffix); + URL jarURL = NativeECLibrary.class.getResource(LIB_RESOURCE_DIR + resource + "." + suffix); if (jarURL == null) { return false; } @@ -71,6 +75,10 @@ public abstract class NativeECLibrary extends ProviderECLibrary { } jarConnection.getInputStream().close(); + for (String requirement : requriements) { + System.loadLibrary(requirement); + } + System.load(libPath.toString()); provider = createProvider(); diff --git a/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java b/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java index fe4a79d..49e810c 100644 --- a/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java +++ b/src/cz/crcs/ectester/standalone/libs/TomcryptLib.java @@ -8,7 +8,7 @@ import java.security.Provider; public class TomcryptLib extends NativeECLibrary { public TomcryptLib() { - super("tomcrypt", "libtomcrypt"); + super("tomcrypt_provider", "tommath", "tomcrypt"); } @Override diff --git a/src/cz/crcs/ectester/standalone/libs/jni/Makefile b/src/cz/crcs/ectester/standalone/libs/jni/Makefile new file mode 100644 index 0000000..837078c --- /dev/null +++ b/src/cz/crcs/ectester/standalone/libs/jni/Makefile @@ -0,0 +1,48 @@ +ifeq ($(JAVA_HOME),) +ifeq ($(OS),Windows_NT) +which = $(shell where $1) +else +which = $(shell which $1) +endif +JAVAC ?= $(realpath $(call which,javac)) +JAVA_HOME = $(abspath $(dir $(JAVAC))..) +endif + +ifneq ($(JAVA_HOME),) +JNI_INCLUDEDIR ?= $(JAVA_HOME)/include +endif + +ifeq ($(JNI_INCLUDEDIR),) +$(error could not determine JNI include dir, try specifying either \ + JAVA_HOME or JNI_INCLUDEDIR) +endif + +TARGETTRIPLET := $(shell $(CC) -dumpmachine) +ifeq ($(JNI_PLATFORM),) +ifeq ($(findstring mingw,$(TARGETTRIPLET)),mingw) +JNI_PLATFORM:= win32 +else +ifeq ($(findstring linux,$(TARGETTRIPLET)),linux) +JNI_PLATFORM:= linux +# add more checks here +endif +endif +endif + +JNI_PLATFORMINCLUDEDIR ?= $(JNI_INCLUDEDIR)/$(JNI_PLATFORM) + + + +all: tomcrypt_provider.so + +tomcrypt_provider.so: tomcrypt.o + gcc -DLTM_DESC -DUSE_LTM -fPIC -shared -o $@ $< -ltommath -ltomcrypt + +%.o: %.c + gcc -fPIC -I"$(JNI_INCLUDEDIR)" -I"$(JNI_PLATFORMINCLUDEDIR)" -I. -c $< + +clean: + rm -rf *.o + rm -rf *.so + +.PHONY: all clean \ No newline at end of file diff --git a/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java b/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java new file mode 100644 index 0000000..43b7827 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java @@ -0,0 +1,25 @@ +package cz.crcs.ectester.standalone.libs.jni; + +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.Provider; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +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; + } + }); + } + + abstract void setup(); + +} diff --git a/src/cz/crcs/ectester/standalone/libs/jni/TomCryptProvider.java b/src/cz/crcs/ectester/standalone/libs/jni/TomCryptProvider.java new file mode 100644 index 0000000..01e4c17 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/libs/jni/TomCryptProvider.java @@ -0,0 +1,11 @@ +package cz.crcs.ectester.standalone.libs.jni; + +public class TomCryptProvider extends NativeProvider { + + public TomCryptProvider(String name, double version, String info) { + super(name, version, info); + } + + @Override + native void setup(); +} diff --git a/src/cz/crcs/ectester/standalone/libs/jni/native.h b/src/cz/crcs/ectester/standalone/libs/jni/native.h new file mode 100644 index 0000000..83ef841 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/libs/jni/native.h @@ -0,0 +1,54 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class cz_crcs_ectester_standalone_libs_TomcryptLib */ + +#ifndef _Included_cz_crcs_ectester_standalone_libs_TomcryptLib +#define _Included_cz_crcs_ectester_standalone_libs_TomcryptLib +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: cz_crcs_ectester_standalone_libs_TomcryptLib + * Method: createProvider + * Signature: ()Ljava/security/Provider; + */ +JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_TomcryptLib_createProvider + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class cz_crcs_ectester_standalone_libs_jni_TomCryptProvider */ + +#ifndef _Included_cz_crcs_ectester_standalone_libs_jni_TomCryptProvider +#define _Included_cz_crcs_ectester_standalone_libs_jni_TomCryptProvider +#ifdef __cplusplus +extern "C" { +#endif +#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID +#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID 1421746759512286392LL +#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_MAX_ARRAY_SIZE +#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_MAX_ARRAY_SIZE 2147483639L +#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_KEYS +#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_KEYS 0L +#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_VALUES +#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_VALUES 1L +#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_ENTRIES +#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_ENTRIES 2L +#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID +#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID 4112578634029874840LL +#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID +#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID -4298000515446427739LL +/* + * Class: cz_crcs_ectester_standalone_libs_jni_TomCryptProvider + * Method: setup + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_setup + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c b/src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c new file mode 100644 index 0000000..43ae06b --- /dev/null +++ b/src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c @@ -0,0 +1,40 @@ +#include "native.h" +#include +#define LTM_DESC +#include + +JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_TomcryptLib_createProvider(JNIEnv *env, jobject this) { + jclass provider_class = (*env)->FindClass(env, "cz/crcs/ectester/standalone/libs/jni/TomCryptProvider"); + + jmethodID init = (*env)->GetMethodID(env, provider_class, "", "(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_TomCryptProvider_setup(JNIEnv *env, jobject this) { + ltc_mp = ltm_desc; + /* Just test ecc key generation at this time. */ + ecc_key mykey; + prng_state prng; + int err; + /* register yarrow */ + if (register_prng(&yarrow_desc) == -1) { + printf("Error registering Yarrow\n"); + return; + } + /* 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 */ + 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; +} \ No newline at end of file diff --git a/src/cz/crcs/ectester/standalone/libs/native.h b/src/cz/crcs/ectester/standalone/libs/native.h deleted file mode 100644 index 979f04a..0000000 --- a/src/cz/crcs/ectester/standalone/libs/native.h +++ /dev/null @@ -1,21 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class cz_crcs_ectester_standalone_libs_TomcryptLib */ - -#ifndef _Included_cz_crcs_ectester_standalone_libs_TomcryptLib -#define _Included_cz_crcs_ectester_standalone_libs_TomcryptLib -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: cz_crcs_ectester_standalone_libs_TomcryptLib - * Method: getProvider - * Signature: ()Ljava/security/Provider; - */ -JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_TomcryptLib_getProvider - (JNIEnv *, jobject); - -#ifdef __cplusplus -} -#endif -#endif -- cgit v1.2.3-70-g09d2 From 58271abb0977ef2179a8506bba41005bb2af2869 Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 28 Nov 2017 23:46:00 +0100 Subject: Move TomCryptProvider into NativeProvider as a nested class. --- build-standalone.xml | 10 ++++-- .../ectester/standalone/libs/NativeECLibrary.java | 2 +- .../standalone/libs/jni/NativeProvider.java | 9 +++++ .../standalone/libs/jni/TomCryptProvider.java | 11 ------- src/cz/crcs/ectester/standalone/libs/jni/native.h | 38 +++++++++++----------- .../crcs/ectester/standalone/libs/jni/tomcrypt.c | 19 +++++++++-- 6 files changed, 54 insertions(+), 35 deletions(-) delete mode 100644 src/cz/crcs/ectester/standalone/libs/jni/TomCryptProvider.java (limited to 'src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java') diff --git a/build-standalone.xml b/build-standalone.xml index 447b9b1..300eec8 100644 --- a/build-standalone.xml +++ b/build-standalone.xml @@ -71,14 +71,20 @@ nbproject/build-impl.xml file. --> - + + + + + + + - + diff --git a/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java b/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java index 5d1b9d7..e059c19 100644 --- a/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java +++ b/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java @@ -83,7 +83,7 @@ public abstract class NativeECLibrary extends ProviderECLibrary { provider = createProvider(); return super.initialize(); - } catch (IOException ignored) { + } catch (IOException | UnsatisfiedLinkError ignored) { } return false; diff --git a/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java b/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java index 43b7827..53f8b3c 100644 --- a/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java +++ b/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java @@ -22,4 +22,13 @@ public abstract class NativeProvider extends Provider { abstract void setup(); + public static class TomCrypt extends NativeProvider { + + public TomCrypt(String name, double version, String info) { + super(name, version, info); + } + + @Override + native void setup(); + } } diff --git a/src/cz/crcs/ectester/standalone/libs/jni/TomCryptProvider.java b/src/cz/crcs/ectester/standalone/libs/jni/TomCryptProvider.java deleted file mode 100644 index 01e4c17..0000000 --- a/src/cz/crcs/ectester/standalone/libs/jni/TomCryptProvider.java +++ /dev/null @@ -1,11 +0,0 @@ -package cz.crcs.ectester.standalone.libs.jni; - -public class TomCryptProvider extends NativeProvider { - - public TomCryptProvider(String name, double version, String info) { - super(name, version, info); - } - - @Override - native void setup(); -} diff --git a/src/cz/crcs/ectester/standalone/libs/jni/native.h b/src/cz/crcs/ectester/standalone/libs/jni/native.h index 83ef841..e4e5009 100644 --- a/src/cz/crcs/ectester/standalone/libs/jni/native.h +++ b/src/cz/crcs/ectester/standalone/libs/jni/native.h @@ -19,33 +19,33 @@ JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_TomcryptLib_crea } #endif #endif -/* Header for class cz_crcs_ectester_standalone_libs_jni_TomCryptProvider */ +/* Header for class cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt */ -#ifndef _Included_cz_crcs_ectester_standalone_libs_jni_TomCryptProvider -#define _Included_cz_crcs_ectester_standalone_libs_jni_TomCryptProvider +#ifndef _Included_cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt +#define _Included_cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt #ifdef __cplusplus extern "C" { #endif -#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID -#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID 1421746759512286392LL -#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_MAX_ARRAY_SIZE -#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_MAX_ARRAY_SIZE 2147483639L -#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_KEYS -#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_KEYS 0L -#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_VALUES -#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_VALUES 1L -#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_ENTRIES -#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_ENTRIES 2L -#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID -#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID 4112578634029874840LL -#undef cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID -#define cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_serialVersionUID -4298000515446427739LL +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_serialVersionUID +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_serialVersionUID 1421746759512286392LL +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_MAX_ARRAY_SIZE +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_MAX_ARRAY_SIZE 2147483639L +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_KEYS +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_KEYS 0L +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_VALUES +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_VALUES 1L +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_ENTRIES +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_ENTRIES 2L +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_serialVersionUID +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_serialVersionUID 4112578634029874840LL +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_serialVersionUID +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt_serialVersionUID -4298000515446427739LL /* - * Class: cz_crcs_ectester_standalone_libs_jni_TomCryptProvider + * Class: cz_crcs_ectester_standalone_libs_jni_NativeProvider_TomCrypt * Method: setup * Signature: ()V */ -JNIEXPORT void JNICALL Java_cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_setup +JNIEXPORT void JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeProvider_00024TomCrypt_setup (JNIEnv *, jobject); #ifdef __cplusplus diff --git a/src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c b/src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c index 43ae06b..db1de88 100644 --- a/src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c +++ b/src/cz/crcs/ectester/standalone/libs/jni/tomcrypt.c @@ -4,7 +4,7 @@ #include JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_TomcryptLib_createProvider(JNIEnv *env, jobject this) { - jclass provider_class = (*env)->FindClass(env, "cz/crcs/ectester/standalone/libs/jni/TomCryptProvider"); + jclass provider_class = (*env)->FindClass(env, "cz/crcs/ectester/standalone/libs/jni/NativeProvider$TomCrypt"); jmethodID init = (*env)->GetMethodID(env, provider_class, "", "(Ljava/lang/String;DLjava/lang/String;)V"); if (init == NULL) { @@ -15,8 +15,23 @@ JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_TomcryptLib_crea return (*env)->NewObject(env, provider_class, init, name, version, name); } -JNIEXPORT void JNICALL Java_cz_crcs_ectester_standalone_libs_jni_TomCryptProvider_setup(JNIEnv *env, jobject this) { +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. */ ecc_key mykey; prng_state prng; -- cgit v1.2.3-70-g09d2 From ad5049198a295c4f918fe08211d860e64e1f73ac Mon Sep 17 00:00:00 2001 From: J08nY Date: Wed, 6 Dec 2017 21:03:08 +0100 Subject: Add Botan library. --- build-standalone.xml | 7 + .../ectester/standalone/ECTesterStandalone.java | 2 +- src/cz/crcs/ectester/standalone/libs/BotanLib.java | 20 +++ .../ectester/standalone/libs/NativeECLibrary.java | 28 +++- src/cz/crcs/ectester/standalone/libs/jni/Makefile | 12 +- .../standalone/libs/jni/NativeECPrivateKey.java | 16 +- .../standalone/libs/jni/NativeECPublicKey.java | 16 +- .../standalone/libs/jni/NativeKeyAgreementSpi.java | 6 + .../libs/jni/NativeKeyPairGeneratorSpi.java | 19 +++ .../standalone/libs/jni/NativeProvider.java | 10 ++ .../standalone/libs/jni/NativeSignatureSpi.java | 8 + src/cz/crcs/ectester/standalone/libs/jni/botan.cpp | 110 +++++++++++++ src/cz/crcs/ectester/standalone/libs/jni/native.h | 171 +++++++++++++++++++++ 13 files changed, 417 insertions(+), 8 deletions(-) create mode 100644 src/cz/crcs/ectester/standalone/libs/BotanLib.java create mode 100644 src/cz/crcs/ectester/standalone/libs/jni/botan.cpp (limited to 'src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java') diff --git a/build-standalone.xml b/build-standalone.xml index ef6ab2a..ea160c8 100644 --- a/build-standalone.xml +++ b/build-standalone.xml @@ -102,6 +102,13 @@ + + + + + + + diff --git a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java index 433e6a8..d9525e9 100644 --- a/src/cz/crcs/ectester/standalone/ECTesterStandalone.java +++ b/src/cz/crcs/ectester/standalone/ECTesterStandalone.java @@ -39,7 +39,7 @@ import java.util.stream.Collectors; * @version v0.1.0 */ public class ECTesterStandalone { - private ProviderECLibrary[] libs = new ProviderECLibrary[]{new SunECLib(), new BouncyCastleLib(), new TomcryptLib()}; + private ProviderECLibrary[] libs = new ProviderECLibrary[]{new SunECLib(), new BouncyCastleLib(), new TomcryptLib(), new BotanLib()}; private EC_Store dataStore; private Config cfg; diff --git a/src/cz/crcs/ectester/standalone/libs/BotanLib.java b/src/cz/crcs/ectester/standalone/libs/BotanLib.java new file mode 100644 index 0000000..cd28791 --- /dev/null +++ b/src/cz/crcs/ectester/standalone/libs/BotanLib.java @@ -0,0 +1,20 @@ +package cz.crcs.ectester.standalone.libs; + +import java.security.Provider; +import java.util.Set; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public class BotanLib extends NativeECLibrary { + + public BotanLib() { + super("botan_provider", "botan-2"); + } + + @Override + native Provider createProvider(); + + @Override + public native Set getCurves(); +} diff --git a/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java b/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java index e059c19..0a420a1 100644 --- a/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java +++ b/src/cz/crcs/ectester/standalone/libs/NativeECLibrary.java @@ -2,6 +2,7 @@ package cz.crcs.ectester.standalone.libs; import java.io.File; import java.io.IOException; +import java.lang.reflect.Field; import java.net.URL; import java.net.URLConnection; import java.nio.file.Files; @@ -27,6 +28,7 @@ public abstract class NativeECLibrary extends ProviderECLibrary { @Override public boolean initialize() { try { + /* Determine what OS are we running on and use appropriate suffix and path. */ String suffix; Path appData; if (System.getProperty("os.name").startsWith("Windows")) { @@ -56,6 +58,10 @@ public abstract class NativeECLibrary extends ProviderECLibrary { } URLConnection jarConnection = jarURL.openConnection(); + /* Only write the file if it does not exist, + * or if the existing one is older than the + * one in the JAR. + */ boolean write = false; if (libDirFile.isDirectory() && libFile.isFile()) { long jarModified = jarConnection.getLastModified(); @@ -75,16 +81,36 @@ public abstract class NativeECLibrary extends ProviderECLibrary { } jarConnection.getInputStream().close(); + /* + * Need to hack in /usr/local/lib to path. + * See: https://stackoverflow.com/questions/5419039/is-djava-library-path-equivalent-to-system-setpropertyjava-library-path/24988095#24988095 + */ + String path = System.getProperty("java.library.path"); + if (suffix.equals("so")) { + String newPath = path + ":/usr/local/lib"; + System.setProperty("java.library.path", newPath); + Field fieldSysPath; + try { + fieldSysPath = ClassLoader.class.getDeclaredField( "sys_paths" ); + fieldSysPath.setAccessible( true ); + fieldSysPath.set( null, null ); + } catch (NoSuchFieldException | IllegalAccessException ignored) { + } + } + for (String requirement : requriements) { System.loadLibrary(requirement); } + if (suffix.equals("so")) { + System.setProperty("java.library.path", path); + } + System.load(libPath.toString()); provider = createProvider(); return super.initialize(); } catch (IOException | UnsatisfiedLinkError ignored) { - } return false; } diff --git a/src/cz/crcs/ectester/standalone/libs/jni/Makefile b/src/cz/crcs/ectester/standalone/libs/jni/Makefile index b60452f..78433c9 100644 --- a/src/cz/crcs/ectester/standalone/libs/jni/Makefile +++ b/src/cz/crcs/ectester/standalone/libs/jni/Makefile @@ -31,16 +31,24 @@ endif JNI_PLATFORMINCLUDEDIR ?= $(JNI_INCLUDEDIR)/$(JNI_PLATFORM) +LOCAL_INCLUDES = /usr/local/include +LOCAL_LIBS = /usr/local/lib -all: tomcrypt_provider.so +all: tomcrypt_provider.so botan_provider.so tomcrypt_provider.so: tomcrypt.o gcc -fPIC -g -shared -o $@ $< -L. -ltommath -ltomcrypt -%.o: %.c +tomcrypt.o: tomcrypt.c gcc -DLTM_DESC -fPIC -g -I"$(JNI_INCLUDEDIR)" -I"$(JNI_PLATFORMINCLUDEDIR)" -I. -c $< +botan_provider.so: botan.o + g++ -fPIC -g -shared -o $@ $< -L. -L"$(LOCAL_LIBS)" -lbotan-2 -fstack-protector -m64 -pthread + +botan.o: botan.cpp + g++ -fPIC -g -I"$(LOCAL_INCLUDES)/botan-2" -I"$(JNI_INCLUDEDIR)" -I"$(JNI_PLATFORMINCLUDEDIR)" -I. -c $< + clean: rm -rf *.o rm -rf *.so diff --git a/src/cz/crcs/ectester/standalone/libs/jni/NativeECPrivateKey.java b/src/cz/crcs/ectester/standalone/libs/jni/NativeECPrivateKey.java index 6f6cde3..22e5329 100644 --- a/src/cz/crcs/ectester/standalone/libs/jni/NativeECPrivateKey.java +++ b/src/cz/crcs/ectester/standalone/libs/jni/NativeECPrivateKey.java @@ -28,11 +28,11 @@ public abstract class NativeECPrivateKey implements ECPrivateKey { return format; } - public static class TomCrypt extends NativeECPrivateKey { + private static class Raw extends NativeECPrivateKey { private byte[] keyData; private ECParameterSpec params; - public TomCrypt(byte[] keyData, ECParameterSpec params) { + public Raw(byte[] keyData, ECParameterSpec params) { super("EC", "raw"); this.keyData = keyData; this.params = params; @@ -53,4 +53,16 @@ public abstract class NativeECPrivateKey implements ECPrivateKey { return params; } } + + public static class TomCrypt extends Raw { + public TomCrypt(byte[] keyData, ECParameterSpec params) { + super(keyData, params); + } + } + + public static class Botan extends Raw { + public Botan(byte[] keyData, ECParameterSpec params) { + super(keyData, params); + } + } } diff --git a/src/cz/crcs/ectester/standalone/libs/jni/NativeECPublicKey.java b/src/cz/crcs/ectester/standalone/libs/jni/NativeECPublicKey.java index c3791c4..8fc4747 100644 --- a/src/cz/crcs/ectester/standalone/libs/jni/NativeECPublicKey.java +++ b/src/cz/crcs/ectester/standalone/libs/jni/NativeECPublicKey.java @@ -29,11 +29,11 @@ public abstract class NativeECPublicKey implements ECPublicKey { return format; } - public static class TomCrypt extends NativeECPublicKey { + private static class ANSIX962 extends NativeECPublicKey { private byte[] keyData; private ECParameterSpec params; - public TomCrypt(byte[] keyData, ECParameterSpec params) { + public ANSIX962(byte[] keyData, ECParameterSpec params) { super("EC", "ANSI X9.62"); this.keyData = keyData; this.params = params; @@ -54,4 +54,16 @@ public abstract class NativeECPublicKey implements ECPublicKey { return params; } } + + public static class TomCrypt extends ANSIX962 { + public TomCrypt(byte[] keyData, ECParameterSpec params) { + super(keyData, params); + } + } + + public static class Botan extends ANSIX962 { + public Botan(byte[] keyData, ECParameterSpec params) { + super(keyData, params); + } + } } diff --git a/src/cz/crcs/ectester/standalone/libs/jni/NativeKeyAgreementSpi.java b/src/cz/crcs/ectester/standalone/libs/jni/NativeKeyAgreementSpi.java index a58c0c8..8875948 100644 --- a/src/cz/crcs/ectester/standalone/libs/jni/NativeKeyAgreementSpi.java +++ b/src/cz/crcs/ectester/standalone/libs/jni/NativeKeyAgreementSpi.java @@ -88,4 +88,10 @@ public abstract class NativeKeyAgreementSpi extends KeyAgreementSpi { @Override native byte[] generateSecret(byte[] pubkey, byte[] privkey, ECParameterSpec params); } + + public static class Botan extends NativeKeyAgreementSpi { + + @Override + native byte[] generateSecret(byte[] pubkey, byte[] privkey, ECParameterSpec params); + } } diff --git a/src/cz/crcs/ectester/standalone/libs/jni/NativeKeyPairGeneratorSpi.java b/src/cz/crcs/ectester/standalone/libs/jni/NativeKeyPairGeneratorSpi.java index d2cc59d..5b8a54b 100644 --- a/src/cz/crcs/ectester/standalone/libs/jni/NativeKeyPairGeneratorSpi.java +++ b/src/cz/crcs/ectester/standalone/libs/jni/NativeKeyPairGeneratorSpi.java @@ -71,4 +71,23 @@ public abstract class NativeKeyPairGeneratorSpi extends KeyPairGeneratorSpi { @Override native KeyPair generate(AlgorithmParameterSpec params, SecureRandom random); } + + public static class Botan extends NativeKeyPairGeneratorSpi { + + public Botan() { + initialize(256, new SecureRandom()); + } + + @Override + native boolean keysizeSupported(int keysize); + + @Override + native boolean paramsSupported(AlgorithmParameterSpec params); + + @Override + native KeyPair generate(int keysize, SecureRandom random); + + @Override + native KeyPair generate(AlgorithmParameterSpec params, SecureRandom random); + } } diff --git a/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java b/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java index a2233e2..a0689d6 100644 --- a/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java +++ b/src/cz/crcs/ectester/standalone/libs/jni/NativeProvider.java @@ -29,4 +29,14 @@ public abstract class NativeProvider extends Provider { @Override native void setup(); } + + public static class Botan extends NativeProvider { + + public Botan(String name, double version, String info) { + super(name, version, info); + } + + @Override + native void setup(); + } } diff --git a/src/cz/crcs/ectester/standalone/libs/jni/NativeSignatureSpi.java b/src/cz/crcs/ectester/standalone/libs/jni/NativeSignatureSpi.java index 76f01f0..8894f84 100644 --- a/src/cz/crcs/ectester/standalone/libs/jni/NativeSignatureSpi.java +++ b/src/cz/crcs/ectester/standalone/libs/jni/NativeSignatureSpi.java @@ -83,6 +83,14 @@ public abstract class NativeSignatureSpi extends SignatureSpi { @Override native boolean verify(byte[] signature, byte[] data, byte[] pubkey, ECParameterSpec params); + } + + public static class Botan extends NativeSignatureSpi { + @Override + native byte[] sign(byte[] data, byte[] privkey, ECParameterSpec params); + + @Override + native boolean verify(byte[] signature, byte[] data, byte[] pubkey, ECParameterSpec params); } } diff --git a/src/cz/crcs/ectester/standalone/libs/jni/botan.cpp b/src/cz/crcs/ectester/standalone/libs/jni/botan.cpp new file mode 100644 index 0000000..9c2394f --- /dev/null +++ b/src/cz/crcs/ectester/standalone/libs/jni/botan.cpp @@ -0,0 +1,110 @@ +#include "native.h" +#include +#include + +static jclass provider_class; + +/* + * Class: cz_crcs_ectester_standalone_libs_BotanLib + * Method: createProvider + * Signature: ()Ljava/security/Provider; + */ +JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_BotanLib_createProvider(JNIEnv *env, jobject self) { + /* Create the custom provider. */ + jclass local_provider_class = env->FindClass("cz/crcs/ectester/standalone/libs/jni/NativeProvider$Botan"); + provider_class = (jclass) env->NewGlobalRef(local_provider_class); + + jmethodID init = env->GetMethodID(local_provider_class, "", "(Ljava/lang/String;DLjava/lang/String;)V"); + + const char* info_str = Botan::version_cstr(); + const char* v_str = Botan::short_version_cstr(); + std::string name_str = Botan::short_version_string(); + name_str.insert(0, "Botan "); + + jstring name = env->NewStringUTF(name_str.c_str()); + double version = strtod(v_str, NULL); + jstring info = env->NewStringUTF(info_str); + + return env->NewObject(provider_class, init, name, version, info); +} + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan + * Method: setup + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeProvider_00024Botan_setup(JNIEnv *env, jobject self){ + +} + +/* + * Class: cz_crcs_ectester_standalone_libs_BotanLib + * Method: getCurves + * Signature: ()Ljava/util/Set; + */ +JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_BotanLib_getCurves(JNIEnv *env, jobject self){ + +} + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_Botan + * Method: keysizeSupported + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_00024Botan_keysizeSupported(JNIEnv *env, jobject self, jint keysize){ + +} + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_Botan + * Method: paramsSupported + * Signature: (Ljava/security/spec/AlgorithmParameterSpec;)Z + */ +JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_00024Botan_paramsSupported(JNIEnv *env, jobject self, jobject params){ + +} + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_Botan + * Method: generate + * Signature: (ILjava/security/SecureRandom;)Ljava/security/KeyPair; + */ +JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_00024Botan_generate__ILjava_security_SecureRandom_2(JNIEnv *env, jobject self, jint keysize, jobject random){ + +} + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_Botan + * Method: generate + * Signature: (Ljava/security/spec/AlgorithmParameterSpec;Ljava/security/SecureRandom;)Ljava/security/KeyPair; + */ +JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_00024Botan_generate__Ljava_security_spec_AlgorithmParameterSpec_2Ljava_security_SecureRandom_2(JNIEnv *env, jobject self, jobject params, jobject random){ + +} + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeKeyAgreementSpi_Botan + * Method: generateSecret + * Signature: ([B[BLjava/security/spec/ECParameterSpec;)[B + */ +JNIEXPORT jbyteArray JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeKeyAgreementSpi_00024Botan_generateSecret(JNIEnv *env, jobject self, jbyteArray pubkey, jbyteArray privkey, jobject params){ + +} + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeSignatureSpi_Botan + * Method: sign + * Signature: ([B[BLjava/security/spec/ECParameterSpec;)[B + */ +JNIEXPORT jbyteArray JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeSignatureSpi_00024Botan_sign(JNIEnv *env, jobject self, jbyteArray data, jbyteArray privkey, jobject params){ + +} + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeSignatureSpi_Botan + * Method: verify + * Signature: ([B[B[BLjava/security/spec/ECParameterSpec;)Z + */ +JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeSignatureSpi_00024Botan_verify(JNIEnv *env, jobject self, jbyteArray signature, jbyteArray data, jbyteArray pubkey, jobject params){ + +} \ No newline at end of file diff --git a/src/cz/crcs/ectester/standalone/libs/jni/native.h b/src/cz/crcs/ectester/standalone/libs/jni/native.h index 852dd53..d714b39 100644 --- a/src/cz/crcs/ectester/standalone/libs/jni/native.h +++ b/src/cz/crcs/ectester/standalone/libs/jni/native.h @@ -171,3 +171,174 @@ JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeSigna } #endif #endif +/* Header for class cz_crcs_ectester_standalone_libs_BotanLib */ + +#ifndef _Included_cz_crcs_ectester_standalone_libs_BotanLib +#define _Included_cz_crcs_ectester_standalone_libs_BotanLib +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: cz_crcs_ectester_standalone_libs_BotanLib + * Method: createProvider + * Signature: ()Ljava/security/Provider; + */ +JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_BotanLib_createProvider + (JNIEnv *, jobject); + +/* + * Class: cz_crcs_ectester_standalone_libs_BotanLib + * Method: getCurves + * Signature: ()Ljava/util/Set; + */ +JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_BotanLib_getCurves + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan */ + +#ifndef _Included_cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan +#define _Included_cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan +#ifdef __cplusplus +extern "C" { +#endif +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_serialVersionUID +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_serialVersionUID 1421746759512286392LL +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_MAX_ARRAY_SIZE +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_MAX_ARRAY_SIZE 2147483639L +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_KEYS +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_KEYS 0L +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_VALUES +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_VALUES 1L +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_ENTRIES +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_ENTRIES 2L +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_serialVersionUID +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_serialVersionUID 4112578634029874840LL +#undef cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_serialVersionUID +#define cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan_serialVersionUID -4298000515446427739LL +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeProvider_Botan + * Method: setup + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeProvider_00024Botan_setup + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_Botan */ + +#ifndef _Included_cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_Botan +#define _Included_cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_Botan +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_Botan + * Method: keysizeSupported + * Signature: (I)Z + */ +JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_00024Botan_keysizeSupported + (JNIEnv *, jobject, jint); + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_Botan + * Method: paramsSupported + * Signature: (Ljava/security/spec/AlgorithmParameterSpec;)Z + */ +JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_00024Botan_paramsSupported + (JNIEnv *, jobject, jobject); + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_Botan + * Method: generate + * Signature: (ILjava/security/SecureRandom;)Ljava/security/KeyPair; + */ +JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_00024Botan_generate__ILjava_security_SecureRandom_2 + (JNIEnv *, jobject, jint, jobject); + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_Botan + * Method: generate + * Signature: (Ljava/security/spec/AlgorithmParameterSpec;Ljava/security/SecureRandom;)Ljava/security/KeyPair; + */ +JNIEXPORT jobject JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeKeyPairGeneratorSpi_00024Botan_generate__Ljava_security_spec_AlgorithmParameterSpec_2Ljava_security_SecureRandom_2 + (JNIEnv *, jobject, jobject, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class cz_crcs_ectester_standalone_libs_jni_NativeECPublicKey_Botan */ + +#ifndef _Included_cz_crcs_ectester_standalone_libs_jni_NativeECPublicKey_Botan +#define _Included_cz_crcs_ectester_standalone_libs_jni_NativeECPublicKey_Botan +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif +/* Header for class cz_crcs_ectester_standalone_libs_jni_NativeECPrivateKey_Botan */ + +#ifndef _Included_cz_crcs_ectester_standalone_libs_jni_NativeECPrivateKey_Botan +#define _Included_cz_crcs_ectester_standalone_libs_jni_NativeECPrivateKey_Botan +#ifdef __cplusplus +extern "C" { +#endif +#ifdef __cplusplus +} +#endif +#endif +/* Header for class cz_crcs_ectester_standalone_libs_jni_NativeKeyAgreementSpi_Botan */ + +#ifndef _Included_cz_crcs_ectester_standalone_libs_jni_NativeKeyAgreementSpi_Botan +#define _Included_cz_crcs_ectester_standalone_libs_jni_NativeKeyAgreementSpi_Botan +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeKeyAgreementSpi_Botan + * Method: generateSecret + * Signature: ([B[BLjava/security/spec/ECParameterSpec;)[B + */ +JNIEXPORT jbyteArray JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeKeyAgreementSpi_00024Botan_generateSecret + (JNIEnv *, jobject, jbyteArray, jbyteArray, jobject); + +#ifdef __cplusplus +} +#endif +#endif +/* Header for class cz_crcs_ectester_standalone_libs_jni_NativeSignatureSpi_Botan */ + +#ifndef _Included_cz_crcs_ectester_standalone_libs_jni_NativeSignatureSpi_Botan +#define _Included_cz_crcs_ectester_standalone_libs_jni_NativeSignatureSpi_Botan +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeSignatureSpi_Botan + * Method: sign + * Signature: ([B[BLjava/security/spec/ECParameterSpec;)[B + */ +JNIEXPORT jbyteArray JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeSignatureSpi_00024Botan_sign + (JNIEnv *, jobject, jbyteArray, jbyteArray, jobject); + +/* + * Class: cz_crcs_ectester_standalone_libs_jni_NativeSignatureSpi_Botan + * Method: verify + * Signature: ([B[B[BLjava/security/spec/ECParameterSpec;)Z + */ +JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeSignatureSpi_00024Botan_verify + (JNIEnv *, jobject, jbyteArray, jbyteArray, jbyteArray, jobject); + +#ifdef __cplusplus +} +#endif +#endif -- cgit v1.2.3-70-g09d2