BIP: 137 Layer: Applications Title: Signatures of Messages using Private Keys Author: Christopher Gilliard <[email protected]> Comments-Summary: No comments yet. Comments-URI: TBD Status: Proposal Type: Informational Created: 2019-02-16 License: BSD-2-Clause
- Abstract #
The specification is intended to describe the standard for signatures of messages that can be signed and verfied between different clients that exist in the field today. Note: that a new signature format has been defined which has a number of advantages over this BIP, but to be backwards compatible with existing implementations this BIP will be useful. See BIP 322 [1] for full details on the new signature scheme.
One of the key problems in this area is that there are several different types of Bitcoin addresses and without introducing specific standards it is unclear which type of address format is being used. See [2]. This BIP will attempt to address these issues and define a clear and concise format for Bitcoin signatures.
- Copyright #
- Motivation #
- Specification #
- Background on ECDSA Signatures ##
A few concepts related to ECDSA:
private key: A secret number, known only to the person that generated it. A private key is essentially a randomly generated number. In Bitcoin, someone with the private key that corresponds to funds on the block chain can spend the funds. In Bitcoin, a private key is a single unsigned 256 bit integer (32 bytes).
public key: A number that corresponds to a private key, but does not need to be kept secret. A public key can be calculated from a private key, but not vice versa. A public key can be used to determine if a signature is genuine (in other words, produced with the proper key) without requiring the private key to be divulged. In Bitcoin, public keys are either compressed or uncompressed. Compressed public keys are 33 bytes, consisting of a prefix either 0x02 or 0x03, and a 256-bit integer called x. The older uncompressed keys are 65 bytes, consisting of constant prefix (0x04), followed by two 256-bit integers called x and y (2 * 32 bytes). The prefix of a compressed key allows for the y value to be derived from the x value.
signature: A number that proves that a signing operation took place. A signature is mathematically generated from a hash of something to be signed, plus a private key. The signature itself is two numbers known as r and s. With the public key, a mathematical algorithm can be used on the signature to determine that it was originally produced from the hash and the private key, without needing to know the private key. Signatures are either 73, 72, or 71 bytes long, with probabilities approximately 25%, 50% and 25% respectively, although sizes even smaller than that are possible with exponentially decreasing probability. Source [3].
- Conventions with signatures used in Bitcoin ##
[1][32][32]
The header byte has a few components to it. First, it stores something known as the recId. This value is stored in the least significant 2 bits of the header. If the header is between a value of 31 and 34, this indicates that it is a compressed address. If the header value is between 35 and 38 inclusive, it is a p2sh segwit address. If the header value is between 39 and 42, it is a bech32 address.
- Procedure for signing/verifying a signature ##
To verify a signature, the recId is obtained by subtracting this constant from the header value.
- Sample Code for processing a signature ##
```Java
// this section is added to support new signature types if(header>= 39) // this is a bech32 signature { header -= 12; compressed = true; } // this is a segwit p2sh signature else if(header >= 35) { header -= 8; compressed = true; } // this is a compressed key signature else if (header >= 31) { compressed = true; header -= 4; }
int recId = header - 27;
ECKey key = ECKey.recoverFromSignature(recId, sig, messageHash, compressed); if (key == null) throw new SignatureException("Could not recover public key from signature"); return key; }
```
- Backwards Compatibility #
- Implications #
- Acknowledgements #
- Konstantin Bay - review
- Holly Casaletto - review
- James Bryrer - review
- References #
[2] - bitcoin/bitcoin#10542
[3] - https://en.bitcoin.it/wiki/Elliptic_Curve_Digital_Signature_Algorithm