aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/standalone
diff options
context:
space:
mode:
authorJ08nY2019-07-16 11:44:17 +0200
committerJ08nY2019-07-16 11:44:17 +0200
commite0a4956cafcbb98bdf18c9a25fbf799e4de4a35e (patch)
tree9803e4d0af26639d972bdeda06f935e051db8350 /src/cz/crcs/ectester/standalone
parent46c0a874e494d2311148700058f61b5d8d426f3c (diff)
downloadECTester-e0a4956cafcbb98bdf18c9a25fbf799e4de4a35e.tar.gz
ECTester-e0a4956cafcbb98bdf18c9a25fbf799e4de4a35e.tar.zst
ECTester-e0a4956cafcbb98bdf18c9a25fbf799e4de4a35e.zip
Add option to use KeyBuilder.
Diffstat (limited to 'src/cz/crcs/ectester/standalone')
-rw-r--r--src/cz/crcs/ectester/standalone/libs/jni/c_timing.c4
-rw-r--r--src/cz/crcs/ectester/standalone/libs/jni/c_utils.c8
-rw-r--r--src/cz/crcs/ectester/standalone/libs/jni/mscng.c45
3 files changed, 38 insertions, 19 deletions
diff --git a/src/cz/crcs/ectester/standalone/libs/jni/c_timing.c b/src/cz/crcs/ectester/standalone/libs/jni/c_timing.c
index a6ffc7e..941cee6 100644
--- a/src/cz/crcs/ectester/standalone/libs/jni/c_timing.c
+++ b/src/cz/crcs/ectester/standalone/libs/jni/c_timing.c
@@ -1,5 +1,9 @@
#include "c_timing.h"
+#if __linux || __posix
+#include<unistd.h>
+#endif
+
#if _POSIX_TIMERS > 0
#include <time.h>
diff --git a/src/cz/crcs/ectester/standalone/libs/jni/c_utils.c b/src/cz/crcs/ectester/standalone/libs/jni/c_utils.c
index a5bc14d..46286fd 100644
--- a/src/cz/crcs/ectester/standalone/libs/jni/c_utils.c
+++ b/src/cz/crcs/ectester/standalone/libs/jni/c_utils.c
@@ -3,6 +3,10 @@
#include <string.h>
#include <stdlib.h>
+#if defined(__WIN32__) || defined(_MSC_VER)
+#include <windows.h>
+#endif
+
jclass ec_parameter_spec_class;
jclass ecgen_parameter_spec_class;
jclass secret_key_spec_class;
@@ -228,7 +232,11 @@ char *biginteger_to_hex(JNIEnv *env, jobject big, jint bytes) {
jstring big_string = (*env)->CallObjectMethod(env, big, to_string, (jint) 16);
jsize len = (*env)->GetStringUTFLength(env, big_string);
+#if defined(__WIN32__) || defined(_MSC_VER)
+ char *raw_string = _alloca(len);
+#else
char raw_string[len];
+#endif
(*env)->GetStringUTFRegion(env, big_string, 0, len, raw_string);
char *result = calloc(bytes, 2);
diff --git a/src/cz/crcs/ectester/standalone/libs/jni/mscng.c b/src/cz/crcs/ectester/standalone/libs/jni/mscng.c
index 2b38860..7f3ff5d 100644
--- a/src/cz/crcs/ectester/standalone/libs/jni/mscng.c
+++ b/src/cz/crcs/ectester/standalone/libs/jni/mscng.c
@@ -1,12 +1,10 @@
-#include <bcrypt.h>
#include <windows.h>
+#include <bcrypt.h>
#include "native.h"
#include "c_timing.h"
#include "c_utils.h"
-#include <stdio.h>
-
// BCRYPT and NT things.
#define NT_SUCCESS(status) (((NTSTATUS)(status)) >= 0)
#define NT_FAILURE(status) !NT_SUCCESS(status)
@@ -17,8 +15,7 @@
typedef struct {
ULONG dwVersion; // Version of the structure
ECC_CURVE_TYPE_ENUM dwCurveType; // Supported curve types.
- ECC_CURVE_ALG_ID_ENUM
- dwCurveGenerationAlgId; // For X.592 verification purposes, if we include Seed we will need to include the algorithm ID.
+ ECC_CURVE_ALG_ID_ENUM dwCurveGenerationAlgId; // For X.592 verification purposes, if we include Seed we will need to include the algorithm ID.
ULONG cbFieldLength; // Byte length of the fields P, A, B, X, Y.
ULONG cbSubgroupOrder; // Byte length of the subgroup.
ULONG cbCofactor; // Byte length of cofactor of G in E.
@@ -1203,6 +1200,12 @@ JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeSigna
return JNI_FALSE;
}
(*env)->ReleaseByteArrayElements(env, pubkey_barray, pub_data, JNI_ABORT);
+
+ jmethodID get_n = (*env)->GetMethodID(env, ec_parameter_spec_class, "getOrder", "()Ljava/math/BigInteger;");
+ jobject n = (*env)->CallObjectMethod(env, params, get_n);
+ jmethodID get_bitlength = (*env)->GetMethodID(env, biginteger_class, "bitLength", "()I");
+ jint ord_bits = (*env)->CallIntMethod(env, n, get_bitlength);
+ jint ord_bytes = (ord_bits + 7) / 8;
jint sig_len = (*env)->GetArrayLength(env, sig);
jbyte *sig_data = (*env)->GetByteArrayElements(env, sig, NULL);
@@ -1224,20 +1227,24 @@ JNIEXPORT jboolean JNICALL Java_cz_crcs_ectester_standalone_libs_jni_NativeSigna
jbyte *r_cpy = r;
jbyte *s_cpy = s;
- if (rlen > slen) {
- r_cpy += rlen - slen;
- rlen = slen;
- } else if (slen > rlen) {
- s_cpy += slen - rlen;
- slen = rlen;
- } else {
- if (r[0] == 0 && s[0] == 0) {
- r_cpy++;
- s_cpy++;
- rlen--;
- slen--;
- }
- }
+ if (rlen > ord_bytes) {
+ r_cpy += ord_bytes - rlen;
+ }
+ if (slen > ord_bytes) {
+ s_cpy += ord_bytes - slen;
+ }
+ if (rlen < ord_bytes) {
+ r_cpy = _alloca(ord_bytes);
+ memset(r_cpy, 0, ord_bytes);
+ memcpy(r_cpy, r + (ord_bytes - rlen), ord_bytes);
+ }
+ if (slen < ord_bytes) {
+ s_cpy = _alloca(ord_bytes);
+ memset(s_cpy, 0, ord_bytes);
+ memcpy(s_cpy, s + (ord_bytes - slen), ord_bytes);
+ }
+ rlen = ord_bytes;
+ slen = ord_bytes;
UCHAR *sig_full = calloc(rlen + slen, 1);
memcpy(sig_full, r_cpy, rlen);