MicrochipTech / cryptoauthlib

Library for interacting with the Crypto Authentication secure elements
Other
374 stars 218 forks source link

Unable to verify the ECDSA signature/message from chip #216

Closed N9SHazpnhYW closed 3 years ago

N9SHazpnhYW commented 3 years ago

I am using Javascript to try to verify the output of the ATECCx08 chip. The information I am attempting to verify is as follows:

uint8_t message[32] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
};

uint8_t signature[64] = {
0xD6, 0x82, 0x25, 0xCC, 0x68, 0x6F, 0x4F, 0x84, 0x91, 0x48, 0x63, 0x6E, 0x67, 0x3C, 0xD4, 0xC0, 0xF8,
0xE5, 0x9D, 0x7B, 0xAD, 0x6B, 0xB3, 0xF1, 0x1C, 0xDB, 0x90, 0xB7, 0x1A, 0x5E, 0x43, 0xCF, 0xD8, 0xC3,
0x8C, 0x77, 0x74, 0xE2, 0xA0, 0x29, 0xFF, 0x43, 0x22, 0x7D, 0xF9, 0x41, 0x56, 0x12, 0x8A, 0x1B, 0xEA, 
0x4D, 0x57, 0x8A, 0x37, 0x9C, 0x6A, 0x85, 0x0A, 0x56, 0xBE, 0xEC, 0x1A, 0x69
};

uint8_t publicKey[64] = {
0x39,0xC3,0xDD,0x74,0x13,0x17,0x29,0x44,0x6D,0xC1,0xB3,0xDA,0x67,0xD4,0x9F,0xC0,
0x46,0xFC,0xBF,0x07,0x2F,0xCC,0x5B,0x9F,0xA5,0x1C,0x05,0xB9,0x74,0x30,0x7F,0x96,
0x9C,0x40,0x3B,0x16,0x35,0xF0,0x44,0x9F,0x02,0xBD,0x42,0x27,0x51,0xE3,0x31,0x21,
0xA4,0x43,0x4F,0x15,0x2F,0x2B,0x2B,0x2A,0x3F,0x67,0x52,0x19,0xC5,0xD9,0x25,0xF6,
};

I need to pad the publicKey with 0x04 in the front in order to successfully import the key into the WebCrypto javascript API. However, when I try to verify the message, and the signature from the message, it always fails.

Is there any other special formatting that I need to be aware of, like there was for the publicKey? The same code can verify an ECDSA message/signature/public key that was generated outside of the ATECC chip (also using P-256).

At the moment I am completely stuck and would be extremely grateful for any help...thanks in advance

N9SHazpnhYW commented 3 years ago

I would like to leave the answer to this question here which was solved on stack exchange. It doesnt have anything to do with the Microchip cryptoauthlib library, so I will close this comment....For reference, here is the answer: https://stackoverflow.com/questions/67135136/unable-to-verify-a-raw-uint8array-ecdsa-secp256r1-message-signature-pubkey-usi