Page 1 of 1

Problem with ECC

Posted: Wed Sep 12, 2018 4:56 am
by listade
Hi, guys. I have written some code for signing messages by ECDSA algorithm. But JavaCard returns me every time different values with different sizes.

For example:

Code: Select all

30450221008443B0B08EACBF7B4F718AF441154CE79391AC2206715A13950DBDF65E2004A2022041C8086F556D4BD4F5B0B87412A3982F75C12447901886BE01F0EBC44C937B2E
I need to get { s, r } values, but getting this. How to parse it? (Sorry for my English)

My code

Code: Select all

private void processSign(APDU apdu) {

        byte[] apduBuffer = apdu.getBuffer();
        apdu.setIncomingAndReceive();

        try {
            privateKey.setS(privateKeyDigest, (short) 0, PRIVATE_KEY_LENGTH);
            signature.init(privateKey, Signature.MODE_SIGN);

            byte[] tempBuffer = JCSystem.makeTransientByteArray(SIGN_BUFFER_LENGTH, JCSystem.CLEAR_ON_DESELECT);

            short len = signature.sign(hashDigest, (short) 0, HASH_LENGTH, tempBuffer, SIGN_BUFFER_OFFSET);
                        
            Util.arrayCopyNonAtomic(tempBuffer, (short) 0, apduBuffer, (short) 0, len);
            apdu.setOutgoingAndSend((short) 0, len);

        } catch (CryptoException e) {
            ISOException.throwIt(e.getReason());
        } catch (SystemException e) {
            ISOException.throwIt(e.getReason());
        }
    }

Thanks, for help!

Re: Problem with ECC

Posted: Thu Sep 13, 2018 3:24 am
by listade
OK, I understood, its TLV format. But I still have question about public key. JavaCard returns me "wrong data" for any tries setW() to ECDSA publicKey object. How to do this? What`s the format?

Re: Problem with ECC

Posted: Fri Sep 14, 2018 3:03 am
by listade
Okey, I coped with setW, the first byte must be 0x04.


But, JavaCard signature doesn't valid for https://www.javacardos.com/tools/ecdsa_sign_verify.html
Why?

Re: Problem with ECC

Posted: Fri Sep 14, 2018 7:01 am
by listade
All right, I solved problem.

Re: Problem with ECC

Posted: Mon Oct 15, 2018 3:13 pm
by ThePhoenyx
Could you possibly detail how you solved it for those of us trying to do the same?

Re: Problem with ECC

Posted: Tue Nov 13, 2018 4:32 pm
by hosseinpro
How do you solve the problem?