1
1
The standard Bitcoin message signature works as follows:
sign(sha256(magicPrefix . length(message) . message))
The "magic prefix" is simply the string '\x18Bitcoin Signed Message:\n', where 0x18 is the length of the prefix text.
In other words, it's this:
sign(sha256(length(prefix) . prefix . length(message) . message))
My question is:
- Why does it use a magic prefix?
- Why does it include the lengths of the two components?
I'm asking mainly from a security point of view. Does adding a prefix or including the length(s) have any security benefits? If not, I'd like to drop it from my signatures.
Is this from the C++ code? Because I saw similar code in pybitcointools'
electrum_sig_hashfunction – Wizard Of Ozzie – 2015-04-09T01:50:44.607It's also in BitcoinJS: https://github.com/bitcoinjs/bitcoinjs-lib/blob/1079bf95c1095f7fb018f6e4757277d83b7b9d07/src/message.js#L13
– Manish – 2015-04-09T02:02:43.6671
The duplicate doesn't address the inclusion of the lengths. The answer is that it's to definitively protect against length extension attacks.
– David Schwartz – 2015-04-09T08:37:15.910