I am using "secp192k1" curve to generate the key for data signing using ECDSA scheme. Signature is generated using "SHA3-256withECDSA" algorithm provided by BouncyCastle.

Theoretically, the length of the signature should be 192*2/8 = 48 bytes. Instead, this length varies from 54 to 56.

My application demands a signature of fixed length. How can I achieve this?


1 Answer 1


To encode the signature you first have to parse the ASN.1 structure also shown in the linked answers provided by dave_thomson_085. Once you have got two integer in the programming language / runtime of your choice then you need to encode them as two statically sized integer encodings. These integers (usually) need to be big endian / network order, unsigned integers.

To do this you need to implement a function called I2OSP from the RSA specifications. You feed this the two numbers and the key size (the size of the order of the curve) rounded upwards to bytes (that's $192 / 8 = 24$ bytes).

There are two ways to do this:

  • directly implement the mathematical functions and concatenate the resulting bytes or
  • encode the integer back to bytes - most platforms have a function for this - and then adjust the encoding by padding and possibly reversing the encoding

The latter is probably faster as it just requires byte operations. I usually opt for the latter, but I've seen many cryptographers (naively, in my opinion) do the first.

Finally you simply concatenate the numbers and presto - you're done (there is also OS2IP in RSA, in case you need to do the reverse).

  • $\begingroup$ Thanks for the answer. What does presto stands for, btw? $\endgroup$ Mar 24, 2017 at 19:17
  • 1
    $\begingroup$ It's italian for in short time, but it's commonly used for almost immediately as far as I know. My parents used it a lot, but as they are not linguists, it may be that they used it incorrectly :) $\endgroup$
    – Maarten Bodewes
    Mar 24, 2017 at 23:19
  • 1
    $\begingroup$ FWIW in the US (at least?) 'presto!' or 'hey presto!' was traditionally and widely used by stage magicians to emphasize the result of a trick. (Back when people actually went somewhere to be entertained instead of vegetating on the couch in front of the 12-foot super-super-high-def TV screen.) en.wiktionary.org/wiki/presto $\endgroup$ Apr 14, 2018 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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