In order to thank you for all members' support of our website, we are holding new events - Getting Free Samples by Paying Freight only.
Want to get free samples? Please check this post for more details.

Problem with ECC

Algorithm School

Moderator: UNKNwYSHSA

listade
Posts: 5
Joined: Wed Sep 12, 2018 4:46 am
Points :40
Contact:

Problem with ECC

Post by listade » Wed Sep 12, 2018 4:56 am

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!

listade
Posts: 5
Joined: Wed Sep 12, 2018 4:46 am
Points :40
Contact:

Re: Problem with ECC

Post by listade » Thu Sep 13, 2018 3:24 am

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?

listade
Posts: 5
Joined: Wed Sep 12, 2018 4:46 am
Points :40
Contact:

Re: Problem with ECC

Post by listade » Fri Sep 14, 2018 3:03 am

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?

listade
Posts: 5
Joined: Wed Sep 12, 2018 4:46 am
Points :40
Contact:

Re: Problem with ECC

Post by listade » Fri Sep 14, 2018 7:01 am

All right, I solved problem.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

JavaCard OS : Disclaimer