I am trying to generate an ECDSA signature using ARM's CryptoCell 310 (hardware cryptography module) and verify the signature using mbedTLS software library.

The harware module documentation says that the ECDSA is performed according to ANS X9.62 standard.

The cryptocell generated signature for SECP256R1 is 64 bytes long and looks like this:


I need to convert it into DER encoded signature so that mbedTLS can verify it, but I don't know how the R and S parameters are encoded in it. I have tried to take first half of that string as the R parameter, second half as S and encode it to DER like this:


Unfortunately it didn't work. I have also tried to do big/little endian swaps, trying the second half as R and first as S, but it still didn't work.

I have tried to obtain the X9.62 standard, but couldn't find anything about the encoding.

Does anyone know what encoding is that?

Thanks in advance.


ANS X9.62–2005 states in appendix E.8:

When a digital signature is represented with ASN.1, the digital signature shall be ASN.1 encoded using the following syntax:

ECDSA-Sig-Value ::= SEQUENCE {
    r INTEGER,

I found no issue with the DER encoding in the question.

Implementing this is a pain in the neck if there's no library for it (from a painful experience: a common language runtime once accepted invalid encoding with more zero bits in the high order bits of $r$ and $s$ than allowed by ASN.1, then became more strict, breaking invalid but working code calling it).

Update: the standard also states:

X.509 certificates and CRLs and CMS SignedData represent signatures as a bit string. Where a certificate, CRL or SignedData is signed with ECDSA, the entire encoding of a value of ASN.1 type ECDSA-Sig-Value shall be the value of the bit string.

But AFAIK this is only for certificates.

Now this looks like a purely programming issue, largely off-topic. Best option seems to be: dig documentation or test case for mbedTLS.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.