Christmas is coming soon! To thank for the support from all our dear customers, Christmas promotional activity is going on in JavaCardOS online store. For more activities details, please check this post.

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.

ThePhoenyx
Posts: 44
Joined: Mon Jul 20, 2015 1:08 pm
Points :400
Contact:

Re: Problem with ECC

Post by ThePhoenyx » Mon Oct 15, 2018 3:13 pm

Could you possibly detail how you solved it for those of us trying to do the same?
The world is full of stories;
And sometimes they permit themselves to be told.
~Cherokee Proverb

hosseinpro
Posts: 13
Joined: Wed Jun 28, 2017 6:35 pm
Points :174
Contact:

Re: Problem with ECC

Post by hosseinpro » Tue Nov 13, 2018 4:32 pm

How do you solve the problem?

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 1 guest

JavaCard OS : Disclaimer