Closed ricardovf closed 5 years ago
What i did so far:
// Pre-allocate all helper structures
ecc = new jcmathlib.ECConfig((short) 256);
// Pre-allocate standard Secp256k1 curve and two EC points on this curve
curve = new jcmathlib.ECCurve(true, Secp256k1.SECP256K1_FP, Secp256k1.SECP256K1_A, Secp256k1.SECP256K1_B, Secp256k1.SECP256K1_G, Secp256k1.SECP256K1_R);
point1 = new jcmathlib.ECPoint(curve, ecc.ech);
point1.setW(Secp256k1.SECP256K1_G, (short)0, (short) Secp256k1.SECP256K1_G.length);
point1.multiplication(privateKey, privateKeyOffset, (short)32);
point1.getX(publicPoint, publicPointOffset);
point1.getY(publicPoint, (short)(publicPointOffset + curve.COORD_SIZE));
// Add 0x04 to the start of the public key
Util.arrayFillNonAtomic(publicPoint, publicPointOffset, (short)1, (byte)0x04);
I am getting: java.lang.ArrayIndexOutOfBoundsException, seems to happen on ech.fnc_multiplication_y1.sqrt_FP(this.theCurve.pBN);
inside multiplication method...
Hi, I'm traveling right now, but will take a look on this next week - I hope it is not too late for you. Thank you for the key causing the crash - shall be easy to debug with it.
You may try to call ECConfig.setECC384Config() as quick test - this call will increase the size of internal arrays to accomodate larger 384b curves - if this will help, we are somewhere optimizing too much wrt internal buffers for intermediate values.
Thanks for the attention petrs! I will wait for you help next week. Im working on a bitcoin wallet for my graduation final paper. Im waiting to receive a new NPX card, with support to ALG_ECDSA_SHA_256 (to sign) and ALG_EC_SVDP_DH_PLAIN_XY (to generate the public key based on the private key). For now i am using the https://github.com/licel/jcardsim and started to test your lib, but need some help navigating it.
jcardsim is fine, I'm also testing with it and jcmathlib code conatins some checking to detect and behave slightly differently whem executed by simulator (as simulator differs from real card in some cases)
Can you also post the whole code how you are using privateKey and publicPoint so I can fully replicate?
Hi Ricardo, have you managed to solve this issue?
I ended using another approach generating part of what I needed outside the card. Not so secure but enough to finish my paper. You can close this now, thanks for the help.
Hi!
I have this code that gets a private key generated on the Secp256k1 curve and returns a 65 byte public key. Can you help me convert it to use JCMathLib? Thanks!