cose-wg / COSE-C

Implementation of COSE in C++; Provides a C interface; Crypto by openssl or mbedtls
BSD 3-Clause "New" or "Revised" License
30 stars 22 forks source link

COSE_ERR_INVALID_PARAMETER on COSE_Sign_Sign with non padded keys #118

Closed bdel80 closed 4 years ago

bdel80 commented 4 years ago

When generating EC2 keys with mbedTLS, you sometime have points that are not always the same size.

My understanding is that this is because of the compressed point format used, when the number it represents starts with zeros, they are not serialized.

This make the 2 checks in mbedtls.c at line 715 and 723 fail for no good reason: CHECK_CONDITION(p->length == cbGroup, COSE_ERR_INVALID_PARAMETER);

I reread the COSE RFC spec, and couldnt find anything about requirind the EC points to be of fixed size.

By changing the checks to: CHECK_CONDITION(p->length <= cbGroup, COSE_ERR_INVALID_PARAMETER); The errors go away. And its produces valid signatures.

Here is a sample of such key in cbor notation format:

{1: 2, -1: 1, -2: h'2C8D30E5F7530680F0414255AF7693119C786BFB3B51DFA0593CE36C8E19C87A', -3: h'0A724DC7AE3606697BBF66678B7E7205450A0EFAC3936643850383A66D4FAD', -4: h'DD81BD437805B6A4957D35DD530D8227B7DC6F16C81AE878D1A479BFB1439B9E', 2: "11"}

jimsch commented 4 years ago

Section 13.1.1

x: This contains the x-coordinate for the EC point. The integer is converted to an octet string as defined in [SEC1]. Leading zero octets MUST be preserved.

bdel80 commented 4 years ago

You have better eyes than me. Thanks !

jimsch commented 4 years ago

I wrote the spec, I hope I have better eyes.