2
I would like to understand how to get Bitcoin ECDSA signature in a compact format, when it's exactly 65 bytes.
In the bitcoin-core repository, secp256k1_ecdsa_recoverable_signature_load is responsible for this. As far as I understand, in it r and s are separately reduced to a 32 byte representation using secp256k1_scalar_set_b32, but I don't understand how it function works. What is a EXHAUSTIVE_TEST_ORDER? Why does the resulting representation of 32b scalar remain valid after it? I would be very grateful if someone could explain it to me.
In fact, I want to get a compact format of signature using the OpenSSL library. it has ECDSA_do_sign function which returns a structure consisting of two pointers to BIGNUM. Could you please tell me how to convert this internal representation from the OpenSSL into a standard one? I cannot find in the interface a function similar to the function from bitcoin-core.
– Oroffe – 2018-12-25T08:25:03.130Of course you won't be able to find how to do that in Bitcoin Core because Bitcoin Core does not use OpenSSL for signature operations anymore. The ways that libsecp and openssl represent things internally are different from each other. You can use
– Andrew Chow – 2018-12-25T16:22:51.343ECDSA_SIG_get0to get theBIGNUMs for r and s, then useBN_bn2binpadto get theBIGNUMs serialized as 32 byte big-endian integers. Then just concatenate the two byte strings to get the compact signature.