title: Is it possibile to know the size of EC signature in advance or, alternatively, set the EC signature size in OperSSL?
body: <p>I'm struggled with OpenSSL ECDSA. The problem is the following. I have this format as a packet (that is generated by my Server application upon receiving some inputs, but it is not important):<a href="https://i.stack.imgur.com/pv9R8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pv9R8.png" alt="packet" /></a></p>
  <p>Now, the signature is performed on <code>TOTAL LENGTH</code> (8 bytes for the length field + variable size for the encrypted stuff + 512 for the signature) and <code>ENCRYPTED STUFF</code>. To do this, with RSA signature, I used the <code>EVP_PKEY_size()</code> API to get in advance the size of the signature (not that it was strictly necessary knowing the modulus of RSA keys, but the point is that I had means to know it). Unfortunately, switching to ECDSA, the signature size is no longer deterministic, and therefore I cannot write it on the length field before signing the message. To avoid uncertainties I specify that the signature process takes into account the 8 bytes of the length and the encrypted stuff. The <code>EVP_PKEY_size()</code> this time returns the maximum bytes needed by the signature. So my question is: is it possible to know in advance the precise size of the signature without computing it (probably not as not being deterministic), or, alternatively, set a sort of padding to the signature in order to compensate the bytes up to the return value of <code>EVP_PKEY_size()</code>? A working solution would be, of course, to exclude the length field by the signature but I'm trying no to do this..</p>