java - ECC memory overflow on Android -
i'm trying make eliptic cureve crypto code work on android. (https://github.com/k3d3/ed25519-java). works fine on computer on android stackoverflowerror.
where problem occurs depends on android device. on 1 it's in scalarmult() on expmod(). debugger shows work while sudden death. ideas? memory problem?
static biginteger[] scalarmult(biginteger[] p, biginteger e) { //system.out.println("scalarmult open e = " + e); if (e.equals(biginteger.zero)) { system.out.println("scalarmult close q = 0,1"); return new biginteger[]{biginteger.zero, biginteger.one}; } biginteger[] q = scalarmult(p, e.divide(biginteger.valueof(2))); //system.out.println("scalarmult asq = " + q[0] + "," + q[1]); q = edwards(q, q); //system.out.println("scalarmult aeq = " + q[0] + "," + q[1] + " e="+e+" testbit="+(e.testbit(0)?1:0)); if (e.testbit(0)) q = edwards(q, p); //system.out.println("scalarmult close q = " + q[0] + "," + q[1]); return q; } static biginteger expmod(biginteger b, biginteger e, biginteger m) { //system.out.println("expmod open b=" + b + " e=" + e + " m=" + m); if (e.equals(biginteger.zero)) { //system.out.println("expmod close 1z"); return biginteger.one; } biginteger t = expmod(b, e.divide(biginteger.valueof(2)), m).pow(2).mod(m); //system.out.println("expmod 1/2 t="+t+" e="+e+" testbit="+(e.testbit(0)?1:0)); if (e.testbit(0)) { t = t.multiply(b).mod(m); } //system.out.println("expmod close " + t); return t; }
stack trace (cut of last part since it's repeating self):
10-06 19:00:17.855: e/androidruntime(749): fatal exception: main 10-06 19:00:17.855: e/androidruntime(749): java.lang.stackoverflowerror 10-06 19:00:17.855: e/androidruntime(749): @ java.lang.ref.finalizerreference.<init>(finalizerreference.java:34) 10-06 19:00:17.855: e/androidruntime(749): @ java.lang.ref.finalizerreference.add(finalizerreference.java:48) 10-06 19:00:17.855: e/androidruntime(749): @ java.math.bigint.<init>(bigint.java:24) 10-06 19:00:17.855: e/androidruntime(749): @ java.math.biginteger.divide(biginteger.java:903) 10-06 19:00:17.855: e/androidruntime(749): @ com.test.crypto.curve25519.expmod(curve25519.java:45) 10-06 19:00:17.855: e/androidruntime(749): @ com.test.crypto.curve25519.expmod(curve25519.java:45) 10-06 19:00:17.855: e/androidruntime(749): @ com.test.crypto.curve25519.expmod(curve25519.java:45) 10-06 19:00:17.855: e/androidruntime(749): @ com.test.crypto.curve25519.expmod(curve25519.java:45) 10-06 19:00:17.855: e/androidruntime(749): @ com.test.crypto.curve25519.expmod(curve25519.java:45) 10-06 19:00:17.855: e/androidruntime(749): @ com.test.crypto.curve25519.expmod(curve25519.java:45)
Comments
Post a Comment